Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarvarela committed Dec 9, 2024
1 parent 3456d04 commit 951645a
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 286 deletions.
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 }) => {

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

0 comments on commit 951645a

Please sign in to comment.