Skip to content

Commit

Permalink
test(e2e): always input a valid date by using the next month
Browse files Browse the repository at this point in the history
  • Loading branch information
sgfost committed Oct 29, 2024
1 parent d105df4 commit cf7f9ea
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion e2e/cypress/fixtures/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"description": "Job Description",
"summary": "Job Summary",
"external-url": "https://www.comses.net/",
"application-deadline": "29"
"application-deadline": "21"
}
]
}
13 changes: 13 additions & 0 deletions e2e/cypress/support/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@
export function getDataCy(value: string): Cypress.Chainable {
return cy.get(`[data-cy="${value}"]`);
}

/**
* Select the given day in the next month using the date picker
* @param {Cypress.Chainable} element - container element of the datepicker input
* @param {number} day - day to select
*/
export function selectNextMonthDate(element: Cypress.Chainable, day: number): Cypress.Chainable {
element.first().click();
return element.within(() => {
cy.get('[aria-label="Next month"]').click();
cy.contains(day).click();
});
}
22 changes: 9 additions & 13 deletions e2e/cypress/tests/event.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loginBeforeEach } from "../support/setup";
import { getDataCy } from "../support/util";
import { getDataCy, selectNextMonthDate } from "../support/util";
import "cypress-file-upload";

describe("Visit events page", () => {
Expand Down Expand Up @@ -31,18 +31,14 @@ describe("Visit events page", () => {
cy.contains("Submit an event").click();
getDataCy("event-title").type(event.title);
getDataCy("event-location").type(event.location);
getDataCy("event-start-date").first().click();
getDataCy("event-start-date").contains(event["start-date"]).click();
getDataCy("event-end-date").first().click();
getDataCy("event-end-date").contains(event["end-date"]).click();
getDataCy("early-registration-deadline").first().click();
getDataCy("early-registration-deadline")
.contains(event["early-registration-deadline"])
.click();
getDataCy("registration-deadline").first().click();
getDataCy("registration-deadline").contains(event["registration-deadline"]).click();
getDataCy("submission-deadline").first().click();
getDataCy("submission-deadline").contains(event["submission-deadline"]).click();
selectNextMonthDate(getDataCy("event-start-date"), event["start-date"]);
selectNextMonthDate(getDataCy("event-end-date"), event["end-date"]);
selectNextMonthDate(
getDataCy("early-registration-deadline"),
event["early-registration-deadline"]
);
selectNextMonthDate(getDataCy("registration-deadline"), event["registration-deadline"]);
selectNextMonthDate(getDataCy("submission-deadline"), event["submission-deadline"]);
getDataCy("description").type(event.description);
getDataCy("summary").type(event.summary);
getDataCy("external-url").type(event["external-url"]);
Expand Down
5 changes: 2 additions & 3 deletions e2e/cypress/tests/job.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loginBeforeEach } from "../support/setup";
import { getDataCy } from "../support/util";
import { getDataCy, selectNextMonthDate } from "../support/util";
import "cypress-file-upload";

describe("Visit jobs page", () => {
Expand All @@ -21,8 +21,7 @@ describe("Visit jobs page", () => {
getDataCy("job-description").type(job.description);
getDataCy("job-summary").type(job.summary);
getDataCy("external-url").type(job["external-url"]);
getDataCy("application-deadline").first().click();
getDataCy("application-deadline").contains(job["application-deadline"]).click();
selectNextMonthDate(getDataCy("application-deadline"), job["application-deadline"]);
getDataCy("create-button").click();
cy.wait(2000);
});
Expand Down

0 comments on commit cf7f9ea

Please sign in to comment.