Skip to content

Commit

Permalink
fix: flaky cypress tests to use data-cy
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael Kabo committed Jul 17, 2024
1 parent a5f8581 commit 21c69fe
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions client/components/mma/identity/MarketingCheckbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const MarketingCheckbox: FC<MarketingCheckboxProps> = (props) => {
const { id, description, selected, title, onClick } = props;
return (
<div
data-cy={id}
onClick={(e) => {
// Checkboxes inside labels will trigger click events twice.
// Ignore the input click event
Expand Down
1 change: 1 addition & 0 deletions client/components/mma/identity/MarketingToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const MarketingToggle: FC<MarketingToggleProps> = (props) => {
const { id, description, selected, title, onClick } = props;
return (
<div
data-cy={id}
css={[
standardSansText,
props.divCss ??
Expand Down
1 change: 1 addition & 0 deletions client/components/mma/identity/NewsletterPreference.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const NewsletterPreference: FC<NewsletterPreferenceProps> = (props) => {
} = props;
return (
<div
data-cy={id}
onClick={(e) => {
// Checkboxes inside labels will trigger click events twice.
// Ignore the input click event
Expand Down
2 changes: 1 addition & 1 deletion client/fixtures/consents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const consents = [
isOptOut: false,
isChannel: false,
isProduct: false,
name: 'Guardian products and support',
name: 'Similar Guardian products',
description:
'Information on our products and ways to support and enjoy our independent journalism.',
},
Expand Down
4 changes: 2 additions & 2 deletions cypress/tests/e2e/e2e.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ describe('E2E with Okta', () => {
context('emails tab', () => {
it('should allow the user to update their email preferences', () => {
cy.visit('/email-prefs');
cy.findByText('Guardian products and support').click();
cy.get('[data-cy="similar_guardian_products"]').click();
cy.visit('/email-prefs');
cy.findByText('Guardian products and support')
cy.get('[data-cy="similar_guardian_products"]')
.parents('div')
.get('input[type="checkbox"]')
.should('be.checked');
Expand Down
4 changes: 2 additions & 2 deletions cypress/tests/mocked/parallel-6/emailAndMarketing.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('Email and Marketing page', () => {
cy.wait('@consents');
cy.wait('@reminders');

cy.findByText('Guardian products and support');
cy.get('[data-cy="similar_guardian_products"]');
cy.findByText('Your subscription/support');
cy.findByText('Supporter newsletter');
});
Expand All @@ -90,7 +90,7 @@ describe('Email and Marketing page', () => {
cy.wait('@consents');
cy.wait('@reminders');

cy.findByText('Guardian products and support');
cy.get('[data-cy="similar_guardian_products"]');
cy.findByText('Your subscription/support');
cy.findByText('Supporter newsletter');
});
Expand Down

0 comments on commit 21c69fe

Please sign in to comment.