Skip to content

Commit

Permalink
Fix cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oyamauchi committed Jun 21, 2024
1 parent dff29a0 commit a11eccd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 68 deletions.
6 changes: 0 additions & 6 deletions cypress/e2e/state-calculator-events.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ describe('rewiring-america-state-calculator events', () => {
element.get(0).addEventListener('calculator-submitted', submit);
});

cy.selectProjects(['hvac', 'ev']);

cy.get('rewiring-america-state-calculator')
.shadow()
.find('input#zip')
Expand All @@ -29,10 +27,6 @@ describe('rewiring-america-state-calculator events', () => {
expect(event.detail).to.exist;
expect(event.detail.formData).to.exist;
expect(event.detail.formData.zip).to.equal('02859');
expect(Array.from(event.detail.formData.projects).sort()).to.eql([
'ev',
'hvac',
]);
});
});

Expand Down
58 changes: 3 additions & 55 deletions cypress/e2e/state-calculator.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ describe('rewiring-america-state-calculator', () => {
});

it('fetches results if you submit after entering a RI zip code', () => {
cy.selectProjects(['hvac']);

cy.get('rewiring-america-state-calculator')
.shadow()
.find('input#zip')
Expand All @@ -51,7 +49,9 @@ describe('rewiring-america-state-calculator', () => {

cy.get('rewiring-america-state-calculator')
.shadow()
.contains('Incentives you’re interested in');
.contains(/We found \d+ results across \d+ projects./);

cy.selectProjects(['hvac']);

cy.get('rewiring-america-state-calculator')
.shadow()
Expand All @@ -73,10 +73,6 @@ describe('rewiring-america-state-calculator', () => {
.shadow()
.contains('$2,000 off an air source heat pump');

cy.get('rewiring-america-state-calculator')
.shadow()
.contains('Other incentives available to you');

cy.get('rewiring-america-state-calculator')
.shadow()
.contains('Brought to you in partnership with');
Expand All @@ -88,54 +84,6 @@ describe('rewiring-america-state-calculator', () => {
});
});

it('shows an empty state if you are not eligible for any incentives for your chosen project', () => {
cy.selectProjects(['cooking']);

cy.get('rewiring-america-state-calculator')
.shadow()
.find('#zip')
.type('02859');

// "force" to work around a Cypress bug
// https://github.com/cypress-io/cypress/issues/5830
cy.get('rewiring-america-state-calculator')
.shadow()
.find('#household_income')
.type('200000{enter}', { force: true });

// make sure we saw an empty result state, and scroll down to it:
cy.get('rewiring-america-state-calculator')
.shadow()
.contains('No incentives available for this project')
.scrollIntoView();

cy.get('rewiring-america-state-calculator')
.shadow()
.checkA11y(null, {
runOnly: ['wcag2a', 'wcag2aa'],
});

// // make sure we have scrolled down
cy.get('rewiring-america-state-calculator')
.shadow()
.contains('Your household info')
.isNotInViewport();

cy.get('rewiring-america-state-calculator')
.shadow()
.contains('Back to calculator')
.click();

// wait for animated scroll
cy.wait(1000);

// make sure we scrolled back up
cy.get('rewiring-america-state-calculator')
.shadow()
.contains('Your household info')
.isInViewport();
});

it('shows an error if you query in the wrong state', () => {
// Add the state-restricting attribute to the element
cy.get('rewiring-america-state-calculator').invoke('attr', 'state', 'RI');
Expand Down
8 changes: 1 addition & 7 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Cypress.Commands.add(
(projects: string[]) => {
cy.get('rewiring-america-state-calculator')
.shadow()
.find('button#projects')
.find('button#project-selector')
.click();

projects.forEach(project =>
Expand All @@ -98,11 +98,5 @@ Cypress.Commands.add(
.find(`li[data-value="${project}"]`)
.click(),
);

// Unfocus the project selector
cy.get('rewiring-america-state-calculator')
.shadow()
.find('button#projects')
.click();
},
);

0 comments on commit a11eccd

Please sign in to comment.