From 35d698765a6b5111e600bb85a344cfe1a0587722 Mon Sep 17 00:00:00 2001 From: Wes Copeland Date: Sat, 28 Sep 2024 07:58:56 -0400 Subject: [PATCH] test: add coverage --- .../PreferencesSectionCard.test.tsx | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/resources/js/features/settings/components/PreferencesSectionCard/PreferencesSectionCard.test.tsx b/resources/js/features/settings/components/PreferencesSectionCard/PreferencesSectionCard.test.tsx index c56f82469..fbbf0cd49 100644 --- a/resources/js/features/settings/components/PreferencesSectionCard/PreferencesSectionCard.test.tsx +++ b/resources/js/features/settings/components/PreferencesSectionCard/PreferencesSectionCard.test.tsx @@ -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( @@ -35,7 +42,6 @@ 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 @@ -43,4 +49,34 @@ describe('Component: PreferencesSectionCard', () => { 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(); + + // 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(); + + // 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, + }); + }); });