|
|
@@ -63,17 +63,16 @@ function resetFetchMock() {
|
|
|
}
|
|
|
|
|
|
async function confirmCodeForEmail(email: string) {
|
|
|
- await screen.findByText(
|
|
|
- `Enter the 6-digit confirmation code sent to ${email}.`
|
|
|
- )
|
|
|
- const inputCode = screen.getByLabelText(/6-digit confirmation code/i)
|
|
|
+ const inputCode = await screen.findByRole('textbox', {
|
|
|
+ name: `Enter the 6-digit confirmation code sent to ${email}.`,
|
|
|
+ })
|
|
|
fireEvent.change(inputCode, { target: { value: '123456' } })
|
|
|
const submitCodeBtn = screen.getByRole<HTMLButtonElement>('button', {
|
|
|
name: 'Confirm',
|
|
|
})
|
|
|
fireEvent.click(submitCodeBtn)
|
|
|
await waitForElementToBeRemoved(() =>
|
|
|
- screen.getByRole('button', { name: /confirming/i })
|
|
|
+ screen.getByRole('button', { name: 'Confirming' })
|
|
|
)
|
|
|
}
|
|
|
|
|
|
@@ -96,7 +95,7 @@ describe('<EmailsSection />', function () {
|
|
|
fetchMock.get('/user/emails?ensureAffiliation=true', [])
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
- await screen.findByRole('button', { name: /add another email/i })
|
|
|
+ await screen.findByRole('button', { name: 'Add another email' })
|
|
|
})
|
|
|
|
|
|
it('renders input', async function () {
|
|
|
@@ -105,11 +104,11 @@ describe('<EmailsSection />', function () {
|
|
|
await fetchMock.callHistory.flush(true)
|
|
|
|
|
|
const button = await screen.findByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add another email/i,
|
|
|
+ name: 'Add another email',
|
|
|
})
|
|
|
fireEvent.click(button)
|
|
|
|
|
|
- await screen.findByLabelText(/email/i, { selector: 'input' })
|
|
|
+ await screen.findByRole('textbox', { name: 'Email' })
|
|
|
})
|
|
|
|
|
|
it('renders "Start adding your address" until a valid email is typed', async function () {
|
|
|
@@ -120,17 +119,17 @@ describe('<EmailsSection />', function () {
|
|
|
await fetchMock.callHistory.flush(true)
|
|
|
|
|
|
const button = await screen.findByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add another email/i,
|
|
|
+ name: 'Add another email',
|
|
|
})
|
|
|
fireEvent.click(button)
|
|
|
|
|
|
- const input = screen.getByLabelText(/email/i, { selector: 'input' })
|
|
|
+ const input = screen.getByRole('textbox', { name: 'Email' })
|
|
|
|
|
|
// initially the text is displayed and the "add email" button disabled
|
|
|
screen.getByText('Start by adding your email address.')
|
|
|
expect(
|
|
|
screen.getByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add new email/i,
|
|
|
+ name: 'Add new email',
|
|
|
}).disabled
|
|
|
).to.be.true
|
|
|
|
|
|
@@ -141,7 +140,7 @@ describe('<EmailsSection />', function () {
|
|
|
screen.getByText('Start by adding your email address.')
|
|
|
expect(
|
|
|
screen.getByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add new email/i,
|
|
|
+ name: 'Add new email',
|
|
|
}).disabled
|
|
|
).to.be.true
|
|
|
|
|
|
@@ -152,7 +151,7 @@ describe('<EmailsSection />', function () {
|
|
|
expect(screen.queryByText('Start by adding your email address.')).to.be.null
|
|
|
expect(
|
|
|
screen.getByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add new email/i,
|
|
|
+ name: 'Add new email',
|
|
|
}).disabled
|
|
|
).to.be.false
|
|
|
})
|
|
|
@@ -162,11 +161,11 @@ describe('<EmailsSection />', function () {
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
const button = await screen.findByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add another email/i,
|
|
|
+ name: 'Add another email',
|
|
|
})
|
|
|
fireEvent.click(button)
|
|
|
|
|
|
- screen.getByRole('button', { name: /add new email/i })
|
|
|
+ screen.getByRole('button', { name: 'Add new email' })
|
|
|
})
|
|
|
|
|
|
it('prevent users from adding new emails when the limit is reached', async function () {
|
|
|
@@ -182,7 +181,7 @@ describe('<EmailsSection />', function () {
|
|
|
'You can have a maximum of 10 email addresses on this account. To add another email address, please delete an existing one.'
|
|
|
)
|
|
|
|
|
|
- expect(screen.queryByRole('button', { name: /add another email/i })).to.not
|
|
|
+ expect(screen.queryByRole('button', { name: 'Add another email' })).to.not
|
|
|
.exist
|
|
|
})
|
|
|
|
|
|
@@ -192,7 +191,7 @@ describe('<EmailsSection />', function () {
|
|
|
|
|
|
const addAnotherEmailBtn = await screen.findByRole<HTMLButtonElement>(
|
|
|
'button',
|
|
|
- { name: /add another email/i }
|
|
|
+ { name: 'Add another email' }
|
|
|
)
|
|
|
|
|
|
await fetchMock.callHistory.flush(true)
|
|
|
@@ -203,14 +202,14 @@ describe('<EmailsSection />', function () {
|
|
|
.post('/user/emails/confirm-secondary', 200)
|
|
|
|
|
|
fireEvent.click(addAnotherEmailBtn)
|
|
|
- const input = screen.getByLabelText(/email/i, { selector: 'input' })
|
|
|
+ const input = screen.getByRole('textbox', { name: 'Email' })
|
|
|
|
|
|
fireEvent.change(input, {
|
|
|
target: { value: userEmailData.email },
|
|
|
})
|
|
|
|
|
|
const submitBtn = screen.getByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add new email/i,
|
|
|
+ name: 'Add new email',
|
|
|
})
|
|
|
|
|
|
expect(submitBtn.disabled).to.be.false
|
|
|
@@ -221,7 +220,7 @@ describe('<EmailsSection />', function () {
|
|
|
|
|
|
await waitForElementToBeRemoved(() =>
|
|
|
screen.getByRole('button', {
|
|
|
- name: /Loading/i,
|
|
|
+ name: 'Loading',
|
|
|
})
|
|
|
)
|
|
|
|
|
|
@@ -235,7 +234,7 @@ describe('<EmailsSection />', function () {
|
|
|
|
|
|
const addAnotherEmailBtn = await screen.findByRole<HTMLButtonElement>(
|
|
|
'button',
|
|
|
- { name: /add another email/i }
|
|
|
+ { name: 'Add another email' }
|
|
|
)
|
|
|
|
|
|
await fetchMock.callHistory.flush(true)
|
|
|
@@ -245,14 +244,14 @@ describe('<EmailsSection />', function () {
|
|
|
.post('/user/emails/secondary', 400)
|
|
|
|
|
|
fireEvent.click(addAnotherEmailBtn)
|
|
|
- const input = screen.getByLabelText(/email/i, { selector: 'input' })
|
|
|
+ const input = screen.getByRole('textbox', { name: 'Email' })
|
|
|
|
|
|
fireEvent.change(input, {
|
|
|
target: { value: userEmailData.email },
|
|
|
})
|
|
|
|
|
|
const submitBtn = screen.getByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add new email/i,
|
|
|
+ name: 'Add new email',
|
|
|
})
|
|
|
|
|
|
expect(submitBtn.disabled).to.be.false
|
|
|
@@ -262,7 +261,7 @@ describe('<EmailsSection />', function () {
|
|
|
expect(submitBtn.disabled).to.be.true
|
|
|
|
|
|
await screen.findByText(
|
|
|
- /Invalid Request. Please correct the data and try again./i
|
|
|
+ 'Invalid Request. Please correct the data and try again.'
|
|
|
)
|
|
|
expect(submitBtn).to.not.be.null
|
|
|
expect(submitBtn.disabled).to.be.false
|
|
|
@@ -273,7 +272,7 @@ describe('<EmailsSection />', function () {
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
const button = await screen.findByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add another email/i,
|
|
|
+ name: 'Add another email',
|
|
|
})
|
|
|
|
|
|
await fetchMock.callHistory.flush(true)
|
|
|
@@ -282,7 +281,7 @@ describe('<EmailsSection />', function () {
|
|
|
|
|
|
await userEvent.click(button)
|
|
|
|
|
|
- const input = screen.getByLabelText(/email/i, { selector: 'input' })
|
|
|
+ const input = screen.getByRole('textbox', { name: 'Email' })
|
|
|
fireEvent.change(input, {
|
|
|
target: { value: 'user@autocomplete.edu' },
|
|
|
})
|
|
|
@@ -297,7 +296,7 @@ describe('<EmailsSection />', function () {
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
const button = await screen.findByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add another email/i,
|
|
|
+ name: 'Add another email',
|
|
|
})
|
|
|
|
|
|
await fetchMock.callHistory.flush(true)
|
|
|
@@ -306,14 +305,14 @@ describe('<EmailsSection />', function () {
|
|
|
await userEvent.click(button)
|
|
|
|
|
|
await userEvent.type(
|
|
|
- screen.getByLabelText(/email/i, { selector: 'input' }),
|
|
|
+ screen.getByRole('textbox', { name: 'Email' }),
|
|
|
userEmailData.email
|
|
|
)
|
|
|
|
|
|
- await userEvent.click(screen.getByRole('button', { name: /let us know/i }))
|
|
|
+ await userEvent.click(screen.getByRole('button', { name: 'Let us know' }))
|
|
|
|
|
|
const universityInput = screen.getByRole<HTMLInputElement>('combobox', {
|
|
|
- name: /university/i,
|
|
|
+ name: 'University',
|
|
|
})
|
|
|
|
|
|
expect(universityInput.disabled).to.be.true
|
|
|
@@ -330,7 +329,7 @@ describe('<EmailsSection />', function () {
|
|
|
// Select the country from dropdown
|
|
|
await userEvent.type(
|
|
|
screen.getByRole('combobox', {
|
|
|
- name: /country/i,
|
|
|
+ name: 'Country',
|
|
|
}),
|
|
|
country
|
|
|
)
|
|
|
@@ -347,10 +346,10 @@ describe('<EmailsSection />', function () {
|
|
|
await screen.findByText(userEmailData.affiliation.institution.name)
|
|
|
)
|
|
|
|
|
|
- const roleInput = screen.getByRole('combobox', { name: /role/i })
|
|
|
+ const roleInput = screen.getByRole('combobox', { name: 'Role' })
|
|
|
await userEvent.type(roleInput, userEmailData.affiliation.role!)
|
|
|
const departmentInput = screen.getByRole('combobox', {
|
|
|
- name: /department/i,
|
|
|
+ name: 'Department',
|
|
|
})
|
|
|
await userEvent.click(departmentInput)
|
|
|
await userEvent.click(screen.getByText(customDepartment))
|
|
|
@@ -370,7 +369,7 @@ describe('<EmailsSection />', function () {
|
|
|
|
|
|
await userEvent.click(
|
|
|
screen.getByRole('button', {
|
|
|
- name: /add new email/i,
|
|
|
+ name: 'Add new email',
|
|
|
})
|
|
|
)
|
|
|
|
|
|
@@ -402,7 +401,7 @@ describe('<EmailsSection />', function () {
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
const button = await screen.findByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add another email/i,
|
|
|
+ name: 'Add another email',
|
|
|
})
|
|
|
|
|
|
await fetchMock.callHistory.flush(true)
|
|
|
@@ -422,14 +421,14 @@ describe('<EmailsSection />', function () {
|
|
|
// open "add new email" section and click "let us know" to open the Country/University form
|
|
|
await userEvent.click(button)
|
|
|
await userEvent.type(
|
|
|
- screen.getByLabelText(/email/i, { selector: 'input' }),
|
|
|
+ screen.getByRole('textbox', { name: 'Email' }),
|
|
|
userEmailData.email
|
|
|
)
|
|
|
- await userEvent.click(screen.getByRole('button', { name: /let us know/i }))
|
|
|
+ await userEvent.click(screen.getByRole('button', { name: 'Let us know' }))
|
|
|
|
|
|
// select a country
|
|
|
const countryInput = screen.getByRole<HTMLInputElement>('combobox', {
|
|
|
- name: /country/i,
|
|
|
+ name: 'Country',
|
|
|
})
|
|
|
await userEvent.click(countryInput)
|
|
|
await userEvent.type(countryInput, 'Germ')
|
|
|
@@ -437,7 +436,7 @@ describe('<EmailsSection />', function () {
|
|
|
|
|
|
// match several universities on initial typing
|
|
|
const universityInput = screen.getByRole<HTMLInputElement>('combobox', {
|
|
|
- name: /university/i,
|
|
|
+ name: 'University',
|
|
|
})
|
|
|
await userEvent.click(universityInput)
|
|
|
await userEvent.type(universityInput, 'bo')
|
|
|
@@ -458,7 +457,7 @@ describe('<EmailsSection />', function () {
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
const button = await screen.findByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add another email/i,
|
|
|
+ name: 'Add another email',
|
|
|
})
|
|
|
|
|
|
await fetchMock.callHistory.flush(true)
|
|
|
@@ -467,14 +466,14 @@ describe('<EmailsSection />', function () {
|
|
|
await userEvent.click(button)
|
|
|
|
|
|
await userEvent.type(
|
|
|
- screen.getByLabelText(/email/i, { selector: 'input' }),
|
|
|
+ screen.getByRole('textbox', { name: 'Email' }),
|
|
|
userEmailData.email
|
|
|
)
|
|
|
|
|
|
- await userEvent.click(screen.getByRole('button', { name: /let us know/i }))
|
|
|
+ await userEvent.click(screen.getByRole('button', { name: 'Let us know' }))
|
|
|
|
|
|
const universityInput = screen.getByRole<HTMLInputElement>('combobox', {
|
|
|
- name: /university/i,
|
|
|
+ name: 'University',
|
|
|
})
|
|
|
|
|
|
expect(universityInput.disabled).to.be.true
|
|
|
@@ -491,7 +490,7 @@ describe('<EmailsSection />', function () {
|
|
|
// Select the country from dropdown
|
|
|
await userEvent.type(
|
|
|
screen.getByRole('combobox', {
|
|
|
- name: /country/i,
|
|
|
+ name: 'Country',
|
|
|
}),
|
|
|
country
|
|
|
)
|
|
|
@@ -505,10 +504,10 @@ describe('<EmailsSection />', function () {
|
|
|
// Enter the university manually
|
|
|
await userEvent.type(universityInput, newUniversity)
|
|
|
|
|
|
- const roleInput = screen.getByRole('combobox', { name: /role/i })
|
|
|
+ const roleInput = screen.getByRole('combobox', { name: 'Role' })
|
|
|
await userEvent.type(roleInput, userEmailData.affiliation.role!)
|
|
|
const departmentInput = screen.getByRole('combobox', {
|
|
|
- name: /department/i,
|
|
|
+ name: 'Department',
|
|
|
})
|
|
|
await userEvent.type(departmentInput, userEmailData.affiliation.department!)
|
|
|
|
|
|
@@ -530,7 +529,7 @@ describe('<EmailsSection />', function () {
|
|
|
|
|
|
await userEvent.click(
|
|
|
screen.getByRole('button', {
|
|
|
- name: /add new email/i,
|
|
|
+ name: 'Add new email',
|
|
|
})
|
|
|
)
|
|
|
|
|
|
@@ -573,7 +572,7 @@ describe('<EmailsSection />', function () {
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
const button = await screen.findByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add another email/i,
|
|
|
+ name: 'Add another email',
|
|
|
})
|
|
|
|
|
|
await fetchMock.callHistory.flush(true)
|
|
|
@@ -586,7 +585,7 @@ describe('<EmailsSection />', function () {
|
|
|
await userEvent.click(button)
|
|
|
|
|
|
await userEvent.type(
|
|
|
- screen.getByLabelText(/email/i, { selector: 'input' }),
|
|
|
+ screen.getByRole('textbox', { name: 'Email' }),
|
|
|
`user@${hostnameFirstChar}`
|
|
|
)
|
|
|
|
|
|
@@ -596,37 +595,37 @@ describe('<EmailsSection />', function () {
|
|
|
|
|
|
expect(
|
|
|
screen.queryByRole('combobox', {
|
|
|
- name: /country/i,
|
|
|
+ name: 'Country',
|
|
|
})
|
|
|
).to.be.null
|
|
|
expect(
|
|
|
screen.queryByRole('combobox', {
|
|
|
- name: /university/i,
|
|
|
+ name: 'University',
|
|
|
})
|
|
|
).to.be.null
|
|
|
screen.getByRole('combobox', {
|
|
|
- name: /role/i,
|
|
|
+ name: 'Role',
|
|
|
})
|
|
|
screen.getByRole('combobox', {
|
|
|
- name: /department/i,
|
|
|
+ name: 'Department',
|
|
|
})
|
|
|
|
|
|
- await userEvent.click(screen.getByRole('button', { name: /change/i }))
|
|
|
+ await userEvent.click(screen.getByRole('button', { name: 'Change' }))
|
|
|
|
|
|
screen.getByRole('combobox', {
|
|
|
- name: /country/i,
|
|
|
+ name: 'Country',
|
|
|
})
|
|
|
screen.getByRole('combobox', {
|
|
|
- name: /university/i,
|
|
|
+ name: 'University',
|
|
|
})
|
|
|
expect(
|
|
|
screen.queryByRole('combobox', {
|
|
|
- name: /role/i,
|
|
|
+ name: 'Role',
|
|
|
})
|
|
|
).to.be.null
|
|
|
expect(
|
|
|
screen.queryByRole('combobox', {
|
|
|
- name: /department/i,
|
|
|
+ name: 'Department',
|
|
|
})
|
|
|
).to.be.null
|
|
|
})
|
|
|
@@ -646,7 +645,7 @@ describe('<EmailsSection />', function () {
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
const button = await screen.findByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add another email/i,
|
|
|
+ name: 'Add another email',
|
|
|
})
|
|
|
|
|
|
await fetchMock.callHistory.flush(true)
|
|
|
@@ -659,7 +658,7 @@ describe('<EmailsSection />', function () {
|
|
|
await userEvent.click(button)
|
|
|
|
|
|
await userEvent.type(
|
|
|
- screen.getByLabelText(/email/i, { selector: 'input' }),
|
|
|
+ screen.getByRole('textbox', { name: 'Email' }),
|
|
|
`user@${hostnameFirstChar}`
|
|
|
)
|
|
|
|
|
|
@@ -686,16 +685,16 @@ describe('<EmailsSection />', function () {
|
|
|
.post('/user/emails/confirm-secondary', 200)
|
|
|
|
|
|
await userEvent.type(
|
|
|
- screen.getByRole('combobox', { name: /role/i }),
|
|
|
+ screen.getByRole('combobox', { name: 'Role' }),
|
|
|
userEmailData.affiliation.role!
|
|
|
)
|
|
|
await userEvent.type(
|
|
|
- screen.getByRole('combobox', { name: /department/i }),
|
|
|
+ screen.getByRole('combobox', { name: 'Department' }),
|
|
|
userEmailData.affiliation.department!
|
|
|
)
|
|
|
await userEvent.click(
|
|
|
screen.getByRole('button', {
|
|
|
- name: /add new email/i,
|
|
|
+ name: 'Add new email',
|
|
|
})
|
|
|
)
|
|
|
|
|
|
@@ -743,12 +742,12 @@ describe('<EmailsSection />', function () {
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
const button = await screen.findByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add another email/i,
|
|
|
+ name: 'Add another email',
|
|
|
})
|
|
|
|
|
|
await userEvent.click(button)
|
|
|
|
|
|
- const input = screen.getByLabelText(/email/i, { selector: 'input' })
|
|
|
+ const input = screen.getByRole('textbox', { name: 'Email' })
|
|
|
fireEvent.change(input, {
|
|
|
target: { value: 'user@autocomplete.edu' },
|
|
|
})
|
|
|
@@ -786,12 +785,12 @@ describe('<EmailsSection />', function () {
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
const button = await screen.findByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add another email/i,
|
|
|
+ name: 'Add another email',
|
|
|
})
|
|
|
|
|
|
await userEvent.click(button)
|
|
|
|
|
|
- const input = screen.getByLabelText(/email/i, { selector: 'input' })
|
|
|
+ const input = screen.getByRole('textbox', { name: 'Email' })
|
|
|
fireEvent.change(input, {
|
|
|
target: { value: 'user@autocomplete.edu' },
|
|
|
})
|
|
|
@@ -833,12 +832,12 @@ describe('<EmailsSection />', function () {
|
|
|
render(<EmailsSection />)
|
|
|
|
|
|
const button = await screen.findByRole<HTMLButtonElement>('button', {
|
|
|
- name: /add another email/i,
|
|
|
+ name: 'Add another email',
|
|
|
})
|
|
|
|
|
|
await userEvent.click(button)
|
|
|
|
|
|
- const input = screen.getByLabelText(/email/i, { selector: 'input' })
|
|
|
+ const input = screen.getByRole('textbox', { name: 'Email' })
|
|
|
fireEvent.change(input, {
|
|
|
target: { value: 'user@autocomplete.edu' },
|
|
|
})
|