|
|
@@ -163,4 +163,56 @@ describe('<EmailsSection />', function () {
|
|
|
screen.getByText(/sorry, something went wrong/i)
|
|
|
screen.getByRole('button', { name: /resend confirmation code/i })
|
|
|
})
|
|
|
+
|
|
|
+ it('sorts emails with primary first, then confirmed, then unconfirmed', async function () {
|
|
|
+ const unconfirmedEmail = { ...unconfirmedUserData, email: 'b@example.com' }
|
|
|
+ const unconfirmedEmailTwo = {
|
|
|
+ ...unconfirmedUserData,
|
|
|
+ email: 'd@example.com',
|
|
|
+ }
|
|
|
+ const confirmedEmail = {
|
|
|
+ ...confirmedUserData,
|
|
|
+ email: 'a@example.com',
|
|
|
+ confirmedAt: new Date().toISOString(),
|
|
|
+ }
|
|
|
+ const confirmedEmailTwo = {
|
|
|
+ ...confirmedUserData,
|
|
|
+ email: 'e@example.com',
|
|
|
+ confirmedAt: new Date().toISOString(),
|
|
|
+ }
|
|
|
+ const primaryEmail = {
|
|
|
+ ...professionalUserData,
|
|
|
+ email: 'c@example.com',
|
|
|
+ default: true,
|
|
|
+ }
|
|
|
+
|
|
|
+ const emails = [
|
|
|
+ confirmedEmailTwo,
|
|
|
+ unconfirmedEmailTwo,
|
|
|
+ unconfirmedEmail,
|
|
|
+ confirmedEmail,
|
|
|
+ primaryEmail,
|
|
|
+ ]
|
|
|
+
|
|
|
+ fetchMock.get('/user/emails?ensureAffiliation=true', emails)
|
|
|
+ render(<EmailsSection />)
|
|
|
+
|
|
|
+ await waitForElementToBeRemoved(() => screen.getByText(/loading/i))
|
|
|
+
|
|
|
+ const emailElements = screen.getAllByTestId(/email-row/i)
|
|
|
+
|
|
|
+ // Primary should be first regardless of alphabetical order
|
|
|
+ expect(within(emailElements[0]).getByText('c@example.com')).to.exist
|
|
|
+ expect(within(emailElements[0]).getByText('Primary')).to.exist
|
|
|
+
|
|
|
+ // Confirmed should be second in alphabetical order
|
|
|
+ expect(within(emailElements[1]).getByText('a@example.com')).to.exist
|
|
|
+ expect(within(emailElements[2]).getByText('e@example.com')).to.exist
|
|
|
+
|
|
|
+ // Unconfirmed should be last in alphabetical order
|
|
|
+ expect(within(emailElements[3]).getByText('b@example.com')).to.exist
|
|
|
+ expect(within(emailElements[3]).getByText(/unconfirmed/i)).to.exist
|
|
|
+ expect(within(emailElements[4]).getByText('d@example.com')).to.exist
|
|
|
+ expect(within(emailElements[4]).getByText(/unconfirmed/i)).to.exist
|
|
|
+ })
|
|
|
})
|