From 48cede92226f08092cd50a38225531d77d8f88da Mon Sep 17 00:00:00 2001 From: mahula Date: Thu, 2 Mar 2023 09:52:56 +0100 Subject: [PATCH] add email step definition for registration test --- e2e-tests/cypress.config.ts | 7 +++ .../support/step_definitions/email_steps.ts | 46 +++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/e2e-tests/cypress.config.ts b/e2e-tests/cypress.config.ts index 16ebb0e97..1fd10f157 100644 --- a/e2e-tests/cypress.config.ts +++ b/e2e-tests/cypress.config.ts @@ -2,6 +2,7 @@ import { defineConfig } from 'cypress' import { addCucumberPreprocessorPlugin } from '@badeball/cypress-cucumber-preprocessor' import browserify from '@badeball/cypress-cucumber-preprocessor/browserify' +let activationLink:string let resetPasswordLink: string async function setupNodeEvents( @@ -24,6 +25,12 @@ async function setupNodeEvents( getResetPasswordLink: () => { return resetPasswordLink }, + setActivationLink: (val) => { + return (activationLink = val) + }, + getActivationLink: () => { + return activationLink + }, }) on('after:run', (results) => { diff --git a/e2e-tests/cypress/support/step_definitions/email_steps.ts b/e2e-tests/cypress/support/step_definitions/email_steps.ts index b313442f2..d06c3879b 100644 --- a/e2e-tests/cypress/support/step_definitions/email_steps.ts +++ b/e2e-tests/cypress/support/step_definitions/email_steps.ts @@ -12,7 +12,7 @@ Then('the user receives an e-mail containing the password reset link', () => { (userEMailSite) => { const linkPattern = /\/reset-password\/[0-9]+\d/ - cy.visit('/') // navigate to user's e-maile site (on fake mail server) + cy.visit('/') // navigate to user's e-mail site (on fake mail server) cy.get(userEMailSite.emailInbox).should('be.visible') cy.get(userEMailSite.emailList) @@ -24,9 +24,9 @@ Then('the user receives an e-mail containing the password reset link', () => { cy.get(userEMailSite.emailMeta) .find(userEMailSite.emailSubject) .contains('asswor') - + cy.get('.email-content') - .find('.plain-text') + .find('.plain-text', { timeout: 2000 }) .contains(linkPattern) .invoke('text') .then((text) => { @@ -37,9 +37,49 @@ Then('the user receives an e-mail containing the password reset link', () => { ) }) +Then('the user receives an e-mail containing the activation link', () => { + cy.origin( + Cypress.env('mailserverURL'), + { args: userEMailSite }, + (userEMailSite) => { + const linkPattern = /\/checkEmail\/[0-9]+\d/ + + cy.visit('/') // navigate to user's e-mail site (on fake mail server) + cy.get(userEMailSite.emailInbox).should('be.visible') + + cy.get(userEMailSite.emailList) + .find('.email-item') + .filter(':contains(E-Mail Überprüfung)') + .first() + .click() + + cy.get(userEMailSite.emailMeta) + .find(userEMailSite.emailSubject) + .contains('E-Mail Überprüfung') + + cy.get('.email-content') + .wait(2000) + .find('.plain-text') + .contains(linkPattern) + .invoke('text') + .then((text) => { + const activationLink = text.match(linkPattern)[0] + cy.task('setActivationLink', activationLink) + }) + } + ) +}) + When('the user opens the password reset link in the browser', () => { cy.task('getResetPasswordLink').then((passwordResetLink) => { cy.visit(passwordResetLink) }) cy.get(resetPasswordPage.newPasswordRepeatBlock).should('be.visible') }) + +When('the user opens the activation link in the browser', () => { + cy.task('getActivationLink').then((activationLink) => { + cy.visit(activationLink) + }) + cy.get(resetPasswordPage.newPasswordRepeatBlock).should('be.visible') +})