Skip to content

Commit

Permalink
Merge pull request #1253 from AletheiaFact/create-source-review-workflow
Browse files Browse the repository at this point in the history
Create source review workflow
  • Loading branch information
thesocialdev authored Jun 19, 2024
2 parents 7a5c765 + ff23e70 commit 987bdc6
Show file tree
Hide file tree
Showing 98 changed files with 1,670 additions and 1,207 deletions.
6 changes: 3 additions & 3 deletions cypress/e2e/tests/header.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ describe("Test the header menus", () => {
cy.url().should("contains", "claim");
});

it("Open side bar and click sources", () => {
it("Open side bar and click source", () => {
cy.get(locators.menu.SIDE_MENU).click();
cy.get("[data-cy=testSourcestItem]").click();
cy.url().should("contains", "sources");
cy.get("[data-cy=testSourcetItem]").click();
cy.url().should("contains", "source");
});

it("Open side bar and click about", () => {
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/tests/image.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ describe("Create image claim", () => {

cy.get(locators.claim.INPUT_SOURCE)
.should("be.visible")
.type(claim.source);
.type(claim.imageSource);
cy.get(locators.claim.BTN_UPLOAD_IMAGE).should("be.visible");
cy.get('input[type="file"]').selectFile(claim.imageSource, {
cy.get('input[type="file"]').selectFile(claim.imageSourceFile, {
force: true,
});
cy.get("[data-cy=testCheckboxAcceptTerms]").click();
Expand Down
52 changes: 27 additions & 25 deletions cypress/e2e/tests/review.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,31 @@ const goToClaimReviewPage = () => {
cy.get(locators.claim.BTN_SEE_FULL_REVIEW).should("exist");
};

const assignUser = () => {
cy.get(locators.claimReview.BTN_START_CLAIM_REVIEW).should("exist").click();
cy.get(locators.claimReview.INPUT_USER)
.should("exist")
.type(review.username, { delay: 200 });
cy.get(".ant-select-item-option-active").click();
cy.get('[title="reCAPTCHA"]').should("exist");
cy.get(locators.claimReview.BTN_ASSIGN_USER).should("be.disabled");
cy.checkRecaptcha();
cy.get(locators.claimReview.BTN_ASSIGN_USER).should("be.enabled").click();
cy.get(locators.claimReview.INPUT_CLASSIFICATION).should("exist");
};

const blockAssignedUserReview = () => {
cy.checkRecaptcha();
cy.get(locators.claimReview.BTN_SELECTED_REVIEW).should("exist").click();
cy.get(locators.claimReview.INPUT_REVIEWER)
.should("exist")
.type(review.username, { delay: 200 });
cy.get(".ant-select-item-option-active").click();
cy.checkRecaptcha();
cy.get(locators.claimReview.BTN_SUBMIT).should("be.enabled").click();
cy.get(locators.claimReview.TEXT_REVIEWER_ERROR).should("exist");
};

describe("Test claim review", () => {
it("should not show start review when not logged in", () => {
cy.visit(
Expand All @@ -36,20 +61,7 @@ describe("Test claim review", () => {
it("should be able to assign a user", () => {
cy.login();
goToClaimReviewPage();
cy.get(locators.claimReview.BTN_START_CLAIM_REVIEW)
.should("exist")
.click();
cy.get(locators.claimReview.INPUT_USER)
.should("exist")
.type(review.username, { delay: 200 });
cy.get(".ant-select-item-option-active").click();
cy.get('[title="reCAPTCHA"]').should("exist");
cy.get(locators.claimReview.BTN_ASSIGN_USER).should("be.disabled");
cy.checkRecaptcha();
cy.get(locators.claimReview.BTN_ASSIGN_USER)
.should("be.enabled")
.click();
cy.get(locators.claimReview.INPUT_CLASSIFICATION).should("exist");
assignUser();
});

it("should be able to submit full review fields", () => {
Expand Down Expand Up @@ -102,16 +114,6 @@ describe("Test claim review", () => {
it("should not be able submit after choosing assigned user as reviewer", () => {
cy.login();
goToClaimReviewPage();
cy.checkRecaptcha();
cy.get(locators.claimReview.BTN_SELECTED_REVIEW)
.should("exist")
.click();
cy.get(locators.claimReview.INPUT_REVIEWER)
.should("exist")
.type(review.username, { delay: 200 });
cy.get(".ant-select-item-option-active").click();
cy.checkRecaptcha();
cy.get(locators.claimReview.BTN_SUBMIT).should("be.enabled").click();
cy.get(locators.claimReview.TEXT_REVIEWER_ERROR).should("exist");
blockAssignedUserReview();
});
});
82 changes: 82 additions & 0 deletions cypress/e2e/tests/source.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* eslint-disable no-undef */
/// <reference types="cypress" />

import locators from "../../support/locators";
import source from "../../fixtures/source";
import review from "../../fixtures/review";

const goToSourceReviewPage = () => {
cy.visit(`http://localhost:3000/source/${source.data_hash}`);
};

describe("Create source and source review", () => {
beforeEach("login", () => cy.login());

it("Should create a new Source", () => {
cy.get(locators.floatButton.FLOAT_BUTTON).should("be.visible").click();
cy.get(locators.floatButton.ADD_SOURCE).should("be.visible").click();

cy.url().should("contains", "source");
cy.get(locators.source.INPUT_SOURCE).type(source.href);
cy.checkRecaptcha();
cy.get(`${locators.source.BTN_SUBMIT_SOURCE}`).click();
});

it("should not show start source review when not logged in", () => {
goToSourceReviewPage();
cy.get(locators.claimReview.BTN_START_CLAIM_REVIEW).should("not.exist");
});

it("should be able to assign a user", () => {
goToSourceReviewPage();
cy.get(locators.claimReview.BTN_START_CLAIM_REVIEW)
.should("exist")
.click();
cy.get(locators.claimReview.INPUT_USER)
.should("exist")
.type(review.username, { delay: 200 });
cy.get(".ant-select-item-option-active").click();
cy.get('[title="reCAPTCHA"]').should("exist");
cy.get(locators.claimReview.BTN_ASSIGN_USER).should("be.disabled");
cy.checkRecaptcha();
cy.get(locators.claimReview.BTN_ASSIGN_USER)
.should("be.enabled")
.click();
cy.get(locators.claimReview.INPUT_CLASSIFICATION).should("exist");
});

it("should be able to submit source review fields", () => {
goToSourceReviewPage();
cy.get(locators.claimReview.INPUT_CLASSIFICATION)
.should("exist")
.click();
cy.get(`[data-cy=${review.classification}]`)
.should("be.visible")
.click();

cy.get(locators.claimReview.INPUT_SUMMARY)
.should("exist")
.type(review.summary);

cy.checkRecaptcha();
cy.get(locators.claimReview.BTN_FINISH_REPORT)
.should("be.enabled")
.click();
cy.get(locators.claimReview.BTN_SELECTED_REVIEW).should("exist");
});

it("should not be able submit after choosing assigned user as reviewer", () => {
goToSourceReviewPage();
cy.checkRecaptcha();
cy.get(locators.claimReview.BTN_SELECTED_REVIEW)
.should("exist")
.click();
cy.get(locators.claimReview.INPUT_REVIEWER)
.should("exist")
.type(review.username, { delay: 200 });
cy.get(".ant-select-item-option-active").click();
cy.checkRecaptcha();
cy.get(locators.claimReview.BTN_SUBMIT).should("be.enabled").click();
cy.get(locators.claimReview.TEXT_REVIEWER_ERROR).should("exist");
});
});
5 changes: 3 additions & 2 deletions cypress/fixtures/claim.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const claim = {
title: "Speech Claim Title",
content: "Speech Claim Content Lorem Ipsum Dolor Sit Amet...",
source: "http://wikipedia.org",
source: "https://wikimedia.org",
imageSource: "https://aletheiafact.org",
slug: "speech-claim-title",
imageTitle: "Image Claim Title",
imageSource: "cypress/fixtures/imageTest1.png",
imageSourceFile: "cypress/fixtures/imageTest1.png",
imagePersonalitySource: "cypress/fixtures/imageTest2.png",
imageSlug: "image-claim-title",
};
Expand Down
4 changes: 2 additions & 2 deletions cypress/fixtures/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const review = {
question2: "Question 2 content",
report: "Verification Report content",
process: "Verification process content",
source1: "https://wikipedia.org",
source1: "https://wikidata.org",
source2: "https://google.com",
classification: "arguable",
editorContent: {
Expand All @@ -32,7 +32,7 @@ const review = {
{
type: "link",
attrs: {
href: "https://wikipedia.org",
href: "https://wikidata.org",
target: null,
auto: false,
id: "lovjnfw8",
Expand Down
6 changes: 6 additions & 0 deletions cypress/fixtures/source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const source = {
href: "https://wikipedia.org",
data_hash: "bb2c466041b713fdd03e28917286baa2",
};

export default source;
6 changes: 6 additions & 0 deletions cypress/support/locators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ const locators = {
INPUT_SOURCE: "[data-cy=testSource1]",
},

source: {
INPUT_SOURCE: "[data-cy=testClaimReviewsource]",
BTN_SUBMIT_SOURCE: "[data-cy=testSaveButton]",
},

floatButton: {
FLOAT_BUTTON: "[data-cy=testFloatButton]",
ADD_CLAIM: "[data-cy=testFloatButtonAddClaim]",
ADD_PERSONALITY: "[data-cy=testFloatButtonAddPersonality]",
ADD_SOURCE: "[data-cy=testFloatButtonAddSources]",
},

claimReview: {
Expand Down
55 changes: 29 additions & 26 deletions lib/editor-parser.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import { ObjectMark, RemirrorJSON } from "remirror";
import { ReviewTaskMachineContextReviewData } from "../server/claim-review-task/dto/create-claim-review-task.dto";
import { ReportModelEnum } from "../server/types/enums";
import { ReportModelEnum, ReviewTaskTypeEnum } from "../server/types/enums";

type BaseSchemaType = {
type ClaimReviewSchemaType = {
summary?: string;
};

type ClaimReviewSchemaType = BaseSchemaType & {
verification?: string;
report?: string;
sources?: any[];
questions?: string[];
};

type SourceReviewSchemaType = BaseSchemaType & {
source?: string;
};

type ReviewSchemaType = ClaimReviewSchemaType | SourceReviewSchemaType;
type ReviewSchemaType = ClaimReviewSchemaType;

const getEditorSchemaArray = (reportModel = ReportModelEnum.FactChecking) => {
if (!reportModel) {
Expand All @@ -35,7 +28,6 @@ const getEditorSchemaArray = (reportModel = ReportModelEnum.FactChecking) => {
"verification",
"questions",
"paragraph",
"source",
],
[ReportModelEnum.InformativeNews]: ["summary", "paragraph"],
};
Expand All @@ -52,15 +44,18 @@ const createParagraphBlock = (
content: [{ type: "paragraph" }],
});

const getDefaultDoc = (reportModel: string): RemirrorJSON => {
const getDefaultDoc = (reviewTaskType, reportModel: string): RemirrorJSON => {
const baseContent = [
createParagraphBlock("summary"),
createParagraphBlock("questions"),
createParagraphBlock("report"),
createParagraphBlock("verification"),
];

if (reportModel === ReportModelEnum.InformativeNews) {
if (
reportModel === ReportModelEnum.InformativeNews ||
reviewTaskType === ReviewTaskTypeEnum.Source
) {
return {
type: "doc",
content: [createParagraphBlock("summary")],
Expand All @@ -75,7 +70,7 @@ const getDefaultDoc = (reportModel: string): RemirrorJSON => {

export class EditorParser {
hasSources(sources): boolean {
return sources.length > 0;
return sources?.length > 0;
}

getSourceByProperty(sources, property) {
Expand Down Expand Up @@ -192,16 +187,25 @@ export class EditorParser {
return newSchema;
}

editor2schema(data: RemirrorJSON): ReviewTaskMachineContextReviewData & {
editor2schema({
content,
attrs = { reviewTaskType: ReviewTaskTypeEnum.Claim },
}: RemirrorJSON): ReviewTaskMachineContextReviewData & {
summary?: string;
source?: string;
} {
const schema: Partial<ReviewSchemaType> = {
summary: "",
sources: [],
};
let schema: Partial<ReviewSchemaType>;
switch (attrs.reviewTaskType) {
case ReviewTaskTypeEnum.Claim:
schema = { summary: "", sources: [] };
break;
default:
schema = {};
break;
}

const questions = [];
for (const cardContent of data?.content) {
for (const cardContent of content) {
if (getEditorSchemaArray().includes(cardContent?.type)) {
if (cardContent?.type === "questions") {
for (const { content } of cardContent.content) {
Expand Down Expand Up @@ -238,10 +242,8 @@ export class EditorParser {
schema.questions = questions;
}

schema.sources = this.replaceSourceContentToTextRange(schema);

if ("source" in schema && schema.source !== "") {
schema.sources.push(schema.source);
if ("sources" in schema) {
schema.sources = this.replaceSourceContentToTextRange(schema);
}

return schema;
Expand Down Expand Up @@ -329,10 +331,11 @@ export class EditorParser {

async schema2editor(
schema: ReviewTaskMachineContextReviewData,
reportModel = ReportModelEnum.FactChecking
reportModel = ReportModelEnum.FactChecking,
reviewTaskType: string = ReviewTaskTypeEnum.Claim
): Promise<RemirrorJSON> {
if (!schema) {
return getDefaultDoc(reportModel);
return getDefaultDoc(reviewTaskType, reportModel);
}

const doc: RemirrorJSON = {
Expand Down
3 changes: 2 additions & 1 deletion public/locales/en/claimReview.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"cardAuthor": "{{name}} reviewed this as:",
"anonymousUserName": "Anonymous",
"claimReview": "Claim reviewed as ",
"titleClaimReview": "Claim reviewed as ",
"titleSourceReview": "Source reviewed as ",
"listTitle": "Reviews",
"summarySectionTitle": "Summary of conclusion",
"questionsSectionTitle": "What questions should the verification answer?",
Expand Down
11 changes: 6 additions & 5 deletions public/locales/en/claimReviewForm.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"titleEmpty": "Choose a sentence to review",
"title": "Review the sentence",
"classificationLabel": "Review this claim",
"addReviewButton": "Start a fact-check",
"addFactCheckingReviewButton": "Start a fact-check",
"addInformativeNewsButton": "Start an informative news",
"addSourceReviewButton": "Start a source review",
"cancelButton": "Cancel",
"classificationPlaceholder": "Choose a classification",
"not-fact": "Not fact",
Expand Down Expand Up @@ -32,10 +33,10 @@
"sourceEditorLabel": "Create source review",
"verificationLabel": "How it was verified",
"verificationPlaceholder": "Describe how the verification was done",
"collaborativeEditorLabel": "Report",
"collaborativeEditorPlaceholder": "Insert report fields",
"sourcesLabel": "Provide at least one link to a reliable source",
"sourcesPlaceholder": "Paste URL",
"visualEditorLabel": "Report",
"visualEditorPlaceholder": "Insert report fields",
"sourceLabel": "Provide one link to a reliable source",
"sourcePlaceholder": "Paste URL",
"addSourceLabel": "Add another source",
"reviewerLabel": "Select a reviewer for review",
"reviewerPlaceholder": "Select a user",
Expand Down
Loading

0 comments on commit 987bdc6

Please sign in to comment.