From 47934af46138fdfba73e5c8b8c499a0b897635b8 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Wed, 11 Dec 2024 17:08:40 -0300 Subject: [PATCH 01/10] Unskip Should display Edit button only for Admin users and Should flag an incident --- .../playwright/e2e-full/apps/discover.spec.ts | 71 +++++++++++++++++++ .../playwright/e2e-full/entities.spec.ts | 23 ++++++ .../playwright/e2e/entities.spec.ts | 12 ---- .../playwright/fixtures/algoliaMock.ts | 43 ++++++++++- 4 files changed, 136 insertions(+), 13 deletions(-) create mode 100644 site/gatsby-site/playwright/e2e-full/apps/discover.spec.ts create mode 100644 site/gatsby-site/playwright/e2e-full/entities.spec.ts diff --git a/site/gatsby-site/playwright/e2e-full/apps/discover.spec.ts b/site/gatsby-site/playwright/e2e-full/apps/discover.spec.ts new file mode 100644 index 0000000000..5ff6b01ac2 --- /dev/null +++ b/site/gatsby-site/playwright/e2e-full/apps/discover.spec.ts @@ -0,0 +1,71 @@ +import { expect, Page, Download } from '@playwright/test'; +import { conditionalIntercept, mockDate, waitForRequest, test, mockAlgolia, query } from '../../utils'; +import { getUnixTime } from 'date-fns'; +import { deleteReportTypenames, transformReportData } from '../../../src/utils/reports'; +import gql from 'graphql-tag'; +import { init } from '../../memory-mongo'; + +test.describe('The Discover app', () => { + const url = '/apps/discover'; + + test('Should flag an incident', async ({ page, skipOnEmptyEnvironment }) => { + + await init({ + aiidprod: { + incidents: [ + { + incident_id: 2, + title: "BlenderBot 3 Cited Dutch Politician", + description: "BlenderBot 3 Cited Dutch Politician as" + }], + reports: [ + { + report_number: 1967, + incident_id: 2, + title: "BlenderBot 3 Cited Dutch Politician", + description: "BlenderBot 3 Cited Dutch Polit", + flag: false, + }] + } + }); + + await mockAlgolia(page); + + const now = new Date('June 21 2026 13:00:00'); + + await mockDate(page, now); + + await page.goto( + url + + '?display=details&incident_id=2&s=Test%20Incident%201' + ); + + await page.click(`[data-cy-report-number="1"] [data-cy="flag-button"]`); + + const modal = page.locator('[data-cy="flag-report-1"]'); + await expect(modal).toBeVisible(); + + await modal.locator('[data-cy="flag-toggle"]').click(); + await expect(modal.locator('[data-cy="flag-toggle"]')).toBeDisabled(); + + const result = await query({ + query: gql`{ + report(filter: { report_number: { EQ: 1 } }) { + report_number + flag + date_modified + epoch_date_modified + } + }` + }); + + const input = result.data.report; + + await expect(input?.flag).toBe(true); + + await expect(modal.locator('[data-cy="flag-toggle"]')).toBeDisabled(); + await modal.locator('[aria-label="Close"]').click(); + await expect(modal).not.toBeVisible(); + }); + +}); \ No newline at end of file diff --git a/site/gatsby-site/playwright/e2e-full/entities.spec.ts b/site/gatsby-site/playwright/e2e-full/entities.spec.ts new file mode 100644 index 0000000000..433afa4083 --- /dev/null +++ b/site/gatsby-site/playwright/e2e-full/entities.spec.ts @@ -0,0 +1,23 @@ + + +import { test } from '../utils'; +import { expect } from '@playwright/test'; +import config from '../config'; + +test.describe('Entities page', () => { + const url = '/entities'; + + test('Should display Edit button only for Admin users', async ({ page, login, skipOnEmptyEnvironment }) => { + + await page.goto(url); + + expect(await page.locator('[data-cy="edit-entity-btn"]').count()).toBe(0); + + await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD, { customData: { roles: ['admin'], first_name: 'John', last_name: 'Doe' } }); + await page.goto(url); + const editButton = page.locator('[data-cy="edit-entity-btn"]').first(); + expect(await editButton.getAttribute('href')).toBe('/entities/edit?entity_id=starbucks-employees'); + await editButton.click(); + await page.waitForURL(url => !url.toString().includes('/entities/edit?entity_id=starbucks-employees')); + }); +}); \ No newline at end of file diff --git a/site/gatsby-site/playwright/e2e/entities.spec.ts b/site/gatsby-site/playwright/e2e/entities.spec.ts index bd53470e55..1d3fc906f9 100644 --- a/site/gatsby-site/playwright/e2e/entities.spec.ts +++ b/site/gatsby-site/playwright/e2e/entities.spec.ts @@ -61,16 +61,4 @@ test.describe('Entities page', () => { await page.goto(url); await page.locator('[data-cy="row"]').first().locator('a:has-text("Facebook")').isVisible(); }); - - test.skip('Should display Edit button only for Admin users', async ({ page, login, skipOnEmptyEnvironment }) => { - await page.goto(url); - expect(await page.locator('[data-cy="edit-entity-btn"]').count()).toBe(0); - - await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD); - await page.goto(url); - const editButton = page.locator('[data-cy="edit-entity-btn"]').first(); - expect(await editButton.getAttribute('href')).toBe('/entities/edit?entity_id=facebook'); - await editButton.click(); - await page.waitForURL(url => !url.toString().includes('/entities/edit?entity_id=facebook')); - }); }); diff --git a/site/gatsby-site/playwright/fixtures/algoliaMock.ts b/site/gatsby-site/playwright/fixtures/algoliaMock.ts index 27c03c8816..169e388be0 100644 --- a/site/gatsby-site/playwright/fixtures/algoliaMock.ts +++ b/site/gatsby-site/playwright/fixtures/algoliaMock.ts @@ -819,8 +819,49 @@ export const algoliaMock = { }, }, }, + { + authors: ["Author 1", "Author 2"], + cloudinary_id: "sample_cloudinary_id", + date_downloaded: "2021-09-14T00:00:00.000Z", + date_modified: "2021-09-14T00:00:00.000Z", + date_published: "2021-09-14T00:00:00.000Z", + date_submitted: "2021-09-14T00:00:00.000Z", + description: "Sample description", + editor_notes: "Sample editor notes", + embedding: { + from_text_hash: "sample_hash", + vector: [0.1, 0.2, 0.3] + }, + epoch_date_downloaded: 1631577600, + epoch_date_modified: 1631577600, + epoch_date_published: 1631577600, + epoch_date_submitted: 1631577600, + flag: false, + image_url: "http://example.com/image.png", + inputs_outputs: ["input1", "output1"], + is_incident_report: true, + language: "en", + plain_text: "Sample plain text", + report_number: 1, + source_domain: "example.com", + submitters: ["Submitter 1", "Submitter 2"], + tags: ["tag1", "tag2"], + text: "Sample text", + title: "Sample title", + url: "http://example.com", + user: "admin", + quiet: false, + featured: 1, + incident_id: 1, + incident_date: '2014-08-14', + epoch_incident_date: 1407974400, + incident_title: + 'Test incident 1', + incident_description: + 'Test incident 1', + } ], - nbHits: 3, + nbHits: 4, page: 0, nbPages: 1, hitsPerPage: 28, From 1febe39babf5ab700d190e4a7626c8513025aed1 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Wed, 11 Dec 2024 17:13:56 -0300 Subject: [PATCH 02/10] Unskip redirect test for login/logout actions --- .../playwright/e2e/discover.spec.ts | 82 +------------------ .../playwright/e2e/landingPage.spec.ts | 8 +- 2 files changed, 5 insertions(+), 85 deletions(-) diff --git a/site/gatsby-site/playwright/e2e/discover.spec.ts b/site/gatsby-site/playwright/e2e/discover.spec.ts index a0223c5fca..a1823f8a17 100644 --- a/site/gatsby-site/playwright/e2e/discover.spec.ts +++ b/site/gatsby-site/playwright/e2e/discover.spec.ts @@ -167,87 +167,7 @@ test.describe('The Discover app', () => { }).toPass(); }); - // TODO: this test needs to be moved to e2e-full folder - test.skip('Should flag an incident', async ({ page, skipOnEmptyEnvironment }) => { - - await conditionalIntercept( - page, - '**/graphql', - (req) => req.postDataJSON().operationName === 'FindReport', - unflaggedReport, - 'findReport', - ); - - - const now = new Date('June 21 2026 13:00:00'); - - await mockDate(page, now); - - await page.goto( - url + - '?display=details&incident_id=10&s=%E2%80%8BIs%20Starbucks%20shortchanging%20its%20baristas%3F' - ); - - const _id = '5d34b8c29ced494f010ed470'; - - - await page.click(`[data-cy="${_id}"] [data-cy="flag-button"]`); - - const modal = page.locator('[data-cy="flag-report-23"]'); - await expect(modal).toBeVisible(); - - await conditionalIntercept( - page, - '**/graphql', - (req) => req.postDataJSON().operationName === 'UpdateReport', - flaggedReport, - 'updateReport', - ); - - await conditionalIntercept( - page, - '**/graphql', - (req) => req.postDataJSON().operationName === 'logReportHistory', - { - data: { - logReportHistory: { - report_number: 10, - }, - }, - }, - 'logReportHistory', - ); - - await modal.locator('[data-cy="flag-toggle"]').click(); - - const updateReportRequest = await waitForRequest('updateReport'); - const updateVariables = updateReportRequest.postDataJSON().variables; - expect(updateVariables.query.report_number).toBe(23); - expect(updateVariables.set).toEqual({ - flag: true, - date_modified: now.toISOString(), - epoch_date_modified: getUnixTime(now), - }); - - const logReportHistoryRequest = await waitForRequest('logReportHistory'); - const input = logReportHistoryRequest.postDataJSON().variables.input; - - const expectedReport = deleteReportTypenames( - transformReportData(flaggedReport.data.updateOneReport) - ); - - expectedReport.modifiedBy = ''; - expectedReport.date_modified = now.toISOString(); - expectedReport.epoch_date_modified = getUnixTime(now); - - expect(input).toEqual(expectedReport); - - await expect(modal.locator('[data-cy="flag-toggle"]')).toBeDisabled(); - await modal.locator('[aria-label="Close"]').click(); - await expect(modal).not.toBeVisible(); - }); - - test.skip('Opens an archive link', async ({ page, skipOnEmptyEnvironment }) => { + test('Opens an archive link', async ({ page, skipOnEmptyEnvironment }) => { await page.goto(url); diff --git a/site/gatsby-site/playwright/e2e/landingPage.spec.ts b/site/gatsby-site/playwright/e2e/landingPage.spec.ts index 40c35ffd22..4cd875874e 100644 --- a/site/gatsby-site/playwright/e2e/landingPage.spec.ts +++ b/site/gatsby-site/playwright/e2e/landingPage.spec.ts @@ -52,20 +52,20 @@ test.describe('The Landing page', () => { }); - test.skip('Should redirect to the account page when logged in', + test('Should redirect to the account page when logged in', async ({ page, skipOnEmptyEnvironment, login }) => { await login(process.env.E2E_ADMIN_USERNAME, process.env.E2E_ADMIN_PASSWORD); await expect(page).toHaveURL('/'); - await page.locator('[data-cy="sidebar-desktop"]').locator('[data-cy="sidebar-user"]').click(); + await page.locator('[data-testid="sidebar-desktop"]').locator('[data-testid="sidebar-user"]').click(); await expect(page).toHaveURL(/\/account\//); } ); - test.skip('Should redirect to the signup page when logged out', async ({ page }) => { + test('Should redirect to the signup page when logged out', async ({ page }) => { await page.setViewportSize({ width: 1920, height: 1080 }); // Set a larger viewport size await page.goto('/'); - await page.locator('[data-cy="sidebar-desktop"]').locator('[data-cy="sidebar-user"]').click(); + await page.locator('[data-testid="sidebar-desktop"]').locator('[data-testid="sidebar-user"]').click(); await expect(page).toHaveURL(/\/signup\//); }); From 90d8288e5b677aceaed3620c28a1d2eaf6d1ada0 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Wed, 11 Dec 2024 17:14:25 -0300 Subject: [PATCH 03/10] Re-skip 'Opens an archive link' until it works --- site/gatsby-site/playwright/e2e/discover.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/gatsby-site/playwright/e2e/discover.spec.ts b/site/gatsby-site/playwright/e2e/discover.spec.ts index a1823f8a17..ee74f639a0 100644 --- a/site/gatsby-site/playwright/e2e/discover.spec.ts +++ b/site/gatsby-site/playwright/e2e/discover.spec.ts @@ -167,7 +167,7 @@ test.describe('The Discover app', () => { }).toPass(); }); - test('Opens an archive link', async ({ page, skipOnEmptyEnvironment }) => { + test.skip('Opens an archive link', async ({ page, skipOnEmptyEnvironment }) => { await page.goto(url); From 296bb93a64454a79db59d9b1ace255781bd29f6d Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Thu, 12 Dec 2024 10:21:57 -0300 Subject: [PATCH 04/10] Move skipped login test to e2e-full --- .../playwright/e2e-full/login.spec.ts | 28 +++++++++++++++++++ site/gatsby-site/playwright/e2e/login.spec.ts | 19 ------------- 2 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 site/gatsby-site/playwright/e2e-full/login.spec.ts diff --git a/site/gatsby-site/playwright/e2e-full/login.spec.ts b/site/gatsby-site/playwright/e2e-full/login.spec.ts new file mode 100644 index 0000000000..6cad599bfb --- /dev/null +++ b/site/gatsby-site/playwright/e2e-full/login.spec.ts @@ -0,0 +1,28 @@ + +import { expect } from '@playwright/test'; +import { test } from '../utils'; +import config from '../config'; +import { init } from '../memory-mongo'; + +test.describe('Login', () => { + + test('Should redirect to the account page if the signup storage key is set', + async ({ page, skipOnEmptyEnvironment, login }) => { + + await page.goto('/'); + await page.evaluate(() => window.localStorage.setItem('signup', '1')); + + const userId = await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD); + + await init({ customData: { users: [{ userId, first_name: 'Test', last_name: 'User', roles: ['admin'] }] } }, { drop: true }); + + await expect(page).toHaveURL('/account/?askToCompleteProfile=1'); + + await expect(page.getByTestId('edit-user-modal')).toBeVisible({ timeout: 30000 }); + + const localStorage = await page.evaluate(() => window.localStorage); + + expect(localStorage.signup).toBeUndefined(); + } + ); +}); \ No newline at end of file diff --git a/site/gatsby-site/playwright/e2e/login.spec.ts b/site/gatsby-site/playwright/e2e/login.spec.ts index 84288eebaf..93fe405d29 100644 --- a/site/gatsby-site/playwright/e2e/login.spec.ts +++ b/site/gatsby-site/playwright/e2e/login.spec.ts @@ -17,25 +17,6 @@ test.describe('Login', () => { } ); - test.skip('Should redirect to the account page if the signup storage key is set', - async ({ page, skipOnEmptyEnvironment, login }) => { - - await page.goto('/'); - - await page.evaluate(() => window.localStorage.setItem('signup', '1')); - - await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD); - - await expect(page).toHaveURL('/account/?askToCompleteProfile=1'); - - await expect(page.getByTestId('edit-user-modal')).toBeVisible({ timeout: 30000 }); - - const localStorage = await page.evaluate(() => window.localStorage); - - expect(localStorage.signup).toBeUndefined(); - } - ); - test('Should redirect to specific page after login if redirectTo is provided', async ({ page, skipOnEmptyEnvironment, login }) => { const redirectTo = '/cite/10/'; From 338952b2d18843bec08354cbcd417b5426aa8ae2 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Thu, 12 Dec 2024 10:26:02 -0300 Subject: [PATCH 05/10] Use fixture to skip on empty env on report pages --- site/gatsby-site/playwright/e2e/report.spec.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/site/gatsby-site/playwright/e2e/report.spec.ts b/site/gatsby-site/playwright/e2e/report.spec.ts index 69ecef4f9e..c53b8c1f87 100644 --- a/site/gatsby-site/playwright/e2e/report.spec.ts +++ b/site/gatsby-site/playwright/e2e/report.spec.ts @@ -3,20 +3,15 @@ import config from '../config'; import { test } from '../utils'; test.describe('Report pages', () => { - test.beforeAll(async () => { - if (config.IS_EMPTY_ENVIRONMENT) { - test.skip(); - } - }); const reportNumber = 2302; const url = `/reports/${reportNumber}`; - test('Successfully loads', async ({ page }) => { + test('Successfully loads', async ({ page, skipOnEmptyEnvironment }) => { await page.goto(url); }); - test('Should always be expanded', async ({ page }) => { + test('Should always be expanded', async ({ page, skipOnEmptyEnvironment }) => { await page.goto(url); await expect(page.getByTestId("incident-report-card")).toHaveClass(/expanded/); }); From d34b6d18cc3d4db49911f9e88a523fef1e17f2db Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Thu, 12 Dec 2024 10:27:33 -0300 Subject: [PATCH 06/10] Use skipOnEmptyEnvironment fixture for cite.spec --- .../playwright/e2e-full/cite.spec.ts | 68 +++++++++---------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/site/gatsby-site/playwright/e2e-full/cite.spec.ts b/site/gatsby-site/playwright/e2e-full/cite.spec.ts index 807a95372a..5c28dd1986 100644 --- a/site/gatsby-site/playwright/e2e-full/cite.spec.ts +++ b/site/gatsby-site/playwright/e2e-full/cite.spec.ts @@ -15,11 +15,7 @@ test.describe('Cite pages', () => { let lastIncidentId: number; - test.beforeAll(async ({ request }) => { - // Skip all tests if the environment is empty since /cite/{incident_id} is not available - if (config.IS_EMPTY_ENVIRONMENT) { - test.skip(); - } + test.beforeAll(async ({ request, skipOnEmptyEnvironment }) => { const response = await query({ query: gql` @@ -34,11 +30,11 @@ test.describe('Cite pages', () => { lastIncidentId = response.data.incidents[0].incident_id; }); - test('Successfully loads', async ({ page }) => { + test('Successfully loads', async ({ page, skipOnEmptyEnvironment }) => { await page.goto(url); }); - test('Should show an edit link to users with the appropriate role', async ({ page, login }) => { + test('Should show an edit link to users with the appropriate role', async ({ page, login, skipOnEmptyEnvironment }) => { await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD); const id = 'r1'; @@ -57,7 +53,7 @@ test.describe('Cite pages', () => { test.skip( 'Should scroll to report when coming from the discover app', - async ({ page }) => { + async ({ page, skipOnEmptyEnvironment }) => { await page.goto(discoverUrl); await page.click('[data-cy="collapse-button"]:visible'); @@ -79,7 +75,7 @@ test.describe('Cite pages', () => { { retries: 4 } ); - test.skip('Should scroll to report when clicking on a report in the timeline', async ({ page }) => { + test.skip('Should scroll to report when clicking on a report in the timeline', async ({ page, skipOnEmptyEnvironment }) => { await page.goto(url); await page.waitForSelector('text=For some Starbucks workers, job leaves bitter taste'); @@ -92,18 +88,18 @@ test.describe('Cite pages', () => { }).toPass(); }); - test('Should show the incident stats table', async ({ page }) => { + test('Should show the incident stats table', async ({ page, skipOnEmptyEnvironment }) => { await page.goto(url); await expect(page.locator('[data-cy=incident-stats]')).toBeVisible(); }); - test('Should show editors in the stats table', async ({ page }) => { + test('Should show editors in the stats table', async ({ page, skipOnEmptyEnvironment }) => { await page.goto(url); const incidentStats = await page.locator('[data-cy=incident-stats] > * > *:has-text("Editors")'); await expect(incidentStats.locator('text=Sean McGregor')).toBeVisible(); }); - test('Should flag an incident', async ({ page }) => { + test('Should flag an incident', async ({ page, skipOnEmptyEnvironment }) => { const _id = '3'; await init(); @@ -135,7 +131,7 @@ test.describe('Cite pages', () => { expect(data.report.flag).toBe(true); }); - test('Should remove duplicate', async ({ page, login }) => { + test('Should remove duplicate', async ({ page, login, skipOnEmptyEnvironment }) => { test.slow(); @@ -182,7 +178,7 @@ test.describe('Cite pages', () => { expect(data.incident_classifications_2).toHaveLength(3); }); - test('Should pre-fill submit report form', async ({ page }) => { + test('Should pre-fill submit report form', async ({ page, skipOnEmptyEnvironment }) => { await page.goto(url); await page.locator('a:has-text("New Report")').click(); @@ -191,7 +187,7 @@ test.describe('Cite pages', () => { await expect(page.locator('.incident-ids-field [data-cy="token"]:has-text("3")')).toBeVisible(); }); - test('Should pre-fill submit report response form', async ({ page }) => { + test('Should pre-fill submit report response form', async ({ page, skipOnEmptyEnvironment }) => { await page.goto(url); await page.locator('a:has-text("New Response")').click(); @@ -200,7 +196,7 @@ test.describe('Cite pages', () => { await expect(page.locator('.incident-ids-field [data-cy="token"]:has-text("3")')).toBeVisible(); }); - test('Should render Next and Previous incident buttons', async ({ page }) => { + test('Should render Next and Previous incident buttons', async ({ page, skipOnEmptyEnvironment }) => { await page.goto('/cite/2'); await expect(page.locator('a:has-text("Next Incident")')).toBeVisible(); @@ -210,7 +206,7 @@ test.describe('Cite pages', () => { await expect(page.locator('a:has-text("Previous Incident")')).toHaveAttribute('href', '/cite/1'); }); - test('Should render duplicate page', async ({ page }) => { + test('Should render duplicate page', async ({ page, skipOnEmptyEnvironment }) => { await page.goto('/cite/5'); await expect(page.getByText('This incident is a duplicate of Incident 3. All new reports and citations should be directed to incident 3. The reports previously found on this page have been migrated to the previously existing incident.')).toBeVisible(); @@ -223,7 +219,7 @@ test.describe('Cite pages', () => { await expect(page.locator('a:has-text("Previous Incident")')).toHaveAttribute('href', '/cite/3'); }); - test('Should render the header next/previous buttons', async ({ page }) => { + test('Should render the header next/previous buttons', async ({ page, skipOnEmptyEnvironment }) => { await page.goto('/cite/2'); await expect(page.locator('[data-cy="header-previous-incident-link"]')).toBeVisible(); @@ -233,7 +229,7 @@ test.describe('Cite pages', () => { await expect(page.locator('[data-cy="header-next-incident-link"]')).toHaveAttribute('href', '/cite/3'); }); - test('Should disable Previous and Next incident buttons in header on first and last incidents', async ({ page }) => { + test('Should disable Previous and Next incident buttons in header on first and last incidents', async ({ page, skipOnEmptyEnvironment }) => { await page.goto('/cite/1'); await expect(page.locator('[data-cy="header-previous-incident-link"]')).not.toHaveAttribute('href'); @@ -249,7 +245,7 @@ test.describe('Cite pages', () => { await expect(page.locator('[data-cy="header-previous-incident-link"]')).toHaveAttribute('href', `/cite/${lastIncidentId - 1}`); }); - test('Should show the edit incident form', async ({ page, login }) => { + test('Should show the edit incident form', async ({ page, login, skipOnEmptyEnvironment }) => { await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD); await page.goto(url); @@ -261,7 +257,7 @@ test.describe('Cite pages', () => { await expect(page.locator('[data-cy="incident-form"]')).toBeVisible(); }); - test('Should display correct BibTex Citation', async ({ page }) => { + test('Should display correct BibTex Citation', async ({ page, skipOnEmptyEnvironment }) => { await page.goto(url); const date = format(new Date(), 'MMMMd,y'); @@ -279,7 +275,7 @@ test.describe('Cite pages', () => { ); }); - test('Should display similar incidents', async ({ page }) => { + test('Should display similar incidents', async ({ page, skipOnEmptyEnvironment }) => { await page.goto('/cite/3'); await expect(async () => { @@ -288,7 +284,7 @@ test.describe('Cite pages', () => { }).toPass(); }); - test('Should display similar incidents with localized links', async ({ page }) => { + test('Should display similar incidents with localized links', async ({ page, skipOnEmptyEnvironment }) => { await page.goto('/es/cite/3'); await expect(async () => { @@ -306,7 +302,7 @@ test.describe('Cite pages', () => { }).toPass(); }); - test('Should not display duplicate similar incidents', async ({ page }) => { + test('Should not display duplicate similar incidents', async ({ page, skipOnEmptyEnvironment }) => { await page.goto('/cite/9'); await expect(async () => { @@ -322,13 +318,13 @@ test.describe('Cite pages', () => { }).toPass(); }); - test('Should not display edit link when not logged in', async ({ page }) => { + test('Should not display edit link when not logged in', async ({ page, skipOnEmptyEnvironment }) => { await page.goto('/cite/3'); await expect(page.locator('[data-cy="edit-similar-incidents"]')).not.toBeVisible(); }); - test('Should display edit link when logged in as editor', async ({ page, login }) => { + test('Should display edit link when logged in as editor', async ({ page, login, skipOnEmptyEnvironment }) => { await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD); await page.goto('/cite/3'); @@ -336,7 +332,7 @@ test.describe('Cite pages', () => { await expect(page.locator('[data-cy="edit-similar-incidents"]').nth(1)).toBeVisible(); }); - test('Should flag an incident as not related (not authenticated)', async ({ page }) => { + test('Should flag an incident as not related (not authenticated)', async ({ page, skipOnEmptyEnvironment }) => { await init(); @@ -357,7 +353,7 @@ test.describe('Cite pages', () => { expect(data.incident.flagged_dissimilar_incidents).toContain(1); }); - test('Should flag an incident as not related (authenticated)', async ({ page, login }) => { + test('Should flag an incident as not related (authenticated)', async ({ page, login, skipOnEmptyEnvironment }) => { await init(); @@ -381,7 +377,7 @@ test.describe('Cite pages', () => { expect(data.incident.flagged_dissimilar_incidents).toContain(1); }); - test('Should have OpenGraph meta tags', async ({ page }) => { + test('Should have OpenGraph meta tags', async ({ page, skipOnEmptyEnvironment }) => { await page.goto(url); const response = await query({ @@ -417,7 +413,7 @@ test.describe('Cite pages', () => { await expect(page.locator('head meta[property="twitter:image"]')).toHaveAttribute('content'); }); - test('Should subscribe to incident updates (user authenticated)', async ({ page, login }) => { + test('Should subscribe to incident updates (user authenticated)', async ({ page, login, skipOnEmptyEnvironment }) => { await init(); @@ -449,14 +445,14 @@ test.describe('Cite pages', () => { expect(data.subscriptions).toEqual([{ type: 'incident', incident_id: { incident_id: 3 } }]); }); - test('Should show proper entities card text', async ({ page }) => { + test('Should show proper entities card text', async ({ page, skipOnEmptyEnvironment }) => { await page.goto('/cite/3/'); await expect(page.locator('[data-cy="alleged-entities"]')).toHaveText( 'Alleged: Kronos developed an AI system deployed by Starbucks, which harmed Starbucks Employees.Implicated AI system: Entity 1' ); }); - test('Should not display response in timeline or in badge', async ({ page }) => { + test('Should not display response in timeline or in badge', async ({ page, skipOnEmptyEnvironment }) => { await page.goto('/cite/1'); await expect(page.locator('[data-cy="responded-badge"]')).not.toBeVisible(); @@ -465,7 +461,7 @@ test.describe('Cite pages', () => { }); // the incident contains reports missing images so it will never pass - test.skip('There should not be image errors (400)', async ({ page }) => { + test.skip('There should not be image errors (400)', async ({ page, skipOnEmptyEnvironment }) => { page.on('console', (msg) => { if (msg.type() === 'error') { expect(msg.text()).not.toContain('the server responded with a status of 400'); @@ -478,7 +474,7 @@ test.describe('Cite pages', () => { await page.waitForTimeout(5000); }); - test('Should open incident from the discover app', async ({ page }) => { + test('Should open incident from the discover app', async ({ page, skipOnEmptyEnvironment }) => { await page.goto(discoverUrl); await page.locator('[data-cy="collapse-button"]:visible').click(); @@ -488,7 +484,7 @@ test.describe('Cite pages', () => { await expect(page).toHaveURL(new RegExp('/cite/1')); }); - test('Should link similar incidents', async ({ page, login }) => { + test('Should link similar incidents', async ({ page, login, skipOnEmptyEnvironment }) => { await init(); @@ -536,7 +532,7 @@ test.describe('Cite pages', () => { expect(data.incident_3).toMatchObject({ editor_dissimilar_incidents: [2], editor_similar_incidents: [1] }); }); - test('Should load incident data not yet in build', async ({ page }) => { + test('Should load incident data not yet in build', async ({ page, skipOnEmptyEnvironment }) => { await init(); From 8444384a878704dd57c2935a76ffe98afaa851e9 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Thu, 12 Dec 2024 10:32:03 -0300 Subject: [PATCH 07/10] Fix indentation for cite test --- .../playwright/e2e-full/cite.spec.ts | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/site/gatsby-site/playwright/e2e-full/cite.spec.ts b/site/gatsby-site/playwright/e2e-full/cite.spec.ts index 5c28dd1986..d3fba54afa 100644 --- a/site/gatsby-site/playwright/e2e-full/cite.spec.ts +++ b/site/gatsby-site/playwright/e2e-full/cite.spec.ts @@ -51,28 +51,26 @@ test.describe('Cite pages', () => { }); - test.skip( - 'Should scroll to report when coming from the discover app', - async ({ page, skipOnEmptyEnvironment }) => { + test.skip('Should scroll to report when coming from the discover app', async ({ page, skipOnEmptyEnvironment }) => { - await page.goto(discoverUrl); - await page.click('[data-cy="collapse-button"]:visible'); + await page.goto(discoverUrl); + await page.click('[data-cy="collapse-button"]:visible'); - await page.click('text="Show Details on Incident #10"'); + await page.click('text="Show Details on Incident #10"'); - await expect(async () => { - expect(page.url()).toContain('/cite/10/#r23'); - }).toPass(); + await expect(async () => { + expect(page.url()).toContain('/cite/10/#r23'); + }).toPass(); - await expect(async () => { + await expect(async () => { - await page.waitForSelector('h5:has-text("Is Starbucks shortchanging its baristas?")', { timeout: 8000 }); - const incidentReportCard = await page.$('[data-cy="incident-report-card"]'); - const boundingBox = await incidentReportCard.boundingBox(); - expect(boundingBox.y).toBeLessThanOrEqual(20); - }).toPass(); - }, - { retries: 4 } + await page.waitForSelector('h5:has-text("Is Starbucks shortchanging its baristas?")', { timeout: 8000 }); + const incidentReportCard = await page.$('[data-cy="incident-report-card"]'); + const boundingBox = await incidentReportCard.boundingBox(); + expect(boundingBox.y).toBeLessThanOrEqual(20); + }).toPass(); + } + ,{ retries: 4 } ); test.skip('Should scroll to report when clicking on a report in the timeline', async ({ page, skipOnEmptyEnvironment }) => { From 0f4ee2cc4ee067faf4cad81ce9a587bf95a16291 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Thu, 12 Dec 2024 10:33:10 -0300 Subject: [PATCH 08/10] Unskip "Should have read-only access for non-logged-in users" --- .../playwright/e2e-full/apps/checklistForm.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/site/gatsby-site/playwright/e2e-full/apps/checklistForm.spec.ts b/site/gatsby-site/playwright/e2e-full/apps/checklistForm.spec.ts index c1fc302235..9225561b82 100644 --- a/site/gatsby-site/playwright/e2e-full/apps/checklistForm.spec.ts +++ b/site/gatsby-site/playwright/e2e-full/apps/checklistForm.spec.ts @@ -20,7 +20,7 @@ test.describe('Checklists App Form', () => { tags_other: [], }; - test.skip('Should have read-only access for non-logged-in users', async ({ page }) => { + test('Should have read-only access for non-logged-in users', async ({ page }) => { await conditionalIntercept( page, '**/graphql', @@ -31,6 +31,8 @@ test.describe('Checklists App Form', () => { await page.goto(url); + await waitForRequest('findChecklist'); + await expect(page.locator('[data-cy="checklist-form"] textarea:not([disabled])')).not.toBeVisible(); await expect(page.locator('[data-cy="checklist-form"] input:not([disabled]):not([readonly])')).not.toBeVisible(); }); From c9a3b53372cca12c06543eace76ec4252073b149 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Thu, 12 Dec 2024 11:49:51 -0300 Subject: [PATCH 09/10] Unskip Should show fallback preview image on initial load --- site/gatsby-site/playwright/e2e-full/submit.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/gatsby-site/playwright/e2e-full/submit.spec.ts b/site/gatsby-site/playwright/e2e-full/submit.spec.ts index acd3c0d899..719bb30ddb 100644 --- a/site/gatsby-site/playwright/e2e-full/submit.spec.ts +++ b/site/gatsby-site/playwright/e2e-full/submit.spec.ts @@ -726,7 +726,7 @@ test.describe('The Submit form', () => { .not.toBeVisible(); }); - test.skip('Should show fallback preview image on initial load', async ({ page }) => { + test('Should show fallback preview image on initial load', async ({ page }) => { const values = { url: 'https://incidentdatabase.ai', title: 'test title', From f6e3f8b3120e9f454b33132187f0ea755608cf25 Mon Sep 17 00:00:00 2001 From: Clara Youdale Date: Thu, 12 Dec 2024 15:40:20 -0300 Subject: [PATCH 10/10] Fix login fixture --- site/gatsby-site/playwright/e2e-full/login.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/site/gatsby-site/playwright/e2e-full/login.spec.ts b/site/gatsby-site/playwright/e2e-full/login.spec.ts index 6cad599bfb..ee0bfd9237 100644 --- a/site/gatsby-site/playwright/e2e-full/login.spec.ts +++ b/site/gatsby-site/playwright/e2e-full/login.spec.ts @@ -9,13 +9,13 @@ test.describe('Login', () => { test('Should redirect to the account page if the signup storage key is set', async ({ page, skipOnEmptyEnvironment, login }) => { + await init(); + await page.goto('/'); await page.evaluate(() => window.localStorage.setItem('signup', '1')); - - const userId = await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD); - await init({ customData: { users: [{ userId, first_name: 'Test', last_name: 'User', roles: ['admin'] }] } }, { drop: true }); - + await login(process.env.E2E_ADMIN_USERNAME, process.env.E2E_ADMIN_PASSWORD, { customData: { roles: ['admin'], first_name: 'John', last_name: 'Doe' } }); + await expect(page).toHaveURL('/account/?askToCompleteProfile=1'); await expect(page.getByTestId('edit-user-modal')).toBeVisible({ timeout: 30000 });