Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cypress/e2e/tests/image.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ describe("Create image claim", () => {
.should("be.visible")
.type(claim.imageTitle);

cy.get(locators.claim.INPUT_DATA).should("be.visible").click();
cy.contains('[role="gridcell"]', today.format("D")).click();
cy.selectDatePickerDate(today)

cy.get(locators.claim.INPUT_SOURCE)
.should("be.visible")
Expand Down
6 changes: 2 additions & 4 deletions cypress/e2e/tests/personality.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ describe("Create personality and claim", () => {
.should("be.visible")
.type(claim.content);

cy.get(locators.claim.INPUT_DATA).should("be.visible").click();
cy.contains('[role="gridcell"]', today.format("D")).click();
cy.selectDatePickerDate(today)

cy.get(locators.claim.INPUT_SOURCE)
.should("be.visible")
Expand Down Expand Up @@ -78,8 +77,7 @@ describe("Create personality and claim", () => {
cy.get(locators.claim.INPUT_TITLE)
.should("be.visible")
.type(claim.imageTitle);
cy.get(locators.claim.INPUT_DATA).should("be.visible").click();
cy.contains('[role="gridcell"]', today.format("D")).click();
cy.selectDatePickerDate(today)
cy.get(locators.claim.INPUT_SOURCE)
.should("be.visible")
.type(claim.source);
Expand Down
16 changes: 5 additions & 11 deletions cypress/e2e/tests/verificationRequest.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import { fullVerificationRequest, regexVerificationRequestPage, updatedSource, minimumContent } from "../../fixtures/verificationRequest";
import locators from "../../support/locators";
import { Dayjs } from "dayjs"
import { getPastDay, today } from "../../utils/dateUtils";

describe("Test verification request", () => {
Expand All @@ -15,11 +14,6 @@ describe("Test verification request", () => {
cy.url().should("contain", "/verification-request/create");
};

const selectPublicationDate = (date: Dayjs) => {
cy.get(locators.verificationRequest.FORM_PUBLICATION_DATE).click();
cy.contains('[role="gridcell"]', date.format("D")).click();
};

const saveVerificationRequest = () => {
cy.checkRecaptcha();
cy.get(locators.verificationRequest.SAVE_BUTTON).click();
Expand Down Expand Up @@ -56,7 +50,7 @@ describe("Test verification request", () => {
cy.intercept("GET", "**/verification-request/**").as("getVerification");

cy.get(locators.verificationRequest.FORM_CONTENT).type(fullVerificationRequest.content);
selectPublicationDate(today);
cy.selectDatePickerDate(today);
cy.get(locators.verificationRequest.FORM_REPORT_TYPE).click();
cy.contains(fullVerificationRequest.reportType).click();
cy.get(locators.verificationRequest.FORM_IMPACT_AREA).type(fullVerificationRequest.impactArea, { delay: 200 });
Expand Down Expand Up @@ -91,7 +85,7 @@ describe("Test verification request", () => {
cy.get(locators.verificationRequest.EDIT_BUTTON).should("be.visible").click();
cy.get(locators.verificationRequest.FORM_SOURCE_ADD).click();
cy.get(locators.verificationRequest.FORM_SOURCE_ITEM_1).type(`https://${updatedSource}`);
selectPublicationDate(getPastDay(1));
cy.selectDatePickerDate(getPastDay(1));
saveVerificationRequest();
cy.url().should("match", regexVerificationRequestPage);

Expand Down Expand Up @@ -131,7 +125,7 @@ describe("Test verification request", () => {
cy.get(locators.verificationRequest.EDIT_BUTTON).should("be.visible").click();
cy.get(locators.verificationRequest.FORM_SOURCE_ADD).click();
cy.get(locators.verificationRequest.FORM_SOURCE_ITEM_1).type(`https://${updatedSource}`);
selectPublicationDate(getPastDay(10));
cy.selectDatePickerDate(getPastDay(10));
cy.get(locators.verificationRequest.CANCEL_BUTTON).click();

cy.get(locators.verificationRequest.DETAIL_PUBLICATION_DATE).should("be.visible").and("not.contain", getPastDay(10).format("DD/MM/YYYY"));
Expand All @@ -147,7 +141,7 @@ describe("Test verification request", () => {
cy.intercept("GET", "**/verification-request/**").as("getVerification");

cy.get(locators.verificationRequest.FORM_CONTENT).type(minimumContent);
selectPublicationDate(today);
cy.selectDatePickerDate(today);
saveVerificationRequest();
cy.wait("@getVerification").then((interception) => {
getHashFromUrl(interception)
Expand All @@ -168,7 +162,7 @@ describe("Test verification request", () => {

cy.get(locators.verificationRequest.EDIT_BUTTON).should("be.visible").click();
cy.get(locators.verificationRequest.FORM_SOURCE_ITEM_0).type(`https://${fullVerificationRequest.source}`);
selectPublicationDate(getPastDay(1));
cy.selectDatePickerDate(getPastDay(1));
saveVerificationRequest();
cy.url().should("match", regexVerificationRequestPage);

Expand Down
16 changes: 16 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import dayjs from "dayjs";
import user from "../fixtures/user";
import locators from "./locators";

Expand Down Expand Up @@ -57,6 +58,20 @@ Cypress.Commands.add(
}
);

Cypress.Commands.add("selectDatePickerDate", (dateToSelect: dayjs.Dayjs) => {
const today = dayjs();

cy.get(locators.claim.INPUT_DATA).click();

if (dateToSelect.month() < today.month() || dateToSelect.year() < today.year()) {
cy.get('[aria-label="Previous month"]').click();
} else if (dateToSelect.month() > today.month() || dateToSelect.year() > today.year()) {
cy.get('[aria-label="Next month"]').click();
}

cy.contains('[role="gridcell"]', dateToSelect.format("D")).click();
});

declare global {
namespace Cypress {
interface Chainable {
Expand All @@ -69,6 +84,7 @@ declare global {
email: string,
password: string
): Chainable<Element>;
selectDatePickerDate(date: dayjs.Dayjs): Chainable<Element>;
}
}
}
1 change: 0 additions & 1 deletion cypress/support/locators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ const locators = {
FORM_REPORT_TYPE: "[data-cy=testClaimReviewreportType]",
FORM_IMPACT_AREA: "[data-cy=testClaimReviewimpactArea]",
FORM_HEARD_FROM: "[data-cy=testClaimReviewheardFrom]",
FORM_PUBLICATION_DATE: "[data-cy=testSelectDate]",
FORM_SOURCE: "[data-cy=testClaimReviewsource]",
FORM_EMAIL: "[data-cy=testClaimReviewemail]",

Expand Down
3 changes: 3 additions & 0 deletions cypress/utils/dateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ export const today = dayjs();

export const getPastDay = (daysAgo: number) =>
dayjs().subtract(daysAgo, "day");

export const getFutureDay = (daysAhead: number) =>
dayjs().add(daysAhead, "day");
Loading