-
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 pull request #2970 from responsible-ai-collaborative/staging
Deploy to Production
- Loading branch information
Showing
5 changed files
with
175 additions
and
130 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { conditionalIntercept, waitForRequest, test } from '../utils'; | ||
import { expect } from '@playwright/test'; | ||
import config from '../config'; | ||
|
||
test.describe('Account', () => { | ||
const url = '/account'; | ||
|
||
const user = { | ||
"data": { | ||
"user": { | ||
"__typename": "User", | ||
"adminData": { | ||
"__typename": "UserAdminDatum", | ||
"creationDate": "2022-09-26T20:34:46Z", | ||
"disabled": false, | ||
"email": process.env.E2E_ADMIN_USERNAME, | ||
"lastAuthenticationDate": "2023-06-06T00:07:30Z" | ||
}, | ||
"first_name": "Test", | ||
"last_name": "User", | ||
"roles": [ | ||
"admin" | ||
], | ||
"userId": "6423479655e4bb918a233bda" | ||
} | ||
} | ||
}; | ||
|
||
test('Should successfully load account page', async ({ page }) => { | ||
await page.goto(url); | ||
}); | ||
|
||
test('Should display account information if the user is logged in', async ({ page, login }) => { | ||
await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD); | ||
|
||
await conditionalIntercept( | ||
page, | ||
'**/graphql', | ||
(req) => | ||
req.postDataJSON().operationName === 'FindUser', | ||
user, | ||
'findUser' | ||
); | ||
|
||
await page.goto(url); | ||
|
||
await waitForRequest('findUser'); | ||
|
||
const detailsTable = page.locator('[data-cy="details-table"]'); | ||
await expect(detailsTable.locator(`td:text-is("${config.E2E_ADMIN_USERNAME}")`)).toBeVisible(); | ||
await expect(detailsTable.locator('td:text-is("Test")')).toBeVisible(); | ||
await expect(detailsTable.locator('td:text-is("User")')).toBeVisible(); | ||
await expect(detailsTable.locator('span:text-is("admin")')).toBeVisible(); | ||
|
||
await expect(page.locator('a:text-is("Log out")')).toBeVisible(); | ||
}); | ||
|
||
test('Should allow editing user data', async ({ page, login }) => { | ||
await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD); | ||
|
||
await conditionalIntercept( | ||
page, | ||
'**/graphql', | ||
(req) => | ||
req.postDataJSON().operationName === 'FindUser', | ||
user, | ||
'findUser' | ||
); | ||
|
||
await page.goto(url); | ||
|
||
await waitForRequest('findUser'); | ||
|
||
await page.locator('button:has-text("Edit")').click(); | ||
|
||
await conditionalIntercept( | ||
page, | ||
'**/graphql', | ||
(req) => req.postDataJSON().operationName == 'UpdateUserRoles', | ||
{ | ||
data: { | ||
updateOneUser: { | ||
__typename: 'User', | ||
roles: ['subscriber', 'bananas', 'ban', 'admin', 'banana'], | ||
userId: '6423479655e4bb918a233bda', | ||
}, | ||
}, | ||
}, | ||
'UpdateUserRoles' | ||
); | ||
const editUserModal = page.getByTestId('edit-user-modal'); | ||
await editUserModal.locator('[id="roles"]').fill('banana'); | ||
await editUserModal.locator('button:has-text("Submit")').click(); | ||
|
||
const updateUserRolesRequest = await waitForRequest('UpdateUserRoles'); | ||
const variables = updateUserRolesRequest.postDataJSON().variables; | ||
expect(variables.roles).toContain('banana'); | ||
}); | ||
|
||
test('Should show edit modal if query parameter is set', async ({ page, login }) => { | ||
await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD); | ||
|
||
await conditionalIntercept( | ||
page, | ||
'**/graphql', | ||
(req) => | ||
req.postDataJSON().operationName === 'FindUser', | ||
user, | ||
'findUser' | ||
); | ||
|
||
await page.goto(url + '?askToCompleteProfile=1'); | ||
|
||
await waitForRequest('findUser'); | ||
|
||
await expect(page.getByTestId('edit-user-modal')).toBeVisible(); | ||
}); | ||
}); |
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,56 @@ | ||
import { expect, Page } from '@playwright/test'; | ||
import { gql } from '@apollo/client'; | ||
import { query, test } from '../../utils'; | ||
|
||
const urls = [ | ||
{ namespace: 'CSETv0', url: '/taxonomy/csetv0' }, | ||
{ namespace: 'CSETv1', url: '/taxonomy/csetv1' }, | ||
]; | ||
|
||
urls.forEach(({ namespace, url }) => { | ||
test(`successfully loads ${namespace}`, async ({ page }) => { | ||
await page.goto(url); | ||
}); | ||
|
||
if (namespace === 'CSETv0') { | ||
test(`Should render ${namespace} fields list and Searchable status`, async ({ page }) => { | ||
await page.goto(url); | ||
|
||
const fieldListQuery = gql` | ||
{ | ||
taxa(query: { namespace_in: ["${namespace}"] }) { | ||
namespace | ||
field_list { | ||
long_name | ||
short_name | ||
instant_facet | ||
public | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const result = await query({ | ||
query: fieldListQuery, | ||
}); | ||
|
||
const field_list = result.data.taxa.field_list.filter( | ||
(entry) => (entry.public === null || entry.public) && entry.short_name !== 'Publish' | ||
); | ||
|
||
await expect(page.locator('[data-cy*="field-"]')).toHaveCount(field_list.length); | ||
|
||
for (const field of field_list) { | ||
const fieldLocator = page.locator('h3', { hasText: field.long_name.replace(/\s{2,}/g, ' ') }); | ||
await expect(fieldLocator).toBeVisible(); | ||
|
||
const searchableLocator = fieldLocator.locator('span', { hasText: 'Searchable in Discover App' }); | ||
if (field.instant_facet) { | ||
await expect(searchableLocator.first()).toBeVisible(); | ||
} else { | ||
await expect(searchableLocator.first()).not.toBeVisible(); | ||
} | ||
} | ||
}); | ||
} | ||
}); |