-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/staging' into feature-netlify-…
…functions
- Loading branch information
Showing
12 changed files
with
161 additions
and
172 deletions.
There are no files selected for viewing
122 changes: 0 additions & 122 deletions
122
site/gatsby-site/cypress/e2e/integration/entityEdit.cy.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
site/gatsby-site/cypress/fixtures/entities/updateOneEntity.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
site/gatsby-site/playwright/e2e-full/entityEdit.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.