Skip to content

Commit

Permalink
update cypress e2e test css selectors .. the checkboxes now don't hav…
Browse files Browse the repository at this point in the history
…e the css class that was being targeted
  • Loading branch information
Richard Bangay committed Oct 14, 2024
1 parent e5b2273 commit ea6ec5e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ html:not(.src-focus-disabled) .emotion-2:focus {
<div
className="emotion-0"
data-cy="13"
>
<div
className="emotion-1"
Expand All @@ -244,6 +243,7 @@ html:not(.src-focus-disabled) .emotion-2:focus {
aria-label="Test title (Test frequency)"
checked={false}
className="emotion-2"
data-cy="13"
id=":r0:"
onChange={[Function]}
type="checkbox"
Expand Down Expand Up @@ -535,7 +535,6 @@ html:not(.src-focus-disabled) .emotion-2:focus {
<div
className="emotion-0"
data-cy="13"
>
<div
className="emotion-1"
Expand All @@ -545,6 +544,7 @@ html:not(.src-focus-disabled) .emotion-2:focus {
aria-label="Test title (Test frequency)"
checked={true}
className="emotion-2"
data-cy="13"
id=":r1:"
onChange={[Function]}
type="checkbox"
Expand Down
2 changes: 1 addition & 1 deletion client/components/mma/identity/NewsletterPreference.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ export const NewsletterPreference: FC<NewsletterPreferenceProps> = (props) => {
return (
<div
key={id}
data-cy={id}
css={[
standardText,
{
Expand All @@ -126,6 +125,7 @@ export const NewsletterPreference: FC<NewsletterPreferenceProps> = (props) => {
]}
>
<Checkbox
data-cy={id}
checked={!!selected}
onChange={interact}
label={title && getTitle(title)}
Expand Down
4 changes: 3 additions & 1 deletion client/components/mma/identity/PageSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface PageSectionProps {
title?: string;
description?: string | ReactNode;
subtext?: string;
testSelector?: string;
}

const getTitle = (title: PageSectionProps['title']) => (
Expand Down Expand Up @@ -50,9 +51,10 @@ const getSubtext = (subtext: PageSectionProps['subtext']) => (
);

export const PageSection: FC<PageSectionProps> = (props) => {
const { children, description, title, subtext } = props;
const { children, description, title, subtext, testSelector } = props;
return (
<div
data-cy={testSelector}
css={{
[from.desktop]: {
display: 'flex',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const NewsletterSection: FC<NewsletterSectionProps> = (props) => {
const { newsletters, clickHandler } = props;
return (
<PageSection
testSelector="your_newsletters"
title="Your newsletters"
description={`
Our regular newsletters help you get closer to our quality,
Expand Down
15 changes: 8 additions & 7 deletions cypress/tests/e2e/e2e.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,20 @@ describe('E2E with Okta', () => {
cy.get('[data-cy="similar_guardian_products"]').click();
cy.visit('/email-prefs');
cy.get('[data-cy="similar_guardian_products"]')
.parents('div')
.get('.checkbox')
.should('have.attr', 'aria-checked')
.and('eq', 'true');
.find('input[type=checkbox]')
.should('be.checked');
});

it('should allow the user to unsubscribe from all emails', () => {
cy.visit('/email-prefs');
cy.findByText('Unsubscribe from all emails').click();
cy.visit('/email-prefs');
cy.get('.checkbox')
.should('have.attr', 'aria-checked')
.and('eq', 'false');
cy.get('[data-cy="similar_guardian_products"]')
.find('input[type=checkbox]')
.should('not.be.checked');
cy.get('[data-cy="your_newsletters"]')
.find('input[type=checkbox]')
.should('not.be.checked');
});
});

Expand Down

0 comments on commit ea6ec5e

Please sign in to comment.