Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/newsdigest playwright #3085

Draft
wants to merge 4 commits into
base: staging
Choose a base branch
from
Draft
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
110 changes: 0 additions & 110 deletions site/gatsby-site/cypress/e2e/integration/apps/newsdigest.cy.js

This file was deleted.

57 changes: 0 additions & 57 deletions site/gatsby-site/cypress/fixtures/candidates/newsArticles.json

This file was deleted.

107 changes: 107 additions & 0 deletions site/gatsby-site/playwright/e2e/apps/newsdigest.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { expect } from '@playwright/test';
import { test, query } from '../../utils';
import { gql } from '@apollo/client';
import { init } from '../../memory-mongo';
import config from '../../config';

test.describe('News Digest', () => {
const url = '/apps/newsdigest';

test('Successfully loads', async ({ page }) => {
await page.goto(url);
});

test('Should load candidate cards', async ({ page }) => {
await init();

await page.goto(url);
await page.locator('[data-cy="candidate-card"]').first().waitFor();
});

test('Should open submit form on pressing submit', async ({ page }) => {
await init();

await page.goto(url);
await page.exposeFunction('open', (url: string) => {
expect(url.slice(0, 12)).toBe('/apps/submit');
});

await page.locator('[data-cy="candidate-dropdown"] button').first().click();
await page.locator('[data-cy="submit-icon"]').first().click();
});

test('Should dismiss and restore items', async ({ page, login, skipOnEmptyEnvironment }) => {

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 page.goto(url);

const dataId = await page.locator('[data-cy="results"] [data-cy="candidate-card"] [data-cy="candidate-dropdown"]').first().evaluate(el => el.closest('[data-id]').getAttribute('data-id'));

await page.locator(`[data-id="${dataId}"] [data-cy="candidate-dropdown"]`).click();
await page.locator(`[data-id="${dataId}"] [data-cy="dismiss-icon"]`).click();

await expect(page.locator(`[data-cy="results"] [data-id="${dataId}"]`)).toHaveCount(0);

await expect(page.locator('[data-cy="toast"]')).toContainText(`Dismissed article:`);

const response = await query(
{
query: gql`
query NewsArticles($filter: CandidateFilterType!) {
candidates(filter: $filter) {
title
url
similarity
matching_keywords
matching_harm_keywords
matching_entities
date_published
dismissed
}
}
`,
variables: {
filter: {
dismissed: { EQ: true },
},
},
},
);
await expect(response.data.candidates).toHaveLength(1);
await page.locator(`[data-cy="dismissed-summary"]`).click();
await page.locator(`[data-id="${dataId}"] [data-cy="candidate-dropdown"]`).click();
await page.locator(`[data-id="${dataId}"] [data-cy="restore-icon"]`).click();

await expect(page.locator(`[data-cy="dismissed"] [data-id="${dataId}"]`)).toHaveCount(0);
await expect(page.locator(`[data-cy="results"] [data-id="${dataId}"]`)).toHaveCount(1);
await expect(page.locator('[data-cy="toast"]').filter({ hasText: 'Restored article:' })).toContainText(`Restored article:`);

const response2 = await query(
{
query: gql`
query NewsArticles($filter: CandidateFilterType!) {
candidates(filter: $filter) {
title
url
similarity
matching_keywords
matching_harm_keywords
matching_entities
date_published
dismissed
}
}
`,
variables: {
filter: {
dismissed: { EQ: true },
},
},
},
);

await expect(response2.data.candidates).toHaveLength(0);
});
});
2 changes: 2 additions & 0 deletions site/gatsby-site/playwright/memory-mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import entities from './seeds/aiidprod/entities';
import reports_es from './seeds/translations/reports_es';
import classifications from './seeds/aiidprod/classifications';
import taxa from './seeds/aiidprod/taxa';
import candidates from './seeds/aiidprod/candidates';

import users from './seeds/customData/users';

Expand All @@ -23,6 +24,7 @@ export const init = async (extra?: Record<string, Record<string, Record<string,
entities,
classifications,
taxa,
candidates
},
customData: {
users,
Expand Down
74 changes: 74 additions & 0 deletions site/gatsby-site/playwright/seeds/aiidprod/candidates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Candidate } from "../../../server/generated/graphql";

export type DBCandidate = Candidate;

const dates = Array(4)
.fill(null, 0, 4)
.map((e, i) => {
const newDate = new Date(
new Date().getTime() - 86400000 * i // i days ago
)

const day = newDate.getDate();
const month = newDate.getMonth();
const year = newDate.getFullYear();

return new Date(year, month, day).toISOString().slice(0, 10);
})

const candidates: DBCandidate[] = [
{
match: true,
title: "Candidate 1",
url: "https://www.candidate1.com",
date_published: dates[0],
dismissed: false,
similarity: 0.99,
matching_keywords: ["keyword1", "keyword2"],
matching_harm_keywords: ["harmkeyword1"],
matching_entities: ["entity1"],
text: "Candidate 1 Text",
plain_text: "Candidate 1 Plain Text"
},
{
match: true,
title: "Candidate 2",
url: "https://www.candidate2.com",
date_published: dates[1],
dismissed: false,
similarity: 0.85,
matching_keywords: ["keyword3"],
matching_harm_keywords: ["harmkeyword2"],
matching_entities: ["entity2"],
text: "Candidate 2 Text",
plain_text: "Candidate 2 Plain Text"
},
{
match: false,
title: "Candidate 3",
url: "https://www.candidate3.com",
date_published: dates[2],
dismissed: false,
similarity: 0.99,
matching_keywords: ["keyword4", "keyword5"],
matching_harm_keywords: ["harmkeyword3"],
matching_entities: [],
text: "Candidate 3 Text",
plain_text: "Candidate 3 Plain Text"
},
{
match: true,
title: "Candidate 4",
url: "https://www.candidate4.com",
date_published: dates[3],
dismissed: false,
similarity: 0.99,
matching_keywords: ["keyword6", "keyword7"],
matching_harm_keywords: ["harmkeyword4"],
matching_entities: ["entity2"],
text: "Candidate 4 Text",
plain_text: "Candidate 4 Plain Text"
},
];

export default candidates;
Loading
Loading