Skip to content

Commit

Permalink
Fix: racey user account page tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorreem committed Aug 27, 2024
1 parent e81f27f commit dead5f3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions components/forms/EmailRemindersSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ const EmailRemindersSettingsForm = () => {
{showUpdateLaterMessage && <Typography variant="body2">{t('update')}</Typography>}

<LoadingButton
qa-id="email-reminders-settings-submit"
sx={{ mt: 3 }}
variant="contained"
fullWidth
Expand Down
29 changes: 23 additions & 6 deletions cypress/integration/tests/user-account-settings.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,30 @@ describe('User account settings page', () => {
});

it('Should have email reminder frequency form and load user data', () => {
const settingsIndexMap = {
TWO_WEEKS: 0,
ONE_MONTH: 1,
TWO_MONTHS: 2,
NEVER: 3,
};

cy.visit('/account/settings');
cy.get('input[name="email-reminders-settings"]', { timeout: 8000 }).eq(1).check();
cy.get('button[type="submit"]').contains('Save email reminders').click();
cy.get('input[name="email-reminders-settings"]', { timeout: 8000 }).eq(1).should('be.checked');
// Reset the value to 'never' so the test works on next run
cy.get('input[name="email-reminders-settings"]').eq(3).check();
cy.get('button[type="submit"]').contains('Save email reminders').click();
// Get currently set value
cy.get('input[name="email-reminders-settings"]:checked').then((item) => {
const currentValue: string = item.val().toString();
// Find the new value to be checked based on whats currently checked so tests don't fail if
// the default settings are changed
const newIndex = Object.values(settingsIndexMap).find((value) => {
return settingsIndexMap[currentValue] !== value;
});
cy.get('h2').contains('Email reminders').should('exist');
cy.get(`input[name="email-reminders-settings"]`).eq(newIndex).check();
cy.get('[qa-id="email-reminders-settings-submit"]', { timeout: 20000 })
.contains('Save email reminders')
.should('not.be.disabled')
.click();
cy.get('input[name="email-reminders-settings"]').eq(newIndex).should('be.checked');
});
});

after(() => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/tests/user-update-email.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('User account settings page', () => {

it('Should successfully update name', () => {
cy.visit('/account/settings');
cy.get('#name', { timeout: 10000 }).clear().type('Updated name');
cy.get('#name', { timeout: 15000 }).clear().type('Updated name');
cy.get('#profile-settings-submit', { timeout: 10000 }).click();
cy.get(`[data-testid='CheckCircleOutlinedIcon']`, { timeout: 10000 }).should('be.visible');
});
Expand Down

0 comments on commit dead5f3

Please sign in to comment.