mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2025-07-29 23:00:08 +02:00

* 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
164 lines
5.2 KiB
TypeScript
164 lines
5.2 KiB
TypeScript
import {
|
|
fireEvent,
|
|
render,
|
|
screen,
|
|
waitFor,
|
|
waitForElementToBeRemoved,
|
|
} from '@testing-library/react'
|
|
import sinon from 'sinon'
|
|
import { expect } from 'chai'
|
|
import fetchMock from 'fetch-mock'
|
|
import { cloneDeep } from 'lodash'
|
|
import ReconfirmationInfo from '../../../../../../frontend/js/features/settings/components/emails/reconfirmation-info'
|
|
import { ssoUserData } from '../../fixtures/test-user-email-data'
|
|
import { UserEmailData } from '../../../../../../types/user-email'
|
|
import { UserEmailsProvider } from '../../../../../../frontend/js/features/settings/context/user-email-context'
|
|
import { location } from '@/shared/components/location'
|
|
import getMeta from '@/utils/meta'
|
|
|
|
function renderReconfirmationInfo(data: UserEmailData) {
|
|
return render(
|
|
<UserEmailsProvider>
|
|
<ReconfirmationInfo userEmailData={data} />
|
|
</UserEmailsProvider>
|
|
)
|
|
}
|
|
|
|
describe('<ReconfirmationInfo/>', function () {
|
|
beforeEach(function () {
|
|
Object.assign(getMeta('ol-ExposedSettings'), {
|
|
samlInitPath: '/saml',
|
|
})
|
|
fetchMock.get('/user/emails?ensureAffiliation=true', [])
|
|
this.locationWrapperSandbox = sinon.createSandbox()
|
|
this.locationWrapperStub = this.locationWrapperSandbox.stub(location)
|
|
})
|
|
|
|
afterEach(function () {
|
|
fetchMock.removeRoutes().clearHistory()
|
|
this.locationWrapperSandbox.restore()
|
|
})
|
|
|
|
describe('reconfirmed via SAML', function () {
|
|
beforeEach(function () {
|
|
window.metaAttributesCache.set(
|
|
'ol-reconfirmedViaSAML',
|
|
'sso-prof-saml-id'
|
|
)
|
|
})
|
|
|
|
it('show reconfirmed confirmation', function () {
|
|
renderReconfirmationInfo(ssoUserData)
|
|
screen.getByText('SSO University')
|
|
screen.getByText(/affiliation is confirmed/)
|
|
screen.getByText(/Thank you!/)
|
|
})
|
|
})
|
|
|
|
describe('in reconfirm notification period', function () {
|
|
let inReconfirmUserData: UserEmailData
|
|
|
|
beforeEach(function () {
|
|
Object.assign(getMeta('ol-ExposedSettings'), {
|
|
samlInitPath: '/saml',
|
|
})
|
|
|
|
inReconfirmUserData = cloneDeep(ssoUserData)
|
|
if (inReconfirmUserData.affiliation) {
|
|
inReconfirmUserData.affiliation.inReconfirmNotificationPeriod = true
|
|
}
|
|
})
|
|
|
|
it('renders prompt', function () {
|
|
renderReconfirmationInfo(inReconfirmUserData)
|
|
screen.getByText(/Are you still at/)
|
|
screen.getByText('SSO University')
|
|
screen.getByText(
|
|
/Please take a moment to confirm your institutional email address/
|
|
)
|
|
screen.getByRole('link', { name: 'Learn more' })
|
|
expect(screen.queryByText(/add a new primary email address/)).to.not.exist
|
|
})
|
|
|
|
it('renders default emails prompt', function () {
|
|
inReconfirmUserData.default = true
|
|
renderReconfirmationInfo(inReconfirmUserData)
|
|
screen.getByText(/add a new primary email address/)
|
|
})
|
|
|
|
describe('SAML reconfirmations', function () {
|
|
beforeEach(function () {
|
|
Object.assign(getMeta('ol-ExposedSettings'), {
|
|
hasSamlFeature: true,
|
|
samlInitPath: '/saml/init',
|
|
})
|
|
})
|
|
|
|
it('redirects to SAML flow', async function () {
|
|
renderReconfirmationInfo(inReconfirmUserData)
|
|
const confirmButton = screen.getByRole('button', {
|
|
name: 'Confirm affiliation',
|
|
}) as HTMLButtonElement
|
|
|
|
await waitFor(() => {
|
|
expect(confirmButton.disabled).to.be.false
|
|
})
|
|
fireEvent.click(confirmButton)
|
|
|
|
await waitFor(() => {
|
|
expect(confirmButton.disabled).to.be.true
|
|
})
|
|
sinon.assert.calledOnce(this.locationWrapperStub.assign)
|
|
sinon.assert.calledWithMatch(
|
|
this.locationWrapperStub.assign,
|
|
'/saml/init?university_id=2&reconfirm=/user/settings'
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('Email reconfirmations', function () {
|
|
beforeEach(function () {
|
|
Object.assign(getMeta('ol-ExposedSettings'), {
|
|
hasSamlFeature: false,
|
|
})
|
|
fetchMock.post('/user/emails/send-reconfirmation', 200)
|
|
})
|
|
|
|
it('sends and resends confirmation email', async function () {
|
|
renderReconfirmationInfo(inReconfirmUserData)
|
|
const confirmButton = (await screen.findByRole('button', {
|
|
name: 'Confirm affiliation',
|
|
})) as HTMLButtonElement
|
|
|
|
await waitFor(() => {
|
|
expect(confirmButton.disabled).to.be.false
|
|
})
|
|
fireEvent.click(confirmButton)
|
|
|
|
await waitFor(() => {
|
|
expect(confirmButton.disabled).to.be.true
|
|
})
|
|
expect(fetchMock.callHistory.called()).to.be.true
|
|
|
|
// the confirmation text should now be displayed
|
|
await screen.findByText(/Please check your email inbox to confirm/)
|
|
|
|
// try the resend button
|
|
fetchMock.clearHistory()
|
|
const resendButton = await screen.findByRole('button', {
|
|
name: 'Resend confirmation email',
|
|
})
|
|
|
|
fireEvent.click(resendButton)
|
|
|
|
// commented out as it's already gone by this point
|
|
// await screen.findByText(/Sending/)
|
|
expect(fetchMock.callHistory.called()).to.be.true
|
|
await waitForElementToBeRemoved(() => screen.getByText('Sending…'))
|
|
await screen.findByRole('button', {
|
|
name: 'Resend confirmation email',
|
|
})
|
|
})
|
|
})
|
|
})
|
|
})
|