Skip to content

Commit

Permalink
Refactor cypress tests to fix retryability flaking
Browse files Browse the repository at this point in the history
  • Loading branch information
smartspot2 committed Jan 14, 2023
1 parent c22757a commit 8a9a74b
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 171 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/course/coordinator-course.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ before(() => {
*/
const timeStringToDate = (time: string): Date => {
// extract hours, minutes, am/pm
const [_, hours_str, minutes, ampm] = time.match(/(\d\d?):(\d\d) (AM|PM)/);
const [, hours_str, minutes, ampm] = time.match(/(\d\d?):(\d\d) (AM|PM)/);

let hours = parseInt(hours_str);
if (ampm === "PM" && hours !== 12) {
Expand All @@ -24,7 +24,7 @@ const timeStringToDate = (time: string): Date => {
/**
* Check that the capacity of a section card is as expected
*/
const checkCapacity = (text: string, isFull: boolean = false) => {
const checkCapacity = (text: string, isFull = false) => {
const groups = text.trim().match(/^(\d+)\/(\d+)$/i);
if (isFull) {
expect(parseInt(groups[1]) / parseInt(groups[2])).to.be.eq(1);
Expand Down
33 changes: 14 additions & 19 deletions cypress/e2e/course/restricted-courses.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,13 @@ describe("whitelisted courses", () => {
cy.contains(".csm-btn", /cs61a/i).should("be.visible");

// view unrestricted courses; should show nothing
cy.contains(".course-menu-sidebar-tab", /unrestricted/i)
.click()
.should("have.class", "active");
cy.contains(".course-menu-sidebar-tab", /unrestricted/i).click();
cy.contains(".course-menu-sidebar-tab", /unrestricted/i).should("have.class", "active");
cy.contains(".csm-btn", /cs61a/i).should("not.exist");

// go to cs61a sections
cy.contains(".course-menu-sidebar-tab", /restricted/i)
.click()
.should("have.class", "active");
cy.contains(".course-menu-sidebar-tab", /restricted/i).click();
cy.contains(".course-menu-sidebar-tab", /restricted/i).should("have.class", "active");
cy.contains(".csm-btn", /cs61a/i).click();
cy.get(".section-card").should("have.length", 1).should("be.visible");

Expand Down Expand Up @@ -145,16 +143,14 @@ describe("whitelisted courses", () => {
cy.contains(".csm-btn", /cs70/i).should("not.exist");

// view unrestricted courses; should show cs70, but not cs61a
cy.contains(".course-menu-sidebar-tab", /unrestricted/i)
.click()
.should("have.class", "active");
cy.contains(".course-menu-sidebar-tab", /unrestricted/i).click();
cy.contains(".course-menu-sidebar-tab", /unrestricted/i).should("have.class", "active");
cy.contains(".csm-btn", /cs61a/i).should("not.exist");
cy.contains(".csm-btn", /cs70/i).should("be.visible");

// go to cs61a sections
cy.contains(".course-menu-sidebar-tab", /restricted/i)
.click()
.should("have.class", "active");
cy.contains(".course-menu-sidebar-tab", /restricted/i).click();
cy.contains(".course-menu-sidebar-tab", /restricted/i).should("have.class", "active");
cy.contains(".csm-btn", /cs61a/i).click();
cy.get(".section-card").should("have.length", 1).should("be.visible");

Expand Down Expand Up @@ -229,18 +225,16 @@ describe("whitelisted courses", () => {
cy.contains(".enrollment-container .enrollment-course", /cs61a/i).should("be.visible");

// view unrestricted courses; should show cs70, but not cs61a
cy.contains(".course-menu-sidebar-tab", /unrestricted/i)
.click()
.should("have.class", "active");
cy.contains(".course-menu-sidebar-tab", /unrestricted/i).click();
cy.contains(".course-menu-sidebar-tab", /unrestricted/i).should("have.class", "active");
cy.contains(".csm-btn", /cs61a/i).should("not.exist");
cy.contains(".csm-btn", /cs70/i).should("be.visible");
// should not show any enrollment times
cy.get(".enrollment-container").should("not.exist");

// go to cs61a sections
cy.contains(".course-menu-sidebar-tab", /restricted/i)
.click()
.should("have.class", "active");
cy.contains(".course-menu-sidebar-tab", /restricted/i).click();
cy.contains(".course-menu-sidebar-tab", /restricted/i).should("have.class", "active");
cy.contains(".csm-btn", /cs61a/i).click();
cy.get(".section-card").should("have.length", 1).should("be.visible");

Expand Down Expand Up @@ -270,7 +264,8 @@ describe("whitelisted courses", () => {
.should("match", /enrollment failed/i);

// dismiss modal
cy.contains(".modal-contents .modal-btn", /ok/i).click().should("not.exist");
cy.contains(".modal-contents .modal-btn", /ok/i).click();
cy.get(".modal-contents").should("not.exist");

// go back to home page
cy.visit("/");
Expand Down

0 comments on commit 8a9a74b

Please sign in to comment.