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: 2 additions & 1 deletion cypress/e2e/tests/image.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import locators from "../../support/locators";
import claim from "../../fixtures/claim";
import { today } from "../../utils/dateUtils";

describe("Create image claim", () => {
beforeEach("login", () => cy.login());
Expand All @@ -15,7 +16,7 @@ describe("Create image claim", () => {
.type(claim.imageTitle);

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

cy.get(locators.claim.INPUT_SOURCE)
.should("be.visible")
Expand Down
5 changes: 3 additions & 2 deletions cypress/e2e/tests/personality.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import locators from "../../support/locators";
import claim from "../../fixtures/claim";
import personality from "../../fixtures/personality";
import { today } from "../../utils/dateUtils";

describe("Create personality and claim", () => {
beforeEach("login", () => cy.login());
Expand Down Expand Up @@ -47,7 +48,7 @@ describe("Create personality and claim", () => {
.type(claim.content);

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

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

/// <reference types="cypress" />

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", () => {
const getHashFromUrl = (interception) => interception.request.url.split("/").pop();

const openCreateVerificationRequestForm = () => {
cy.get(locators.floatButton.FLOAT_BUTTON).click();
cy.get(locators.floatButton.ADD_VERIFICATION_REQUEST).click();
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();
};

const assertDetailFields = (fields: Array<[string, string]>) => {
fields.forEach(([selector, expected]) => {
cy.get(selector).should("be.visible").and("contain", expected);
});
};

const goToVerificationRequest = (data_hash: string) => {
cy.intercept("GET", "**/verification-request/**").as("getVerification");
cy.visit(`/verification-request/${data_hash}`);
cy.wait("@getVerification");
}

describe("lifecycle verification request", () => {
beforeEach("login", () => cy.login());

it("should prevent submission when required fields are missing", () => {
openCreateVerificationRequestForm();
saveVerificationRequest();
cy.get(locators.verificationRequest.ERROR_VALIDATION_CONTENT).should("be.visible")
cy.get(locators.verificationRequest.ERROR_VALIDATION_PUBLICATION_DATE).should("be.visible")
cy.url().should("contain", "/verification-request/create");
});

describe("Full verification request flow", () => {
let fullRequestHash: string;

it("should create a verification request with all optional and mandatory fields", () => {
openCreateVerificationRequestForm();
cy.intercept("GET", "**/verification-request/**").as("getVerification");

cy.get(locators.verificationRequest.FORM_CONTENT).type(fullVerificationRequest.content);
selectPublicationDate(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 });
cy.contains(fullVerificationRequest.impactArea).click();

cy.get(locators.verificationRequest.FORM_HEARD_FROM).type(fullVerificationRequest.heardFrom);
cy.get(locators.verificationRequest.FORM_SOURCE).type(`https://${fullVerificationRequest.source}`);
cy.get(locators.verificationRequest.FORM_EMAIL).type(fullVerificationRequest.email);
saveVerificationRequest();

cy.wait("@getVerification").then((interception) => {
getHashFromUrl(interception)
fullRequestHash = getHashFromUrl(interception);
cy.log("Hash capturado:", fullRequestHash);
});
cy.url().should("match", regexVerificationRequestPage);

assertDetailFields([
[locators.verificationRequest.DETAIL_CONTENT, fullVerificationRequest.content],
[locators.verificationRequest.DETAIL_REPORT_TYPE, fullVerificationRequest.reportType],
[locators.verificationRequest.DETAIL_IMPACT_AREA, fullVerificationRequest.impactArea],
[locators.verificationRequest.DETAIL_SOURCE_CHANNEL, "Web"],
[locators.verificationRequest.DETAIL_HEARD_FROM, fullVerificationRequest.heardFrom],
[locators.verificationRequest.DETAIL_PUBLICATION_DATE, today.format("DD/MM/YYYY")],
[locators.verificationRequest.DETAIL_DATE, today.format("DD/MM/YYYY")],
[locators.verificationRequest.DETAIL_SOURCE_0, fullVerificationRequest.source],
]);

it("should update an existing request by adding additional sources and modifying the publication date", () => {
goToVerificationRequest(fullRequestHash)

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));
saveVerificationRequest();
cy.url().should("match", regexVerificationRequestPage);

assertDetailFields([
[locators.verificationRequest.DETAIL_PUBLICATION_DATE, getPastDay(1).format("DD/MM/YYYY")],
[locators.verificationRequest.DETAIL_SOURCE_1, updatedSource],
])
})
})

it("should manage topic tags by adding and removing them", () => {
goToVerificationRequest(fullRequestHash)
cy.intercept("PUT", "**/verification-request/*/topics").as("updateTopics");

cy.get(locators.verificationRequest.ADD_TOPIC_ICON).click();
cy.get(locators.verificationRequest.TYPE_TOPIC_INPUT).type(fullVerificationRequest.topic, { delay: 200 });
cy.contains(fullVerificationRequest.topic).click();
cy.get(locators.verificationRequest.ADD_TOPIC_SUBMIT).click();

cy.wait("@updateTopics").then((interception) => {
expect(interception.response.statusCode).to.be.oneOf([200, 201]);
});

cy.contains(locators.verificationRequest.DETAIL_TOPIC_TAG, fullVerificationRequest.topic.toUpperCase())
.should("be.visible")
.within(() => {
cy.get(locators.verificationRequest.REMOVE_TOPIC_ICON).click();
});


cy.contains(locators.verificationRequest.DETAIL_TOPIC_TAG, fullVerificationRequest.topic.toUpperCase()).should("not.exist");
})

it("should discard unsaved changes when the edition form is canceled", () => {
goToVerificationRequest(fullRequestHash)

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.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"));
cy.get(locators.verificationRequest.DETAIL_SOURCE_1).should("not.exist");
})
});

describe("Minimum verification request flow", () => {
let minRequestHash: string;

it("should allow request creation using only the minimum mandatory information", () => {
openCreateVerificationRequestForm();
cy.intercept("GET", "**/verification-request/**").as("getVerification");

cy.get(locators.verificationRequest.FORM_CONTENT).type(minimumContent);
selectPublicationDate(today);
saveVerificationRequest();
cy.wait("@getVerification").then((interception) => {
getHashFromUrl(interception)
minRequestHash = getHashFromUrl(interception);

cy.log("Hash capturado:", minRequestHash);
});
cy.url().should("match", regexVerificationRequestPage);

assertDetailFields([
[locators.verificationRequest.DETAIL_CONTENT, minimumContent],
[locators.verificationRequest.DETAIL_PUBLICATION_DATE, today.format("DD/MM/YYYY")],
])
});

it("should supplement a minimalist request by adding its first source during edition", () => {
goToVerificationRequest(minRequestHash)

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));
saveVerificationRequest();
cy.url().should("match", regexVerificationRequestPage);

assertDetailFields([
[locators.verificationRequest.DETAIL_PUBLICATION_DATE, getPastDay(1).format("DD/MM/YYYY")],
[locators.verificationRequest.DETAIL_SOURCE_0, fullVerificationRequest.source],
])
})
})
});
});
16 changes: 16 additions & 0 deletions cypress/fixtures/verificationRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const fullVerificationRequest = {
content: "Verification Request Content",
reportType: "Discurso",
impactArea: "Ambientalismo",
topic: "Socialismo",
heardFrom: "Verification Request heardFrom",
source: "wikimedia.org",
email: "test-cypress@aletheiafact.org",
};

const minimumContent = "Verification Request Content minimium"

const regexVerificationRequestPage = /\/verification-request\/[\w-]+$/
const updatedSource = "www.wikidata.org"

export { fullVerificationRequest, regexVerificationRequestPage, updatedSource, minimumContent }
45 changes: 44 additions & 1 deletion cypress/support/locators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const locators = {
BTN_SUBMIT_CLAIM: "[data-cy=testSaveButton]",
INPUT_TITLE: "[data-cy=testTitleClaimForm]",
INPUT_DATA: "[data-cy=testSelectDate]",
INPUT_DATA_TODAY: ".MuiPickersDay-today",
INPUT_SOURCE: "[data-cy=testSource1]",
},

Expand All @@ -52,6 +51,7 @@ const locators = {
ADD_CLAIM: "[data-cy=testFloatButtonAddClaim]",
ADD_PERSONALITY: "[data-cy=testFloatButtonAddPersonality]",
ADD_SOURCE: "[data-cy=testFloatButtonAddSources]",
ADD_VERIFICATION_REQUEST: "[data-cy=testFloatButtonAddVerificationRequest]"
},

claimReview: {
Expand Down Expand Up @@ -83,6 +83,49 @@ const locators = {
"[data-cy=testClaimReviewSourcesButton]",
},

verificationRequest: {
FORM_CONTENT: "[data-cy=testClaimReviewcontent]",
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]",

FORM_SOURCE_ITEM_0: "[data-cy=testClaimReviewsourceEdit-0]",
FORM_SOURCE_ITEM_1: "[data-cy=testClaimReviewsourceEdit-1]",
FORM_SOURCE_ADD: "[data-cy=testClaimReviewsource-addSources]",
FORM_SOURCE_REMOVE_2: "[data-cy=testClaimReviewsourceRemove-2]",

DETAIL_CONTENT: "[data-cy=testVerificationRequestContent]",
DETAIL_REPORT_TYPE: "[data-cy=testVerificationRequestReportType]",
DETAIL_IMPACT_AREA: "[data-cy=testVerificationRequestImpactArea]",
DETAIL_SOURCE_CHANNEL: "[data-cy=testVerificationRequestSourceChannel]",
DETAIL_SEVERITY: "[data-cy=testVerificationRequestSeverity]",
DETAIL_HEARD_FROM: "[data-cy=testVerificationRequestHeardFrom]",
DETAIL_PUBLICATION_DATE: "[data-cy=testVerificationRequestPublicationDate]",
DETAIL_DATE: "[data-cy=testVerificationRequestDate]",
DETAIL_SOURCE_0: "[data-cy=testVerificationRequestSource0]",
DETAIL_SOURCE_1: "[data-cy=testVerificationRequestSource1]",

ERROR_VALIDATION_CONTENT: "[data-cy=testClaimReviewErrorcontent]",
ERROR_VALIDATION_PUBLICATION_DATE: "[data-cy=testClaimReviewErrorpublicationDate]",

DETAIL_CARD_CONTENT: "[data-cy=testVerificationRequestCardContent0]",
DETAIL_CARD_CONTENT_1: "[data-cy=testVerificationRequestCardContent1]",

ADD_TOPIC_ICON: "[data-cy=testVerificationRequestTopicsToggle]",
TYPE_TOPIC_INPUT: "[data-cy=testVerificationRequestTopicsInput]",
ADD_TOPIC_SUBMIT: "[data-cy=testVerificationRequestAddTopicButton]",
DETAIL_TOPIC_TAG: "[data-cy=testVerificationRequestTopicChip0]",
REMOVE_TOPIC_ICON: "[data-cy=testVerificationRequestTopicRemoveButton0]",

SEE_FULL_BUTTON: "[data-cy=testSeeFullVerificationRequest]",
EDIT_BUTTON: "[data-cy=testVerificationRequestEditButton]",
SAVE_BUTTON: "[data-cy=testSaveButton]",
CANCEL_BUTTON: "[data-cy=testCancelButton]",
},

menu: {
SIDE_MENU: "[data-cy=testOpenSideMenu]",
USER_ICON: "[data-cy=testUserIcon]",
Expand Down
6 changes: 6 additions & 0 deletions cypress/utils/dateUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import dayjs from "dayjs";

export const today = dayjs();

export const getPastDay = (daysAgo: number) =>
dayjs().subtract(daysAgo, "day");
3 changes: 2 additions & 1 deletion src/components/AletheiaMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Roles } from "../types/enums";
import { NameSpaceEnum } from "../types/Namespace";
import { currentNameSpace } from "../atoms/namespace";
import localConfig from "../../config/localConfig";
import { isAdmin } from "../utils/GetUserPermission";

const AletheiaMenu = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -99,7 +100,7 @@ const AletheiaMenu = () => {
{t("menu:kanbanItem")}
</ListItemButton>
)}
{(role === Roles.Admin || role === Roles.SuperAdmin) && (
{isAdmin(role) && (
<>
<ListItemButton
data-cy={"testadminItem"}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Claim/ClaimView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import claimApi from "../../api/claim";
import { currentUserRole } from "../../atoms/currentUser";
import { useAtom } from "jotai";
import AffixButtonV2 from "../Collaborative/Components/AffixButtonV2";
import { isAdmin } from "../../utils/GetUserPermission";

const ClaimView = ({ personality, claim, href, hideDescriptions }) => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -44,7 +45,7 @@ const ClaimView = ({ personality, claim, href, hideDescriptions }) => {

return (
<>
{(role === Roles.Admin || role === Roles.SuperAdmin) && (
{isAdmin(role) && (
<AdminToolBar
content={claim}
deleteApiFunction={claimApi.deleteClaim}
Expand Down
3 changes: 2 additions & 1 deletion src/components/ClaimReview/ClaimReviewForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useAtom } from "jotai";
import { useSelector } from "@xstate/react";
import ReportModelButtons from "./ReportModelButtons";
import LoginButton from "../LoginButton";
import { isAdmin } from "../../utils/GetUserPermission";

const ClaimReviewForm = ({
dataHash,
Expand Down Expand Up @@ -48,7 +49,7 @@ const ClaimReviewForm = ({
const [formCollapsed, setFormCollapsed] = useState(
isUnassigned && !reportModel
);
const userIsAdmin = role === Roles.Admin || role === Roles.SuperAdmin;
const userIsAdmin = isAdmin(role);
const [showForm, setShowForm] = useState(false);

useEffect(() => {
Expand Down
Loading
Loading