diff --git a/cypress/e2e/adgangsplatformen.cy.ts b/cypress/e2e/adgangsplatformen.cy.ts index 6d802a855d..57aa9f2a81 100644 --- a/cypress/e2e/adgangsplatformen.cy.ts +++ b/cypress/e2e/adgangsplatformen.cy.ts @@ -1,12 +1,12 @@ -describe("Adgangsplatformen", () => { +describe('Adgangsplatformen', () => { beforeEach(() => { Cypress.session.clearAllSavedSessions(); }); - it("supports login with both uniqueId and CPR attribute", () => { - const authorizationCode = "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc"; - const accessToken = "447131b0a03fe0421204c54e5c21a60d70030fd1"; - const userGuid = "19a4ae39-be07-4db9-a8b7-8bbb29f03da6"; + it('supports login with both uniqueId and CPR attribute', () => { + const authorizationCode = '7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc'; + const accessToken = '447131b0a03fe0421204c54e5c21a60d70030fd1'; + const userGuid = '19a4ae39-be07-4db9-a8b7-8bbb29f03da6'; const userCPR = 9999999999; cy.adgangsplatformenLogin({ @@ -15,14 +15,14 @@ describe("Adgangsplatformen", () => { userCPR, userGuid, }); - cy.visit("/user"); - cy.url().should("match", /user\/\d+/); + cy.visit('/user'); + cy.url().should('match', /user\/\d+/); }); - it("supports login for user with only CPR attribute.", () => { + it('supports login for user with only CPR attribute.', () => { // If a user does not have uniqueId attribute, it is a user not previously related to any library. - const authorizationCode = "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc"; - const accessToken = "447131b0a03fe0421204c54e5c21a60-new-user"; + const authorizationCode = '7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc'; + const accessToken = '447131b0a03fe0421204c54e5c21a60-new-user'; const userCPR = 9999999999; cy.adgangsplatformenLogin({ @@ -30,135 +30,135 @@ describe("Adgangsplatformen", () => { accessToken, userCPR, }); - cy.visit("/user"); - cy.url().should("match", /user\/\d+/); + cy.visit('/user'); + cy.url().should('match', /user\/\d+/); }); - it("supports login for user only with uniqueId attribute.", () => { + it('supports login for user only with uniqueId attribute.', () => { // If a user do not have a CPR attribute, it is probably a test user. - const authorizationCode = "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc"; - const accessToken = "447131b0a03fe0421204c54e5c21a60-new-user"; - const userGuid = "19a4ae39-be07-4db9-a8b7-8bbb29f03da6"; + const authorizationCode = '7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc'; + const accessToken = '447131b0a03fe0421204c54e5c21a60-new-user'; + const userGuid = '19a4ae39-be07-4db9-a8b7-8bbb29f03da6'; cy.adgangsplatformenLogin({ authorizationCode, accessToken, userGuid, }); - cy.visit("/user"); - cy.url().should("match", /user\/\d+/); + cy.visit('/user'); + cy.url().should('match', /user\/\d+/); }); // TODO: Figure out how to check failed logins when using cy.session(). - it.skip("does not support login with users missing both uniqueId and CPR attribute.", () => { + it.skip('does not support login with users missing both uniqueId and CPR attribute.', () => { // If a user do not have a CPR attribute, it is probably a test user. - const authorizationCode = "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc"; - const accessToken = "447131b0a03fe0421204c54e5c21a60-new-user"; + const authorizationCode = '7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc'; + const accessToken = '447131b0a03fe0421204c54e5c21a60-new-user'; cy.adgangsplatformenLogin({ authorizationCode, accessToken, }); cy.contains( - "body", - "The website encountered an unexpected error. Please try again later." + 'body', + 'The website encountered an unexpected error. Please try again later.', ); }); // When a user comes back from authentication with MitID, the user should // not be able to do anything else other than registering or cancelling. // Check that the header and footer sections is not vissible. - it("does not show header and footer section for unregistered user", () => { + it('does not show header and footer section for unregistered user', () => { cy.setupAdgangsplatformenRegisterMappinngs({ - authorizationCode: "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc", - accessToken: "447131b0a03fe0421204c54e5c21a60-new-user", + authorizationCode: '7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc', + accessToken: '447131b0a03fe0421204c54e5c21a60-new-user', userCPR: 1412749999, }); cy.clearCookies(); - cy.visit("/arrangementer"); + cy.visit('/arrangementer'); // Open user menu. - cy.getBySel("header-menu-profile-button").click(); + cy.getBySel('header-menu-profile-button').click(); // Click create profile. - cy.get(".modal-login__btn-create-profile").click(); - cy.get("main#main-content") - .get(".paragraphs__item--user_registration_section__link") + cy.get('.modal-login__btn-create-profile').click(); + cy.get('main#main-content') + .get('.paragraphs__item--user_registration_section__link') .first() .click(); cy.verifyToken({ - tokenType: "unregistered-user", - token: "447131b0a03fe0421204c54e5c21a60-new-user", + tokenType: 'unregistered-user', + token: '447131b0a03fe0421204c54e5c21a60-new-user', }); - cy.get(".header").should("not.exist"); - cy.get(".footer").should("not.exist"); + cy.get('.header').should('not.exist'); + cy.get('.footer').should('not.exist'); }); - it("can register a new user - expose the right tokens for the react apps - and force logout.", () => { + it('can register a new user - expose the right tokens for the react apps - and force logout.', () => { cy.setupAdgangsplatformenRegisterMappinngs({ - authorizationCode: "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc", - accessToken: "447131b0a03fe0421204c54e5c21a60-new-user", + authorizationCode: '7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc', + accessToken: '447131b0a03fe0421204c54e5c21a60-new-user', userCPR: 1412749999, }); cy.clearCookies(); - cy.visit("/arrangementer"); - cy.getBySel("header-menu-profile-button").click(); - cy.get(".modal-login__btn-create-profile").click(); - cy.get("main#main-content") - .get(".paragraphs__item--user_registration_section__link") + cy.visit('/arrangementer'); + cy.getBySel('header-menu-profile-button').click(); + cy.get('.modal-login__btn-create-profile').click(); + cy.get('main#main-content') + .get('.paragraphs__item--user_registration_section__link') .first() .click(); cy.verifyToken({ - tokenType: "unregistered-user", - token: "447131b0a03fe0421204c54e5c21a60-new-user", + tokenType: 'unregistered-user', + token: '447131b0a03fe0421204c54e5c21a60-new-user', }); - cy.get('[data-cy="phone-input"]').type("12345678"); - cy.get('[data-cy="email-address-input"]').type("john@doe.com"); - cy.get('[data-cy="pincode-input"]').type("1234"); - cy.get('[data-cy="pincode-confirm-input"]').type("1234"); - cy.get("#branches-dropdown").select("DK-775100"); + cy.get('[data-cy="phone-input"]').type('12345678'); + cy.get('[data-cy="email-address-input"]').type('john@doe.com'); + cy.get('[data-cy="pincode-input"]').type('1234'); + cy.get('[data-cy="pincode-confirm-input"]').type('1234'); + cy.get('#branches-dropdown').select('DK-775100'); cy.get('[data-cy="complete-user-registration-button"]').click(); cy.get('[data-cy="button"]').click(); - cy.origin("login.bib.dk", () => { - cy.url().should("to.match", /^https:\/\/login.bib.dk\/logout\?.*/); + cy.origin('login.bib.dk', () => { + cy.url().should('to.match', /^https:\/\/login.bib.dk\/logout\?.*/); cy.url().should( - "to.match", - /.*redirect_uri=.*\/login%3Fcurrent-path%3D\/velkommen.*/ + 'to.match', + /.*redirect_uri=.*\/login%3Fcurrent-path%3D\/velkommen.*/, ); }); }); - it("can cancel user registration from the user registration page", () => { + it('can cancel user registration from the user registration page', () => { cy.setupAdgangsplatformenRegisterMappinngs({ - authorizationCode: "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc", - accessToken: "447131b0a03fe0421204c54e5c21a60-new-user", + authorizationCode: '7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc', + accessToken: '447131b0a03fe0421204c54e5c21a60-new-user', userCPR: 1412749999, }); cy.clearCookies(); - cy.visit("/arrangementer"); - cy.getBySel("header-menu-profile-button").click(); - cy.get(".modal-login__btn-create-profile").click(); - cy.get("main#main-content") - .get(".paragraphs__item--user_registration_section__link") + cy.visit('/arrangementer'); + cy.getBySel('header-menu-profile-button').click(); + cy.get('.modal-login__btn-create-profile').click(); + cy.get('main#main-content') + .get('.paragraphs__item--user_registration_section__link') .first() .click(); cy.verifyToken({ - tokenType: "unregistered-user", - token: "447131b0a03fe0421204c54e5c21a60-new-user", + tokenType: 'unregistered-user', + token: '447131b0a03fe0421204c54e5c21a60-new-user', }); cy.get('[data-cy="cancel-user-registration-button"]').click(); - cy.request("/dpl-react/user-tokens").then((response) => { + cy.request('/dpl-react/user-tokens').then((response) => { expect(response.body).not.contain( - 'window.dplReact = window.dplReact || {};\nwindow.dplReact.setToken("user", "447131b0a03fe0421204c54e5c21a60-new-user")' + 'window.dplReact = window.dplReact || {};\nwindow.dplReact.setToken("user", "447131b0a03fe0421204c54e5c21a60-new-user")', ); expect(response.body).not.contain( - 'window.dplReact = window.dplReact || {};\nwindow.dplReact.setToken("unregistered-user", "447131b0a03fe0421204c54e5c21a60-new-user")' + 'window.dplReact = window.dplReact || {};\nwindow.dplReact.setToken("unregistered-user", "447131b0a03fe0421204c54e5c21a60-new-user")', ); }); }); diff --git a/cypress/e2e/campaign.cy.ts b/cypress/e2e/campaign.cy.ts index 8a69cd1208..7fb7872148 100644 --- a/cypress/e2e/campaign.cy.ts +++ b/cypress/e2e/campaign.cy.ts @@ -1,40 +1,40 @@ // The campaign types and titles. const campaigns = { - authorCampaign: "Promote authors: H. P. Lovecraft and Stephen King", - booksByJKRowling: "Read books by J. K. Rowling", - rankingAndCampaign: "An AND campaign for testing ranking matching", - rankingOrCampaign: "An OR campaign for testing ranking matching", + authorCampaign: 'Promote authors: H. P. Lovecraft and Stephen King', + booksByJKRowling: 'Read books by J. K. Rowling', + rankingAndCampaign: 'An AND campaign for testing ranking matching', + rankingOrCampaign: 'An OR campaign for testing ranking matching', } as const; -describe("Campaign creation and endpoint", () => { - it("Select the expected campaign based on OR rules", () => { - cy.api("POST", "/dpl_campaign/match", [ +describe('Campaign creation and endpoint', () => { + it('Select the expected campaign based on OR rules', () => { + cy.api('POST', '/dpl_campaign/match', [ { - name: "type", + name: 'type', values: [ { - key: "Bog", - term: "Bog", + key: 'Bog', + term: 'Bog', score: 1, }, { - key: "E-bog", - term: "E-bog", + key: 'E-bog', + term: 'E-bog', score: 1, }, ], }, { - name: "creators", + name: 'creators', values: [ { - key: "Stephen King", - term: "Stephen King", + key: 'Stephen King', + term: 'Stephen King', score: 1, }, { - key: "Suzanne Bjerrehuus", - term: "Suzanne Bjerrehuus", + key: 'Suzanne Bjerrehuus', + term: 'Suzanne Bjerrehuus', score: 1, }, ], @@ -43,45 +43,45 @@ describe("Campaign creation and endpoint", () => { const campaign = getCampaignFromResponse(response); expect(campaign.title).to.eq( - "Promote authors: H. P. Lovecraft and Stephen King" + 'Promote authors: H. P. Lovecraft and Stephen King', ); expect(campaign.text).to.eq( - "Promote authors: H. P. Lovecraft and Stephen King" + 'Promote authors: H. P. Lovecraft and Stephen King', ); expect(campaign.url).to.eq( - "https://example.com/promote-authors-h-p-lovecraft-and-stephen-king" + 'https://example.com/promote-authors-h-p-lovecraft-and-stephen-king', ); }); }); - it("Select OR campaign when not all AND rules are met", () => { - cy.api("POST", "/dpl_campaign/match", [ + it('Select OR campaign when not all AND rules are met', () => { + cy.api('POST', '/dpl_campaign/match', [ { - name: "creators", + name: 'creators', values: [ { - key: "Stephen King", - term: "Stephen King", + key: 'Stephen King', + term: 'Stephen King', score: 1, }, ], }, { - name: "mainLanguages", + name: 'mainLanguages', values: [ { - key: "Dansk", - term: "Dansk", + key: 'Dansk', + term: 'Dansk', score: 1, }, ], }, { - name: "materialTypes", + name: 'materialTypes', values: [ { - key: "Bog", - term: "Bog", + key: 'Bog', + term: 'Bog', score: 1, }, ], @@ -90,52 +90,52 @@ describe("Campaign creation and endpoint", () => { const campaign = getCampaignFromResponse(response); expect(Object.keys(campaign).length).to.eq(4); - expect(campaign).to.have.property("id"); + expect(campaign).to.have.property('id'); expect(campaign.title).to.eq( - "Promote authors: H. P. Lovecraft and Stephen King" + 'Promote authors: H. P. Lovecraft and Stephen King', ); expect(campaign.text).to.eq( - "Promote authors: H. P. Lovecraft and Stephen King" + 'Promote authors: H. P. Lovecraft and Stephen King', ); expect(campaign.url).to.eq( - "https://example.com/promote-authors-h-p-lovecraft-and-stephen-king" + 'https://example.com/promote-authors-h-p-lovecraft-and-stephen-king', ); }); }); - it("Select AND campaign that are more specific than OR campaigns", () => { - cy.api("POST", "/dpl_campaign/match", [ + it('Select AND campaign that are more specific than OR campaigns', () => { + cy.api('POST', '/dpl_campaign/match', [ { - name: "creators", + name: 'creators', values: [ { - key: "J. K. Rowling", - term: "J. K. Rowling", + key: 'J. K. Rowling', + term: 'J. K. Rowling', score: 1, }, { - key: "Stephen King", - term: "Stephen King", + key: 'Stephen King', + term: 'Stephen King', score: 1, }, ], }, { - name: "mainLanguages", + name: 'mainLanguages', values: [ { - key: "Dansk", - term: "Dansk", + key: 'Dansk', + term: 'Dansk', score: 1, }, ], }, { - name: "materialTypes", + name: 'materialTypes', values: [ { - key: "Bog", - term: "Bog", + key: 'Bog', + term: 'Bog', score: 1, }, ], @@ -144,60 +144,60 @@ describe("Campaign creation and endpoint", () => { const campaign = getCampaignFromResponse(response); expect(Object.keys(campaign).length).to.eq(4); - expect(campaign).to.have.property("id"); - expect(campaign.title).to.eq("Read books by J. K. Rowling"); - expect(campaign.text).to.eq("Read books by J. K. Rowling"); + expect(campaign).to.have.property('id'); + expect(campaign.title).to.eq('Read books by J. K. Rowling'); + expect(campaign.text).to.eq('Read books by J. K. Rowling'); expect(campaign.url).to.eq( - "https://example.com/read-books-by-j-k-rowling" + 'https://example.com/read-books-by-j-k-rowling', ); }); }); it("Select campaigns by matching an 'AND campaign' with matching ranking", () => { - cy.request("POST", "/dpl_campaign/match", [ + cy.request('POST', '/dpl_campaign/match', [ { - name: "creators", + name: 'creators', values: [ { - key: "A", - term: "A", + key: 'A', + term: 'A', score: 4, }, { - key: "B", - term: "B", + key: 'B', + term: 'B', score: 3, }, { - key: "rankingTestAnd", - term: "rankingTestAnd", + key: 'rankingTestAnd', + term: 'rankingTestAnd', // This score is supposed to give a ranking of 3 // which is the max value of the rule and therefore a match: score: 2, }, { - key: "C", - term: "C", + key: 'C', + term: 'C', score: 1, }, ], }, { - name: "mainLanguages", + name: 'mainLanguages', values: [ { - key: "rankingTestAnd", - term: "rankingTestAnd", + key: 'rankingTestAnd', + term: 'rankingTestAnd', score: 5, }, ], }, { - name: "materialTypes", + name: 'materialTypes', values: [ { - key: "rankingTestAnd", - term: "rankingTestAnd", + key: 'rankingTestAnd', + term: 'rankingTestAnd', score: 5, }, ], @@ -206,96 +206,96 @@ describe("Campaign creation and endpoint", () => { const campaign = getCampaignFromResponse(response); expect(Object.keys(campaign).length).to.eq(4); - expect(campaign).to.have.property("id"); + expect(campaign).to.have.property('id'); expect(campaign.title).to.eq( - "An AND campaign for testing ranking matching" + 'An AND campaign for testing ranking matching', ); expect(campaign.text).to.eq( - "An AND campaign for testing ranking matching" + 'An AND campaign for testing ranking matching', ); expect(campaign.url).to.eq( - "https://example.com/an-and-campaign-for-testing-ranking-matching" + 'https://example.com/an-and-campaign-for-testing-ranking-matching', ); }); }); it("Return NOT FOUND when ranking does not match ranking span in 'AND campaign'", () => { cy.api({ - url: "/dpl_campaign/match", - method: "POST", + url: '/dpl_campaign/match', + method: 'POST', failOnStatusCode: false, body: [ { - name: "creators", + name: 'creators', values: [ { - key: "A", - term: "A", + key: 'A', + term: 'A', score: 6, }, { - key: "B", - term: "B", + key: 'B', + term: 'B', score: 5, }, { - key: "C", - term: "C", + key: 'C', + term: 'C', score: 4, }, { - key: "D", - term: "D", + key: 'D', + term: 'D', score: 3, }, { - key: "E", - term: "E", + key: 'E', + term: 'E', score: 2, }, { - key: "rankingTestAnd", - term: "rankingTestAnd", + key: 'rankingTestAnd', + term: 'rankingTestAnd', // This is supposed to be outside of the ranking span. score: 1, }, ], }, { - name: "mainLanguages", + name: 'mainLanguages', values: [ { - key: "rankingTestAnd", - term: "rankingTestAnd", + key: 'rankingTestAnd', + term: 'rankingTestAnd', score: 5, }, ], }, { - name: "materialTypes", + name: 'materialTypes', values: [ { - key: "rankingTestAnd", - term: "rankingTestAnd", + key: 'rankingTestAnd', + term: 'rankingTestAnd', score: 5, }, ], }, ], }) - .its("status") - .should("equal", 404); + .its('status') + .should('equal', 404); }); - it("returns data for editorial users", () => { + it('returns data for editorial users', () => { cy.drupalLogin(); - cy.api("POST", "/dpl_campaign/match", [ + cy.api('POST', '/dpl_campaign/match', [ { - name: "materialTypes", + name: 'materialTypes', values: [ { - key: "Bog", - term: "Bog", + key: 'Bog', + term: 'Bog', score: 1, }, ], @@ -306,20 +306,20 @@ describe("Campaign creation and endpoint", () => { cy.anonymousUser(); }); - it("returns data for patron users", () => { + it('returns data for patron users', () => { cy.adgangsplatformenLogin({ - authorizationCode: "auth-code", + authorizationCode: 'auth-code', userCPR: 1234567890, - userGuid: "abcd-1234-efgh", - accessToken: "some-token", + userGuid: 'abcd-1234-efgh', + accessToken: 'some-token', }); - cy.api("POST", "/dpl_campaign/match", [ + cy.api('POST', '/dpl_campaign/match', [ { - name: "materialTypes", + name: 'materialTypes', values: [ { - key: "Bog", - term: "Bog", + key: 'Bog', + term: 'Bog', score: 1, }, ], @@ -364,22 +364,22 @@ describe("Campaign creation and endpoint", () => { const createAuthorCampaign = () => { createCampaign(() => { - createCampaignMainProperties(campaigns.authorCampaign, "OR"); + createCampaignMainProperties(campaigns.authorCampaign, 'OR'); createCampaignRule(0, { - facet: "creators", - term: "H. P. Lovecraft", + facet: 'creators', + term: 'H. P. Lovecraft', maxValue: 1, }); - cy.get("[id^=field-campaign-rules-campaign-rule-add-more]").click(); + cy.get('[id^=field-campaign-rules-campaign-rule-add-more]').click(); createCampaignRule(1, { - facet: "creators", - term: "Stephen King", + facet: 'creators', + term: 'Stephen King', maxValue: 2, }); - cy.get("[id^=field-campaign-rules-campaign-rule-add-more]").click(); + cy.get('[id^=field-campaign-rules-campaign-rule-add-more]').click(); createCampaignRule(2, { - facet: "materialTypes", - term: "Bog", + facet: 'materialTypes', + term: 'Bog', maxValue: 3, }); }); @@ -387,22 +387,22 @@ const createAuthorCampaign = () => { const createCampaignBooksByJKRowling = () => { createCampaign(() => { - createCampaignMainProperties(campaigns.booksByJKRowling, "AND"); + createCampaignMainProperties(campaigns.booksByJKRowling, 'AND'); createCampaignRule(0, { - facet: "creators", - term: "J. K. Rowling", + facet: 'creators', + term: 'J. K. Rowling', maxValue: 1, }); - cy.get("[id^=field-campaign-rules-campaign-rule-add-more]").click(); + cy.get('[id^=field-campaign-rules-campaign-rule-add-more]').click(); createCampaignRule(1, { - facet: "mainLanguages", - term: "Dansk", + facet: 'mainLanguages', + term: 'Dansk', maxValue: 2, }); - cy.get("[id^=field-campaign-rules-campaign-rule-add-more]").click(); + cy.get('[id^=field-campaign-rules-campaign-rule-add-more]').click(); createCampaignRule(2, { - facet: "materialTypes", - term: "Bog", + facet: 'materialTypes', + term: 'Bog', maxValue: 3, }); }); @@ -410,22 +410,22 @@ const createCampaignBooksByJKRowling = () => { const createRankingAndCampaign = () => { createCampaign(() => { - createCampaignMainProperties(campaigns.rankingAndCampaign, "AND"); + createCampaignMainProperties(campaigns.rankingAndCampaign, 'AND'); createCampaignRule(0, { - facet: "creators", - term: "rankingTestAnd", + facet: 'creators', + term: 'rankingTestAnd', maxValue: 3, }); - cy.get("[id^=field-campaign-rules-campaign-rule-add-more]").click(); + cy.get('[id^=field-campaign-rules-campaign-rule-add-more]').click(); createCampaignRule(1, { - facet: "mainLanguages", - term: "rankingTestAnd", + facet: 'mainLanguages', + term: 'rankingTestAnd', maxValue: 3, }); - cy.get("[id^=field-campaign-rules-campaign-rule-add-more]").click(); + cy.get('[id^=field-campaign-rules-campaign-rule-add-more]').click(); createCampaignRule(2, { - facet: "materialTypes", - term: "rankingTestAnd", + facet: 'materialTypes', + term: 'rankingTestAnd', maxValue: 3, }); }); @@ -433,77 +433,77 @@ const createRankingAndCampaign = () => { const createRankingOrCampaign = () => { createCampaign(() => { - createCampaignMainProperties(campaigns.rankingOrCampaign, "OR"); + createCampaignMainProperties(campaigns.rankingOrCampaign, 'OR'); createCampaignRule(0, { - facet: "creators", - term: "rankingTestOr", + facet: 'creators', + term: 'rankingTestOr', maxValue: 5, }); - cy.get("[id^=field-campaign-rules-campaign-rule-add-more]").click(); + cy.get('[id^=field-campaign-rules-campaign-rule-add-more]').click(); createCampaignRule(1, { - facet: "mainLanguages", - term: "rankingTestOr", + facet: 'mainLanguages', + term: 'rankingTestOr', maxValue: 5, }); - cy.get("[id^=field-campaign-rules-campaign-rule-add-more]").click(); + cy.get('[id^=field-campaign-rules-campaign-rule-add-more]').click(); createCampaignRule(2, { - facet: "materialTypes", - term: "rankingTestOr", + facet: 'materialTypes', + term: 'rankingTestOr', maxValue: 5, }); }); }; const createCampaign = (callback: () => void) => { - cy.visit("/node/add/campaign"); + cy.visit('/node/add/campaign'); callback(); cy.get('input[value="Save"]').click(); }; const deleteCampaign = (title: string) => { - cy.visit("/admin/content"); + cy.visit('/admin/content'); cy.contains(title) - .parents("tr") - .find("td li.dropbutton-toggle button") + .parents('tr') + .find('td li.dropbutton-toggle button') .click() .then(($button) => { cy.wrap($button) - .parent(".dropbutton-toggle") - .parent("ul.dropbutton") - .find("li.delete a") + .parent('.dropbutton-toggle') + .parent('ul.dropbutton') + .find('li.delete a') .click(); - cy.get(".ui-dialog .form-submit") - .filter(":visible") - .should("exist") + cy.get('.ui-dialog .form-submit') + .filter(':visible') + .should('exist') .click(); }); }; -const createCampaignMainProperties = (name: string, logic: "AND" | "OR") => { +const createCampaignMainProperties = (name: string, logic: 'AND' | 'OR') => { const campaignUri = name - .replace(/ /g, "-") - .replace(/[.:]/g, "") + .replace(/ /g, '-') + .replace(/[.:]/g, '') .toLowerCase(); - cy.get("#edit-title-0-value").type(name); - cy.get("#edit-field-campaign-link-0-uri").type( - `https://example.com/${campaignUri}` + cy.get('#edit-title-0-value').type(name); + cy.get('#edit-field-campaign-link-0-uri').type( + `https://example.com/${campaignUri}`, ); - cy.get("#edit-field-campaign-text-0-value").type(name); - cy.get("#edit-field-campaign-rules-logic").select(logic); + cy.get('#edit-field-campaign-text-0-value').type(name); + cy.get('#edit-field-campaign-rules-logic').select(logic); }; const createCampaignRule = ( index: number, - { facet, term, maxValue }: { facet: string; term: string; maxValue: number } + { facet, term, maxValue }: { facet: string; term: string; maxValue: number }, ) => { cy.get(`select[id*="-${index}-subform-field-campaign-rule-facet"]`).select( - facet + facet, ); cy.get( - `input[id*="-${index}-subform-field-campaign-rule-term-0-value"]` + `input[id*="-${index}-subform-field-campaign-rule-term-0-value"]`, ).type(term); cy.get( - `input[id*="-${index}-subform-field-campaign-rule-ranking-max-0-value"]` + `input[id*="-${index}-subform-field-campaign-rule-ranking-max-0-value"]`, ).type(maxValue.toString()); }; diff --git a/cypress/e2e/check-static-pages.cy.ts b/cypress/e2e/check-static-pages.cy.ts index 266328a7ad..a37dc831f8 100644 --- a/cypress/e2e/check-static-pages.cy.ts +++ b/cypress/e2e/check-static-pages.cy.ts @@ -1,26 +1,26 @@ -describe("Check static pages", () => { +describe('Check static pages', () => { it("does 'Privatlivspolitik' page exist", () => { - cy.visit("/privatlivspolitik"); - cy.get("main#main-content").get(".article-header").should("exist"); + cy.visit('/privatlivspolitik'); + cy.get('main#main-content').get('.article-header').should('exist'); }); it("does 'Velkommen' page exist", () => { - cy.visit("/velkommen"); - cy.get("main#main-content").get(".article-header").should("exist"); + cy.visit('/velkommen'); + cy.get('main#main-content').get('.article-header').should('exist'); }); it("does 'Pausefunktion' page exist", () => { - cy.visit("/pausefunktion"); - cy.get("main#main-content").get(".article-header").should("exist"); + cy.visit('/pausefunktion'); + cy.get('main#main-content').get('.article-header').should('exist'); }); it("does 'Takster' page exist", () => { - cy.visit("/takster"); - cy.get("main#main-content").get(".article-header").should("exist"); + cy.visit('/takster'); + cy.get('main#main-content').get('.article-header').should('exist'); }); it("does 'Reglement' page exist", () => { - cy.visit("/reglement"); - cy.get("main#main-content").get(".article-header").should("exist"); + cy.visit('/reglement'); + cy.get('main#main-content').get('.article-header').should('exist'); }); it("does 'Opret bruger' page exist", () => { - cy.visit("/opret-bruger"); - cy.get("main#main-content").get(".article-header").should("exist"); + cy.visit('/opret-bruger'); + cy.get('main#main-content').get('.article-header').should('exist'); }); }); diff --git a/cypress/e2e/dpl-react-apps.cy.ts b/cypress/e2e/dpl-react-apps.cy.ts index 501ee58e6e..2c906afb5f 100644 --- a/cypress/e2e/dpl-react-apps.cy.ts +++ b/cypress/e2e/dpl-react-apps.cy.ts @@ -1,18 +1,18 @@ -describe("DPL React Apps", () => { - it("exposes tokens", () => { +describe('DPL React Apps', () => { + it('exposes tokens', () => { // These dummy values resemble what is used in production scenarios. - const libraryAccessToken = "447131b0a03fe0421204c54e5c21a60d70030fd2"; - const authorizationCode = "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc"; - const accessToken = "447131b0a03fe0421204c54e5c21a60d70030fd1"; - const userGuid = "19a4ae39-be07-4db9-a8b7-8bbb29f03da6"; + const libraryAccessToken = '447131b0a03fe0421204c54e5c21a60d70030fd2'; + const authorizationCode = '7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc'; + const accessToken = '447131b0a03fe0421204c54e5c21a60d70030fd1'; + const userGuid = '19a4ae39-be07-4db9-a8b7-8bbb29f03da6'; const userCPR = 9999999999; // Running cron will issue a request to retrieve a library token using OAuth // password type grants. cy.createMapping({ request: { - method: "POST", - urlPath: "/oauth/token/", + method: 'POST', + urlPath: '/oauth/token/', headers: { Authorization: { contains: `Basic`, @@ -20,13 +20,13 @@ describe("DPL React Apps", () => { }, bodyPatterns: [ { - contains: "grant_type=password", + contains: 'grant_type=password', }, { - contains: "username=", + contains: 'username=', }, { - contains: "password=", + contains: 'password=', }, ], }, @@ -47,8 +47,8 @@ describe("DPL React Apps", () => { userGuid, }); - cy.verifyToken({ tokenType: "library", token: libraryAccessToken }); - cy.verifyToken({ tokenType: "user", token: accessToken }); + cy.verifyToken({ tokenType: 'library', token: libraryAccessToken }); + cy.verifyToken({ tokenType: 'user', token: accessToken }); }); beforeEach(() => { diff --git a/cypress/e2e/events.cy.ts b/cypress/e2e/events.cy.ts index c8fa26d156..26e6f9d307 100644 --- a/cypress/e2e/events.cy.ts +++ b/cypress/e2e/events.cy.ts @@ -1,97 +1,97 @@ -import * as dayjs from "dayjs"; -import "cypress-if"; +import * as dayjs from 'dayjs'; +import 'cypress-if'; const events = { singleEvent: { - title: "Single event", - subtitle: "A subtitle", - recurType: "Custom/Single Event", - start: dayjs("2030-01-01T10:00:00"), - end: dayjs("2030-01-01T16:00:00"), + title: 'Single event', + subtitle: 'A subtitle', + recurType: 'Custom/Single Event', + start: dayjs('2030-01-01T10:00:00'), + end: dayjs('2030-01-01T16:00:00'), }, }; -const setDate = (field: "Start date" | "End date", date: dayjs.Dayjs) => { +const setDate = (field: 'Start date' | 'End date', date: dayjs.Dayjs) => { cy.findByText(field) .siblings() - .findByLabelText("Date") - .type(date.format("YYYY-MM-DD")); + .findByLabelText('Date') + .type(date.format('YYYY-MM-DD')); cy.findByText(field) .siblings() - .findByLabelText("Time") - .type(date.format("HH:mm")); + .findByLabelText('Time') + .type(date.format('HH:mm')); }; -describe("Events", () => { - it("can be created with a single occurrence", () => { +describe('Events', () => { + it('can be created with a single occurrence', () => { // Login as admin. - cy.drupalLogin("/events/add/default"); - cy.findByLabelText("Title").type(events.singleEvent.title); - cy.findByLabelText("Subtitle").type(events.singleEvent.subtitle); - cy.findByLabelText("Recur Type").select(events.singleEvent.recurType, { + cy.drupalLogin('/events/add/default'); + cy.findByLabelText('Title').type(events.singleEvent.title); + cy.findByLabelText('Subtitle').type(events.singleEvent.subtitle); + cy.findByLabelText('Recur Type').select(events.singleEvent.recurType, { // We have to use force when using Select2. force: true, }); - setDate("Start date", events.singleEvent.start); - setDate("End date", events.singleEvent.end); - cy.findByRole("button", { name: "Save" }).click(); + setDate('Start date', events.singleEvent.start); + setDate('End date', events.singleEvent.end); + cy.findByRole('button', { name: 'Save' }).click(); // Ensure that the core data from the event is displayed on the resulting page. // @todo This should probably be replaced by a visual regression test. cy.contains(events.singleEvent.title); - cy.contains(events.singleEvent.start.format("DD MMMM YYYY")); + cy.contains(events.singleEvent.start.format('DD MMMM YYYY')); cy.contains( `${events.singleEvent.start.format( - "HH:mm" - )} - ${events.singleEvent.end.format("HH:mm")}` + 'HH:mm', + )} - ${events.singleEvent.end.format('HH:mm')}`, ); }); - it("prefills end date/time based on start date/time", () => { + it('prefills end date/time based on start date/time', () => { // Login as admin. - cy.drupalLogin("/events/add/default"); - setDate("Start date", events.singleEvent.start); - cy.findByText("End date") + cy.drupalLogin('/events/add/default'); + setDate('Start date', events.singleEvent.start); + cy.findByText('End date') .siblings() - .findByLabelText("Date") + .findByLabelText('Date') .focus() - .should("have.value", events.singleEvent.start.format("YYYY-MM-DD")); - cy.findByText("End date") + .should('have.value', events.singleEvent.start.format('YYYY-MM-DD')); + cy.findByText('End date') .siblings() - .findByLabelText("Time") + .findByLabelText('Time') .focus() .should( - "have.value", - events.singleEvent.start.add(1, "hour").format("HH:mm") + 'have.value', + events.singleEvent.start.add(1, 'hour').format('HH:mm'), ); }); before(() => { - cy.drupalLogin("/admin/content/eventseries"); + cy.drupalLogin('/admin/content/eventseries'); // Delete all preexisting instances of each event. - cy.get("a") + cy.get('a') .contains(events.singleEvent.title) .if() .each(() => { // We have to repeat the selector as Cypress will otherwise complain about // missing references to elements when clicking the page. - cy.findAllByRole("link", { name: events.singleEvent.title }) + cy.findAllByRole('link', { name: events.singleEvent.title }) .first() .click(); - cy.findByRole("link", { + cy.findByRole('link', { name: `Edit ${events.singleEvent.title}`, }).click(); - cy.findByRole("button", { name: "More actions" }) + cy.findByRole('button', { name: 'More actions' }) .click() .parent() - .findByRole("link", { name: "Delete" }) + .findByRole('link', { name: 'Delete' }) .click(); - cy.findByRole("dialog") - .findByRole("button", { name: "Delete" }) + cy.findByRole('dialog') + .findByRole('button', { name: 'Delete' }) .click(); // Return to the event list to prepare for the next iteration. - cy.visit("/admin/content/eventseries"); + cy.visit('/admin/content/eventseries'); }); }); }); diff --git a/cypress/e2e/mapp-tracking.cy.ts b/cypress/e2e/mapp-tracking.cy.ts index 91f754358a..2aee40b387 100644 --- a/cypress/e2e/mapp-tracking.cy.ts +++ b/cypress/e2e/mapp-tracking.cy.ts @@ -1,12 +1,12 @@ -describe("Mapp Tracking", () => { - it("tracks page views", () => { - const customerId = "1234"; +describe('Mapp Tracking', () => { + it('tracks page views', () => { + const customerId = '1234'; // Mapp will not perform requests if wt_r cookie is set so clear it before // our test and also use cookie debugging to help understand the process. cy.clearCookies(); cy.drupalLogin(); - cy.visit("/admin/config/system/dpl-mapp") + cy.visit('/admin/config/system/dpl-mapp') .get('[name="id"]') .clear() .type(customerId) @@ -14,10 +14,10 @@ describe("Mapp Tracking", () => { .get('[value="Save configuration"]') .first() .click(); - cy.visit("/"); + cy.visit('/'); cy.getRequestCount({ urlPathPattern: `^/resp/api/get/${customerId}.*`, - }).should("be.greaterThan", 0); + }).should('be.greaterThan', 0); }); beforeEach(() => { diff --git a/cypress/e2e/opening-hours-editor.cy.ts b/cypress/e2e/opening-hours-editor.cy.ts index 23489adf3f..425b8c199b 100644 --- a/cypress/e2e/opening-hours-editor.cy.ts +++ b/cypress/e2e/opening-hours-editor.cy.ts @@ -1,12 +1,12 @@ -const branchTitle = "Test branch"; -const firstDateOfJanuary2024 = "2024-01-01"; +const branchTitle = 'Test branch'; +const firstDateOfJanuary2024 = '2024-01-01'; enum OpeningHourCategories { - Opening = "Åbent", - CitizenService = "Borgerservice", - WithService = "Med betjening", - SelfService = "Selvbetjening", - PhoneTime = "Telefontid", + Opening = 'Åbent', + CitizenService = 'Borgerservice', + WithService = 'Med betjening', + SelfService = 'Selvbetjening', + PhoneTime = 'Telefontid', } type TimeString = `${number}:${number}`; @@ -27,15 +27,15 @@ type OpeningHourFormType = { endDate?: string; }; -type PartialOpeningHourFormType = Omit & { +type PartialOpeningHourFormType = Omit & { timeDuration?: PartialTimeDurationType; }; -const reverseDateString = (date: string) => date.split("-").reverse().join("-"); +const reverseDateString = (date: string) => date.split('-').reverse().join('-'); const createTestBranchAndVisitOpeningHoursAdmin = () => { - cy.drupalLogin("/node/add/branch"); - cy.get("#edit-title-0-value").type(branchTitle); + cy.drupalLogin('/node/add/branch'); + cy.get('#edit-title-0-value').type(branchTitle); cy.get('button[title="Show all Paragraphs"]').click(); // Forcing and multiple was the only way I could get this to work cy.get('button[value="Opening Hours"]').click({ @@ -43,49 +43,49 @@ const createTestBranchAndVisitOpeningHoursAdmin = () => { force: true, }); // Forcing is necessary because the fields are hidden by and shown in a "popup" - cy.get("#edit-field-address-0-address-address-line1") - .type("Example Street", { force: true }) - .should("have.value", "Example Street"); - cy.get("#edit-field-address-0-address-postal-code") - .type("1234", { force: true }) - .should("have.value", "1234"); - cy.get("#edit-field-address-0-address-locality") - .type("Example City", { force: true }) - .should("have.value", "Example City"); + cy.get('#edit-field-address-0-address-address-line1') + .type('Example Street', { force: true }) + .should('have.value', 'Example Street'); + cy.get('#edit-field-address-0-address-postal-code') + .type('1234', { force: true }) + .should('have.value', '1234'); + cy.get('#edit-field-address-0-address-locality') + .type('Example City', { force: true }) + .should('have.value', 'Example City'); cy.get('input[value="Save"]').click(); cy.get('a[href^="/node/"][href$="/edit"]').click({ force: true }); cy.get('a[href*="/edit/opening-hours"]').click(); // Save the URL for the admin page and the page itself for later use cy.url().then((url) => { - Cypress.env("adminUrl", url); - const pageUrl = url.replace("/edit/opening-hours", ""); - Cypress.env("pageUrl", pageUrl); + Cypress.env('adminUrl', url); + const pageUrl = url.replace('/edit/opening-hours', ''); + Cypress.env('pageUrl', pageUrl); }); }; const deleteAllTestBranchesIfExists = () => { - const formattedSearchString = branchTitle.toLowerCase().replace(/ /g, "+"); + const formattedSearchString = branchTitle.toLowerCase().replace(/ /g, '+'); cy.drupalLogin(); cy.visit( - `/admin/content?title=${formattedSearchString}&type=branch&status=All&langcode=All` + `/admin/content?title=${formattedSearchString}&type=branch&status=All&langcode=All`, ); - cy.get("tbody").then((tbody) => { - if (tbody.find("td.views-empty").length) { - cy.log("No branches to delete."); + cy.get('tbody').then((tbody) => { + if (tbody.find('td.views-empty').length) { + cy.log('No branches to delete.'); } else { cy.get('input[title="Select all rows in this table"]').check({ force: true, }); - cy.get("#edit-action").select("node_delete_action"); - cy.contains("input", "Apply to selected items").click(); - cy.contains("input", "Delete").click(); + cy.get('#edit-action').select('node_delete_action'); + cy.contains('input', 'Apply to selected items').click(); + cy.contains('input', 'Delete').click(); } }); }; const visitOpeningHoursPage = (initialDate?: string) => { - const pageUrl = Cypress.env("pageUrl"); + const pageUrl = Cypress.env('pageUrl'); if (pageUrl) { const url = initialDate ? `${pageUrl}?initialDate=${initialDate}` : pageUrl; cy.visit(url); @@ -93,7 +93,7 @@ const visitOpeningHoursPage = (initialDate?: string) => { }; const visitOpeningHoursAdmin = (initialDate?: string) => { - const adminUrl = Cypress.env("adminUrl"); + const adminUrl = Cypress.env('adminUrl'); if (adminUrl) { const url = initialDate ? `${adminUrl}?initialDate=${initialDate}` @@ -107,14 +107,14 @@ const navigateToNextWeekOrMonthAdmin = () => { }; const navigateToMonthViewAdmin = () => { - cy.get(".fc-dayGridMonth-button").click(); + cy.get('.fc-dayGridMonth-button').click(); }; const selectTodayFromMonthViewAdmin = () => { - cy.get(".fc-day-today").click(); + cy.get('.fc-day-today').click(); }; -const firstDateOfFebruary2024 = "2024-02-01"; +const firstDateOfFebruary2024 = '2024-02-01'; const clickFirstDayInMonthViewAdmin = () => { cy.get('[data-date$="-01"]').first().click(); @@ -132,25 +132,25 @@ const fillOpeningHourForm = ({ timeDuration: { start, end }, endDate, }: Partial) => { - cy.getBySel("opening-hours-editor-form").should("be.visible"); + cy.getBySel('opening-hours-editor-form').should('be.visible'); if (openingHourCategory) { - cy.getBySel("opening-hours-editor-form-select").select(openingHourCategory); + cy.getBySel('opening-hours-editor-form-select').select(openingHourCategory); } if (start) { - cy.getBySel("opening-hours-editor-form-start-time").focus().type(start); + cy.getBySel('opening-hours-editor-form-start-time').focus().type(start); } if (end) { - cy.getBySel("opening-hours-editor-form-end-time").focus().type(end); + cy.getBySel('opening-hours-editor-form-end-time').focus().type(end); } if (endDate) { - cy.getBySel("opening-hours-editor-form-repeated").check(); - cy.getBySel("opening-hours-editor-form-end-date").focus().type(endDate); + cy.getBySel('opening-hours-editor-form-repeated').check(); + cy.getBySel('opening-hours-editor-form-end-date').focus().type(endDate); } }; const submitOpeningHourForm = () => { - cy.getBySel("opening-hours-editor-form-submit").click(); + cy.getBySel('opening-hours-editor-form-submit').click(); }; const checkConfirmationDialog = ({ @@ -158,27 +158,27 @@ const checkConfirmationDialog = ({ timeDuration: { start, end }, endDate, }: Required) => { - cy.getBySel("opening-hours-editor-confirm-add-repeated-form") - .should("be.visible") - .and("contain", openingHourCategory) - .and("contain", start) - .and("contain", end) - .and("contain", reverseDateString(endDate)); + cy.getBySel('opening-hours-editor-confirm-add-repeated-form') + .should('be.visible') + .and('contain', openingHourCategory) + .and('contain', start) + .and('contain', end) + .and('contain', reverseDateString(endDate)); }; const confirmAddRepeatedOpeningHourForm = () => { - cy.getBySel("opening-hours-editor-form__confirm").click(); + cy.getBySel('opening-hours-editor-form__confirm').click(); }; const validateOpeningHoursPage = ({ openingHourCategory, timeDuration: { start, end }, }: OpeningHourFormType) => { - cy.getBySel("opening-hours-week-list") + cy.getBySel('opening-hours-week-list') .scrollIntoView() - .should("be.visible") - .and("contain", openingHourCategory) - .and("contain", `${start} - ${end}`); + .should('be.visible') + .and('contain', openingHourCategory) + .and('contain', `${start} - ${end}`); }; const validateNumberOfOpeningHoursExistAdmin = ({ @@ -188,7 +188,7 @@ const validateNumberOfOpeningHoursExistAdmin = ({ }: OpeningHourFormType & { expectedOpeningHours: number }) => { return cy .get('tbody[role="presentation"]') - .should("be.visible") + .should('be.visible') .find('div[data-cy="opening-hours-editor-event-content"]') .filter((index, element) => { const openingHour = Cypress.$(element).text(); @@ -197,7 +197,7 @@ const validateNumberOfOpeningHoursExistAdmin = ({ openingHour.includes(`${start} - ${end}`) ); }) - .should("have.length", expectedOpeningHours); + .should('have.length', expectedOpeningHours); }; const validateOpeningHoursRemovedAdmin = ({ @@ -207,13 +207,13 @@ const validateOpeningHoursRemovedAdmin = ({ }) => { return cy .get('tbody[role="presentation"]') - .should("be.visible") + .should('be.visible') .find('div[data-cy="opening-hours-editor-event-content"]') - .should("have.length", editSeriesFromIndex) + .should('have.length', editSeriesFromIndex) .each((element) => { cy.wrap(element) - .should("contain", openingHourCategory) - .and("contain", `${start} - ${end}`); + .should('contain', openingHourCategory) + .and('contain', `${start} - ${end}`); }); }; @@ -221,11 +221,11 @@ const validateOpeningHoursNotPresentPage = ({ openingHourCategory, timeDuration: { start, end }, }: OpeningHourFormType) => { - cy.getBySel("opening-hours-week-list") - .should("be.visible") - .should("not.contain", openingHourCategory) - .should("not.contain", `${start} - ${end}`) - .contains("The library is closed this day"); + cy.getBySel('opening-hours-week-list') + .should('be.visible') + .should('not.contain', openingHourCategory) + .should('not.contain', `${start} - ${end}`) + .contains('The library is closed this day'); }; const validateOpeningHoursNotPresentAdmin = ({ @@ -233,16 +233,16 @@ const validateOpeningHoursNotPresentAdmin = ({ timeDuration: { start, end }, }: OpeningHourFormType) => { cy.get('tbody[role="presentation"]') - .should("be.visible") - .should("not.contain", openingHourCategory) - .should("not.contain", `${start} - ${end}`); + .should('be.visible') + .should('not.contain', openingHourCategory) + .should('not.contain', `${start} - ${end}`); }; -const confirmEditRepeatedOpeningHourForm = (value?: "all") => { +const confirmEditRepeatedOpeningHourForm = (value?: 'all') => { const selector = - value === "all" - ? "opening-hours-editor-form__radio-all" - : "opening-hours-editor-form__radio-this"; + value === 'all' + ? 'opening-hours-editor-form__radio-all' + : 'opening-hours-editor-form__radio-this'; cy.getBySel(selector).click(); confirmAddRepeatedOpeningHourForm(); @@ -277,10 +277,10 @@ const createOpeningHourInNextWeek = ({ navigateToNextWeekOrMonthAdmin(); selectTimeOnThursdayFromWeekView(start); fillOpeningHourForm({ openingHourCategory, timeDuration: { end } }); - cy.getBySel("opening-hours-editor-form-start-time").should( - "have.attr", - "value", - start + cy.getBySel('opening-hours-editor-form-start-time').should( + 'have.attr', + 'value', + start, ); submitOpeningHourForm(); visitOpeningHoursPage(); @@ -288,7 +288,7 @@ const createOpeningHourInNextWeek = ({ openingHourCategory, timeDuration: { start, end }, }); - cy.getBySel("opening-hours-next-week-button").click(); + cy.getBySel('opening-hours-next-week-button').click(); validateOpeningHoursPage({ openingHourCategory, timeDuration: { start, end }, @@ -334,7 +334,7 @@ const createOpeningHoursSeries = ({ openingHourCategory, timeDuration: { start, end }, }); - cy.getBySel("opening-hours-next-week-button").click(); + cy.getBySel('opening-hours-next-week-button').click(); } }; @@ -345,7 +345,7 @@ const updateOpeningHour = ({ // Assume that the event is already created and is visible visitOpeningHoursAdmin(); navigateToMonthViewAdmin(); - cy.getBySel("opening-hours-editor-event-content") + cy.getBySel('opening-hours-editor-event-content') .contains(openingHourCategory) .click(); fillOpeningHourForm({ timeDuration: { start, end } }); @@ -370,13 +370,13 @@ const updateOpeningHoursSeries = ({ // Assume that the event is already created and is visible visitOpeningHoursAdmin(firstDateOfJanuary2024); navigateToMonthViewAdmin(); - cy.getBySel("opening-hours-editor-event-content") + cy.getBySel('opening-hours-editor-event-content') .eq(editSeriesFromIndex) .contains(openingHourCategory) .click(); fillOpeningHourForm({ timeDuration: { start, end } }); submitOpeningHourForm(); - confirmEditRepeatedOpeningHourForm("all"); + confirmEditRepeatedOpeningHourForm('all'); visitOpeningHoursAdmin(firstDateOfJanuary2024); navigateToMonthViewAdmin(); }; @@ -392,7 +392,7 @@ const deleteOpeningHour = ({ openingHourCategory, timeDuration: { start, end }, }).click(); - cy.getBySel("opening-hours-editor-form__remove").click(); + cy.getBySel('opening-hours-editor-form__remove').click(); validateOpeningHoursNotPresentAdmin({ openingHourCategory, timeDuration: { start, end }, @@ -417,8 +417,8 @@ const deleteOpeningHoursSeries = ({ }) .first() .click(); - cy.getBySel("opening-hours-editor-form__remove").click(); - confirmEditRepeatedOpeningHourForm("all"); + cy.getBySel('opening-hours-editor-form__remove').click(); + confirmEditRepeatedOpeningHourForm('all'); visitOpeningHoursAdmin(firstDateOfJanuary2024); navigateToMonthViewAdmin(); validateOpeningHoursNotPresentAdmin({ @@ -433,7 +433,7 @@ const deleteOpeningHoursSeries = ({ openingHourCategory, timeDuration: { start, end }, }); - cy.getBySel("opening-hours-next-week-button").click(); + cy.getBySel('opening-hours-next-week-button').click(); } }; @@ -451,95 +451,95 @@ const deleteRestOfOpeningHoursSeries = ({ }) .eq(editSeriesFromIndex) .click(); - cy.getBySel("opening-hours-editor-form__remove").click(); - confirmEditRepeatedOpeningHourForm("all"); + cy.getBySel('opening-hours-editor-form__remove').click(); + confirmEditRepeatedOpeningHourForm('all'); }; -describe("Opening hours editor", () => { +describe('Opening hours editor', () => { beforeEach(() => { deleteAllTestBranchesIfExists(); createTestBranchAndVisitOpeningHoursAdmin(); }); - it("Checks opening hours categories", () => { + it('Checks opening hours categories', () => { visitOpeningHoursAdmin(); navigateToMonthViewAdmin(); selectTodayFromMonthViewAdmin(); - cy.getBySel("opening-hours-editor-form-select") - .find("option") - .should("have.length", 5) - .and("contain", OpeningHourCategories.Opening) - .and("contain", OpeningHourCategories.CitizenService) - .and("contain", OpeningHourCategories.WithService) - .and("contain", OpeningHourCategories.SelfService) - .and("contain", OpeningHourCategories.PhoneTime); + cy.getBySel('opening-hours-editor-form-select') + .find('option') + .should('have.length', 5) + .and('contain', OpeningHourCategories.Opening) + .and('contain', OpeningHourCategories.CitizenService) + .and('contain', OpeningHourCategories.WithService) + .and('contain', OpeningHourCategories.SelfService) + .and('contain', OpeningHourCategories.PhoneTime); }); - it("Can create an opening hour", () => { + it('Can create an opening hour', () => { createOpeningHour({ openingHourCategory: OpeningHourCategories.Opening, - timeDuration: { start: "08:00", end: "16:00" }, + timeDuration: { start: '08:00', end: '16:00' }, }); }); - it("Can update an opening hour", () => { + it('Can update an opening hour', () => { createOpeningHour({ openingHourCategory: OpeningHourCategories.PhoneTime, - timeDuration: { start: "10:00", end: "11:00" }, + timeDuration: { start: '10:00', end: '11:00' }, }); updateOpeningHour({ openingHourCategory: OpeningHourCategories.PhoneTime, - timeDuration: { start: "10:00", end: "15:00" }, + timeDuration: { start: '10:00', end: '15:00' }, }); }); - it("Can delete an opening hour", () => { + it('Can delete an opening hour', () => { const openingHour: OpeningHourFormType = { openingHourCategory: OpeningHourCategories.WithService, - timeDuration: { start: "10:00", end: "11:00" }, + timeDuration: { start: '10:00', end: '11:00' }, }; createOpeningHour(openingHour); deleteOpeningHour(openingHour); }); - it("Can create opening hour in next week", () => { + it('Can create opening hour in next week', () => { createOpeningHourInNextWeek({ openingHourCategory: OpeningHourCategories.CitizenService, - timeDuration: { start: "10:00", end: "11:00" }, + timeDuration: { start: '10:00', end: '11:00' }, }); }); - it("Can create opening hours series", () => { + it('Can create opening hours series', () => { createOpeningHoursSeries({ openingHourCategory: OpeningHourCategories.SelfService, - timeDuration: { start: "10:00", end: "16:00" }, + timeDuration: { start: '10:00', end: '16:00' }, endDate: firstDateOfFebruary2024, }); }); - it("Can edit all opening hours series", () => { + it('Can edit all opening hours series', () => { createOpeningHoursSeries({ openingHourCategory: OpeningHourCategories.SelfService, - timeDuration: { start: "10:00", end: "16:00" }, + timeDuration: { start: '10:00', end: '16:00' }, endDate: firstDateOfFebruary2024, }); updateOpeningHoursSeries({ openingHourCategory: OpeningHourCategories.SelfService, - timeDuration: { start: "09:00", end: "15:00" }, + timeDuration: { start: '09:00', end: '15:00' }, }); validateNumberOfOpeningHoursExistAdmin({ expectedOpeningHours: 5, openingHourCategory: OpeningHourCategories.SelfService, - timeDuration: { start: "09:00", end: "15:00" }, + timeDuration: { start: '09:00', end: '15:00' }, }); visitOpeningHoursPage(firstDateOfJanuary2024); // Because we use firstDateOfFebruary2024 as endDate we can check the four next weeks for (let i = 0; i < 5; i++) { validateOpeningHoursPage({ openingHourCategory: OpeningHourCategories.SelfService, - timeDuration: { start: "09:00", end: "15:00" }, + timeDuration: { start: '09:00', end: '15:00' }, }); - cy.getBySel("opening-hours-next-week-button").click(); + cy.getBySel('opening-hours-next-week-button').click(); } }); @@ -550,12 +550,12 @@ describe("Opening hours editor", () => { updatedTimeDuration: TimeDurationType; }; - it("Can edit rest of opening hours series", () => { + it('Can edit rest of opening hours series', () => { const editData: EditRestOfOpeningHoursSeriesType = { editSeriesFromIndex: 1, openingHourCategory: OpeningHourCategories.SelfService, - originalTimeDuration: { start: "10:00", end: "16:00" }, - updatedTimeDuration: { start: "09:00", end: "15:00" }, + originalTimeDuration: { start: '10:00', end: '16:00' }, + updatedTimeDuration: { start: '09:00', end: '15:00' }, }; createOpeningHoursSeries({ @@ -586,22 +586,22 @@ describe("Opening hours editor", () => { }); }); - it("Can delete all opening hours series", () => { + it('Can delete all opening hours series', () => { const openingHour: Required = { openingHourCategory: OpeningHourCategories.WithService, - timeDuration: { start: "10:00", end: "11:00" }, + timeDuration: { start: '10:00', end: '11:00' }, endDate: firstDateOfFebruary2024, }; createOpeningHoursSeries(openingHour); deleteOpeningHoursSeries(openingHour); }); - it("Can delete rest of opening hours series", () => { + it('Can delete rest of opening hours series', () => { const editData: Required & { editSeriesFromIndex: number; } = { openingHourCategory: OpeningHourCategories.WithService, - timeDuration: { start: "10:00", end: "11:00" }, + timeDuration: { start: '10:00', end: '11:00' }, endDate: firstDateOfFebruary2024, editSeriesFromIndex: 1, }; diff --git a/cypress/e2e/patron-collisions.cy.ts b/cypress/e2e/patron-collisions.cy.ts index 4156a1deca..03c9c77d9f 100644 --- a/cypress/e2e/patron-collisions.cy.ts +++ b/cypress/e2e/patron-collisions.cy.ts @@ -1,46 +1,46 @@ -describe("Adgangsplatformen / CMS user / session mapping", () => { +describe('Adgangsplatformen / CMS user / session mapping', () => { const patron1 = { - authorizationCode: "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856db", - accessToken: "patron1-token", + authorizationCode: '7c5e3213aea6ef42ec97dfeaa6f5b1d454d856db', + accessToken: 'patron1-token', userCPR: 9999999998, - userGuid: "19a4ae39-be07-4db9-a8b7-8bbb29f03da5", + userGuid: '19a4ae39-be07-4db9-a8b7-8bbb29f03da5', }; const patron2 = { // All values here are shifted by 1 digit. - authorizationCode: "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc", - accessToken: "patron2-token", + authorizationCode: '7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc', + accessToken: 'patron2-token', // This patron has a CPR which partially overlaps with patron1. userCPR: 9999999999, - userGuid: "19a4ae39-be07-4db9-a8b7-8bbb29f03da6", + userGuid: '19a4ae39-be07-4db9-a8b7-8bbb29f03da6', }; const patron3 = { - authorizationCode: "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dd", - accessToken: "patron3-token", + authorizationCode: '7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dd', + accessToken: 'patron3-token', // This patron has a CPR which is entirely different from patron 1. userCPR: 1111111111, - userGuid: "19a4ae39-be07-4db9-a8b7-8bbb29f03da7", + userGuid: '19a4ae39-be07-4db9-a8b7-8bbb29f03da7', }; const patron4 = { - authorizationCode: "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856de", - accessToken: "patron4-token", - userGuid: "19a4ae39-be07-4db9-a8b7-8bbb29f03da8", + authorizationCode: '7c5e3213aea6ef42ec97dfeaa6f5b1d454d856de', + accessToken: 'patron4-token', + userGuid: '19a4ae39-be07-4db9-a8b7-8bbb29f03da8', }; const patron5 = { - authorizationCode: "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856df", - accessToken: "patron5-token", + authorizationCode: '7c5e3213aea6ef42ec97dfeaa6f5b1d454d856df', + accessToken: 'patron5-token', // This patron has a GUID which partially overlaps with patron4. - userGuid: "19a4ae39-be07-4db9-a8b7-8bbb29f03da9", + userGuid: '19a4ae39-be07-4db9-a8b7-8bbb29f03da9', }; const patron6 = { - authorizationCode: "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856df", - accessToken: "patron5-token", + authorizationCode: '7c5e3213aea6ef42ec97dfeaa6f5b1d454d856df', + accessToken: 'patron5-token', // This patron has a GUID which is entirely different from patron 4. - userGuid: "12345678-abcd-1234-abcd-123456789012", + userGuid: '12345678-abcd-1234-abcd-123456789012', }; beforeEach(() => { @@ -52,60 +52,60 @@ describe("Adgangsplatformen / CMS user / session mapping", () => { cy.logMappingRequests(); }); - it("handles logins with identical idents", () => { + it('handles logins with identical idents', () => { cy.adgangsplatformenLogin(patron1); - cy.verifyToken({ tokenType: "user", token: patron1.accessToken }); + cy.verifyToken({ tokenType: 'user', token: patron1.accessToken }); // Restoring the session should retain the access token. // This is simulated by adgangsplatformenLogin() as this will restore the // session for the patron when invoked with the same parameters. cy.adgangsplatformenLogin(patron1); - cy.verifyToken({ tokenType: "user", token: patron1.accessToken }); + cy.verifyToken({ tokenType: 'user', token: patron1.accessToken }); }); - it("handles logins with overlapping CPRs", () => { + it('handles logins with overlapping CPRs', () => { cy.adgangsplatformenLogin(patron1); - cy.verifyToken({ tokenType: "user", token: patron1.accessToken }); + cy.verifyToken({ tokenType: 'user', token: patron1.accessToken }); cy.adgangsplatformenLogin(patron2); - cy.verifyToken({ tokenType: "user", token: patron2.accessToken }); + cy.verifyToken({ tokenType: 'user', token: patron2.accessToken }); // When patron 1 continues with her session site she must retain her access // token even though the CPRs are adjacent. cy.adgangsplatformenLogin(patron1); - cy.verifyToken({ tokenType: "user", token: patron1.accessToken }); + cy.verifyToken({ tokenType: 'user', token: patron1.accessToken }); }); - it("handles logins with different CPRs", () => { + it('handles logins with different CPRs', () => { cy.adgangsplatformenLogin(patron1); - cy.verifyToken({ tokenType: "user", token: patron1.accessToken }); + cy.verifyToken({ tokenType: 'user', token: patron1.accessToken }); cy.adgangsplatformenLogin(patron3); - cy.verifyToken({ tokenType: "user", token: patron3.accessToken }); + cy.verifyToken({ tokenType: 'user', token: patron3.accessToken }); cy.adgangsplatformenLogin(patron1); - cy.verifyToken({ tokenType: "user", token: patron1.accessToken }); + cy.verifyToken({ tokenType: 'user', token: patron1.accessToken }); }); - it("handles logins with overlapping GUIDs", () => { + it('handles logins with overlapping GUIDs', () => { cy.adgangsplatformenLogin(patron4); - cy.verifyToken({ tokenType: "user", token: patron4.accessToken }); + cy.verifyToken({ tokenType: 'user', token: patron4.accessToken }); cy.adgangsplatformenLogin(patron5); - cy.verifyToken({ tokenType: "user", token: patron5.accessToken }); + cy.verifyToken({ tokenType: 'user', token: patron5.accessToken }); cy.adgangsplatformenLogin(patron4); - cy.verifyToken({ tokenType: "user", token: patron4.accessToken }); + cy.verifyToken({ tokenType: 'user', token: patron4.accessToken }); }); - it("handles logins with different GUIDs", () => { + it('handles logins with different GUIDs', () => { cy.adgangsplatformenLogin(patron4); - cy.verifyToken({ tokenType: "user", token: patron4.accessToken }); + cy.verifyToken({ tokenType: 'user', token: patron4.accessToken }); cy.adgangsplatformenLogin(patron6); - cy.verifyToken({ tokenType: "user", token: patron6.accessToken }); + cy.verifyToken({ tokenType: 'user', token: patron6.accessToken }); cy.adgangsplatformenLogin(patron4); - cy.verifyToken({ tokenType: "user", token: patron4.accessToken }); + cy.verifyToken({ tokenType: 'user', token: patron4.accessToken }); }); }); diff --git a/cypress/e2e/smoke-test.cy.ts b/cypress/e2e/smoke-test.cy.ts index 3f305b960a..79138181b6 100644 --- a/cypress/e2e/smoke-test.cy.ts +++ b/cypress/e2e/smoke-test.cy.ts @@ -1,15 +1,15 @@ -describe("DPL CMS", () => { - it("supports login", () => { +describe('DPL CMS', () => { + it('supports login', () => { cy.drupalLogin(); // We do not have a proper way to determine that the user is actually // logged in. For now we simply check whether the user is logged in. If that // is the case then the /user route will redirect to the user/id route. // Conversely when logged out the /user route will redirect to the // frontpage route. - cy.visit("/user") + cy.visit('/user') .url() - .should("match", /user\/\d+/); + .should('match', /user\/\d+/); cy.drupalLogout(); - cy.visit("user").url().should("match", /\//); + cy.visit('user').url().should('match', /\//); }); }); diff --git a/cypress/e2e/varnish.cy.ts b/cypress/e2e/varnish.cy.ts index e49e27a146..e95bff1fd2 100644 --- a/cypress/e2e/varnish.cy.ts +++ b/cypress/e2e/varnish.cy.ts @@ -1,54 +1,54 @@ -import "cypress-if"; +import 'cypress-if'; const node = { - title: "Varnish test", - subtitle: "A subtitle", - path: "/articles/varnish-test", + title: 'Varnish test', + subtitle: 'A subtitle', + path: '/articles/varnish-test', }; -const varnishCacheHeader = "x-varnish-cache"; +const varnishCacheHeader = 'x-varnish-cache'; -describe("Varnish", () => { - it("is caching responses for anonymous users", () => { +describe('Varnish', () => { + it('is caching responses for anonymous users', () => { cy.anonymousUser(); // Query the front page twice to ensure that Varnish has had a chance to // cache the response. - cy.request("/"); - cy.request("/").then((response) => { - cy.log("Headers", response.headers); - expect(response.headers).to.have.property(varnishCacheHeader, "HIT"); + cy.request('/'); + cy.request('/').then((response) => { + cy.log('Headers', response.headers); + expect(response.headers).to.have.property(varnishCacheHeader, 'HIT'); }); }); - it("is purged when updating content", () => { + it('is purged when updating content', () => { // Create a node as admin. - cy.drupalLogin("/node/add/article"); - cy.findByLabelText("Title").type(node.title); - cy.findByRole("button", { name: "Save" }).click(); + cy.drupalLogin('/node/add/article'); + cy.findByLabelText('Title').type(node.title); + cy.findByRole('button', { name: 'Save' }).click(); cy.contains(node.title); - cy.should("not.contain", node.subtitle); + cy.should('not.contain', node.subtitle); // We do not have a good way to store the current path between tests so // instead we ensure that the expected path is correct. - cy.url().should("include", node.path); + cy.url().should('include', node.path); // Check that the node is accessible and rendered with the expected content // for anonymous users. cy.anonymousUser(); cy.visit(node.path); cy.contains(node.title); - cy.should("not.contain", node.subtitle); + cy.should('not.contain', node.subtitle); // Edit the page as admin and ensure that it is updated. cy.drupalLogin(); cy.visit(node.path); - cy.findByRole("link", { + cy.findByRole('link', { name: `Edit ${node.title}`, }).click({ // Use force as the toolbar may cover the Edit link. force: true, }); - cy.findByLabelText("Subtitle").type(node.subtitle); - cy.findByRole("button", { name: "Save" }).click(); + cy.findByLabelText('Subtitle').type(node.subtitle); + cy.findByRole('button', { name: 'Save' }).click(); cy.contains(node.title); cy.contains(node.subtitle); @@ -56,8 +56,8 @@ describe("Varnish", () => { // anonymous users. cy.anonymousUser(); cy.request(node.path).then((response) => { - cy.log("Headers", response.headers); - expect(response.headers).to.have.property(varnishCacheHeader, "MISS"); + cy.log('Headers', response.headers); + expect(response.headers).to.have.property(varnishCacheHeader, 'MISS'); }); cy.visit(node.path); cy.contains(node.title); @@ -65,29 +65,29 @@ describe("Varnish", () => { }); before(() => { - cy.drupalLogin("/admin/content"); + cy.drupalLogin('/admin/content'); // Delete all preexisting instances of the node. - cy.get("a") + cy.get('a') .contains(node.title) .if() .each(() => { // We have to repeat the selector as Cypress will otherwise complain about // missing references to elements when clicking the page. - cy.findAllByRole("link", { name: node.title }).first().click(); - cy.findByRole("link", { + cy.findAllByRole('link', { name: node.title }).first().click(); + cy.findByRole('link', { name: `Edit ${node.title}`, }).click(); - cy.findByRole("button", { name: "More actions" }) + cy.findByRole('button', { name: 'More actions' }) .click() .parent() - .findByRole("link", { name: "Delete" }) + .findByRole('link', { name: 'Delete' }) .click(); - cy.findByRole("dialog") - .findByRole("button", { name: "Delete" }) + cy.findByRole('dialog') + .findByRole('button', { name: 'Delete' }) .click(); // Return to the node list to prepare for the next iteration. - cy.visit("/admin/content"); + cy.visit('/admin/content'); }); cy.anonymousUser(); diff --git a/cypress/e2e/wiremock.cy.ts b/cypress/e2e/wiremock.cy.ts index 60753c2644..bff1060c11 100644 --- a/cypress/e2e/wiremock.cy.ts +++ b/cypress/e2e/wiremock.cy.ts @@ -1,22 +1,22 @@ -describe("Wiremock", () => { - it("returns stubbed responses", () => { +describe('Wiremock', () => { + it('returns stubbed responses', () => { cy.createMapping({ request: { - method: "GET", - urlPath: "/smoke/test", + method: 'GET', + urlPath: '/smoke/test', }, response: { headers: { - "Content-Type": "application/json", + 'Content-Type': 'application/json', }, jsonBody: { success: true, }, }, }); - cy.request("http://dummy/smoke/test") - .its("body") - .should("deep.equal", { success: true }); + cy.request('http://dummy/smoke/test') + .its('body') + .should('deep.equal', { success: true }); }); beforeEach(() => { diff --git a/cypress/e2e/withMappings/advanced-search.cy.ts b/cypress/e2e/withMappings/advanced-search.cy.ts index 754532aed3..96b13abf27 100644 --- a/cypress/e2e/withMappings/advanced-search.cy.ts +++ b/cypress/e2e/withMappings/advanced-search.cy.ts @@ -1,36 +1,36 @@ -describe("User journey", () => { - it("Can access the advanced search page from home page", () => { - cy.visit("/arrangementer").getBySel("search-header-dropdown-icon").click(); - cy.getBySel("search-header-dropdown").click(); - cy.url().should("include", "advanced-search"); - cy.get("h1").should("contain", "advanced search"); +describe('User journey', () => { + it('Can access the advanced search page from home page', () => { + cy.visit('/arrangementer').getBySel('search-header-dropdown-icon').click(); + cy.getBySel('search-header-dropdown').click(); + cy.url().should('include', 'advanced-search'); + cy.get('h1').should('contain', 'advanced search'); }); - it("Can fill out the search form, translate it into CQL & switch to CQL search with the same translation", () => { - cy.visit("/advanced-search"); - cy.getBySel("advanced-search-header-row").first().click().type("Harry"); - cy.getBySel("advanced-search-header-row").eq(1).click().type("Prince"); - cy.getBySel("advanced-search-header-row") + it('Can fill out the search form, translate it into CQL & switch to CQL search with the same translation', () => { + cy.visit('/advanced-search'); + cy.getBySel('advanced-search-header-row').first().click().type('Harry'); + cy.getBySel('advanced-search-header-row').eq(1).click().type('Prince'); + cy.getBySel('advanced-search-header-row') .eq(1) - .getBySel("clauses") - .getBySel("clause-NOT") + .getBySel('clauses') + .getBySel('clause-NOT') .click(); - cy.getBySel("preview-section") + cy.getBySel('preview-section') .first() - .should("contain", "'Harry' NOT 'Prince'"); - cy.getBySel("advanced-search-edit-cql").eq(1).click(); - cy.getBySel("cql-search-header-input").should( - "contain", - "'Harry' NOT 'Prince'" + .should('contain', "'Harry' NOT 'Prince'"); + cy.getBySel('advanced-search-edit-cql').eq(1).click(); + cy.getBySel('cql-search-header-input').should( + 'contain', + "'Harry' NOT 'Prince'", ); }); - it("Can search and show search results", () => { - cy.visit("/advanced-search"); - cy.getBySel("advanced-search-header-row").first().click().type("Harry"); - cy.getBySel("advanced-search-header-row").eq(1).click().type("Prince"); - cy.getBySel("search-button").click(); - cy.getBySel("search-result-list").should("exist"); - cy.getBySel("card-list-item").should("exist"); + it('Can search and show search results', () => { + cy.visit('/advanced-search'); + cy.getBySel('advanced-search-header-row').first().click().type('Harry'); + cy.getBySel('advanced-search-header-row').eq(1).click().type('Prince'); + cy.getBySel('search-button').click(); + cy.getBySel('search-result-list').should('exist'); + cy.getBySel('card-list-item').should('exist'); }); }); diff --git a/cypress/e2e/withMappings/user-journey.cy.ts b/cypress/e2e/withMappings/user-journey.cy.ts index 52ca012cea..056df611d8 100644 --- a/cypress/e2e/withMappings/user-journey.cy.ts +++ b/cypress/e2e/withMappings/user-journey.cy.ts @@ -1,50 +1,50 @@ -describe("User journey", () => { - it("Shows search suggestions & redirects to search result page", () => { - cy.visit("/arrangementer") - .getBySel("search-header-input") - .type("harry") - .getBySel("autosuggest") - .should("be.visible") - .getBySel("autosuggest-text-item") +describe('User journey', () => { + it('Shows search suggestions & redirects to search result page', () => { + cy.visit('/arrangementer') + .getBySel('search-header-input') + .type('harry') + .getBySel('autosuggest') + .should('be.visible') + .getBySel('autosuggest-text-item') .first() .click() .url() - .should("include", "search?q=Harry%2520Potter"); + .should('include', 'search?q=Harry%2520Potter'); }); - it("Shows search results & redirects to material page", () => { - cy.visit("/search?q=Harry+Potter") - .getBySel("search-result-header") - .should("contain", 'Showing results for "Harry Potter"') - .getBySel("card-list-item-availability") - .should("exist"); + it('Shows search results & redirects to material page', () => { + cy.visit('/search?q=Harry+Potter') + .getBySel('search-result-header') + .should('contain', 'Showing results for "Harry Potter"') + .getBySel('card-list-item-availability') + .should('exist'); - cy.getBySel("card-list-item") + cy.getBySel('card-list-item') .first() .click() .url() - .should("include", "work/work-of:870970-basis:54181744"); + .should('include', 'work/work-of:870970-basis:54181744'); }); - it("Shows material page & reservation button is rendered", () => { - cy.visit("/work/work-of:870970-basis:54181744") - .getBySel("material-header-content") + it('Shows material page & reservation button is rendered', () => { + cy.visit('/work/work-of:870970-basis:54181744') + .getBySel('material-header-content') .scrollIntoView() - .contains("Harry Potter og Fønixordenen"); + .contains('Harry Potter og Fønixordenen'); // Wait for service to fill reserve button with the right text. // TODO: Consider using the pipe package in the future... // eslint-disable-next-line cypress/no-unnecessary-waiting cy.wait(2000); - cy.getBySel("material-header-buttons-physical").should( - "contain", - "Reserve bog" + cy.getBySel('material-header-buttons-physical').should( + 'contain', + 'Reserve bog', ); }); - it("Can open reservation modal & reserve a material", () => { - const authorizationCode = "7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc"; - const accessToken = "447131b0a03fe0421204c54e5c21a60d70030fd1"; - const userGuid = "19a4ae39-be07-4db9-a8b7-8bbb29f03da6"; + it('Can open reservation modal & reserve a material', () => { + const authorizationCode = '7c5e3213aea6ef42ec97dfeaa6f5b1d454d856dc'; + const accessToken = '447131b0a03fe0421204c54e5c21a60d70030fd1'; + const userGuid = '19a4ae39-be07-4db9-a8b7-8bbb29f03da6'; const userCPR = 9999999999; cy.adgangsplatformenLogin({ authorizationCode, @@ -52,25 +52,25 @@ describe("User journey", () => { userCPR, userGuid, }); - cy.visit("/work/work-of:870970-basis:54181744"); - cy.getBySel("material-header-author-text").scrollIntoView(); - cy.getBySel("material-header-buttons-physical").click(); + cy.visit('/work/work-of:870970-basis:54181744'); + cy.getBySel('material-header-author-text').scrollIntoView(); + cy.getBySel('material-header-buttons-physical').click(); // We have to wait for the modal to be fully rendered. // eslint-disable-next-line cypress/no-unnecessary-waiting cy.wait(2000); - cy.getBySel("reservation-modal-parallel") - .should("be.visible") - .and("contain", "Harry Potter og Fønixordenen"); + cy.getBySel('reservation-modal-parallel') + .should('be.visible') + .and('contain', 'Harry Potter og Fønixordenen'); // We have to wait for the modal to be fully rendered // and the event listeners to be attached. // Read more: https://www.cypress.io/blog/2019/01/22/when-can-the-test-click/ // TODO: Consider using the pipe package in the future... // eslint-disable-next-line cypress/no-unnecessary-waiting cy.wait(2000); - cy.getBySel("reservation-modal-submit-button").click(); - cy.getBySel("reservation-success-title-text") - .should("exist") - .and("contain", "The material is available and is now reserved for you!"); + cy.getBySel('reservation-modal-submit-button').click(); + cy.getBySel('reservation-success-title-text') + .should('exist') + .and('contain', 'The material is available and is now reserved for you!'); }); afterEach(() => { diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 9b7bf294bd..e187993b72 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -1,31 +1,31 @@ -import "@testing-library/cypress/add-commands"; -import { WireMockRestClient } from "wiremock-rest-client"; -import { Options } from "wiremock-rest-client/dist/model/options.model"; -import { StubMapping } from "wiremock-rest-client/dist/model/stub-mapping.model"; -import { RequestPattern } from "wiremock-rest-client/dist/model/request-pattern.model"; +import '@testing-library/cypress/add-commands'; +import { WireMockRestClient } from 'wiremock-rest-client'; +import { Options } from 'wiremock-rest-client/dist/model/options.model'; +import { StubMapping } from 'wiremock-rest-client/dist/model/stub-mapping.model'; +import { RequestPattern } from 'wiremock-rest-client/dist/model/request-pattern.model'; const wiremock = (baseUri?: string, options?: Options) => { return new WireMockRestClient( - baseUri || Cypress.env("WIREMOCK_URL"), - options + baseUri || Cypress.env('WIREMOCK_URL'), + options, ); }; -Cypress.Commands.add("createMapping", (stub: StubMapping) => { +Cypress.Commands.add('createMapping', (stub: StubMapping) => { cy.wrap(wiremock().mappings.createMapping(stub)); }); -Cypress.Commands.add("resetMappings", () => { +Cypress.Commands.add('resetMappings', () => { cy.wrap(wiremock().mappings.resetAllMappings()); }); -Cypress.Commands.add("logMappingRequests", () => { +Cypress.Commands.add('logMappingRequests', () => { cy.wrap( wiremock() .mappings.getAllMappings() .then((mappings) => { Cypress.log({ - name: "Wiremock", + name: 'Wiremock', message: `Mappings: ${mappings.meta.total}`, }); mappings.mappings.forEach((stub) => { @@ -38,30 +38,30 @@ Cypress.Commands.add("logMappingRequests", () => { stub.request.urlPath || stub.request.urlPathPattern; Cypress.log({ - name: "Wiremock", + name: 'Wiremock', message: `${stub.request.method}: ${requestUrlPath}: ${request.count} hit(s)`, }); }); }); - }) + }), ); }); -Cypress.Commands.add("getRequestCount", (request: RequestPattern) => { +Cypress.Commands.add('getRequestCount', (request: RequestPattern) => { cy.wrap( wiremock() .requests.getCount(request) .then((response: { count: number }) => { return response.count; - }) + }), ); }); -Cypress.Commands.add("resetRequests", () => { +Cypress.Commands.add('resetRequests', () => { cy.wrap(wiremock().requests.resetAllRequests()); }); -Cypress.Commands.add("logRequests", () => { +Cypress.Commands.add('logRequests', () => { cy.wrap( wiremock() .requests.getAllRequests() @@ -69,19 +69,19 @@ Cypress.Commands.add("logRequests", () => { data.requests.forEach((requestResponse) => { const request = requestResponse.request; Cypress.log({ - name: "Wiremock", + name: 'Wiremock', message: `${request.method}: ${request.url}`, }); }); - }) + }), ); }); -Cypress.Commands.add("drupalLogin", (url?: string) => { - const username = Cypress.env("DRUPAL_USERNAME"); - const password = Cypress.env("DRUPAL_PASSWORD"); +Cypress.Commands.add('drupalLogin', (url?: string) => { + const username = Cypress.env('DRUPAL_USERNAME'); + const password = Cypress.env('DRUPAL_PASSWORD'); cy.session({ username, password }, () => { - cy.visit("/user/login"); + cy.visit('/user/login'); cy.get('[name="name"]') .type(username) .parent() @@ -95,24 +95,24 @@ Cypress.Commands.add("drupalLogin", (url?: string) => { } }); -Cypress.Commands.add("anonymousUser", () => { - cy.session("anonymous", () => {}); +Cypress.Commands.add('anonymousUser', () => { + cy.session('anonymous', () => {}); }); -Cypress.Commands.add("drupalLogout", () => { - cy.visit("/logout"); +Cypress.Commands.add('drupalLogout', () => { + cy.visit('/logout'); }); -Cypress.Commands.add("drupalCron", () => { +Cypress.Commands.add('drupalCron', () => { // Because we run Wiremock as a proxy only services configured with the // proxy will use it. We need to proxy requests during cron and only the // web container is configured to use the proxy and thus we have to run // cron through the web frontend. Using the proxy with the CLI container would // cause too many irrelevant requests to pass throuh the proxy. cy.drupalLogin(); - cy.visit("/admin/config/system/cron"); + cy.visit('/admin/config/system/cron'); cy.get('[value="Run cron"]').click(); - cy.contains("Cron ran successfully."); + cy.contains('Cron ran successfully.'); cy.drupalLogout(); }); @@ -131,11 +131,11 @@ const adgangsplatformenLoginOauthMappings = ({ }) => { cy.createMapping({ request: { - method: "GET", - urlPath: "/oauth/authorize", + method: 'GET', + urlPath: '/oauth/authorize', queryParameters: { response_type: { - equalTo: "code", + equalTo: 'code', }, }, }, @@ -144,17 +144,17 @@ const adgangsplatformenLoginOauthMappings = ({ headers: { location: `{{request.query.[redirect_uri]}}?code=${authorizationCode}&state={{request.query.[state]}}`, }, - transformers: ["response-template"], + transformers: ['response-template'], }, }); cy.createMapping({ request: { - method: "POST", - urlPath: "/oauth/token/", + method: 'POST', + urlPath: '/oauth/token/', bodyPatterns: [ { - contains: "grant_type=authorization_code", + contains: 'grant_type=authorization_code', }, { contains: `code=${authorizationCode}`, @@ -164,7 +164,7 @@ const adgangsplatformenLoginOauthMappings = ({ response: { jsonBody: { access_token: accessToken, - token_type: "Bearer", + token_type: 'Bearer', expires_in: 2591999, }, }, @@ -172,8 +172,8 @@ const adgangsplatformenLoginOauthMappings = ({ cy.createMapping({ request: { - method: "GET", - urlPath: "/userinfo/", + method: 'GET', + urlPath: '/userinfo/', headers: { Authorization: { equalTo: `Bearer ${accessToken}`, @@ -192,7 +192,7 @@ const adgangsplatformenLoginOauthMappings = ({ const patronBody = (userIsAlreadyRegistered: boolean) => { return { - authenticateStatus: userIsAlreadyRegistered ? "VALID" : "INVALID", + authenticateStatus: userIsAlreadyRegistered ? 'VALID' : 'INVALID', patron: { // This is not a complete patron object but with regards to login/register we only need to ensure an empty blocked // status so we leave out all other information. @@ -203,8 +203,8 @@ const adgangsplatformenLoginOauthMappings = ({ cy.createMapping({ request: { - method: "GET", - urlPath: "/external/agencyid/patrons/patronid/v2", + method: 'GET', + urlPath: '/external/agencyid/patrons/patronid/v2', headers: { Authorization: { equalTo: `Bearer ${accessToken}`, @@ -218,7 +218,7 @@ const adgangsplatformenLoginOauthMappings = ({ }; Cypress.Commands.add( - "adgangsplatformenLogin", + 'adgangsplatformenLogin', ({ authorizationCode, accessToken, @@ -239,13 +239,13 @@ Cypress.Commands.add( userGuid, }); - cy.visit("/user/login"); - cy.contains("Log in with Adgangsplatformen").click(); + cy.visit('/user/login'); + cy.contains('Log in with Adgangsplatformen').click(); }); - } + }, ); Cypress.Commands.add( - "setupAdgangsplatformenRegisterMappinngs", + 'setupAdgangsplatformenRegisterMappinngs', ({ authorizationCode, accessToken, @@ -266,8 +266,8 @@ Cypress.Commands.add( }); cy.createMapping({ request: { - method: "POST", - urlPattern: ".*/external/agencyid/patrons/v4", + method: 'POST', + urlPattern: '.*/external/agencyid/patrons/v4', }, response: { jsonBody: { @@ -278,9 +278,9 @@ Cypress.Commands.add( }); cy.createMapping({ request: { - method: "GET", + method: 'GET', // TODO: Create more exact urlPatterns - urlPattern: ".*/fees.*", + urlPattern: '.*/fees.*', }, response: { jsonBody: {}, @@ -288,8 +288,8 @@ Cypress.Commands.add( }); cy.createMapping({ request: { - method: "GET", - urlPattern: ".*/reservations.*", + method: 'GET', + urlPattern: '.*/reservations.*', }, response: { jsonBody: {}, @@ -297,36 +297,36 @@ Cypress.Commands.add( }); cy.createMapping({ request: { - method: "GET", - urlPattern: ".*/loans.*", + method: 'GET', + urlPattern: '.*/loans.*', }, response: { jsonBody: {}, }, }); - } + }, ); Cypress.Commands.add( - "verifyToken", + 'verifyToken', ({ token, tokenType, }: { - tokenType: "library" | "user" | "unregistered-user"; + tokenType: 'library' | 'user' | 'unregistered-user'; token: string; }) => { - cy.request("/dpl-react/user-tokens") - .its("body") + cy.request('/dpl-react/user-tokens') + .its('body') .should( - "contain", - `window.dplReact.setToken("${tokenType}", "${token}")` + 'contain', + `window.dplReact.setToken("${tokenType}", "${token}")`, ); - } + }, ); -const visible = (checkVisible: boolean) => (checkVisible ? ":visible" : ""); -Cypress.Commands.add("getBySel", (selector, checkVisible = false, ...args) => { +const visible = (checkVisible: boolean) => (checkVisible ? ':visible' : ''); +Cypress.Commands.add('getBySel', (selector, checkVisible = false, ...args) => { return cy.get(`[data-cy="${selector}"]${visible(checkVisible)}`, ...args); }); @@ -359,7 +359,7 @@ declare global { userGuid?: string; }): Chainable; verifyToken(params: { - tokenType: "library" | "user" | "unregistered-user"; + tokenType: 'library' | 'user' | 'unregistered-user'; token: string; }): Chainable; getBySel( diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts index f46af39bfd..f8c05a6250 100644 --- a/cypress/support/e2e.ts +++ b/cypress/support/e2e.ts @@ -14,9 +14,9 @@ // *********************************************************** // Import commands.ts using ES2015 syntax: -import "./commands"; +import './commands'; // Alternatively you can use CommonJS syntax: // require('./commands') -import "cypress-plugin-api"; +import 'cypress-plugin-api';