mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-07 08:09:01 +02:00
b901bb6c75
* Update fetch-mock to version 12 * Replace `fetchMock.done` by `fetchMock.callHistory.done` * Replace `…Mock.called` by `…Mock.callHistory.called` * Replace `fetchMock.reset` by `fetchMock.hardReset` * Replace `fetchMock.restore` by `fetchMock.hardReset` * Replace `fetchMock.resetHistory` by `fetchMock.clearHistory` * Replace `fetchMock.calls` by `fetchMock.callHistory.calls` * Replace `fetchMock.flush` by `fetchMock.callHistory.flush` * Update tests for fetch-mock version 12 See https://www.wheresrhys.co.uk/fetch-mock/docs/Usage/upgrade-guide * Update stories for fetch-mock version 12 * Remove `overwriteRoutes` option * Add `fetchMock.spyGlobal()` to storybook * Remove deprecated `sendAsJson` param * Replace `fetchMock.hardReset()` by `fetchMock.removeRoutes().clearHistory()` * Fixup fetch-mock in storybook: Call `mockGlobal` inside the hook, call `removeRoutes` and `unmockGlobal` on cleanup Behaviour can be tested by navigating between https://storybook.dev-overleaf.com/main/?path=/story/editor-ai-error-assistant-compile-log-entries--first-log-entry https://storybook.dev-overleaf.com/main/?path=/story/editor-ai-error-assistant-compile-log-entries--rate-limited https://storybook.dev-overleaf.com/main/?path=/story/project-list-notifications--project-invite https://storybook.dev-overleaf.com/main/?path=/story/project-list-notifications--project-invite-network-error And clicking the buttons GitOrigin-RevId: 35611b4430259e4c21c3d819ad18b2e6dab66242
61 lines
1.8 KiB
React
61 lines
1.8 KiB
React
import { fireEvent, screen, waitFor } from '@testing-library/react'
|
|
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 * 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,
|
|
replace: sinon.stub(),
|
|
reload: sinon.stub(),
|
|
})
|
|
})
|
|
|
|
afterEach(function () {
|
|
this.locationStub.restore()
|
|
fetchMock.removeRoutes().clearHistory()
|
|
})
|
|
|
|
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')
|
|
})
|
|
})
|
|
})
|