From 398c8180f2298438260afc7c9eaf716159d0b932 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Tue, 10 Dec 2024 16:13:49 -0300 Subject: [PATCH 1/5] Fix queries and test for related reports in submission form --- .../playwright/e2e-full/submit.spec.ts | 158 ++++++------------ .../src/components/RelatedIncidents.js | 10 +- 2 files changed, 55 insertions(+), 113 deletions(-) diff --git a/site/gatsby-site/playwright/e2e-full/submit.spec.ts b/site/gatsby-site/playwright/e2e-full/submit.spec.ts index acd3c0d899..9d74af74ef 100644 --- a/site/gatsby-site/playwright/e2e-full/submit.spec.ts +++ b/site/gatsby-site/playwright/e2e-full/submit.spec.ts @@ -464,112 +464,60 @@ test.describe('The Submit form', () => { }); - test.skip('Should show a list of related reports', async ({ page, skipOnEmptyEnvironment }) => { - - const relatedReports = { - byURL: { - data: { - reports: [ - { - __typename: 'Report', - report_number: 1501, - title: 'Zillow to exit its home buying business, cut 25% of staff', - url: 'https://www.cnn.com/2021/11/02/homes/zillow-exit-ibuying-home-business/index.html', - }, - ], - }, - }, - byDatePublished: { - data: { - reports: [ - { - __typename: 'Report', - report_number: 810, - title: "Google's Nest Stops Selling Its Smart Smoke Alarm For Now Due To Faulty Feature", - url: 'https://www.forbes.com/sites/aarontilley/2014/04/03/googles-nest-stops-selling-its-smart-smoke-alarm-for-now', - }, - { - __typename: 'Report', - report_number: 811, - title: 'Why Nest’s Smoke Detector Fail Is Actually A Win For Everyone', - url: 'https://readwrite.com/2014/04/04/nest-smoke-detector-fail/', - }, - ], - }, - }, - byAuthors: { - data: { reports: [] }, - }, - byIncidentId: { - data: { - incidents: [ - { - __typename: 'Incident', - incident_id: 1, - title: 'Google’s YouTube Kids App Presents Inappropriate Content', - reports: [ - { - __typename: 'Report', - report_number: 10, - title: 'Google’s YouTube Kids App Presents Inappropriate Content', - url: 'https://www.change.org/p/remove-youtube-kids-app-until-it-eliminates-its-inappropriate-content', - }, - ], - }, - ], - }, - }, - }; - - await trackRequest( - page, - '**/graphql', - (req) => req.postDataJSON().operationName == 'FindSubmissions', - 'findSubmissions' - ); + test('Should show a list of related reports', async ({ page, skipOnEmptyEnvironment }) => { await page.goto(url); - await waitForRequest('findSubmissions'); - - await conditionalIntercept( - page, - '**/graphql', - (req) => - req.postDataJSON().operationName == 'ProbablyRelatedReports' && - req.postDataJSON().variables.query?.url_in, - relatedReports.byURL, - 'RelatedReportsByURL' - ); - - await conditionalIntercept( - page, - '**/graphql', - (req) => - req.postDataJSON().operationName == 'ProbablyRelatedReports' && - req.postDataJSON().variables.query?.epoch_date_published_gt && - req.postDataJSON().variables.query?.epoch_date_published_lt, - relatedReports.byDatePublished, - 'RelatedReportsByPublishedDate' - ); + const authors = "author1"; + const date_published = "2014-08-14"; + const reportUrl = 'https://www.thisisatest.nomeaning.com'; + const dateTime = new Date(date_published).getTime() / 1000; - await conditionalIntercept( - page, - '**/graphql', - (req) => - req.postDataJSON().operationName == 'ProbablyRelatedReports' && - req.postDataJSON().variables.query?.authors_in?.length, - relatedReports.byAuthors, - 'RelatedReportsByAuthor' - ); const values = { - url: 'https://www.cnn.com/2021/11/02/homes/zillow-exit-ibuying-home-business/index.html', - authors: 'test author', - date_published: '2014-03-30', + url: reportUrl, + authors, + date_published, incident_ids: 1, }; + const { data: { reports: reportsAuthors } } = await query({ + query: gql` + query { + reports(filter: { authors: {IN: ["${authors}"] } }) { + report_number + } + } + `, + }); + + const { data: { reports: reportsPublished } } = await query({ + query: gql` + query { + reports(filter: { epoch_date_published: {GTE: ${dateTime}, LTE: ${dateTime} } }) { + report_number + } + } + `, + }); + + const { data: { reports: reportsUrl } } = await query({ + query: gql` + query { + reports(filter: { url: {IN: ["${reportUrl}"] } }) { + report_number + } + } + `, + }); + + const reports = { + byAuthors: reportsAuthors, + byDatePublished: reportsPublished, + byURL: reportsUrl, + } + + for (const key in values) { if (key == 'incident_ids') { await page.locator(`input[name="${key}"]`).fill(values[key].toString()); @@ -580,29 +528,21 @@ test.describe('The Submit form', () => { } } - await waitForRequest('RelatedReportsByAuthor'); - await waitForRequest('RelatedReportsByURL'); - await waitForRequest('RelatedReportsByPublishedDate'); - - for (const key of ['byURL', 'byDatePublished']) { - const reports = - key == 'byIncidentId' - ? relatedReports[key].data.incidents[0].reports - : relatedReports[key].data.reports; + for (const key of ['byAuthors', 'byDatePublished']) { const parentLocator = page.locator(`[data-cy="related-${key}"]`); await expect(async () => { - await expect(parentLocator.locator('[data-cy="result"]')).toHaveCount(reports.length); + await expect(parentLocator.locator('[data-cy="result"]')).toHaveCount(reports[key].length); }).toPass(); - for (const report of reports) { + for (const report of reports[key]) { await expect(parentLocator.locator('[data-cy="result"]', { hasText: report.title })).toBeVisible(); } } - await expect(page.locator(`[data-cy="related-byAuthors"]`).locator('[data-cy="no-related-reports"]')).toHaveText('No related reports found.'); + await expect(page.locator(`[data-cy="related-byURL"]`).locator('[data-cy="no-related-reports"]')).toHaveText('No related reports found.'); } ); diff --git a/site/gatsby-site/src/components/RelatedIncidents.js b/site/gatsby-site/src/components/RelatedIncidents.js index d5396185d0..fc2c610cb1 100644 --- a/site/gatsby-site/src/components/RelatedIncidents.js +++ b/site/gatsby-site/src/components/RelatedIncidents.js @@ -93,7 +93,9 @@ const allSearchColumns = { const epoch_date_published_lt = getUnixTime(addWeeks(datePublished, 2)); - return { epoch_date_published_gt, epoch_date_published_lt }; + return { + epoch_date_published: { GTE: epoch_date_published_gt, LTE: epoch_date_published_lt }, + }; }, }, @@ -136,7 +138,7 @@ const allSearchColumns = { getReports: async (result, client) => reportsWithIncidentIds(result.data.reports, client), isSet: (incident) => incident.authors, getQueryVariables: (incident) => ({ - authors_in: isArray(incident.authors) ? incident.authors : incident.authors.split(','), + authors: { IN: isArray(incident.authors) ? incident.authors : incident.authors.split(',') }, }), }, @@ -155,7 +157,7 @@ const allSearchColumns = { query: relatedReportsQuery, getReports: async (result, client) => reportsWithIncidentIds(result.data.reports, client), isSet: (incident) => incident.url, - getQueryVariables: (incident) => ({ url_in: [incident.url] }), + getQueryVariables: (incident) => ({ url: { IN: [incident.url] } }), editSimilar: false, }, }; @@ -208,7 +210,7 @@ const RelatedIncidents = ({ if (key != 'byText') { setLoading((loading) => ({ ...loading, [key]: true })); } - const variables = { query: queryVariables[key] }; + const variables = { filter: queryVariables[key] }; const query = column.query; From 8d74ee5367ad0837df98e1140d8c2348f24ae996 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Tue, 10 Dec 2024 16:14:27 -0300 Subject: [PATCH 2/5] Remove unnecessary additional break lines --- site/gatsby-site/playwright/e2e-full/submit.spec.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/site/gatsby-site/playwright/e2e-full/submit.spec.ts b/site/gatsby-site/playwright/e2e-full/submit.spec.ts index 9d74af74ef..d57577eece 100644 --- a/site/gatsby-site/playwright/e2e-full/submit.spec.ts +++ b/site/gatsby-site/playwright/e2e-full/submit.spec.ts @@ -473,7 +473,6 @@ test.describe('The Submit form', () => { const reportUrl = 'https://www.thisisatest.nomeaning.com'; const dateTime = new Date(date_published).getTime() / 1000; - const values = { url: reportUrl, authors, @@ -517,7 +516,6 @@ test.describe('The Submit form', () => { byURL: reportsUrl, } - for (const key in values) { if (key == 'incident_ids') { await page.locator(`input[name="${key}"]`).fill(values[key].toString()); From cc55100080a4044ef44583bcabda589a7c739691 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Wed, 11 Dec 2024 08:45:03 -0300 Subject: [PATCH 3/5] Use GT and LT instead of GTE and LTE to check for related reports for published date --- site/gatsby-site/playwright/e2e-full/submit.spec.ts | 7 ++++++- site/gatsby-site/src/components/RelatedIncidents.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/site/gatsby-site/playwright/e2e-full/submit.spec.ts b/site/gatsby-site/playwright/e2e-full/submit.spec.ts index d57577eece..801e21f950 100644 --- a/site/gatsby-site/playwright/e2e-full/submit.spec.ts +++ b/site/gatsby-site/playwright/e2e-full/submit.spec.ts @@ -4,6 +4,7 @@ import { expect } from '@playwright/test'; import config from '../config'; import { init } from '../memory-mongo'; import gql from 'graphql-tag'; +import { addWeeks, getUnixTime, subWeeks } from 'date-fns'; test.describe('The Submit form', () => { @@ -480,6 +481,10 @@ test.describe('The Submit form', () => { incident_ids: 1, }; + const epoch_date_published_gt = getUnixTime(subWeeks(new Date(date_published), 2)); + + const epoch_date_published_lt = getUnixTime(addWeeks(new Date(date_published), 2)); + const { data: { reports: reportsAuthors } } = await query({ query: gql` query { @@ -493,7 +498,7 @@ test.describe('The Submit form', () => { const { data: { reports: reportsPublished } } = await query({ query: gql` query { - reports(filter: { epoch_date_published: {GTE: ${dateTime}, LTE: ${dateTime} } }) { + reports(filter: { epoch_date_published: {GT: ${epoch_date_published_gt}, LT: ${epoch_date_published_lt} } }) { report_number } } diff --git a/site/gatsby-site/src/components/RelatedIncidents.js b/site/gatsby-site/src/components/RelatedIncidents.js index fc2c610cb1..86b7100729 100644 --- a/site/gatsby-site/src/components/RelatedIncidents.js +++ b/site/gatsby-site/src/components/RelatedIncidents.js @@ -94,7 +94,7 @@ const allSearchColumns = { const epoch_date_published_lt = getUnixTime(addWeeks(datePublished, 2)); return { - epoch_date_published: { GTE: epoch_date_published_gt, LTE: epoch_date_published_lt }, + epoch_date_published: { GT: epoch_date_published_gt, LT: epoch_date_published_lt }, }; }, }, From 8b3f39d55aa25ca0e0ca46cd8d7a64bc29489814 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Fri, 13 Dec 2024 10:50:23 -0300 Subject: [PATCH 4/5] Fix test that checks related and add new one that checks when no related present --- .../playwright/e2e-full/submit.spec.ts | 86 ++++++++++++++++++- 1 file changed, 82 insertions(+), 4 deletions(-) diff --git a/site/gatsby-site/playwright/e2e-full/submit.spec.ts b/site/gatsby-site/playwright/e2e-full/submit.spec.ts index 801e21f950..9e637cee96 100644 --- a/site/gatsby-site/playwright/e2e-full/submit.spec.ts +++ b/site/gatsby-site/playwright/e2e-full/submit.spec.ts @@ -471,8 +471,7 @@ test.describe('The Submit form', () => { const authors = "author1"; const date_published = "2014-08-14"; - const reportUrl = 'https://www.thisisatest.nomeaning.com'; - const dateTime = new Date(date_published).getTime() / 1000; + const reportUrl = 'http://example.com'; const values = { url: reportUrl, @@ -531,7 +530,7 @@ test.describe('The Submit form', () => { } } - for (const key of ['byAuthors', 'byDatePublished']) { + for (const key of Object.keys(reports)) { const parentLocator = page.locator(`[data-cy="related-${key}"]`); @@ -545,10 +544,89 @@ test.describe('The Submit form', () => { } - await expect(page.locator(`[data-cy="related-byURL"]`).locator('[data-cy="no-related-reports"]')).toHaveText('No related reports found.'); + // await expect(page.locator(`[data-cy="related-byURL"]`).locator('[data-cy="no-related-reports"]')).toHaveText('No related reports found.'); } ); + + + test('Should not show a list of related reports', async ({ page, skipOnEmptyEnvironment }) => { + + await page.goto(url); + + const authors = "this is a new non existing author"; + const date_published = "2034-01-01"; + const reportUrl = 'http://nonExistingUrlForReport.com'; + + const values = { + url: reportUrl, + authors, + date_published, + }; + + const epoch_date_published_gt = getUnixTime(subWeeks(new Date(date_published), 2)); + + const epoch_date_published_lt = getUnixTime(addWeeks(new Date(date_published), 2)); + + const { data: { reports: reportsAuthors } } = await query({ + query: gql` + query { + reports(filter: { authors: {IN: ["${authors}"] } }) { + report_number + } + } + `, + }); + + const { data: { reports: reportsPublished } } = await query({ + query: gql` + query { + reports(filter: { epoch_date_published: {GT: ${epoch_date_published_gt}, LT: ${epoch_date_published_lt} } }) { + report_number + } + } + `, + }); + + const { data: { reports: reportsUrl } } = await query({ + query: gql` + query { + reports(filter: { url: {IN: ["${reportUrl}"] } }) { + report_number + } + } + `, + }); + + const reports = { + byAuthors: reportsAuthors, + byDatePublished: reportsPublished, + byURL: reportsUrl, + } + + for (const key in values) { + if (key == 'incident_ids') { + await page.locator(`input[name="${key}"]`).fill(values[key].toString()); + await page.waitForSelector(`[role="option"]`); + await page.locator(`[role="option"]`).first().click(); + } else { + await page.locator(`input[name="${key}"]`).fill(values[key]); + } + } + + for (const key of Object.keys(reports)) { + + const parentLocator = page.locator(`[data-cy="related-${key}"]`); + + await expect(async () => { + await expect(parentLocator.locator('[data-cy="result"]')).toHaveCount(0); + }).toPass(); + + await expect(page.locator(`[data-cy="related-${key}"]`).locator('[data-cy="no-related-reports"]')).toHaveText('No related reports found.'); + } + } + ); + test.skip('Should show a preliminary checks message', async ({ page }) => { const relatedReports = { byURL: { From 6bdc57f8936a5a76f037114c7d76e2ea7f8ccc56 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Fri, 13 Dec 2024 11:30:29 -0300 Subject: [PATCH 5/5] Fix add as similar and dissimilar tests --- .../playwright/e2e-full/submit.spec.ts | 78 +++++++++++++++---- 1 file changed, 63 insertions(+), 15 deletions(-) diff --git a/site/gatsby-site/playwright/e2e-full/submit.spec.ts b/site/gatsby-site/playwright/e2e-full/submit.spec.ts index 9e637cee96..fbbc9140a5 100644 --- a/site/gatsby-site/playwright/e2e-full/submit.spec.ts +++ b/site/gatsby-site/playwright/e2e-full/submit.spec.ts @@ -543,14 +543,12 @@ test.describe('The Submit form', () => { } } - - // await expect(page.locator(`[data-cy="related-byURL"]`).locator('[data-cy="no-related-reports"]')).toHaveText('No related reports found.'); } ); - test('Should not show a list of related reports', async ({ page, skipOnEmptyEnvironment }) => { + test('Should *not* show a list of related reports', async ({ page, skipOnEmptyEnvironment }) => { await page.goto(url); @@ -1109,23 +1107,59 @@ test.describe('The Submit form', () => { await page.locator('button[type="submit"]').click(); }); - test.skip('Should show related reports based on author', async ({ page }) => { + test('Should show related reports based on author and add as similar', async ({ page }) => { - await trackRequest( - page, - '**/graphql', - (req) => req.postDataJSON().operationName == 'FindSubmissions', - 'findSubmissions' - ); + await init(); await page.goto(url); - await waitForRequest('findSubmissions'); + const values = { + url: 'https://incidentdatabase.ai', + title: 'test title', + authors: 'author1', + incident_date: '2022-01-01', + date_published: '2021-01-02', + date_downloaded: '2021-01-03', + }; + + for (const key in values) { + await page.locator(`[name="${key}"]`).fill(values[key]); + } + + await setEditorText(page, 'Sit quo accusantium quia assumenda. Quod delectus similique labore optio quaease'); + + await expect(page.locator('[data-cy="related-byAuthors"] [data-cy="result"]').first()).toBeVisible(); + await page.locator('[data-cy="related-byAuthors"] [data-cy="result"]').nth(0).locator('[data-cy="similar"]').first().click(); + + await page.locator('button[data-cy="submit-step-1"]').click(); + + await expect(page.locator('.tw-toast:has-text("Report successfully added to review queue")')).toBeVisible(); + + const { data } = await query({ + query: gql` + query { + submission(sort: { date_submitted:DESC }){ + editor_similar_incidents + } + } + `, + }); + + expect(data.submission).toMatchObject({ + editor_similar_incidents: [1], + }); + }); + + test('Should show related reports based on author and add as dissimilar', async ({ page }) => { + + await init(); + + await page.goto(url); const values = { url: 'https://incidentdatabase.ai', title: 'test title', - authors: 'BBC News', + authors: 'author1', incident_date: '2022-01-01', date_published: '2021-01-02', date_downloaded: '2021-01-03', @@ -1138,11 +1172,25 @@ test.describe('The Submit form', () => { await setEditorText(page, 'Sit quo accusantium quia assumenda. Quod delectus similique labore optio quaease'); await expect(page.locator('[data-cy="related-byAuthors"] [data-cy="result"]').first()).toBeVisible(); - await page.locator('[data-cy="related-byAuthors"] [data-cy="result"]').nth(0).locator('[data-cy="unspecified"]').first().click(); - await page.locator('[data-cy="related-byAuthors"] [data-cy="result"]').nth(1).locator('[data-cy="dissimilar"]').first().click(); - await page.locator('[data-cy="related-byAuthors"] [data-cy="result"]').nth(2).locator('[data-cy="similar"]').first().click(); + await page.locator('[data-cy="related-byAuthors"] [data-cy="result"]').nth(0).locator('[data-cy="dissimilar"]').first().click(); await page.locator('button[data-cy="submit-step-1"]').click(); + + await expect(page.locator('.tw-toast:has-text("Report successfully added to review queue")')).toBeVisible(); + + const { data } = await query({ + query: gql` + query { + submission(sort: { date_submitted:DESC }){ + editor_dissimilar_incidents + } + } + `, + }); + + expect(data.submission).toMatchObject({ + editor_dissimilar_incidents: [1], + }); }); test('Should hide incident_date, description, deployers, developers & harmed_parties if incident_ids is set', async ({ page }) => {