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

Migrate checklists #3267

Open
wants to merge 13 commits into
base: staging
Choose a base branch
from
173 changes: 37 additions & 136 deletions site/gatsby-site/playwright/e2e-full/apps/checklistForm.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { expect } from '@playwright/test';
import riskSortingRisks from '../../fixtures/checklists/riskSortingChecklist.json';
import riskSortingChecklist from '../../fixtures/checklists/riskSortingChecklist.json';
import { conditionalIntercept, test, waitForRequest } from '../../utils';
import { conditionalIntercept, query, test, waitForRequest } from '../../utils';
import config from '../../config';
import { init } from '../../memory-mongo';
import gql from 'graphql-tag';

test.describe('Checklists App Form', () => {
const url = '/apps/checklists?id=testChecklist';
Expand All @@ -20,17 +21,13 @@ test.describe('Checklists App Form', () => {
tags_other: [],
};

test.skip('Should have read-only access for non-logged-in users', async ({ page }) => {
await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON()?.operationName === 'findChecklist',
{ data: { checklist: defaultChecklist } },
'findChecklist'
);
test('Should have read-only access for non-logged-in users', async ({ page }) => {

await init({ aiidprod: { checklists: [defaultChecklist] } }, { drop: true });

await page.goto(url);

await expect(page.getByText('Test Checklist')).toBeVisible();
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();
});
Expand All @@ -39,18 +36,11 @@ test.describe('Checklists App Form', () => {

await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD, { customData: { first_name: 'Test', last_name: 'User', roles: ['admin'] } });

await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON()?.operationName === 'findChecklist',
{ data: { checklist: defaultChecklist } },
'findChecklist',
);
await init({ aiidprod: { checklists: [defaultChecklist] } }, { drop: true });

await page.goto(url);

await waitForRequest('findChecklist');

await expect(page.getByText('Test Checklist')).toBeVisible();
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();
});
Expand All @@ -59,145 +49,75 @@ test.describe('Checklists App Form', () => {

const [userId] = await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD, { customData: { first_name: 'Test', last_name: 'User', roles: ['admin'] } });

await init({ aiidprod: { checklists: [{ ...defaultChecklist, owner_id: userId }] } }, { drop: true });

await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON()?.operationName === 'findChecklist',
{ data: { checklist: { ...defaultChecklist, owner_id: userId } } },
'findChecklist',
);
await page.goto(url);

await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON()?.operationName === 'upsertChecklist',
{
data: {
checklist: {
...defaultChecklist,
owner_id: userId,
about: "It's a system that does something probably.",
},
},
},
'upsertChecklist',
);
await expect(page.getByText('Test Checklist')).toBeVisible();

await page.goto(url);

await waitForRequest('findChecklist');
const response = page.waitForResponse((response) => response.request()?.postDataJSON()?.variables?.checklist?.about === 'It\'s a system that does something probably.');

await page.locator('[data-cy="about"]').type("It's a system that does something probably.");
await page.locator('[data-cy="about"]').fill("It's a system that does something probably.");

await waitForRequest('upsertChecklist');
await response;

const { data } = await query({
query: gql`
{
checklists {
about
}
}
`,
});

expect(data).toMatchObject({ checklists: [{ about: "It's a system that does something probably." }] });
});

test('Should trigger GraphQL upsert query on adding tag', async ({ page, login }) => {

const [userId] = await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD, { customData: { first_name: 'Test', last_name: 'User', roles: ['admin'] } });

await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON()?.operationName === 'findChecklist',
{ data: { checklist: { ...defaultChecklist, owner_id: userId } } },
'findChecklist',
);

await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON()?.operationName === 'upsertChecklist',
{ data: { checklist: {} } },
'upsertChecklist',
);
await init({ aiidprod: { checklists: [{ ...defaultChecklist, owner_id: userId }] } }, { drop: true });

await page.goto(url);

await waitForRequest('findChecklist');

await page.locator('#tags_goals_input').type('Code Generation');
const response = page.waitForResponse((response) => response.request()?.postDataJSON()?.operationName === 'upsertChecklist');

await page.locator('#tags_goals_input').fill('Code Generation');
await page.locator('#tags_goals').click();

await waitForRequest('upsertChecklist');
await response;
});

test('Should trigger GraphQL update on removing tag', async ({ page, login }) => {

const [userId] = await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD, { customData: { first_name: 'Test', last_name: 'User', roles: ['admin'] } });

await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON()?.operationName === 'findChecklist',
{
data: {
checklist: {
...defaultChecklist,
owner_id: userId,
tags_goals: ['GMF:Known AI Goal:Code Generation'],
},
},
},
'findChecklist',
);

await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON()?.operationName === 'upsertChecklist',
{ data: { checklist: {} } },
'upsertChecklist',
);
await init({ aiidprod: { checklists: [{ ...defaultChecklist, owner_id: userId, tags_goals: ['GMF:Known AI Goal:Code Generation'] }] } }, { drop: true });

await page.goto(url);

await waitForRequest('findChecklist');
const response = page.waitForResponse((response) => response.request()?.postDataJSON()?.operationName === 'upsertChecklist');

await page.locator('[option="GMF:Known AI Goal:Code Generation"] .close').click();

await waitForRequest('upsertChecklist');
await response;
});

test('Should trigger UI update on adding and removing tag', async ({ page, login }) => {

const [userId] = await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD, { customData: { first_name: 'Test', last_name: 'User', roles: ['admin'] } });

await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON()?.operationName === 'findChecklist',
{ data: { checklist: { ...defaultChecklist, owner_id: userId } } },
'findChecklist',
);

await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON()?.operationName === 'upsertChecklist',
{ data: { checklist: {} } },
'upsertChecklist',
);

await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON()?.operationName === 'FindRisks',
{ data: { risks: riskSortingRisks.data.checklist.risks } },
'risks'
);
await init({ aiidprod: { checklists: [{ ...defaultChecklist, owner_id: userId }] } }, { drop: true });

await page.goto(url);

await waitForRequest('findChecklist');

await page.locator('#tags_methods_input').type('Transformer');
await page.locator('#tags_methods_input').fill('Transformer');
await page.locator('#tags_methods').click();

await waitForRequest('upsertChecklist');

await waitForRequest('risks');

await expect(page.locator('details').first()).toBeVisible();

Expand All @@ -206,33 +126,14 @@ test.describe('Checklists App Form', () => {
await expect(page.locator('details')).not.toBeVisible();
});

test('Should change sort order of risk items', async ({ page, login }) => {
test.skip('Should change sort order of risk items', async ({ page, login }) => {
Copy link
Collaborator Author

@cesarvarela cesarvarela Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please help me create more seed data for this test.

(This can be done in another pr so we don’t let this one go stale)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, opened an issue and assigned to myself #3300.


const [userId] = await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD, { customData: { first_name: 'Test', last_name: 'User', roles: ['admin'] } });

await page.setViewportSize({ width: 1920, height: 1080 });

await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON()?.operationName === 'findChecklist',
{ data: { checklist: { ...riskSortingChecklist.data.checklist, owner_id: userId } } },
'findChecklist'
);

await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON()?.query.includes('GMF'),
{ data: { risks: riskSortingRisks.data.checklist.risks } },
'risks'
);

await page.goto(url);

await waitForRequest('findChecklist');
await waitForRequest('risks');

await page.locator('text=Mitigated').first().click();
await expect(page.locator('details:nth-child(2)')).toContainText('Distributional Bias');

Expand Down
Loading
Loading