Skip to content

Commit

Permalink
Cypress test for MM-T247: Mark Posts with mentions as Unread (matterm…
Browse files Browse the repository at this point in the history
…ost#6315)

* Cypress test for MM-T247: Mark Posts with mentions as Unread

* Fixed Typos

Co-authored-by: Saturnino Abril <[email protected]>

* MM-T247: Moved import lines to correct position

Co-authored-by: Saturnino Abril <[email protected]>
Co-authored-by: Mattermod <[email protected]>
  • Loading branch information
3 people committed Sep 2, 2020
1 parent 841a4e7 commit 7b1583a
Showing 1 changed file with 178 additions and 0 deletions.
178 changes: 178 additions & 0 deletions e2e/cypress/integration/mark_as_unread/mark_mentions_as_unread_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

// ***************************************************************
// - [#] indicates a test step (e.g. # Go to a page)
// - [*] indicates an assertion (e.g. * Check the title)
// - Use element ID when selecting an element. Create one if none.
// ***************************************************************

// Group: @mark_as_unread

import {beUnread} from '../../support/assertions';

import {markAsUnreadByPostIdFromMenu, verifyPostNextToNewMessageSeparator, switchToChannel} from './helpers';

describe('Mark post with mentions as unread', () => {
let userA;
let userB;

let channelA;
let channelB;

before(() => {
cy.apiInitSetup().then(({team, user, channel}) => {
userA = user;
channelA = channel;

// # Create second channel and add userA
cy.apiCreateChannel(team.id, 'channel-b', 'Channel B').then((resp) => {
channelB = resp.body;
cy.apiAddUserToChannel(channelB.id, userA.id);
});

// # Create a second user
cy.apiCreateUser().then(({user: user2}) => {
userB = user2;

// # Add userB to channel team and channels
cy.apiAddUserToTeam(team.id, userB.id).then(() => {
cy.apiAddUserToChannel(channelA.id, userB.id);
cy.apiAddUserToChannel(channelB.id, userB.id);
});

cy.visit(`/${team.name}/channels/town-square`);
});
});
});

it('MM-T247 Marks posts with mentions as unread', () => {
// # Login as userB
cy.apiLogin(userB);

// # Navigate to both channels, so the new messages line appears above posts
switchToChannel(channelA);
switchToChannel(channelB);

// # Mention userB in channel A as userA
cy.postMessageAs({
sender: userA,
message: `@${userB.username} : hello1`,
channelId: channelA.id,
});

// * Verify that channelA has unread in LHS
cy.get(`#sidebarItem_${channelA.name}`).should(beUnread);

// * Verify that ChannelA has unread mention in LHS
cy.get(`#sidebarItem_${channelA.name}`).children('#unreadMentions').should('have.text', '1');

// # Navigate to channel A
switchToChannel(channelA);

// * Verify that ChannelA no longer has unread mention in LHS
cy.get(`#sidebarItem_${channelA.name}`).children('#unreadMentions').should('not.exist');

// * Verify that new message separator exists above the unread message
verifyPostNextToNewMessageSeparator(`@${userB.username} : hello1`);

// # Navigate to channel B
switchToChannel(channelB);

// # Navigate back to channel A
switchToChannel(channelA);

// * Verify that new message separator is gone
cy.get('.NotificationSeparator').should('not.exist');

// # Mention userB in channel B as userA
cy.postMessageAs({
sender: userA,
message: `@${userB.username} : hello2`,
channelId: channelB.id,
});

// # Navigate to channel B
switchToChannel(channelB);

// * Verify that new message separator exists above the unread message
verifyPostNextToNewMessageSeparator(`@${userB.username} : hello2`);

// # Refresh the page
cy.reload();

// * Verify the new message separator is gone
cy.get('.NotificationSeparator').should('not.exist');

// # Mention userB in channelA as userA
cy.postMessageAs({
sender: userA,
message: `@${userB.username} : hello3`,
channelId: channelA.id,
});

// # Navigate back to channel A
switchToChannel(channelA);

// * Verify the new message separator exists above the unread message
verifyPostNextToNewMessageSeparator(`@${userB.username} : hello3`);

// # Get the ID of the last post
cy.getLastPostId().then((postId) => {
// # Mark last post as unread from menu
markAsUnreadByPostIdFromMenu(postId);
});

// * Verify the new message separator still exists above the unread message
verifyPostNextToNewMessageSeparator(`@${userB.username} : hello3`);

// * Verify that channelA has unread in LHS
cy.get(`#sidebarItem_${channelA.name}`).should(beUnread);

// * Verify that ChannelA has unread mention in LHS
cy.get(`#sidebarItem_${channelA.name}`).children('#unreadMentions').should('have.text', '1');

// # Navigate to channel B
switchToChannel(channelB);

// # Navigate back to channel A
switchToChannel(channelA);

// * Verify the new message separator still exists above the unread message
verifyPostNextToNewMessageSeparator(`@${userB.username} : hello3`);

// * Verify that ChannelA no longer has unread mention in LHS
cy.get(`#sidebarItem_${channelA.name}`).children('#unreadMentions').should('not.exist');

// # Mention userB in channelB as userA
cy.postMessageAs({
sender: userA,
message: `@${userB.username} : hello4`,
channelId: channelB.id,
});

// # Navigate to channel B
switchToChannel(channelB);

// # Get the ID of the last post
cy.getLastPostId().then((postId) => {
// # Mark last post as unread from menu
markAsUnreadByPostIdFromMenu(postId);
});

// * Verify the new message separator exists above the unread message
verifyPostNextToNewMessageSeparator(`@${userB.username} : hello4`);

// * Verify that ChannelB has unread mention in LHS
cy.get(`#sidebarItem_${channelB.name}`).children('#unreadMentions').should('have.text', '1');

// # Refresh the page
cy.reload();

// * Verify the new message separator still exists above the unread message
verifyPostNextToNewMessageSeparator(`@${userB.username} : hello4`);

// * Verify that ChannelB no longer has unread mention in LHS
cy.get(`#sidebarItem_${channelB.name}`).children('#unreadMentions').should('not.exist');
});
});

0 comments on commit 7b1583a

Please sign in to comment.