overleaf-cep/services/web/test/frontend/features/clone-project-modal/components/clone-project-modal.test.jsx
Antoine Clausse e0f3bea9ad [web] De-capitalize english translations (#24123)
* Create decapitalize.sh script

* Remove `text-capitalize` classes, rely on translations instead

* `Account Linking` -> `Account linking`

* `Account Settings` -> `Account settings`

* `Add Affiliation` -> `Add affiliation`

* `Add Email` -> `Add email`

* `Add Files` -> `Add files`

* `Add to Dictionary` -> `Add to dictionary`

* `All Projects` -> `All projects`

* `All Templates` -> `All templates`

* `Archive Projects` -> `Archive projects`

* `Archived Projects` -> `Archived projects`

* `Auto Compile` -> `Auto compile`

* `Back to Subscription` -> `Back to subscription`

* `Blank Project` -> `Blank project`

* `Change Password` -> `Change password`

* `Change Project Owner` -> `Change project owner`

* `Clear Sessions` -> `Clear sessions`

* `Company Name` -> `Company name`

* `Compile Error Handling` -> `Compile error handling`

* `Compile Mode` -> `Compile mode`

* `Compromised Password` -> `Compromised password`

* `Confirm Affiliation` -> `Confirm affiliation`

* `Confirm Email` -> `Confirm email`

* `Connected Users` -> `Connected users`

* `Contact Sales` -> `Contact sales`

* `Contact Support` -> `Contact support`

* `Contact Us` -> `Contact us`

* `Copy Project` -> `Copy project`

* `Delete Account` -> `Delete account`

* `Emails and Affiliations` -> `Emails and affiliations`

* `Git Integration` -> `Git integration`

* `Group Settings` -> `Group settings`

* `Link Accounts` -> `Link accounts`

* `Make Primary` -> `Make primary`

* `Mendeley Integration` -> `Mendeley integration`

* `Papers Integration` -> `Papers integration`

* `Project Synchronisation` -> `Project synchronisation`

* `Sessions Cleared` -> `Sessions cleared`

* `Stop Compilation` -> `Stop compilation`

* `Update Account Info` -> `Update account info`

* `the Sales team` -> `the sales team`

* `your Group settings` -> `your group settings`

* `Zotero Integration` -> `Zotero integration`

* Update decapitalize.sh

* Decapitalize some translations

* `Example Project` -> `Example project`

* `New Project` -> `New project`

* `New Tag` -> `New tag`

* `Trashed Projects` -> `Trashed projects`

* `Upload Project` -> `Upload project`

* `Your Projects` -> `Your projects`

* Revert "Create decapitalize.sh script"

This reverts commit 8c79f367096c206c704c7c01e3572a18f3961d5e.

* Revert changes to stories

* Fix tests

* `Contact us of` -> `Contact us if`

* Make `Contact us` bold in tex files

* `sales team` -> `Sales team`

* `Link accounts and Add email` -> `Link accounts and add email`

* `Make Private` -> `Make private`

* `contact support` -> `contact Support`

* Make `Make primary` tests case sensitive

* Use `add_email` translation string

* Revert changes to non-english locales

* Remove redundant `Account settings` translation

* `New project Name` -> `New project name`

GitOrigin-RevId: 675c46f96ddbf3d259a8d723fed62aa4a7ed40b7
2025-05-22 08:07:46 +00:00

183 lines
4.9 KiB
JavaScript

import { fireEvent, screen, waitFor } from '@testing-library/react'
import { expect } from 'chai'
import sinon from 'sinon'
import fetchMock from 'fetch-mock'
import EditorCloneProjectModalWrapper from '../../../../../frontend/js/features/clone-project-modal/components/editor-clone-project-modal-wrapper'
import { renderWithEditorContext } from '../../../helpers/render-with-context'
describe('<EditorCloneProjectModalWrapper />', function () {
beforeEach(function () {
fetchMock.removeRoutes().clearHistory()
window.metaAttributesCache.set('ol-preventCompileOnLoad', true)
})
after(function () {
fetchMock.removeRoutes().clearHistory()
})
const project = {
_id: 'project-1',
name: 'Test Project',
}
it('renders the translated modal title', async function () {
const handleHide = sinon.stub()
const openProject = sinon.stub()
renderWithEditorContext(
<EditorCloneProjectModalWrapper
handleHide={handleHide}
openProject={openProject}
show
/>,
{ scope: { project } }
)
await screen.findByText('Copy project')
})
it('posts the generated project name', async function () {
fetchMock.post(
'express:/project/:projectId/clone',
{
status: 200,
body: { project_id: 'cloned-project' },
},
{ delay: 10 }
)
const handleHide = sinon.stub()
const openProject = sinon.stub()
renderWithEditorContext(
<EditorCloneProjectModalWrapper
handleHide={handleHide}
openProject={openProject}
show
/>,
{ scope: { project } }
)
const cancelButton = await screen.findByRole('button', { name: 'Cancel' })
expect(cancelButton.disabled).to.be.false
const submitButton = await screen.findByRole('button', { name: 'Copy' })
expect(submitButton.disabled).to.be.false
const input = await screen.getByLabelText('New Name')
fireEvent.change(input, {
target: { value: '' },
})
expect(submitButton.disabled).to.be.true
fireEvent.change(input, {
target: { value: 'A Cloned Project' },
})
expect(submitButton.disabled).to.be.false
fireEvent.click(submitButton)
expect(submitButton.disabled).to.be.true
await fetchMock.callHistory.flush(true)
expect(fetchMock.callHistory.done()).to.be.true
const { url, options } = fetchMock.callHistory
.calls('express:/project/:projectId/clone')
.at(-1)
expect(url).to.equal(
'https://www.test-overleaf.com/project/project-1/clone'
)
expect(JSON.parse(options.body)).to.deep.equal({
projectName: 'A Cloned Project',
tags: [],
})
await waitFor(() => {
expect(openProject).to.be.calledOnce
})
const errorMessage = screen.queryByText('Sorry, something went wrong')
expect(errorMessage).to.be.null
await waitFor(() => {
expect(submitButton.disabled).to.be.false
expect(cancelButton.disabled).to.be.false
})
})
it('handles a generic error response', async function () {
const matcher = 'express:/project/:projectId/clone'
fetchMock.postOnce(matcher, {
status: 500,
body: 'There was an error!',
})
const handleHide = sinon.stub()
const openProject = sinon.stub()
renderWithEditorContext(
<EditorCloneProjectModalWrapper
handleHide={handleHide}
openProject={openProject}
show
/>,
{ scope: { project } }
)
const button = await screen.findByRole('button', { name: 'Copy' })
expect(button.disabled).to.be.false
const cancelButton = await screen.findByRole('button', { name: 'Cancel' })
expect(cancelButton.disabled).to.be.false
fireEvent.click(button)
expect(fetchMock.callHistory.done(matcher)).to.be.true
expect(openProject).not.to.be.called
await screen.findByText('Sorry, something went wrong')
expect(button.disabled).to.be.false
expect(cancelButton.disabled).to.be.false
})
it('handles a specific error response', async function () {
const matcher = 'express:/project/:projectId/clone'
fetchMock.postOnce(matcher, {
status: 400,
body: 'There was an error!',
})
const handleHide = sinon.stub()
const openProject = sinon.stub()
renderWithEditorContext(
<EditorCloneProjectModalWrapper
handleHide={handleHide}
openProject={openProject}
show
/>,
{ scope: { project } }
)
const button = await screen.findByRole('button', { name: 'Copy' })
expect(button.disabled).to.be.false
const cancelButton = await screen.findByRole('button', { name: 'Cancel' })
expect(cancelButton.disabled).to.be.false
fireEvent.click(button)
await fetchMock.callHistory.flush(true)
expect(fetchMock.callHistory.done(matcher)).to.be.true
expect(openProject).not.to.be.called
await screen.findByText('There was an error!')
expect(button.disabled).to.be.false
expect(cancelButton.disabled).to.be.false
})
})