mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 01:33:53 -05:00
2bed549195
[web] Confirmation modal when leaving project on sharing updates screen GitOrigin-RevId: a19201f5157c2e92f98480bc59ad1f405601945d
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import { expect } from 'chai'
|
|
import sinon from 'sinon'
|
|
import { render, screen } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import LeaveProjectModal from '@/features/token-access/components/leave-project-modal'
|
|
|
|
describe('<LeaveProjectModal/>', function () {
|
|
const closeHandler = sinon.stub()
|
|
const leaveHandler = sinon.stub()
|
|
it('does not render when no show prop is passed', function () {
|
|
render(
|
|
<LeaveProjectModal
|
|
handleCloseModal={closeHandler}
|
|
handleLeaveAction={leaveHandler}
|
|
showModal={false}
|
|
/>
|
|
)
|
|
const leaveText = screen.queryByText('Leave Project')
|
|
expect(leaveText).to.be.null
|
|
})
|
|
|
|
it('renders when the show prop is passed', function () {
|
|
render(
|
|
<LeaveProjectModal
|
|
handleCloseModal={closeHandler}
|
|
handleLeaveAction={leaveHandler}
|
|
showModal
|
|
/>
|
|
)
|
|
const leaveText = screen.queryByText('Leave Project')
|
|
expect(leaveText).to.exist
|
|
})
|
|
|
|
it('calls the close handler when dismissed', async function () {
|
|
const user = userEvent.setup()
|
|
render(
|
|
<LeaveProjectModal
|
|
handleCloseModal={closeHandler}
|
|
handleLeaveAction={leaveHandler}
|
|
showModal
|
|
/>
|
|
)
|
|
await user.click(screen.getByRole('button', { name: /Cancel/i }))
|
|
expect(closeHandler).to.have.been.calledOnce
|
|
})
|
|
|
|
it('calls the leave handler when confirmed', async function () {
|
|
const user = userEvent.setup()
|
|
render(
|
|
<LeaveProjectModal
|
|
handleCloseModal={closeHandler}
|
|
handleLeaveAction={leaveHandler}
|
|
showModal
|
|
/>
|
|
)
|
|
await user.click(screen.getByRole('button', { name: /Confirm/i }))
|
|
expect(leaveHandler).to.have.been.calledOnce
|
|
})
|
|
})
|