Skip to content

Commit

Permalink
test: Add user dropdown toggle test
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin-codecov committed Jan 8, 2025
1 parent 08f6fb6 commit 3a50f0c
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/layouts/Header/components/UserDropdown/UserDropdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { type Mock } from 'vitest'

import config from 'config'

import { OnboardingContainerProvider } from 'pages/OwnerPage/OnboardingContainerContext/context'
import {
OnboardingContainerProvider,
useOnboardingContainer,
} from 'pages/OwnerPage/OnboardingContainerContext/context'
import { LOCAL_STORAGE_SHOW_ONBOARDING_CONTAINER } from 'pages/OwnerPage/OnboardingOrg/constants'
import { useImage } from 'services/image'
import { Plans } from 'shared/utils/billing'

Expand Down Expand Up @@ -289,4 +293,38 @@ describe('UserDropdown', () => {
})
})
})
describe('toggle onboarding container', () => {
beforeEach(() => {
vi.clearAllMocks()
localStorage.clear()
})

it('toggles onboarding container visibility and updates localStorage', async () => {
const setShowOnboardingContainer = vi.fn()
const mockUseOnboardingContainer = useOnboardingContainer as Mock
mockUseOnboardingContainer.mockReturnValue({

Check failure on line 305 in src/layouts/Header/components/UserDropdown/UserDropdown.test.tsx

View workflow job for this annotation

GitHub Actions / Test Runner #0 - Vitest

src/layouts/Header/components/UserDropdown/UserDropdown.test.tsx > UserDropdown > toggle onboarding container > toggles onboarding container visibility and updates localStorage

TypeError: mockUseOnboardingContainer.mockReturnValue is not a function ❯ src/layouts/Header/components/UserDropdown/UserDropdown.test.tsx:305:34
showOnboardingContainer: false,
setShowOnboardingContainer,
})

const { user } = setup()
render(<UserDropdown />)

// Open dropdown
const trigger = screen.getByTestId('user-dropdown-trigger')
await user.click(trigger)

const toggleButton = screen.getByText('Show getting started')
await user.click(toggleButton)

expect(setShowOnboardingContainer).toHaveBeenCalledWith(true)

// Verify localStorage was updated
await waitFor(() => {
expect(
localStorage.getItem(LOCAL_STORAGE_SHOW_ONBOARDING_CONTAINER)
).toBe('true')
})
})
})
})

0 comments on commit 3a50f0c

Please sign in to comment.