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 entityEdit to playwright #3047

Merged
Merged
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
122 changes: 0 additions & 122 deletions site/gatsby-site/cypress/e2e/integration/entityEdit.cy.js

This file was deleted.

10 changes: 0 additions & 10 deletions site/gatsby-site/cypress/fixtures/entities/entity.json

This file was deleted.

This file was deleted.

106 changes: 106 additions & 0 deletions site/gatsby-site/playwright/e2e-full/entityEdit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { conditionalIntercept, waitForRequest, test, query } from '../utils';
import entities from '../seeds/aiidprod/entities';
import { expect } from '@playwright/test';
import { init } from '../memory-mongo';
import gql from 'graphql-tag';

test.describe('Edit Entity', () => {
const entity_id = 'entity1';
const url = `/entities/edit?entity_id=${entity_id}`;

function isDateApproximatelyEqual(expectedDate, actualDate, toleranceInSeconds = 5) {
const expectedTime = new Date(expectedDate).getTime();
const actualTime = new Date(actualDate).getTime();
return Math.abs(expectedTime - actualTime) <= toleranceInSeconds * 1000;
}

test('Should successfully edit Entity fields', async ({ page, login, skipOnEmptyEnvironment }) => {

const userId = await login(process.env.E2E_ADMIN_USERNAME, process.env.E2E_ADMIN_PASSWORD);

await init({ customData: { users: [{ userId, first_name: 'Test', last_name: 'User', roles: ['admin'] }] }, }, { drop: true });

await page.goto(url);

const values = {
name: 'Google new',
};

for (const key in values) {
await page.locator(`[name=${key}]`).fill(values[key]);
}

await page.getByText("Save", { exact: true }).click();

const now = new Date();

await page.addInitScript(() => {
Date.now = () => now.getTime();
});

await expect(page.locator('.tw-toast')).toContainText('Entity updated successfully.');

const { data } = await query({
query: gql`{
entity(filter: { entity_id: { EQ: "${entity_id}" } }) {
entity_id
name
created_at
date_modified
}
}`,
});

expect(data.entity).toMatchObject({
entity_id,
created_at: entities[0].created_at,
name: values.name,
});

expect(isDateApproximatelyEqual(data.entity.date_modified, now.toISOString())).toBe(true);

await expect(page.locator('.tw-toast')).toContainText('Entity updated successfully.');
});


test('Should display an error message when editing Entity fails',
async ({ page, login, skipOnEmptyEnvironment }) => {
const userId = await login(process.env.E2E_ADMIN_USERNAME, process.env.E2E_ADMIN_PASSWORD);

await init({ customData: { users: [{ userId, first_name: 'Test', last_name: 'User', roles: ['admin'] }] }, }, { drop: true });

await page.goto(url);

const values = {
name: 'Google new',
};

for (const key in values) {
await page.locator(`[name=${key}]`).fill(values[key]);
}

await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON().operationName === 'UpdateEntity',
{
data: null,
errors: [
{
message: 'Dummy error message',
},
],
},
'UpdateEntity'
);

await page.getByText("Save", { exact: true }).click();

const updateEntityRequest = await waitForRequest('UpdateEntity');
expect(updateEntityRequest.postDataJSON().variables.filter.entity_id.EQ).toBe(entity_id);
expect(updateEntityRequest.postDataJSON().variables.update.set.name).toBe(values.name);

await expect(page.locator('.tw-toast')).toContainText('Error updating Entity.');
}
);
});
18 changes: 12 additions & 6 deletions site/gatsby-site/playwright/seeds/aiidprod/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,42 @@ const entities: DBEntity[] = [
{
entity_id: 'entity1',
name: 'Entity 1',
created_at: new Date(1609459200000).toString(),
created_at: new Date(1609459200000).toISOString(),
date_modified: new Date(1609459200000).toISOString(),
},

{
entity_id: 'entity2',
name: 'Entity 2',
created_at: new Date(1609459200000).toString(),
created_at: new Date(1609459200000).toISOString(),
date_modified: new Date(1609459200000).toISOString(),
},

{
entity_id: 'entity3',
name: 'Entity 3',
created_at: new Date(1609459200000).toString(),
created_at: new Date(1609459200000).toISOString(),
date_modified: new Date(1609459200000).toISOString(),
},
{
entity_id: 'starbucks',
name: 'Starbucks',
created_at: new Date(1609459200000).toString(),
created_at: new Date(1609459200000).toISOString(),
date_modified: new Date(1609459200000).toISOString(),
},

{
entity_id: 'kronos',
name: 'Kronos',
created_at: new Date(1609459200000).toString(),
created_at: new Date(1609459200000).toISOString(),
date_modified: new Date(1609459200000).toISOString(),
},

{
entity_id: 'starbucks-employees',
name: 'Starbucks Employees',
created_at: new Date(1609459200000).toString(),
created_at: new Date(1609459200000).toISOString(),
date_modified: new Date(1609459200000).toISOString(),
},
]

Expand Down
4 changes: 2 additions & 2 deletions site/gatsby-site/server/generated/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const documents = {
"\n mutation InsertDuplicate($duplicate: DuplicateInsertInput!) {\n insertOneDuplicate(data: $duplicate) {\n duplicate_incident_number\n true_incident_number\n }\n }\n": types.InsertDuplicateDocument,
"\n mutation UpsertEntity($filter: EntityFilterType!, $update: EntityInsertType!) {\n upsertOneEntity(filter: $filter, update: $update) {\n entity_id\n name\n }\n }\n": types.UpsertEntityDocument,
"\n query FindEntities {\n entities {\n entity_id\n name\n }\n }\n": types.FindEntitiesDocument,
"\n query FindEntity($filter: EntityFilterType) {\n entity(filter: $filter) {\n entity_id\n name\n created_at\n }\n }\n": types.FindEntityDocument,
"\n query FindEntity($filter: EntityFilterType) {\n entity(filter: $filter) {\n entity_id\n name\n created_at\n date_modified\n }\n }\n": types.FindEntityDocument,
"\n mutation UpdateEntity($filter: EntityFilterType!, $update: EntityUpdateType!) {\n updateOneEntity(filter: $filter, update: $update) {\n entity_id\n }\n }\n": types.UpdateEntityDocument,
"\n query FindIncident($filter: IncidentFilterType) {\n incident(filter: $filter) {\n incident_id\n title\n description\n editors {\n userId\n first_name\n last_name\n }\n date\n AllegedDeployerOfAISystem {\n entity_id\n name\n }\n AllegedDeveloperOfAISystem {\n entity_id\n name\n }\n AllegedHarmedOrNearlyHarmedParties {\n entity_id\n name\n }\n nlp_similar_incidents {\n incident_id\n similarity\n }\n editor_similar_incidents\n editor_dissimilar_incidents\n flagged_dissimilar_incidents\n reports {\n report_number\n }\n embedding {\n from_reports\n vector\n }\n editor_notes\n }\n }\n": types.FindIncidentDocument,
"\n query FindIncidentsTable($filter: IncidentFilterType) {\n incidents(filter: $filter) {\n incident_id\n title\n description\n editors {\n userId\n first_name\n last_name\n }\n date\n AllegedDeployerOfAISystem {\n entity_id\n name\n }\n AllegedDeveloperOfAISystem {\n entity_id\n name\n }\n AllegedHarmedOrNearlyHarmedParties {\n entity_id\n name\n }\n reports {\n report_number\n }\n }\n }\n": types.FindIncidentsTableDocument,
Expand Down Expand Up @@ -108,7 +108,7 @@ export function gql(source: "\n query FindEntities {\n entities {\n ent
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function gql(source: "\n query FindEntity($filter: EntityFilterType) {\n entity(filter: $filter) {\n entity_id\n name\n created_at\n }\n }\n"): (typeof documents)["\n query FindEntity($filter: EntityFilterType) {\n entity(filter: $filter) {\n entity_id\n name\n created_at\n }\n }\n"];
export function gql(source: "\n query FindEntity($filter: EntityFilterType) {\n entity(filter: $filter) {\n entity_id\n name\n created_at\n date_modified\n }\n }\n"): (typeof documents)["\n query FindEntity($filter: EntityFilterType) {\n entity(filter: $filter) {\n entity_id\n name\n created_at\n date_modified\n }\n }\n"];
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
Loading
Loading