Skip to content

E2e fixtures#243

Merged
rosemcc merged 28 commits into
masterfrom
e2e-fixtures
Mar 7, 2022
Merged

E2e fixtures#243
rosemcc merged 28 commits into
masterfrom
e2e-fixtures

Conversation

@rosemcc
Copy link
Copy Markdown
Contributor

@rosemcc rosemcc commented Mar 3, 2022

Description

This PR introduces the use of fixtures (mocked data) for some of the e2e tests. We have previously been unable to test certain page types, including Funding and Case Study, because they are all SSO protected, and also we have not been able to test certain page elements easily. Intercepting graphql requests and returning mocked data in the response can solve these problems, without having to add functionality for automated login for testing the sso protected page types.

Solution

  • Set up fixtures for each of the page types (Cypress Fixtures)
  • Use cy.intercept() to access and modify the request and respond with the mocked data, e.g.:
    cy.intercept('POST', Cypress.env('graphql_server'), (req) => { if (hasOperationName(req, 'GetArticleBySlug')) { req.alias = 'gqlGetArticleBySlug'; req.reply({ fixture: 'article' }); } });
  • Ref: Cypress working with graphql
  • Some of the tests were using '.should('not.be.empty')' - replaced these with '.should('exist')' to ensure that we are checking that the element is actually present in the DOM.
  • Reviewed all e2e tests and added tests where certain page elements were not being checked. Most components should now have some tests associated with them.
  • Solution works on CI also, by setting the graphql server url as an environment variable which cypress can access.

Screenshots

N/A

Testing

Lots of e2e test changes/additions

Have the changes been checked in the following browsers?

N/A

@rosemcc rosemcc requested review from Trombach and robmint March 3, 2022 04:13
Copy link
Copy Markdown
Contributor

@Trombach Trombach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few suggestions. Otherwise looks good to me!

Comment thread research-hub-web/cypress/utils/graphql-utils.ts
Comment thread research-hub-web/cypress/integration/navbar.e2e.ts Outdated
Comment thread research-hub-web/cypress/integration/routing.e2e.ts Outdated
rosemcc and others added 4 commits March 7, 2022 16:26
Co-authored-by: Lukas Trombach <19306765+Trombach@users.noreply.github.com>
Co-authored-by: Lukas Trombach <19306765+Trombach@users.noreply.github.com>
Co-authored-by: Lukas Trombach <19306765+Trombach@users.noreply.github.com>
@rosemcc rosemcc removed the request for review from robmint March 7, 2022 03:37
@rosemcc rosemcc merged commit a3b2a8c into master Mar 7, 2022
@rosemcc rosemcc deleted the e2e-fixtures branch March 7, 2022 03:44
@rosemcc rosemcc mentioned this pull request Mar 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants