Skip to content

Commit

Permalink
Merge pull request #8927 from guardian/gb/override-okta-cypress
Browse files Browse the repository at this point in the history
Use fixtures for Sign In Gate Cypress tests
  • Loading branch information
georgeblahblah authored Sep 27, 2023
2 parents d50e5d4 + 323fcba commit cd6558a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
5 changes: 1 addition & 4 deletions dotcom-rendering/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ module.exports = defineConfig({

// Adding this here so that we can import the fixture in the sign-in-gate.cy.js file
rules.push({
test: path.resolve(
__dirname,
`./fixtures/generated/articles/Standard.ts`,
),
test: path.resolve(__dirname, `./fixtures/generated/articles`),
exclude: ['/node_modules/'],
loader: 'ts-loader',
options: {
Expand Down
41 changes: 25 additions & 16 deletions dotcom-rendering/cypress/e2e/parallel-1/sign-in-gate.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { disableCMP } from '../../lib/disableCMP';
import { setLocalBaseUrl } from '../../lib/setLocalBaseUrl.js';
import { Standard } from '../../../fixtures/generated/articles/Standard';
import { Labs } from '../../../fixtures/generated/articles/Labs';
/* eslint-disable no-undef */
/* eslint-disable func-names */

Expand Down Expand Up @@ -43,20 +44,17 @@ describe('Sign In Gate Tests', function () {
const GATE_HEADER_ALT = 'Take a moment to register';
// helper method over the cypress visit method to avoid having to repeat the same url by setting a default
// can override the parameter if required
const visitArticle = (
url = 'https://www.theguardian.com/games/2018/aug/23/nier-automata-yoko-taro-interview',
) => {
cy.visit(`/Article/${url}`);
};

const postArticle = ({ switchOverride } = {}) => {
const postArticle = ({ fixture, switchOverride }) => {
const articleJson = {
...Standard,
...fixture,
config: {
...Standard.config,
...fixture.config,
switches: {
...Standard.switches,
...fixture.switches,
...switchOverride,
okta: false,
idCookieRefresh: false,
},
},
};
Expand All @@ -78,18 +76,18 @@ describe('Sign In Gate Tests', function () {
// we call visit and scroll for most test, so this wrapper combines the two
// while preserving the ability to set the parameters if required
const visitArticleAndScrollToGateForLazyLoad = ({
url,
fixture = Standard,
roughPosition,
} = {}) => {
visitArticle(url);
postArticle({ fixture });
scrollToGateForLazyLoading(roughPosition);
};

const postArticleAndScrollToGateForLazyLoad = ({
roughPosition,
switchOverride,
switchOverride = {},
} = {}) => {
postArticle({ switchOverride });
postArticle({ fixture: Standard, switchOverride });
scrollToGateForLazyLoading(roughPosition);
};

Expand Down Expand Up @@ -157,16 +155,27 @@ describe('Sign In Gate Tests', function () {

it('should not load the sign in gate if the article is not a valid section (membership)', function () {
visitArticleAndScrollToGateForLazyLoad({
url: 'https://www.theguardian.com/membership/2018/nov/15/support-guardian-readers-future-journalism',
fixture: {
...Standard,
config: {
...Standard.config,
section: 'membership',
},
},
});

cy.get('[data-cy=sign-in-gate-main]').should('not.exist');
});

it('should not load the sign in gate if the article is a paid article', function () {
visitArticleAndScrollToGateForLazyLoad({
url: 'https://www.theguardian.com/defining-moment/2016/jun/29/challenges-opportunities-life-coach-goals-empower-proactive',
cy.on('uncaught:exception', (err) => {
if (err.message.includes('window.require')) {
// This error is unrelated to the test in question so return false to prevent
// this error from failing this test
return false;
}
});
visitArticleAndScrollToGateForLazyLoad({ fixture: Labs });

cy.get('[data-cy=sign-in-gate-main]').should('not.exist');
});
Expand Down

0 comments on commit cd6558a

Please sign in to comment.