2022-04-25 07:05:07 -04:00
|
|
|
import {
|
|
|
|
render,
|
|
|
|
screen,
|
|
|
|
fireEvent,
|
|
|
|
waitForElementToBeRemoved,
|
|
|
|
} from '@testing-library/react'
|
2022-04-27 04:42:48 -04:00
|
|
|
import userEvent from '@testing-library/user-event'
|
2022-04-25 07:05:07 -04:00
|
|
|
import EmailsSection from '../../../../../../frontend/js/features/settings/components/emails-section'
|
|
|
|
import { expect } from 'chai'
|
|
|
|
import fetchMock from 'fetch-mock'
|
|
|
|
import { UserEmailData } from '../../../../../../types/user-email'
|
2022-05-31 05:08:49 -04:00
|
|
|
import { Affiliation } from '../../../../../../types/affiliation'
|
2022-04-25 07:05:07 -04:00
|
|
|
|
2022-05-31 05:08:49 -04:00
|
|
|
const userEmailData: UserEmailData & { affiliation: Affiliation } = {
|
2022-04-25 07:05:07 -04:00
|
|
|
affiliation: {
|
|
|
|
cachedConfirmedAt: null,
|
2022-05-16 04:03:29 -04:00
|
|
|
cachedEntitlement: null,
|
|
|
|
cachedLastDayToReconfirm: null,
|
2022-04-25 07:05:07 -04:00
|
|
|
cachedPastReconfirmDate: false,
|
|
|
|
cachedReconfirmedAt: null,
|
|
|
|
department: 'Art History',
|
|
|
|
institution: {
|
|
|
|
commonsAccount: false,
|
|
|
|
confirmed: true,
|
|
|
|
id: 1,
|
2022-04-27 04:42:48 -04:00
|
|
|
isUniversity: true,
|
2022-05-16 04:03:29 -04:00
|
|
|
maxConfirmationMonths: null,
|
2022-04-25 07:05:07 -04:00
|
|
|
name: 'Overleaf',
|
|
|
|
ssoEnabled: false,
|
|
|
|
ssoBeta: false,
|
|
|
|
},
|
|
|
|
inReconfirmNotificationPeriod: false,
|
|
|
|
inferred: false,
|
|
|
|
licence: 'pro_plus',
|
|
|
|
pastReconfirmDate: false,
|
|
|
|
portal: { slug: '', templates_count: 1 },
|
|
|
|
role: 'Reader',
|
|
|
|
},
|
|
|
|
email: 'baz@overleaf.com',
|
|
|
|
default: false,
|
|
|
|
}
|
|
|
|
|
2022-04-27 12:13:17 -04:00
|
|
|
const institutionDomainData = [
|
|
|
|
{
|
|
|
|
university: {
|
|
|
|
id: 1234,
|
|
|
|
ssoEnabled: true,
|
|
|
|
name: 'Auto Complete University',
|
|
|
|
},
|
|
|
|
hostname: 'autocomplete.edu',
|
|
|
|
confirmed: true,
|
|
|
|
},
|
2022-05-16 04:03:04 -04:00
|
|
|
] as const
|
2022-04-27 12:13:17 -04:00
|
|
|
|
|
|
|
function resetFetchMock() {
|
|
|
|
fetchMock.reset()
|
|
|
|
fetchMock.get('express:/institutions/domains', [])
|
|
|
|
}
|
|
|
|
|
2022-04-25 07:05:07 -04:00
|
|
|
describe('<EmailsSection />', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
window.metaAttributesCache.set('ol-ExposedSettings', {
|
|
|
|
hasAffiliationsFeature: true,
|
2022-04-27 12:13:17 -04:00
|
|
|
hasSamlFeature: true,
|
|
|
|
samlInitPath: 'saml/init',
|
2022-04-25 07:05:07 -04:00
|
|
|
})
|
2022-04-29 07:10:10 -04:00
|
|
|
fetchMock.reset()
|
2022-04-25 07:05:07 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
window.metaAttributesCache = new Map()
|
2022-04-27 12:13:17 -04:00
|
|
|
resetFetchMock()
|
2022-04-25 07:05:07 -04:00
|
|
|
})
|
|
|
|
|
2022-04-29 07:10:10 -04:00
|
|
|
it('renders "add another email" button', async function () {
|
2022-04-25 07:05:07 -04:00
|
|
|
fetchMock.get('/user/emails?ensureAffiliation=true', [])
|
|
|
|
render(<EmailsSection />)
|
|
|
|
|
2022-04-29 07:10:10 -04:00
|
|
|
await fetchMock.flush(true)
|
|
|
|
|
2022-04-25 07:05:07 -04:00
|
|
|
screen.getByRole('button', { name: /add another email/i })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('renders input', async function () {
|
|
|
|
fetchMock.get('/user/emails?ensureAffiliation=true', [])
|
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
|
|
const addAnotherEmailBtn = (await screen.findByRole('button', {
|
|
|
|
name: /add another email/i,
|
|
|
|
})) as HTMLButtonElement
|
|
|
|
fireEvent.click(addAnotherEmailBtn)
|
|
|
|
|
|
|
|
screen.getByLabelText(/email/i)
|
|
|
|
})
|
|
|
|
|
2022-05-30 09:47:58 -04:00
|
|
|
it('renders "Start adding your address" until a valid email is typed', async function () {
|
|
|
|
fetchMock.get('/user/emails?ensureAffiliation=true', [])
|
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
|
|
const addAnotherEmailBtn = (await screen.findByRole('button', {
|
|
|
|
name: /add another email/i,
|
|
|
|
})) as HTMLButtonElement
|
|
|
|
fireEvent.click(addAnotherEmailBtn)
|
|
|
|
|
|
|
|
const input = screen.getByLabelText(/email/i)
|
|
|
|
|
|
|
|
// initially the text is displayed and the "add email" button disabled
|
|
|
|
screen.getByText('Start by adding your email address.')
|
|
|
|
expect(
|
|
|
|
(
|
|
|
|
screen.getByRole('button', {
|
|
|
|
name: /add new email/i,
|
|
|
|
}) as HTMLButtonElement
|
|
|
|
).disabled
|
|
|
|
).to.be.true
|
|
|
|
|
|
|
|
// no changes while writing the email address
|
|
|
|
fireEvent.change(input, {
|
|
|
|
target: { value: 'partial@email' },
|
|
|
|
})
|
|
|
|
screen.getByText('Start by adding your email address.')
|
|
|
|
expect(
|
|
|
|
(
|
|
|
|
screen.getByRole('button', {
|
|
|
|
name: /add new email/i,
|
|
|
|
}) as HTMLButtonElement
|
|
|
|
).disabled
|
|
|
|
).to.be.true
|
|
|
|
|
|
|
|
// the text is removed when the complete email address is typed, and the "add button" is reenabled
|
|
|
|
fireEvent.change(input, {
|
|
|
|
target: { value: 'valid@email.com' },
|
|
|
|
})
|
|
|
|
expect(screen.queryByText('Start by adding your email address.')).to.be.null
|
|
|
|
expect(
|
|
|
|
(
|
|
|
|
screen.getByRole('button', {
|
|
|
|
name: /add new email/i,
|
|
|
|
}) as HTMLButtonElement
|
|
|
|
).disabled
|
|
|
|
).to.be.false
|
|
|
|
})
|
|
|
|
|
2022-04-25 07:05:07 -04:00
|
|
|
it('renders "add new email" button', async function () {
|
|
|
|
fetchMock.get('/user/emails?ensureAffiliation=true', [])
|
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
|
|
const addAnotherEmailBtn = (await screen.findByRole('button', {
|
|
|
|
name: /add another email/i,
|
|
|
|
})) as HTMLButtonElement
|
|
|
|
fireEvent.click(addAnotherEmailBtn)
|
|
|
|
|
|
|
|
screen.getByRole('button', { name: /add new email/i })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('adds new email address', async function () {
|
|
|
|
fetchMock.get('/user/emails?ensureAffiliation=true', [])
|
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
|
|
await fetchMock.flush(true)
|
2022-04-27 12:13:17 -04:00
|
|
|
resetFetchMock()
|
2022-04-25 07:05:07 -04:00
|
|
|
fetchMock
|
|
|
|
.get('/user/emails?ensureAffiliation=true', [userEmailData])
|
|
|
|
.post('/user/emails', 200)
|
|
|
|
|
|
|
|
const addAnotherEmailBtn = await screen.findByRole('button', {
|
|
|
|
name: /add another email/i,
|
|
|
|
})
|
|
|
|
|
|
|
|
fireEvent.click(addAnotherEmailBtn)
|
|
|
|
const input = screen.getByLabelText(/email/i)
|
|
|
|
|
|
|
|
fireEvent.change(input, {
|
|
|
|
target: { value: userEmailData.email },
|
|
|
|
})
|
|
|
|
|
|
|
|
const submitBtn = screen.getByRole('button', {
|
|
|
|
name: /add new email/i,
|
|
|
|
}) as HTMLButtonElement
|
|
|
|
|
|
|
|
expect(submitBtn.disabled).to.be.false
|
|
|
|
|
|
|
|
fireEvent.click(submitBtn)
|
|
|
|
|
|
|
|
expect(submitBtn.disabled).to.be.true
|
|
|
|
|
|
|
|
await waitForElementToBeRemoved(() =>
|
|
|
|
screen.getByRole('button', {
|
|
|
|
name: /add new email/i,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
screen.getByText(userEmailData.email)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('fails to add add new email address', async function () {
|
|
|
|
fetchMock.get('/user/emails?ensureAffiliation=true', [])
|
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
|
|
await fetchMock.flush(true)
|
2022-04-27 12:13:17 -04:00
|
|
|
resetFetchMock()
|
2022-04-25 07:05:07 -04:00
|
|
|
fetchMock
|
|
|
|
.get('/user/emails?ensureAffiliation=true', [])
|
2022-04-29 07:10:10 -04:00
|
|
|
.post('/user/emails', 400)
|
2022-04-25 07:05:07 -04:00
|
|
|
|
2022-04-27 04:42:48 -04:00
|
|
|
const addAnotherEmailBtn = screen.getByRole('button', {
|
2022-04-25 07:05:07 -04:00
|
|
|
name: /add another email/i,
|
|
|
|
})
|
|
|
|
|
|
|
|
fireEvent.click(addAnotherEmailBtn)
|
|
|
|
const input = screen.getByLabelText(/email/i)
|
|
|
|
|
|
|
|
fireEvent.change(input, {
|
|
|
|
target: { value: userEmailData.email },
|
|
|
|
})
|
|
|
|
|
|
|
|
const submitBtn = screen.getByRole('button', {
|
|
|
|
name: /add new email/i,
|
|
|
|
}) as HTMLButtonElement
|
|
|
|
|
|
|
|
expect(submitBtn.disabled).to.be.false
|
|
|
|
|
|
|
|
fireEvent.click(submitBtn)
|
|
|
|
|
|
|
|
expect(submitBtn.disabled).to.be.true
|
|
|
|
|
|
|
|
await screen.findByText(
|
2022-04-29 07:10:10 -04:00
|
|
|
/Invalid Request. Please correct the data and try again./i
|
2022-04-25 07:05:07 -04:00
|
|
|
)
|
|
|
|
expect(submitBtn).to.not.be.null
|
|
|
|
expect(submitBtn.disabled).to.be.false
|
|
|
|
})
|
2022-04-27 04:42:48 -04:00
|
|
|
|
2022-04-27 12:13:17 -04:00
|
|
|
it('can link email address to an existing SSO institution', async function () {
|
|
|
|
fetchMock.get('/user/emails?ensureAffiliation=true', [])
|
|
|
|
render(<EmailsSection />)
|
|
|
|
|
2022-04-29 07:10:10 -04:00
|
|
|
await fetchMock.flush(true)
|
|
|
|
fetchMock.reset()
|
|
|
|
fetchMock.get('express:/institutions/domains', institutionDomainData)
|
|
|
|
|
2022-04-27 12:13:17 -04:00
|
|
|
await userEvent.click(
|
|
|
|
screen.getByRole('button', {
|
|
|
|
name: /add another email/i,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
const input = screen.getByLabelText(/email/i)
|
|
|
|
fireEvent.change(input, {
|
|
|
|
target: { value: 'user@autocomplete.edu' },
|
|
|
|
})
|
|
|
|
|
2022-05-30 09:47:42 -04:00
|
|
|
await screen.findByRole('button', { name: 'Link Accounts and Add Email' })
|
2022-04-27 12:13:17 -04:00
|
|
|
})
|
|
|
|
|
2022-04-29 07:09:53 -04:00
|
|
|
it('adds new email address with existing institution and custom departments', async function () {
|
2022-04-27 04:42:48 -04:00
|
|
|
const country = 'Germany'
|
2022-04-29 07:09:53 -04:00
|
|
|
const customDepartment = 'Custom department'
|
2022-04-27 04:42:48 -04:00
|
|
|
fetchMock.get('/user/emails?ensureAffiliation=true', [])
|
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
|
|
await fetchMock.flush(true)
|
2022-04-27 12:13:17 -04:00
|
|
|
resetFetchMock()
|
2022-04-27 04:42:48 -04:00
|
|
|
|
|
|
|
await userEvent.click(
|
|
|
|
screen.getByRole('button', {
|
|
|
|
name: /add another email/i,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
await userEvent.type(screen.getByLabelText(/email/i), userEmailData.email)
|
|
|
|
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /let us know/i }))
|
|
|
|
|
|
|
|
const universityInput = screen.getByRole('textbox', {
|
|
|
|
name: /university/i,
|
|
|
|
}) as HTMLInputElement
|
|
|
|
|
|
|
|
expect(universityInput.disabled).to.be.true
|
|
|
|
|
|
|
|
fetchMock.get(/\/institutions\/list/, [
|
|
|
|
{
|
|
|
|
id: userEmailData.affiliation.institution.id,
|
|
|
|
name: userEmailData.affiliation.institution.name,
|
|
|
|
country_code: 'de',
|
2022-04-29 07:09:53 -04:00
|
|
|
departments: [customDepartment],
|
2022-04-27 04:42:48 -04:00
|
|
|
},
|
|
|
|
])
|
|
|
|
|
|
|
|
// Select the country from dropdown
|
|
|
|
await userEvent.type(
|
|
|
|
screen.getByRole('textbox', {
|
|
|
|
name: /country/i,
|
|
|
|
}),
|
|
|
|
country
|
|
|
|
)
|
|
|
|
await userEvent.click(screen.getByText(country))
|
|
|
|
|
|
|
|
expect(universityInput.disabled).to.be.false
|
|
|
|
|
|
|
|
await fetchMock.flush(true)
|
2022-04-27 12:13:17 -04:00
|
|
|
resetFetchMock()
|
2022-04-27 04:42:48 -04:00
|
|
|
|
|
|
|
// Select the university from dropdown
|
|
|
|
await userEvent.click(universityInput)
|
|
|
|
await userEvent.click(
|
|
|
|
screen.getByText(userEmailData.affiliation.institution.name)
|
|
|
|
)
|
|
|
|
|
|
|
|
const roleInput = screen.getByRole('textbox', { name: /role/i })
|
2022-05-31 05:08:49 -04:00
|
|
|
await userEvent.type(roleInput, userEmailData.affiliation.role!)
|
2022-04-27 04:42:48 -04:00
|
|
|
const departmentInput = screen.getByRole('textbox', { name: /department/i })
|
2022-04-29 07:09:53 -04:00
|
|
|
await userEvent.click(departmentInput)
|
|
|
|
await userEvent.click(screen.getByText(customDepartment))
|
|
|
|
|
|
|
|
const userEmailDataCopy = {
|
|
|
|
...userEmailData,
|
|
|
|
affiliation: {
|
|
|
|
...userEmailData.affiliation,
|
|
|
|
department: customDepartment,
|
|
|
|
},
|
|
|
|
}
|
2022-04-27 04:42:48 -04:00
|
|
|
|
|
|
|
fetchMock
|
2022-04-29 07:09:53 -04:00
|
|
|
.get('/user/emails?ensureAffiliation=true', [userEmailDataCopy])
|
2022-04-27 04:42:48 -04:00
|
|
|
.post(/\/user\/emails/, 200)
|
|
|
|
|
|
|
|
await userEvent.click(
|
|
|
|
screen.getByRole('button', {
|
|
|
|
name: /add new email/i,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
const [[, request]] = fetchMock.calls(/\/user\/emails/)
|
|
|
|
|
|
|
|
expect(JSON.parse(request?.body?.toString() || '{}')).to.deep.equal({
|
|
|
|
email: userEmailData.email,
|
|
|
|
university: {
|
|
|
|
id: userEmailData.affiliation?.institution.id,
|
|
|
|
},
|
|
|
|
role: userEmailData.affiliation?.role,
|
2022-04-29 07:09:53 -04:00
|
|
|
department: customDepartment,
|
2022-04-27 04:42:48 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
screen.getByText(userEmailData.email)
|
|
|
|
screen.getByText(userEmailData.affiliation.institution.name)
|
2022-05-31 05:08:49 -04:00
|
|
|
screen.getByText(userEmailData.affiliation.role!, { exact: false })
|
2022-04-29 07:09:53 -04:00
|
|
|
screen.getByText(customDepartment, { exact: false })
|
2022-04-27 04:42:48 -04:00
|
|
|
})
|
|
|
|
|
2022-05-30 06:19:00 -04:00
|
|
|
it('autocompletes institution name', async function () {
|
|
|
|
fetchMock.get('/user/emails?ensureAffiliation=true', [])
|
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
|
|
await fetchMock.flush(true)
|
|
|
|
resetFetchMock()
|
|
|
|
|
|
|
|
fetchMock.get(/\/institutions\/list/, [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
name: 'University of Bonn',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
name: 'Bochum institute of Science',
|
|
|
|
},
|
|
|
|
])
|
|
|
|
|
|
|
|
// open "add new email" section and click "let us know" to open the Country/University form
|
|
|
|
await userEvent.click(
|
|
|
|
screen.getByRole('button', {
|
|
|
|
name: /add another email/i,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
await userEvent.type(screen.getByLabelText(/email/i), userEmailData.email)
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /let us know/i }))
|
|
|
|
|
|
|
|
// select a country
|
|
|
|
const countryInput = screen.getByRole('textbox', {
|
|
|
|
name: /country/i,
|
|
|
|
}) as HTMLInputElement
|
|
|
|
await userEvent.click(countryInput)
|
|
|
|
await userEvent.type(countryInput, 'Germ')
|
|
|
|
await userEvent.click(await screen.findByText('Germany'))
|
|
|
|
|
|
|
|
// match several universities on initial typing
|
|
|
|
const universityInput = screen.getByRole('textbox', {
|
|
|
|
name: /university/i,
|
|
|
|
}) as HTMLInputElement
|
|
|
|
await userEvent.click(universityInput)
|
|
|
|
await userEvent.type(universityInput, 'bo')
|
|
|
|
screen.getByText('University of Bonn')
|
|
|
|
screen.getByText('Bochum institute of Science')
|
|
|
|
|
|
|
|
// match a single university when typing to refine the search
|
|
|
|
await userEvent.type(universityInput, 'nn')
|
|
|
|
screen.getByText('University of Bonn')
|
|
|
|
expect(screen.queryByText('Bochum institute of Science')).to.be.null
|
|
|
|
})
|
|
|
|
|
2022-04-27 04:42:48 -04:00
|
|
|
it('adds new email address without existing institution', async function () {
|
|
|
|
const country = 'Germany'
|
|
|
|
const countryCode = 'de'
|
|
|
|
const newUniversity = 'Abcdef'
|
|
|
|
fetchMock.get('/user/emails?ensureAffiliation=true', [])
|
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
|
|
await fetchMock.flush(true)
|
2022-04-27 12:13:17 -04:00
|
|
|
resetFetchMock()
|
2022-04-27 04:42:48 -04:00
|
|
|
|
|
|
|
await userEvent.click(
|
|
|
|
screen.getByRole('button', {
|
|
|
|
name: /add another email/i,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
await userEvent.type(screen.getByLabelText(/email/i), userEmailData.email)
|
|
|
|
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /let us know/i }))
|
|
|
|
|
|
|
|
const universityInput = screen.getByRole('textbox', {
|
|
|
|
name: /university/i,
|
|
|
|
}) as HTMLInputElement
|
|
|
|
|
|
|
|
expect(universityInput.disabled).to.be.true
|
|
|
|
|
|
|
|
fetchMock.get(/\/institutions\/list/, [
|
|
|
|
{
|
|
|
|
id: userEmailData.affiliation.institution.id,
|
|
|
|
name: userEmailData.affiliation.institution.name,
|
|
|
|
country_code: 'de',
|
|
|
|
departments: [],
|
|
|
|
},
|
|
|
|
])
|
|
|
|
|
|
|
|
// Select the country from dropdown
|
|
|
|
await userEvent.type(
|
|
|
|
screen.getByRole('textbox', {
|
|
|
|
name: /country/i,
|
|
|
|
}),
|
|
|
|
country
|
|
|
|
)
|
|
|
|
await userEvent.click(screen.getByText(country))
|
|
|
|
|
|
|
|
expect(universityInput.disabled).to.be.false
|
|
|
|
|
|
|
|
await fetchMock.flush(true)
|
2022-04-27 12:13:17 -04:00
|
|
|
resetFetchMock()
|
2022-04-27 04:42:48 -04:00
|
|
|
|
|
|
|
// Enter the university manually
|
|
|
|
await userEvent.type(universityInput, newUniversity)
|
|
|
|
|
|
|
|
const roleInput = screen.getByRole('textbox', { name: /role/i })
|
2022-05-31 05:08:49 -04:00
|
|
|
await userEvent.type(roleInput, userEmailData.affiliation.role!)
|
2022-04-27 04:42:48 -04:00
|
|
|
const departmentInput = screen.getByRole('textbox', { name: /department/i })
|
2022-05-31 05:08:49 -04:00
|
|
|
await userEvent.type(departmentInput, userEmailData.affiliation.department!)
|
2022-04-27 04:42:48 -04:00
|
|
|
|
|
|
|
const userEmailDataCopy = {
|
|
|
|
...userEmailData,
|
|
|
|
affiliation: {
|
|
|
|
...userEmailData.affiliation,
|
|
|
|
institution: {
|
|
|
|
...userEmailData.affiliation.institution,
|
|
|
|
name: newUniversity,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchMock
|
|
|
|
.get('/user/emails?ensureAffiliation=true', [userEmailDataCopy])
|
|
|
|
.post(/\/user\/emails/, 200)
|
|
|
|
|
|
|
|
await userEvent.click(
|
|
|
|
screen.getByRole('button', {
|
|
|
|
name: /add new email/i,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
const [[, request]] = fetchMock.calls(/\/user\/emails/)
|
|
|
|
|
|
|
|
expect(JSON.parse(request?.body?.toString() || '{}')).to.deep.equal({
|
|
|
|
email: userEmailData.email,
|
|
|
|
university: {
|
|
|
|
name: newUniversity,
|
|
|
|
country_code: countryCode,
|
|
|
|
},
|
|
|
|
role: userEmailData.affiliation?.role,
|
|
|
|
department: userEmailData.affiliation?.department,
|
|
|
|
})
|
|
|
|
|
|
|
|
screen.getByText(userEmailData.email)
|
|
|
|
screen.getByText(newUniversity)
|
2022-05-31 05:08:49 -04:00
|
|
|
screen.getByText(userEmailData.affiliation.role!, { exact: false })
|
|
|
|
screen.getByText(userEmailData.affiliation.department!, { exact: false })
|
2022-04-27 04:42:48 -04:00
|
|
|
})
|
2022-05-16 04:03:04 -04:00
|
|
|
|
|
|
|
it('shows country, university, role and department fields based on whether `change` was clicked or not', async function () {
|
|
|
|
const institutionDomainDataCopy = [
|
|
|
|
{
|
|
|
|
...institutionDomainData[0],
|
|
|
|
university: {
|
|
|
|
...institutionDomainData[0].university,
|
|
|
|
ssoEnabled: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
const hostnameFirstChar = institutionDomainDataCopy[0].hostname.charAt(0)
|
|
|
|
fetchMock.get('/user/emails?ensureAffiliation=true', [])
|
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
|
|
await fetchMock.flush(true)
|
|
|
|
fetchMock.reset()
|
|
|
|
fetchMock.get(
|
|
|
|
`/institutions/domains?hostname=${hostnameFirstChar}&limit=1`,
|
|
|
|
institutionDomainDataCopy
|
|
|
|
)
|
|
|
|
|
|
|
|
await userEvent.click(
|
|
|
|
screen.getByRole('button', {
|
|
|
|
name: /add another email/i,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
await userEvent.type(
|
|
|
|
screen.getByLabelText(/email/i),
|
|
|
|
`user@${hostnameFirstChar}`
|
|
|
|
)
|
|
|
|
|
|
|
|
await userEvent.keyboard('{Tab}')
|
|
|
|
await fetchMock.flush(true)
|
|
|
|
fetchMock.reset()
|
|
|
|
|
|
|
|
expect(
|
|
|
|
screen.queryByRole('textbox', {
|
|
|
|
name: /country/i,
|
|
|
|
})
|
|
|
|
).to.be.null
|
|
|
|
expect(
|
|
|
|
screen.queryByRole('textbox', {
|
|
|
|
name: /university/i,
|
|
|
|
})
|
|
|
|
).to.be.null
|
|
|
|
screen.getByRole('textbox', {
|
|
|
|
name: /role/i,
|
|
|
|
})
|
|
|
|
screen.getByRole('textbox', {
|
|
|
|
name: /department/i,
|
|
|
|
})
|
|
|
|
|
|
|
|
await userEvent.click(screen.getByRole('button', { name: /change/i }))
|
|
|
|
|
|
|
|
screen.getByRole('textbox', {
|
|
|
|
name: /country/i,
|
|
|
|
})
|
|
|
|
screen.getByRole('textbox', {
|
|
|
|
name: /university/i,
|
|
|
|
})
|
|
|
|
expect(
|
|
|
|
screen.queryByRole('textbox', {
|
|
|
|
name: /role/i,
|
|
|
|
})
|
|
|
|
).to.be.null
|
|
|
|
expect(
|
|
|
|
screen.queryByRole('textbox', {
|
|
|
|
name: /department/i,
|
|
|
|
})
|
|
|
|
).to.be.null
|
|
|
|
})
|
|
|
|
|
|
|
|
it('displays institution name with change button when autocompleted and adds new record', async function () {
|
|
|
|
const institutionDomainDataCopy = [
|
|
|
|
{
|
|
|
|
...institutionDomainData[0],
|
|
|
|
university: {
|
|
|
|
...institutionDomainData[0].university,
|
|
|
|
ssoEnabled: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
const hostnameFirstChar = institutionDomainDataCopy[0].hostname.charAt(0)
|
|
|
|
fetchMock.get('/user/emails?ensureAffiliation=true', [])
|
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
|
|
await fetchMock.flush(true)
|
|
|
|
fetchMock.reset()
|
|
|
|
fetchMock.get(
|
|
|
|
`/institutions/domains?hostname=${hostnameFirstChar}&limit=1`,
|
|
|
|
institutionDomainDataCopy
|
|
|
|
)
|
|
|
|
|
|
|
|
await userEvent.click(
|
|
|
|
screen.getByRole('button', {
|
|
|
|
name: /add another email/i,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
await userEvent.type(
|
|
|
|
screen.getByLabelText(/email/i),
|
|
|
|
`user@${hostnameFirstChar}`
|
|
|
|
)
|
|
|
|
|
|
|
|
await userEvent.keyboard('{Tab}')
|
|
|
|
await fetchMock.flush(true)
|
|
|
|
fetchMock.reset()
|
|
|
|
|
|
|
|
screen.getByText(institutionDomainDataCopy[0].university.name)
|
|
|
|
|
|
|
|
const userEmailDataCopy = {
|
|
|
|
...userEmailData,
|
|
|
|
affiliation: {
|
|
|
|
...userEmailData.affiliation,
|
|
|
|
institution: {
|
|
|
|
...userEmailData.affiliation.institution,
|
|
|
|
name: institutionDomainDataCopy[0].university.name,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchMock
|
|
|
|
.get('/user/emails?ensureAffiliation=true', [userEmailDataCopy])
|
|
|
|
.post('/user/emails', 200)
|
|
|
|
|
|
|
|
await userEvent.type(
|
|
|
|
screen.getByRole('textbox', { name: /role/i }),
|
2022-05-31 05:08:49 -04:00
|
|
|
userEmailData.affiliation.role!
|
2022-05-16 04:03:04 -04:00
|
|
|
)
|
|
|
|
await userEvent.type(
|
|
|
|
screen.getByRole('textbox', { name: /department/i }),
|
2022-05-31 05:08:49 -04:00
|
|
|
userEmailData.affiliation.department!
|
2022-05-16 04:03:04 -04:00
|
|
|
)
|
|
|
|
await userEvent.click(
|
|
|
|
screen.getByRole('button', {
|
|
|
|
name: /add new email/i,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
await fetchMock.flush(true)
|
|
|
|
fetchMock.reset()
|
|
|
|
|
|
|
|
screen.getByText(userEmailDataCopy.affiliation.institution.name, {
|
|
|
|
exact: false,
|
|
|
|
})
|
2022-05-31 05:08:49 -04:00
|
|
|
screen.getByText(userEmailDataCopy.affiliation.role!, { exact: false })
|
|
|
|
screen.getByText(userEmailDataCopy.affiliation.department!, {
|
|
|
|
exact: false,
|
|
|
|
})
|
2022-05-16 04:03:04 -04:00
|
|
|
})
|
2022-04-25 07:05:07 -04:00
|
|
|
})
|