From 8abef9c9323c293c97d3769ea203bc426be61540 Mon Sep 17 00:00:00 2001 From: mahula Date: Fri, 11 Apr 2025 12:59:27 +0200 Subject: [PATCH] e2e: add email check step to chat notification test --- cypress/e2e/Chat.Message.Notification.feature | 8 ++--- cypress/support/step_definitions/email.js | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 cypress/support/step_definitions/email.js diff --git a/cypress/e2e/Chat.Message.Notification.feature b/cypress/e2e/Chat.Message.Notification.feature index 1547cd72a..f4e0b3cc7 100644 --- a/cypress/e2e/Chat.Message.Notification.feature +++ b/cypress/e2e/Chat.Message.Notification.feature @@ -16,8 +16,8 @@ Feature: Notifications for Chat Messages via E-Mail Scenario: No Chat Notification Email when Online Given I am logged in as "bob-der-baumeister" - When "jenny-rostock" sends a chat message to "bob-der-baumeister" - And "nathan-narrator" sends a chat message to "bob-der-baumeister" - Then "Bob der Baumeister" should receive "one" chat notification email (referencing "Jenny Rostock") - But "Bob der Baumeister" should receive "no" chat notification email (referencing "nathan-narrator") + # When "Jenny Rostock" sends a chat message to "Bob der Baumeister" + # And "Nathan Narrator" sends a chat message to "Bob der Baumeister" + Then "moderator@example.org" should receive no chat notification email + # And "Bob der Baumeister" should receive "0" chat notification email referencing "Nathan Narrator" \ No newline at end of file diff --git a/cypress/support/step_definitions/email.js b/cypress/support/step_definitions/email.js new file mode 100644 index 000000000..dd9294ce8 --- /dev/null +++ b/cypress/support/step_definitions/email.js @@ -0,0 +1,32 @@ +import { defineStep } from '@badeball/cypress-cucumber-preprocessor' + +defineStep('{string} should receive no chat notification email', (recipientEmailAddress) => { + const emailTitle = 'Neue Chat-Nachricht | New chat message' + + cy.origin( + Cypress.env('mailserverURL'), + { args: { recipientEmailAddress, emailTitle } }, + ({ recipientEmailAddress, emailTitle }) => { + const emailClientList = '.email-list' + cy.visit('/') + cy.get(emailClientList).should('be.visible') + + // check the email list for unread emails with the specific title and recipient address + cy.get(emailClientList).find('li').then(($emails) => { + if ($emails.length === 0) { + expect($emails.length).to.equal(0) + return + } + + const unreadEmails = $emails.filter((_, email) => { + const subjectText = Cypress.$(email).find('.title').text().trim() + const senderEmail = Cypress.$(email).find('.subline-from').text().trim() + const isUnread = Cypress.$(email).find('.unread-icon').not('.ng-hide').length > 0 + return subjectText.includes(emailTitle) && senderEmail === recipientEmailAddress && isUnread + }) + + expect(unreadEmails.length).to.equal(0) + }) + }, + ) +})