2022-10-27 12:19:50 -04:00
|
|
|
import { fireEvent, screen } from '@testing-library/dom'
|
|
|
|
import fetchMock from 'fetch-mock'
|
2022-10-28 09:33:51 -04:00
|
|
|
import sinon from 'sinon'
|
|
|
|
import { expect } from 'chai'
|
2022-10-27 12:19:50 -04:00
|
|
|
import ActionsCopyProject from '../../../../../frontend/js/features/editor-left-menu/components/actions-copy-project'
|
|
|
|
import { renderWithEditorContext } from '../../../helpers/render-with-context'
|
2022-10-28 09:33:51 -04:00
|
|
|
import { waitFor } from '@testing-library/react'
|
2023-03-16 08:32:48 -04:00
|
|
|
import * as useLocationModule from '../../../../../frontend/js/shared/hooks/use-location'
|
2022-10-27 12:19:50 -04:00
|
|
|
|
|
|
|
describe('<ActionsCopyProject />', function () {
|
2022-10-28 09:33:51 -04:00
|
|
|
let assignStub
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2023-03-16 08:32:48 -04:00
|
|
|
assignStub = sinon.stub()
|
|
|
|
this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
|
|
|
|
assign: assignStub,
|
|
|
|
reload: sinon.stub(),
|
|
|
|
})
|
2022-10-28 09:33:51 -04:00
|
|
|
})
|
|
|
|
|
2022-10-27 12:19:50 -04:00
|
|
|
afterEach(function () {
|
2023-03-16 08:32:48 -04:00
|
|
|
this.locationStub.restore()
|
2022-10-27 12:19:50 -04:00
|
|
|
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')
|
|
|
|
})
|
2022-10-28 09:33:51 -04:00
|
|
|
|
|
|
|
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')
|
|
|
|
})
|
|
|
|
})
|
2022-10-27 12:19:50 -04:00
|
|
|
})
|