overleaf/services/web/test/frontend/features/settings/components/leave/modal-content.test.tsx
Jakob Ackermann aa480a2663 Merge pull request #18898 from overleaf/jpa-no-window
[web] migrate from window attributes to getMeta

GitOrigin-RevId: 3dcf1ab6b01155e5e4abeb3e78d0fa9053e055bc
2024-06-19 08:04:21 +00:00

50 lines
1.4 KiB
TypeScript

import { expect } from 'chai'
import { screen, render } from '@testing-library/react'
import fetchMock from 'fetch-mock'
import LeaveModalContent from '../../../../../../frontend/js/features/settings/components/leave/modal-content'
import getMeta from '@/utils/meta'
describe('<LeaveModalContent />', function () {
beforeEach(function () {
Object.assign(getMeta('ol-ExposedSettings'), { isOverleaf: true })
window.metaAttributesCache.set('ol-hasPassword', true)
})
afterEach(function () {
fetchMock.reset()
})
it('disable delete button if form is not valid', function () {
render(
<LeaveModalContent
handleHide={() => {}}
inFlight={false}
setInFlight={() => {}}
/>
)
screen.getByLabelText('Email')
const deleteButton = screen.getByRole('button', {
name: 'Delete',
})
expect(deleteButton.hasAttribute('disabled')).to.be.true
})
it('shows no password message', function () {
window.metaAttributesCache.set('ol-isSaas', true)
window.metaAttributesCache.set('ol-hasPassword', false)
render(
<LeaveModalContent
handleHide={() => {}}
inFlight={false}
setInFlight={() => {}}
/>
)
const link = screen.getByRole('link', {
name: 'Please use the password reset form to set a password before deleting your account',
})
expect(link.getAttribute('href')).to.equal('/user/password/reset')
})
})