mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #10195 from overleaf/ae-editor-left-menu-actions-test
Add test for clone project modal action GitOrigin-RevId: 7dfa3f4c394efe3c138112f0cfff1f4858b06960
This commit is contained in:
parent
f8ddacafd0
commit
1bee2cfba3
1 changed files with 38 additions and 0 deletions
|
@ -1,10 +1,21 @@
|
||||||
import { fireEvent, screen } from '@testing-library/dom'
|
import { fireEvent, screen } from '@testing-library/dom'
|
||||||
import fetchMock from 'fetch-mock'
|
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 ActionsCopyProject from '../../../../../frontend/js/features/editor-left-menu/components/actions-copy-project'
|
||||||
import { renderWithEditorContext } from '../../../helpers/render-with-context'
|
import { renderWithEditorContext } from '../../../helpers/render-with-context'
|
||||||
|
import * as locationModule from '../../../../../frontend/js/shared/components/location'
|
||||||
|
import { waitFor } from '@testing-library/react'
|
||||||
|
|
||||||
describe('<ActionsCopyProject />', function () {
|
describe('<ActionsCopyProject />', function () {
|
||||||
|
let assignStub
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
assignStub = sinon.stub(locationModule, 'assign')
|
||||||
|
})
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
|
assignStub.restore()
|
||||||
fetchMock.reset()
|
fetchMock.reset()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -15,4 +26,31 @@ describe('<ActionsCopyProject />', function () {
|
||||||
|
|
||||||
screen.getByPlaceholderText('New Project Name')
|
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')
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue