diff --git a/cypress/e2e/Chat.Notification.feature b/cypress/e2e/Chat.Notification.feature new file mode 100644 index 000000000..0dd540cb2 --- /dev/null +++ b/cypress/e2e/Chat.Notification.feature @@ -0,0 +1,17 @@ +Feature: Chat notification badge + As a user + I want to see a notification badge on the chat icon + When another user sends me a chat message + + Background: + Given the following "users" are in the database: + | slug | email | password | id | name | termsAndConditionsAgreedVersion | + | alice | alice@example.org | 1234 | alice | Alice | 0.0.4 | + | bob | bob@example.org | 4321 | bob | Bob | 0.0.4 | + + Scenario: Receive chat notification live via websocket + Given I am logged in as "bob" + And I navigate to page "/" + And I see no unread chat messages in the header + When "alice" sends a chat message "Hello Bob!" to "bob" + Then I see 1 unread chat message in the header diff --git a/cypress/support/step_definitions/Chat.Notification/I_see_{int}_unread_chat_message_in_the_header.js b/cypress/support/step_definitions/Chat.Notification/I_see_{int}_unread_chat_message_in_the_header.js new file mode 100644 index 000000000..45f0bc298 --- /dev/null +++ b/cypress/support/step_definitions/Chat.Notification/I_see_{int}_unread_chat_message_in_the_header.js @@ -0,0 +1,13 @@ +import { defineStep } from '@badeball/cypress-cucumber-preprocessor' + +defineStep('I see no unread chat messages in the header', () => { + cy.get('.chat-notification-menu:visible', { timeout: 15000 }).should('exist') + cy.get('.chat-notification-menu:visible .count.--danger').should('not.exist') +}) + +defineStep('I see {int} unread chat message in the header', (count) => { + cy.get('.chat-notification-menu:visible .count.--danger', { timeout: 15000 }).should( + 'contain', + count, + ) +}) diff --git a/cypress/support/step_definitions/Chat.Notification/{string}_sends_a_chat_message_{string}_to_{string}.js b/cypress/support/step_definitions/Chat.Notification/{string}_sends_a_chat_message_{string}_to_{string}.js new file mode 100644 index 000000000..6f079dbaa --- /dev/null +++ b/cypress/support/step_definitions/Chat.Notification/{string}_sends_a_chat_message_{string}_to_{string}.js @@ -0,0 +1,46 @@ +import { defineStep } from '@badeball/cypress-cucumber-preprocessor' +import './../../commands' +import './../../factories' + +const createRoomMutation = ` + mutation ($userId: ID!) { + CreateRoom(userId: $userId) { + id + } + } +` + +const createMessageMutation = ` + mutation ($roomId: ID!, $content: String) { + CreateMessage(roomId: $roomId, content: $content) { + id + } + } +` + +defineStep( + '{string} sends a chat message {string} to {string}', + (senderSlug, message, recipientSlug) => { + cy.neode() + .then((neode) => { + return neode.cypher( + `MATCH (sender:User {slug: $senderSlug})-[:PRIMARY_EMAIL]->(e:EmailAddress) + MATCH (recipient:User {slug: $recipientSlug}) + RETURN e.email AS senderEmail, recipient.id AS recipientId`, + { senderSlug, recipientSlug }, + ) + }) + .then((result) => { + expect(result.records).to.have.length.greaterThan(0, + `No users found for sender "${senderSlug}" or recipient "${recipientSlug}"`) + const senderEmail = result.records[0].get('senderEmail') + const recipientId = result.records[0].get('recipientId') + return cy.authenticateAs({ email: senderEmail, password: '1234' }).then((client) => { + return client.request(createRoomMutation, { userId: recipientId }).then((roomData) => { + const roomId = roomData.CreateRoom.id + return client.request(createMessageMutation, { roomId, content: message }) + }) + }) + }) + }, +)