mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
5b0c122f5d
List of user emails GitOrigin-RevId: 28a8e405812932ba7ebd8043a4dc9d3c573a68b2
159 lines
4.3 KiB
TypeScript
159 lines
4.3 KiB
TypeScript
import {
|
|
render,
|
|
screen,
|
|
within,
|
|
fireEvent,
|
|
waitForElementToBeRemoved,
|
|
} from '@testing-library/react'
|
|
import EmailsSection from '../../../../../../frontend/js/features/settings/components/emails-section'
|
|
import { expect } from 'chai'
|
|
import fetchMock from 'fetch-mock'
|
|
|
|
const confirmedUserData = {
|
|
confirmedAt: '2022-03-10T10:59:44.139Z',
|
|
email: 'bar@overleaf.com',
|
|
default: false,
|
|
}
|
|
|
|
const unconfirmedUserData = {
|
|
email: 'baz@overleaf.com',
|
|
default: false,
|
|
}
|
|
|
|
const professionalUserData = {
|
|
affiliation: {
|
|
institution: {
|
|
confirmed: true,
|
|
},
|
|
licence: 'pro_plus',
|
|
},
|
|
confirmedAt: '2022-03-09T10:59:44.139Z',
|
|
email: 'foo@overleaf.com',
|
|
default: true,
|
|
}
|
|
|
|
const fakeUsersData = [
|
|
{ ...confirmedUserData },
|
|
{ ...unconfirmedUserData },
|
|
{ ...professionalUserData },
|
|
]
|
|
|
|
describe('<EmailsSection />', function () {
|
|
afterEach(function () {
|
|
window.metaAttributesCache = new Map()
|
|
fetchMock.reset()
|
|
})
|
|
|
|
it('renders translated heading', function () {
|
|
window.metaAttributesCache.set('ol-userEmails', fakeUsersData)
|
|
render(<EmailsSection />)
|
|
|
|
screen.getByRole('heading', { name: /emails and affiliations/i })
|
|
})
|
|
|
|
it('renders translated description', function () {
|
|
window.metaAttributesCache.set('ol-userEmails', fakeUsersData)
|
|
render(<EmailsSection />)
|
|
|
|
screen.getByText(/add additional email addresses/i)
|
|
screen.getByText(/to change your primary email/i)
|
|
})
|
|
|
|
it('renders user emails', function () {
|
|
window.metaAttributesCache.set('ol-userEmails', fakeUsersData)
|
|
render(<EmailsSection />)
|
|
|
|
fakeUsersData.forEach(userData => {
|
|
screen.getByText(new RegExp(userData.email, 'i'))
|
|
})
|
|
})
|
|
|
|
it('renders primary status', function () {
|
|
window.metaAttributesCache.set('ol-userEmails', fakeUsersData)
|
|
render(<EmailsSection />)
|
|
|
|
const primary = fakeUsersData.find(userData => userData.default)
|
|
|
|
screen.getByText(`${primary.email} (primary)`)
|
|
})
|
|
|
|
it('shows confirmation status for unconfirmed users', function () {
|
|
window.metaAttributesCache.set('ol-userEmails', [unconfirmedUserData])
|
|
render(<EmailsSection />)
|
|
|
|
screen.getByText(/please check your inbox/i)
|
|
})
|
|
|
|
it('hides confirmation status for confirmed users', function () {
|
|
window.metaAttributesCache.set('ol-userEmails', [confirmedUserData])
|
|
render(<EmailsSection />)
|
|
|
|
expect(screen.queryByText(/please check your inbox/i)).to.be.null
|
|
})
|
|
|
|
it('renders resend link', function () {
|
|
window.metaAttributesCache.set('ol-userEmails', [unconfirmedUserData])
|
|
render(<EmailsSection />)
|
|
|
|
screen.getByRole('button', { name: /resend confirmation email/i })
|
|
})
|
|
|
|
it('renders professional label', function () {
|
|
window.metaAttributesCache.set('ol-userEmails', [professionalUserData])
|
|
render(<EmailsSection />)
|
|
|
|
const node = screen.getByText(professionalUserData.email, {
|
|
exact: false,
|
|
})
|
|
expect(within(node).getByText(/professional/i)).to.exist
|
|
})
|
|
|
|
it('shows loader when resending email', async function () {
|
|
fetchMock.post('/user/emails/resend_confirmation', 200)
|
|
window.metaAttributesCache.set('ol-userEmails', [unconfirmedUserData])
|
|
render(<EmailsSection />)
|
|
|
|
const button = screen.getByRole('button', {
|
|
name: /resend confirmation email/i,
|
|
})
|
|
fireEvent.click(button)
|
|
|
|
expect(
|
|
screen.queryByRole('button', {
|
|
name: /resend confirmation email/i,
|
|
})
|
|
).to.be.null
|
|
|
|
await waitForElementToBeRemoved(() => screen.getByText(/sending/i))
|
|
|
|
expect(
|
|
screen.queryByText(/an error has occurred while performing your request/i)
|
|
).to.be.null
|
|
|
|
await screen.findByRole('button', {
|
|
name: /resend confirmation email/i,
|
|
})
|
|
})
|
|
|
|
it('shows error when resending email fails', async function () {
|
|
fetchMock.post('/user/emails/resend_confirmation', 503)
|
|
window.metaAttributesCache.set('ol-userEmails', [unconfirmedUserData])
|
|
render(<EmailsSection />)
|
|
|
|
const button = screen.getByRole('button', {
|
|
name: /resend confirmation email/i,
|
|
})
|
|
fireEvent.click(button)
|
|
|
|
expect(
|
|
screen.queryByRole('button', {
|
|
name: /resend confirmation email/i,
|
|
})
|
|
).to.be.null
|
|
|
|
await waitForElementToBeRemoved(() => screen.getByText(/sending/i))
|
|
|
|
screen.getByText(/an error has occurred while performing your request/i)
|
|
screen.getByRole('button', { name: /resend confirmation email/i })
|
|
})
|
|
})
|