Skip to content

Commit

Permalink
Remove mocked handleJoyrideCallback testing
Browse files Browse the repository at this point in the history
  • Loading branch information
FestiveKyle committed Oct 16, 2024
1 parent fb8ac10 commit 7a19d53
Showing 1 changed file with 2 additions and 44 deletions.
46 changes: 2 additions & 44 deletions frontend/src/userOnboarding/__tests__/TourComponent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MemoryRouter } from 'react-router-dom'
import { TourProvider } from '../contexts/TourContext'
import { setupI18n } from '@lingui/core'
import { en } from 'make-plural'
import { fireEvent, screen } from '@testing-library/dom'
import { fireEvent } from '@testing-library/dom'

const i18n = setupI18n({
locale: 'en',
Expand Down Expand Up @@ -70,26 +70,22 @@ describe('TourComponent', () => {
)

// Element will exist but not be visible
expect(getByText(/Landing Step 1/)).not.toBeNull()
expect(queryByText(/Landing Step 1/)).not.toBeNull()

await waitFor(() => {
expect(getByText(/Landing Step 1/)).toBeVisible()
})

let nextBtn = getByRole('button', { name: /Next/ })

expect(nextBtn).toBeInTheDocument()

fireEvent.click(nextBtn)

await waitFor(() => {
expect(getByText(/Landing Step 2/)).toBeVisible()
})

nextBtn = getByRole('button', { name: /Finish/ })

expect(nextBtn).toBeInTheDocument()

fireEvent.click(nextBtn)

await waitFor(() => {
Expand Down Expand Up @@ -127,41 +123,3 @@ describe('TourComponent', () => {
expect(queryByText(/Landing Step 1/)).toBeNull()
})
})

describe('handleJoyrideCallback', () => {
const endTourMock = jest.fn()
const originalSetItem = localStorage.setItem

function createHandleJoyrideCallbackFunction() {
return function handleJoyrideCallback({ status }) {
if (status === 'finished' || status === 'skipped') {
localStorage.setItem(`hasSeenTour_home`, 'true')
endTourMock()
}
}
}

beforeEach(() => {
localStorage.setItem = jest.fn()
endTourMock.mockClear()
useTour.mockReturnValue({
isTourOpen: false,
startTour: jest.fn(),
endTour: jest.fn(),
})
})

afterEach(() => {
localStorage.setItem = originalSetItem
})

it.each(['finished', 'skipped'])('sets localStorage and ends tour when status is %s', (status) => {
const page = 'home'
const handleJoyrideCallback = createHandleJoyrideCallbackFunction({ endTour: jest.fn(), page })

handleJoyrideCallback({ status, type: 'any', action: 'any' })

expect(localStorage.setItem).toHaveBeenCalledWith(`hasSeenTour_${page}`, 'true')
expect(endTourMock).toHaveBeenCalled()
})
})

0 comments on commit 7a19d53

Please sign in to comment.