Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
394 changes: 191 additions & 203 deletions __tests__/app/layout.test.tsx

Large diffs are not rendered by default.

637 changes: 302 additions & 335 deletions __tests__/app/onboarding.test.tsx

Large diffs are not rendered by default.

16 changes: 5 additions & 11 deletions __tests__/components/settings/SettingsContent.analytics.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ describe('SettingsContent Analytics Tracking', () => {
);

const analyticsDebugToggle = screen.getByTestId('toggle-analytics-debug');

// First toggle enables it
fireEvent.press(analyticsDebugToggle);
jest.clearAllMocks();
Expand All @@ -412,7 +412,7 @@ describe('SettingsContent Analytics Tracking', () => {
});

describe('Analytics Not Fired for Non-Preference Changes', () => {
it('does not track analytics for What\'s New button press', () => {
it("does not track analytics for What's New button press", () => {
render(
<SettingsContent
profile={mockProfile}
Expand All @@ -428,10 +428,7 @@ describe('SettingsContent Analytics Tracking', () => {
fireEvent.press(whatsNewButton);

// Should only show toast, not track event
expect(mockTrackEvent).not.toHaveBeenCalledWith(
'Settings Changed',
expect.any(Object)
);
expect(mockTrackEvent).not.toHaveBeenCalledWith('Settings Changed', expect.any(Object));
});

it('does not track analytics for sign out button press', () => {
Expand All @@ -449,10 +446,7 @@ describe('SettingsContent Analytics Tracking', () => {
const signOutButton = screen.getByText('Sign Out');
fireEvent.press(signOutButton);

expect(mockTrackEvent).not.toHaveBeenCalledWith(
'Settings Changed',
expect.any(Object)
);
expect(mockTrackEvent).not.toHaveBeenCalledWith('Settings Changed', expect.any(Object));
});
});
});
});
238 changes: 119 additions & 119 deletions __tests__/components/sheets/EditSavingsSheet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -596,156 +596,156 @@ describe('EditSavingsSheet', () => {
});
});

describe('Analytics Tracking', () => {
beforeEach(() => {
jest.clearAllMocks();
});
describe('Analytics Tracking', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('tracks SAVINGS_UPDATED event when savings are saved', async () => {
const { trackEvent } = require('@/lib/analytics');

const sheetRef = { current: null };
renderWithProviders(
<EditSavingsSheet ref={sheetRef} profile={mockProfile} onSave={mockOnSave} />
);
it('tracks SAVINGS_UPDATED event when savings are saved', async () => {
const { trackEvent } = require('@/lib/analytics');

// Present the sheet
act(() => {
sheetRef.current?.present();
});
const sheetRef = { current: null };
renderWithProviders(
<EditSavingsSheet ref={sheetRef} profile={mockProfile} onSave={mockOnSave} />
);

// Update amount
const amountInput = screen.getByTestId('savings-amount-input');
fireEvent.changeText(amountInput, '75');
// Present the sheet
act(() => {
sheetRef.current?.present();
});

// Change frequency
const monthlyButton = screen.getByTestId('frequency-monthly');
fireEvent.press(monthlyButton);
// Update amount
const amountInput = screen.getByTestId('savings-amount-input');
fireEvent.changeText(amountInput, '75');

jest.clearAllMocks();
// Change frequency
const monthlyButton = screen.getByTestId('frequency-monthly');
fireEvent.press(monthlyButton);

// Save
const saveButton = screen.getByTestId('save-savings-button');
fireEvent.press(saveButton);
jest.clearAllMocks();

await waitFor(() => {
expect(trackEvent).toHaveBeenCalledWith(
'Savings Updated',
expect.objectContaining({
amount: 75,
frequency: 'monthly',
is_setup: false,
})
);
});
// Save
const saveButton = screen.getByTestId('save-savings-button');
fireEvent.press(saveButton);

await waitFor(() => {
expect(trackEvent).toHaveBeenCalledWith(
'Savings Updated',
expect.objectContaining({
amount: 75,
frequency: 'monthly',
is_setup: false,
})
);
});
});

it('tracks SAVINGS_UPDATED with is_setup=true in setup mode', async () => {
const { trackEvent } = require('@/lib/analytics');

const profileWithoutSavings = {
...mockProfile,
spend_amount: null,
spend_frequency: null,
};
it('tracks SAVINGS_UPDATED with is_setup=true in setup mode', async () => {
const { trackEvent } = require('@/lib/analytics');

const sheetRef = { current: null };
renderWithProviders(
<EditSavingsSheet ref={sheetRef} profile={profileWithoutSavings} onSave={mockOnSave} />
);
const profileWithoutSavings = {
...mockProfile,
spend_amount: null,
spend_frequency: null,
};

act(() => {
sheetRef.current?.present();
});
const sheetRef = { current: null };
renderWithProviders(
<EditSavingsSheet ref={sheetRef} profile={profileWithoutSavings} onSave={mockOnSave} />
);

const amountInput = screen.getByTestId('savings-amount-input');
fireEvent.changeText(amountInput, '100');
act(() => {
sheetRef.current?.present();
});

jest.clearAllMocks();
const amountInput = screen.getByTestId('savings-amount-input');
fireEvent.changeText(amountInput, '100');

const saveButton = screen.getByText('Get Started');
fireEvent.press(saveButton);
jest.clearAllMocks();

await waitFor(() => {
expect(trackEvent).toHaveBeenCalledWith(
'Savings Updated',
expect.objectContaining({
amount: 100,
frequency: 'weekly',
is_setup: true,
})
);
});
const saveButton = screen.getByText('Get Started');
fireEvent.press(saveButton);

await waitFor(() => {
expect(trackEvent).toHaveBeenCalledWith(
'Savings Updated',
expect.objectContaining({
amount: 100,
frequency: 'weekly',
is_setup: true,
})
);
});
});

it('tracks SAVINGS_UPDATED with amount=0 when clearing data', async () => {
const { trackEvent } = require('@/lib/analytics');

const sheetRef = { current: null };
renderWithProviders(
<EditSavingsSheet ref={sheetRef} profile={mockProfile} onSave={mockOnSave} />
);
it('tracks SAVINGS_UPDATED with amount=0 when clearing data', async () => {
const { trackEvent } = require('@/lib/analytics');

act(() => {
sheetRef.current?.present();
});
const sheetRef = { current: null };
renderWithProviders(
<EditSavingsSheet ref={sheetRef} profile={mockProfile} onSave={mockOnSave} />
);

jest.clearAllMocks();
act(() => {
sheetRef.current?.present();
});

// Press clear button
const clearButton = screen.getByTestId('clear-savings-button');
fireEvent.press(clearButton);
jest.clearAllMocks();

// Confirm
await waitFor(() => {
expect(mockConfirm).toHaveBeenCalled();
});
// Press clear button
const clearButton = screen.getByTestId('clear-savings-button');
fireEvent.press(clearButton);

mockConfirm.mockResolvedValueOnce(true);
fireEvent.press(clearButton);
// Confirm
await waitFor(() => {
expect(mockConfirm).toHaveBeenCalled();
});

await waitFor(() => {
expect(trackEvent).toHaveBeenCalledWith(
'Savings Updated',
expect.objectContaining({
amount: 0,
frequency: null,
is_setup: false,
})
);
});
mockConfirm.mockResolvedValueOnce(true);
fireEvent.press(clearButton);

await waitFor(() => {
expect(trackEvent).toHaveBeenCalledWith(
'Savings Updated',
expect.objectContaining({
amount: 0,
frequency: null,
is_setup: false,
})
);
});
});

it('does not track analytics when save fails', async () => {
const { trackEvent } = require('@/lib/analytics');

it('does not track analytics when save fails', async () => {
const { trackEvent } = require('@/lib/analytics');

mockSupabase.from.mockReturnValue({
update: jest.fn().mockReturnValue({
eq: jest.fn().mockResolvedValue({
error: new Error('Update failed'),
}),
mockSupabase.from.mockReturnValue({
update: jest.fn().mockReturnValue({
eq: jest.fn().mockResolvedValue({
error: new Error('Update failed'),
}),
});
}),
});

const sheetRef = { current: null };
renderWithProviders(
<EditSavingsSheet ref={sheetRef} profile={mockProfile} onSave={mockOnSave} />
);
const sheetRef = { current: null };
renderWithProviders(
<EditSavingsSheet ref={sheetRef} profile={mockProfile} onSave={mockOnSave} />
);

act(() => {
sheetRef.current?.present();
});
act(() => {
sheetRef.current?.present();
});

const amountInput = screen.getByTestId('savings-amount-input');
fireEvent.changeText(amountInput, '75');
const amountInput = screen.getByTestId('savings-amount-input');
fireEvent.changeText(amountInput, '75');

jest.clearAllMocks();
jest.clearAllMocks();

const saveButton = screen.getByTestId('save-savings-button');
fireEvent.press(saveButton);
const saveButton = screen.getByTestId('save-savings-button');
fireEvent.press(saveButton);

await waitFor(() => {
expect(trackEvent).not.toHaveBeenCalled();
});
await waitFor(() => {
expect(trackEvent).not.toHaveBeenCalled();
});
});
});
Loading
Loading