From 653f766efb094bea8431f4e9a2851e1cc07875e4 Mon Sep 17 00:00:00 2001 From: Rohitesh Gupta Date: Tue, 6 Oct 2020 18:39:00 +0530 Subject: [PATCH 1/4] Added some cypress tests part of MM-29347 --- .../group_mentions_system_messages_spec.js | 288 ++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100644 e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js diff --git a/e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js b/e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js new file mode 100644 index 000000000000..8ce02f8a169b --- /dev/null +++ b/e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js @@ -0,0 +1,288 @@ +// 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: @system_console @group_mentions + +import ldapUsers from '../../../fixtures/ldap_users.json'; +import TIMEOUTS from '../../../fixtures/timeouts'; + +import { + disablePermission, + enablePermission, + saveConfigForChannel, + visitChannelConfigPage, +} from '../system_console/channel_moderation/helpers'; +import {checkboxesTitleToIdMap} from '../system_console/channel_moderation/constants'; + +// assumes the CYPRESS_* variables are set +// assumes that E20 license is uploaded +// for setup with AWS: Follow the instructions mentioned in the mattermost/platform-private/config/ldap-test-setup.txt file + +describe('Group Mentions', () => { + let groupID; + let boardUser; + let regularUser; + let testTeam; + + before(() => { + // * Check if server has license for LDAP Groups + cy.apiRequireLicenseForFeature('LDAPGroups'); + + // # Enable Guest Account Settings + cy.apiUpdateConfig({ + GuestAccountsSettings: { + Enable: true, + }, + }); + + cy.apiInitSetup().then(({team, user}) => { + regularUser = user; + testTeam = team; + }); + + // # Login as admin + cy.apiAdminLogin(); + + // # Test LDAP configuration and server connection + // # Synchronize user attributes + cy.apiLDAPTest(); + cy.apiLDAPSync(); + + // # Get board group id + cy.apiGetGroups().then((res) => { + res.body.forEach((group) => { + if (group.display_name === 'board') { + // # Set groupID to navigate to group page directly + groupID = group.id; + + // # Set allow reference false to ensure correct data for test cases + cy.apiPatchGroup(groupID, {allow_reference: false}); + } + }); + }); + + // # Enable Group Mention for the group - board + cy.visit('/admin_console/user_management/groups'); + cy.get('#board_group').then((el) => { + if (!el.text().includes('Edit')) { + // # Link the Group if its not linked before + if (el.find('.icon.fa-unlink').length > 0) { + el.find('.icon.fa-unlink').click(); + } + } + }); + + // # Login once as board user to ensure the user is created in the system + boardUser = ldapUsers['board-1']; + cy.apiLogin(boardUser); + + // # Login as sysadmin + cy.apiAdminLogin(); + + // # Add board user to test team to ensure that it exists in the team and set its preferences to skip tutorial step + cy.apiGetUserByEmail(boardUser.email).then(({user}) => { + cy.apiGetChannelByName(testTeam.name, 'town-square').then(({channel}) => { + cy.apiAddUserToTeam(testTeam.id, user.id).then(() => { + cy.apiAddUserToChannel(channel.id, user.id); + }); + }); + + const preferences = [{ + user_id: user.id, + category: 'tutorial_step', + name: user.id, + value: '999', + }]; + cy.apiSaveUserPreference(preferences, user.id); + }); + }); + + it('MM-T2456 - Group Mentions when group members are in the team but not in the channel', () => { + const groupName = `board_test_case_${Date.now()}`; + + // # Login as sysadmin and enable group mention with the group name + cy.apiAdminLogin(); + enableGroupMention(groupName); + + // # Login as a regular user + cy.apiLogin(regularUser); + + // # Create a new channel as a regular user + cy.apiCreateChannel(testTeam.id, 'group-mention', 'Group Mentions').then(({channel}) => { + // # Visit the channel + cy.visit(`/${testTeam.name}/channels/${channel.name}`); + + // # Submit a post containing the group mention + cy.postMessage(`@${groupName}`); + + // * Verify if a system message is displayed indicating that list of members were not notified + cy.getLastPostId().then((postId) => { + cy.get(`#postMessageText_${postId}`).should('include.text', `@${boardUser.username} did not get notified by this mention because they are not in the channel. Would you like to add them to the channel? They will have access to all message history.`); + + // * Verify if an option should be given to add them to channel + cy.get('a.PostBody_addChannelMemberLink').should('be.visible'); + }); + }); + }); + + it('MM-T2457 - Group Mentions when group members are not in the team and the channel', () => { + const groupName = `board_test_case_${Date.now()}`; + + // # Login as sysadmin and enable group mention with the group name + cy.apiAdminLogin(); + enableGroupMention(groupName); + + // # Create a new team and channel as a sysadmin + cy.apiCreateTeam('team', 'Test NoMember').then(({team}) => { + cy.apiCreateChannel(team.id, 'group-mention', 'Group Mentions').then(({channel}) => { + cy.apiCreateUser().then(({user}) => { // eslint-disable-line + // # Add user to the team and channel + cy.apiAddUserToTeam(team.id, user.id).then(() => { + cy.apiAddUserToChannel(channel.id, user.id); + }); + + // # Login as a regular user + cy.apiLogin(user); + + // # Visit the channel + cy.visit(`/${team.name}/channels/${channel.name}`); + + // # Submit a post containing the group mention + cy.postMessage(`@${groupName}`); + + // * Verify if a system message is displayed indicating that there are no members in this team + cy.getLastPostId().then((postId) => { + cy.get(`#postMessageText_${postId}`). + should('include.text', `@${groupName} has no members on this team`); + + // * Verify that the group mention is not highlighted + cy.get(`#postMessageText_${postId}`).find('.mention--highlight').should('not.exist'); + }); + }); + }); + }); + }); + + it('MM-T2458 - Group Mentions when group members are not in the channel as a Guest User', () => { + const groupName = `board_test_case_${Date.now()}`; + + // # Login as sysadmin and enable group mention with the group name + cy.apiAdminLogin(); + enableGroupMention(groupName); + + // # Enable Group Mentions for Guest Users + cy.visit('/admin_console/user_management/permissions/system_scheme'); + enablePermission('guests-guest_use_group_mentions-checkbox'); + saveConfig(); + + // # Create a new channel as a sysadmin + cy.apiCreateChannel(testTeam.id, 'group-mention', 'Group Mentions').then(({channel}) => { + cy.apiCreateUser().then(({user}) => { // eslint-disable-line + // # Add user to the team and channel + cy.apiAddUserToTeam(testTeam.id, user.id).then(() => { + cy.apiAddUserToChannel(channel.id, user.id); + }); + + // # Demote the user as a guest user + cy.apiDemoteUserToGuest(user.id); + + // # Login as a guest user + cy.apiLogin(user); + + // # Visit the channel + cy.visit(`/${testTeam.name}/channels/${channel.name}`); + + // # Submit a post containing the group mention + cy.postMessage(`@${groupName}`); + + // * Verify if a system message is displayed indicating that list of members were not notified + cy.getLastPostId().then((postId) => { + cy.get(`#postMessageText_${postId}`). + should('include.text', `@${boardUser.username} did not get notified by this mention because they are not in the channel.`); + + // * Verify that the option to add them to channel is not given + cy.get('a.PostBody_addChannelMemberLink').should('not.exist'); + }); + }); + }); + }); + + it('MM-T2459 - Group Mentions when group members are not in the channel when Manage Members is disabled', () => { + const groupName = `board_test_case_${Date.now()}`; + + // # Login as sysadmin and enable group mention with the group name + cy.apiAdminLogin(); + enableGroupMention(groupName); + + // # Create a new channel as a sysadmin + cy.apiCreateChannel(testTeam.id, 'group-mention', 'Group Mentions').then(({channel}) => { + // # Disable Manage Members permission for the channel + visitChannelConfigPage(channel); + disablePermission(checkboxesTitleToIdMap.MANAGE_MEMBERS_MEMBERS); + saveConfigForChannel(); + + // # Add regular user to the channel + cy.apiAddUserToChannel(channel.id, regularUser.id); + + // # Login as a regular user + cy.apiLogin(regularUser); + + // # Visit the channel + cy.visit(`/${testTeam.name}/channels/${channel.name}`); + + // # Submit a post containing the group mention + cy.postMessage(`@${groupName}`); + + // * Verify if a system message is displayed indicating that list of members were not notified + cy.getLastPostId().then((postId) => { + cy.get(`#postMessageText_${postId}`). + should('include.text', `@${boardUser.username} did not get notified by this mention because they are not in the channel.`); + + // * Verify that the option to add them to channel is not given + cy.get('a.PostBody_addChannelMemberLink').should('not.exist'); + }); + }); + }); + + function enableGroupMention(groupName) { + // # Visit Group Configurations page + cy.visit(`/admin_console/user_management/groups/${groupID}`); + + // # Scroll users list into view and then make sure it has loaded before scrolling back to the top + cy.get('#group_users').scrollIntoView(); + cy.findByText(boardUser.email).should('be.visible'); + cy.get('#group_profile').scrollIntoView().wait(TIMEOUTS.TWO_SEC); + + // # Click the allow reference button + cy.findByTestId('allowReferenceSwitch').then((el) => { + const button = el.find('button'); + const classAttribute = button[0].getAttribute('class'); + if (!classAttribute.includes('active')) { + button[0].click(); + } + }); + + // # Give the group a custom name different from its DisplayName attribute + cy.get('#groupMention').find('input').clear().type(groupName); + + // # Click save button + saveConfig(); + } + + function saveConfig() { + cy.get('#saveSetting').then((btn) => { + if (btn.is(':enabled')) { + btn.click(); + + cy.waitUntil(() => cy.get('#saveSetting').then((el) => { + return el[0].innerText === 'Save'; + })); + } + }); + } +}); From 784b95ecac2dd9308c49255f121ba167bcc55d8c Mon Sep 17 00:00:00 2001 From: Rohitesh Gupta Date: Wed, 7 Oct 2020 17:40:12 +0530 Subject: [PATCH 2/4] Fixed issue on fresh LDAP setup --- .../group_mentions_system_messages_spec.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js b/e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js index 8ce02f8a169b..8af6a0fbf8a2 100644 --- a/e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js +++ b/e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js @@ -53,6 +53,17 @@ describe('Group Mentions', () => { cy.apiLDAPTest(); cy.apiLDAPSync(); + // # Link the group - board + cy.visit('/admin_console/user_management/groups'); + cy.get('#board_group').then((el) => { + if (!el.text().includes('Edit')) { + // # Link the Group if its not linked before + if (el.find('.icon.fa-unlink').length > 0) { + el.find('.icon.fa-unlink').click(); + } + } + }); + // # Get board group id cy.apiGetGroups().then((res) => { res.body.forEach((group) => { @@ -66,17 +77,6 @@ describe('Group Mentions', () => { }); }); - // # Enable Group Mention for the group - board - cy.visit('/admin_console/user_management/groups'); - cy.get('#board_group').then((el) => { - if (!el.text().includes('Edit')) { - // # Link the Group if its not linked before - if (el.find('.icon.fa-unlink').length > 0) { - el.find('.icon.fa-unlink').click(); - } - } - }); - // # Login once as board user to ensure the user is created in the system boardUser = ldapUsers['board-1']; cy.apiLogin(boardUser); From 7ccabdcc80af25edd0839ae24cf0cd019571e832 Mon Sep 17 00:00:00 2001 From: Rohitesh Gupta Date: Wed, 7 Oct 2020 22:27:14 +0530 Subject: [PATCH 3/4] Added additional timeouts after cy.visit --- .../group_mentions_system_messages_spec.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js b/e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js index 8af6a0fbf8a2..a763572344af 100644 --- a/e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js +++ b/e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js @@ -9,7 +9,7 @@ // Group: @system_console @group_mentions import ldapUsers from '../../../fixtures/ldap_users.json'; -import TIMEOUTS from '../../../fixtures/timeouts'; +import * as TIMEOUTS from '../../../fixtures/timeouts'; import { disablePermission, @@ -55,7 +55,7 @@ describe('Group Mentions', () => { // # Link the group - board cy.visit('/admin_console/user_management/groups'); - cy.get('#board_group').then((el) => { + cy.get('#board_group', {timeout: TIMEOUTS.ONE_MIN}).then((el) => { if (!el.text().includes('Edit')) { // # Link the Group if its not linked before if (el.find('.icon.fa-unlink').length > 0) { @@ -116,6 +116,7 @@ describe('Group Mentions', () => { cy.apiCreateChannel(testTeam.id, 'group-mention', 'Group Mentions').then(({channel}) => { // # Visit the channel cy.visit(`/${testTeam.name}/channels/${channel.name}`); + cy.get('#post_textbox', {timeout: TIMEOUTS.ONE_MIN}).should('be.visible'); // # Submit a post containing the group mention cy.postMessage(`@${groupName}`); @@ -151,6 +152,7 @@ describe('Group Mentions', () => { // # Visit the channel cy.visit(`/${team.name}/channels/${channel.name}`); + cy.get('#post_textbox', {timeout: TIMEOUTS.ONE_MIN}).should('be.visible'); // # Submit a post containing the group mention cy.postMessage(`@${groupName}`); @@ -177,6 +179,7 @@ describe('Group Mentions', () => { // # Enable Group Mentions for Guest Users cy.visit('/admin_console/user_management/permissions/system_scheme'); + cy.get('.admin-console__header', {timeout: TIMEOUTS.ONE_MIN}).should('be.visible').and('have.text', 'System Scheme'); enablePermission('guests-guest_use_group_mentions-checkbox'); saveConfig(); @@ -196,6 +199,7 @@ describe('Group Mentions', () => { // # Visit the channel cy.visit(`/${testTeam.name}/channels/${channel.name}`); + cy.get('#post_textbox', {timeout: TIMEOUTS.ONE_MIN}).should('be.visible'); // # Submit a post containing the group mention cy.postMessage(`@${groupName}`); @@ -234,6 +238,7 @@ describe('Group Mentions', () => { // # Visit the channel cy.visit(`/${testTeam.name}/channels/${channel.name}`); + cy.get('#post_textbox', {timeout: TIMEOUTS.ONE_MIN}).should('be.visible'); // # Submit a post containing the group mention cy.postMessage(`@${groupName}`); @@ -254,7 +259,7 @@ describe('Group Mentions', () => { cy.visit(`/admin_console/user_management/groups/${groupID}`); // # Scroll users list into view and then make sure it has loaded before scrolling back to the top - cy.get('#group_users').scrollIntoView(); + cy.get('#group_users', {timeout: TIMEOUTS.ONE_MIN}).scrollIntoView(); cy.findByText(boardUser.email).should('be.visible'); cy.get('#group_profile').scrollIntoView().wait(TIMEOUTS.TWO_SEC); From 3e3aaa939a04314460a03392739268e1b885076f Mon Sep 17 00:00:00 2001 From: Rohitesh Gupta Date: Wed, 14 Oct 2020 18:50:05 +0530 Subject: [PATCH 4/4] Fixed as per PR review comments --- .../group_mentions_system_messages_spec.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js b/e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js index a763572344af..ba7d92d85f21 100644 --- a/e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js +++ b/e2e/cypress/integration/enterprise/group_mentions/group_mentions_system_messages_spec.js @@ -45,9 +45,6 @@ describe('Group Mentions', () => { testTeam = team; }); - // # Login as admin - cy.apiAdminLogin(); - // # Test LDAP configuration and server connection // # Synchronize user attributes cy.apiLDAPTest(); @@ -92,13 +89,7 @@ describe('Group Mentions', () => { }); }); - const preferences = [{ - user_id: user.id, - category: 'tutorial_step', - name: user.id, - value: '999', - }]; - cy.apiSaveUserPreference(preferences, user.id); + cy.apiSaveTutorialStep(user.id, '999'); }); });