Skip to content

Commit

Permalink
Merge pull request #2970 from responsible-ai-collaborative/staging
Browse files Browse the repository at this point in the history
Deploy to Production
  • Loading branch information
kepae authored Jul 18, 2024
2 parents faff383 + c966cb5 commit 23bb138
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 130 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
E2E_ADMIN_PASSWORD: ${{ secrets.E2E_ADMIN_PASSWORD }}
E2E_ADMIN_USERNAME: ${{ secrets.E2E_ADMIN_USERNAME }}
IS_EMPTY_ENVIRONMENT: ${{ vars.IS_EMPTY_ENVIRONMENT }}
GATSBY_AVAILABLE_LANGUAGES: ${{ vars.GATSBY_AVAILABLE_LANGUAGES }}

- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
Expand Down
73 changes: 0 additions & 73 deletions site/gatsby-site/cypress/e2e/integration/account.cy.js

This file was deleted.

57 changes: 0 additions & 57 deletions site/gatsby-site/cypress/e2e/integration/cset.cy.js

This file was deleted.

118 changes: 118 additions & 0 deletions site/gatsby-site/playwright/e2e/account.spec.ts
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();
});
});
56 changes: 56 additions & 0 deletions site/gatsby-site/playwright/e2e/integration/cset.spec.ts
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();
}
}
});
}
});

0 comments on commit 23bb138

Please sign in to comment.