Skip to content

Commit

Permalink
test: add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
wescopeland committed Sep 28, 2024
1 parent 654a84f commit 35d6987
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import { render, screen } from '@/test';
import { PreferencesSectionCard } from './PreferencesSectionCard';

describe('Component: PreferencesSectionCard', () => {
// TODO remove when multiset isnt behind a feature flag
const originalMultisetFlag = import.meta.env.VITE_FEATURE_MULTISET;

beforeEach(() => {
import.meta.env.VITE_FEATURE_MULTISET = originalMultisetFlag;
});

it('renders without crashing', () => {
// ARRANGE
const { container } = render(
Expand Down Expand Up @@ -35,12 +42,41 @@ describe('Component: PreferencesSectionCard', () => {

// ACT
await userEvent.click(screen.getByRole('switch', { name: /only people i follow/i }));

await userEvent.click(screen.getByRole('button', { name: /update/i }));

// ASSERT
expect(putSpy).toHaveBeenCalledWith(route('api.settings.preferences.update'), {
websitePrefs: 8399,
});
});

it('given the user does not have the game subsets opt out setting enabled, shows the toggle as checked', () => {
// ARRANGE
import.meta.env.VITE_FEATURE_MULTISET = 'true';

render(<PreferencesSectionCard currentWebsitePrefs={127} onUpdateWebsitePrefs={vi.fn()} />);

// ASSERT
const switchEl = screen.getByRole('switch', { name: /automatically opt in/i });

expect(switchEl).toBeChecked();
});

it('allows the user to change their game subsets opt out preference', async () => {
// ARRANGE
import.meta.env.VITE_FEATURE_MULTISET = 'true';

const putSpy = vi.spyOn(axios, 'put').mockResolvedValueOnce({ success: true });

render(<PreferencesSectionCard currentWebsitePrefs={127} onUpdateWebsitePrefs={vi.fn()} />);

// ACT
await userEvent.click(screen.getByRole('switch', { name: /automatically opt in/i }));
await userEvent.click(screen.getByRole('button', { name: /update/i }));

// ASSERT
expect(putSpy).toHaveBeenCalledWith(route('api.settings.preferences.update'), {
websitePrefs: 262271,
});
});
});

0 comments on commit 35d6987

Please sign in to comment.