mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 04:28:48 -05:00
aa480a2663
[web] migrate from window attributes to getMeta GitOrigin-RevId: 3dcf1ab6b01155e5e4abeb3e78d0fa9053e055bc
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import sinon from 'sinon'
|
|
import { fireEvent, screen, render, waitFor } from '@testing-library/react'
|
|
import fetchMock from 'fetch-mock'
|
|
|
|
import LeaveModal from '../../../../../../frontend/js/features/settings/components/leave/modal'
|
|
import getMeta from '@/utils/meta'
|
|
|
|
describe('<LeaveModal />', function () {
|
|
beforeEach(function () {
|
|
window.metaAttributesCache.set('ol-usersEmail', 'foo@bar.com')
|
|
Object.assign(getMeta('ol-ExposedSettings'), { isOverleaf: true })
|
|
window.metaAttributesCache.set('ol-hasPassword', true)
|
|
})
|
|
|
|
afterEach(function () {
|
|
fetchMock.reset()
|
|
})
|
|
|
|
it('closes modal on cancel', async function () {
|
|
const handleClose = sinon.stub()
|
|
render(<LeaveModal isOpen handleClose={handleClose} />)
|
|
|
|
const cancelButton = screen.getByRole('button', {
|
|
name: 'Cancel',
|
|
})
|
|
fireEvent.click(cancelButton)
|
|
|
|
sinon.assert.calledOnce(handleClose)
|
|
})
|
|
|
|
it('does not close modal while in flight', async function () {
|
|
fetchMock.post('/user/delete', new Promise(() => {}))
|
|
const handleClose = sinon.stub()
|
|
render(<LeaveModal isOpen handleClose={handleClose} />)
|
|
|
|
fillValidForm()
|
|
|
|
const deleteButton = screen.getByRole('button', {
|
|
name: 'Delete',
|
|
})
|
|
fireEvent.click(deleteButton)
|
|
|
|
await waitFor(() => {
|
|
screen.getByRole('button', {
|
|
name: 'Deleting…',
|
|
})
|
|
})
|
|
|
|
const cancelButton = screen.getByRole('button', {
|
|
name: 'Cancel',
|
|
})
|
|
fireEvent.click(cancelButton)
|
|
|
|
sinon.assert.notCalled(handleClose)
|
|
})
|
|
})
|
|
|
|
function fillValidForm() {
|
|
fireEvent.change(screen.getByLabelText('Email'), {
|
|
target: { value: 'foo@bar.com' },
|
|
})
|
|
fireEvent.change(screen.getByLabelText('Password'), {
|
|
target: { value: 'foobar' },
|
|
})
|
|
fireEvent.click(screen.getByLabelText(/I understand/))
|
|
}
|