diff --git a/.github/workflows/test-playwright.yml b/.github/workflows/test-playwright.yml index f13020e3da..567dcd71d5 100644 --- a/.github/workflows/test-playwright.yml +++ b/.github/workflows/test-playwright.yml @@ -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() }} diff --git a/site/gatsby-site/cypress/e2e/integration/account.cy.js b/site/gatsby-site/cypress/e2e/integration/account.cy.js deleted file mode 100644 index dc1f1c7972..0000000000 --- a/site/gatsby-site/cypress/e2e/integration/account.cy.js +++ /dev/null @@ -1,73 +0,0 @@ -import { maybeIt } from '../../support/utils'; - -describe('Account', () => { - const url = '/account'; - - it('Should successfully load account page', () => { - cy.visit(url); - }); - - maybeIt('Should display account information if the user is logged in', () => { - cy.login(Cypress.env('e2eUsername'), Cypress.env('e2ePassword')); - - cy.visit(url); - - cy.waitForStableDOM(); - - cy.get('[data-cy="details-table"]').within(() => { - cy.contains(Cypress.env('e2eUsername')).should('be.visible'); - cy.contains('td', 'Test').should('be.visible'); - cy.contains('td', 'User').should('be.visible'); - cy.contains('td', 'admin').should('be.visible'); - }); - - cy.contains('Log out').should('exist'); - }); - - maybeIt('Should allow editing user data', () => { - cy.login(Cypress.env('e2eUsername'), Cypress.env('e2ePassword')); - - cy.visit(url); - - cy.waitForStableDOM(); - - cy.contains('button', 'Edit').click(); - - cy.waitForStableDOM(); - - cy.conditionalIntercept( - '**/graphql', - (req) => req.body.operationName == 'UpdateUserRoles', - 'UpdateUserRoles', - { - data: { - updateOneUser: { - __typename: 'User', - roles: ['subscriber', 'bananas', 'ban', 'admin', 'banana'], - userId: '6423479655e4bb918a233bda', - }, - }, - } - ); - - cy.get('[data-cy="edit-user-modal"]').within(() => { - cy.get('[id="roles"]', { timeout: 30000 }).type('banana{enter}'); - - cy.contains('Submit').click(); - - cy.wait('@UpdateUserRoles').then((xhr) => { - expect(xhr.request.body.variables.roles).includes('banana'); - }); - }); - }); - - maybeIt('Should show edit modal if query parameter is is set', () => { - cy.login(Cypress.env('e2eUsername'), Cypress.env('e2ePassword')); - - cy.visit(url + '?askToCompleteProfile=1'); - - cy.waitForStableDOM(); - - cy.get('[data-cy="edit-user-modal"]').should('be.visible'); - }); -}); diff --git a/site/gatsby-site/cypress/e2e/integration/cset.cy.js b/site/gatsby-site/cypress/e2e/integration/cset.cy.js deleted file mode 100644 index 9f74d18a2c..0000000000 --- a/site/gatsby-site/cypress/e2e/integration/cset.cy.js +++ /dev/null @@ -1,57 +0,0 @@ -const { gql } = require('@apollo/client'); - -describe('The CSET taxonomy page', () => { - const urls = [ - { namespace: 'CSETv0', url: '/taxonomy/csetv0' }, - { namespace: 'CSETv1', url: '/taxonomy/csetv1' }, - ]; - - urls.forEach(({ namespace, url }) => { - it.skip(`successfully loads ${namespace}`, () => { - cy.visit(url); - }); - - it.skip(`Should render ${namespace} fields list and Searchable status`, () => { - cy.visit(url); - - cy.waitForStableDOM(); - - cy.query({ - query: gql` - { - taxa(query: { namespace_in: ["${namespace}"] }) { - namespace - field_list { - long_name - short_name - instant_facet - public - } - } - } - `, - }) - .then( - ({ - data: { - taxa: { field_list }, - }, - }) => { - return field_list.filter( - (entry) => (entry.public === null || entry.public) && entry.short_name !== 'Publish' - ); - } - ) - .then((field_list) => { - cy.get('[data-cy*="field-"]').should('have.length', field_list.length); - - field_list.forEach((field) => { - cy.contains('h3', field.long_name.replace(/\s{2,}/g, ' ')) - .should('exist') - .contains('span', 'Searchable in Discover App') - .should(field.instant_facet ? 'exist' : 'not.exist'); - }); - }); - }); - }); -}); diff --git a/site/gatsby-site/playwright/e2e/account.spec.ts b/site/gatsby-site/playwright/e2e/account.spec.ts new file mode 100644 index 0000000000..e50783cb61 --- /dev/null +++ b/site/gatsby-site/playwright/e2e/account.spec.ts @@ -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(); + }); +}); \ No newline at end of file diff --git a/site/gatsby-site/playwright/e2e/integration/cset.spec.ts b/site/gatsby-site/playwright/e2e/integration/cset.spec.ts new file mode 100644 index 0000000000..2725b68961 --- /dev/null +++ b/site/gatsby-site/playwright/e2e/integration/cset.spec.ts @@ -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(); + } + } + }); + } +});