mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
f375362894
* Always use mockable location methods * Add eslint rules for window.location calls/assignment * Add useLocation hook * Update tests GitOrigin-RevId: eafb846db89f884a7a9a8570cce7745be605152c
60 lines
1.8 KiB
JavaScript
60 lines
1.8 KiB
JavaScript
import { fireEvent, screen } from '@testing-library/dom'
|
|
import fetchMock from 'fetch-mock'
|
|
import sinon from 'sinon'
|
|
import { expect } from 'chai'
|
|
import ActionsCopyProject from '../../../../../frontend/js/features/editor-left-menu/components/actions-copy-project'
|
|
import { renderWithEditorContext } from '../../../helpers/render-with-context'
|
|
import { waitFor } from '@testing-library/react'
|
|
import * as useLocationModule from '../../../../../frontend/js/shared/hooks/use-location'
|
|
|
|
describe('<ActionsCopyProject />', function () {
|
|
let assignStub
|
|
|
|
beforeEach(function () {
|
|
assignStub = sinon.stub()
|
|
this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
|
|
assign: assignStub,
|
|
reload: sinon.stub(),
|
|
})
|
|
})
|
|
|
|
afterEach(function () {
|
|
this.locationStub.restore()
|
|
fetchMock.reset()
|
|
})
|
|
|
|
it('shows correct modal when clicked', async function () {
|
|
renderWithEditorContext(<ActionsCopyProject />)
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: 'Copy Project' }))
|
|
|
|
screen.getByPlaceholderText('New Project Name')
|
|
})
|
|
|
|
it('loads the project page when submitted', async function () {
|
|
fetchMock.post('express:/project/:id/clone', {
|
|
status: 200,
|
|
body: {
|
|
project_id: 'new-project',
|
|
},
|
|
})
|
|
|
|
renderWithEditorContext(<ActionsCopyProject />)
|
|
|
|
fireEvent.click(screen.getByRole('button', { name: 'Copy Project' }))
|
|
|
|
const input = screen.getByPlaceholderText('New Project Name')
|
|
fireEvent.change(input, { target: { value: 'New Project' } })
|
|
|
|
const button = screen.getByRole('button', { name: 'Copy' })
|
|
button.click()
|
|
|
|
await waitFor(() => {
|
|
expect(button.textContent).to.equal('Copying…')
|
|
})
|
|
|
|
await waitFor(() => {
|
|
expect(assignStub).to.have.been.calledOnceWith('/project/new-project')
|
|
})
|
|
})
|
|
})
|