overleaf/services/web/test/frontend/features/settings/components/leavers-survey-alert.test.tsx
Timothée Alby 3580ec6db3 Merge pull request #8029 from overleaf/ta-settings-fix-7
[SettingsPage] Small Fixes 7

GitOrigin-RevId: 2716fe13af3f5f6b56d6bba47505fad75ba1adbf
2022-05-24 08:04:47 +00:00

55 lines
2.2 KiB
TypeScript

import { expect } from 'chai'
import { fireEvent, screen, render } from '@testing-library/react'
import { UserEmailsProvider } from '../../../../../frontend/js/features/settings/context/user-email-context'
import { LeaversSurveyAlert } from '../../../../../frontend/js/features/settings/components/leavers-survey-alert'
import localStorage from '../../../../../frontend/js/infrastructure/local-storage'
function renderWithProvider() {
render(<LeaversSurveyAlert />, {
wrapper: ({ children }) => (
<UserEmailsProvider>{children}</UserEmailsProvider>
),
})
}
describe('<LeaversSurveyAlert/>', function () {
it('should render before the expiration date', function () {
const tomorrow = Date.now() + 1000 * 60 * 60 * 24
localStorage.setItem('showInstitutionalLeaversSurveyUntil', tomorrow)
localStorage.setItem('hideInstitutionalLeaversSurvey', false)
renderWithProvider()
screen.getByRole('alert')
screen.getByText(/Provide some quick feedback/)
screen.getByRole('link', { name: 'Take a short survey' })
})
it('should not render after the expiration date', function () {
const yesterday = Date.now() - 1000 * 60 * 60 * 24
localStorage.setItem('showInstitutionalLeaversSurveyUntil', yesterday)
localStorage.setItem('hideInstitutionalLeaversSurvey', false)
renderWithProvider()
expect(screen.queryByRole('alert')).to.be.null
})
it('should not render if it has been hidden', function () {
const tomorrow = Date.now() + 1000 * 60 * 60 * 24
localStorage.setItem('showInstitutionalLeaversSurveyUntil', tomorrow)
localStorage.setItem('hideInstitutionalLeaversSurvey', true)
renderWithProvider()
expect(screen.queryByRole('alert')).to.be.null
})
it('should reset the expiration date when it is closed', function () {
const tomorrow = Date.now() + 1000 * 60 * 60 * 24
localStorage.setItem('showInstitutionalLeaversSurveyUntil', tomorrow)
localStorage.setItem('hideInstitutionalLeaversSurvey', false)
renderWithProvider()
screen.getByRole('alert')
fireEvent.click(screen.getByRole('button'))
expect(screen.queryByRole('alert')).to.be.null
expect(localStorage.getItem('showInstitutionalLeaversSurveyUntil')).to.be
.null
})
})