Этот коммит содержится в:
Mario Vitale
2023-03-27 16:28:42 +02:00
родитель da7a6825ce
Коммит ba6b97fb62
1142 изменённых файлов: 44 добавлений и 44 удалений

Просмотреть файл

@@ -0,0 +1,102 @@
// 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.
// ***************************************************************
import {
getPostTextboxInput,
getQuickChannelSwitcherInput,
SimpleUser,
startAtMention,
verifySuggestionAtChannelSwitcher,
verifySuggestionAtPostTextbox,
} from './helpers';
export function doTestPostextbox(mention: string, ...suggestion: Cypress.UserProfile[]) {
getPostTextboxInput();
startAtMention(mention);
verifySuggestionAtPostTextbox(...suggestion);
}
export function doTestQuickChannelSwitcher(mention: string, ...suggestion: Cypress.UserProfile[]) {
getQuickChannelSwitcherInput();
startAtMention(mention);
verifySuggestionAtChannelSwitcher(...suggestion);
}
export function doTestUserChannelSection(prefix: string, testTeam: Cypress.Team, testUsers: Record<string, SimpleUser>) {
const thor = testUsers.thor;
const loki = testUsers.loki;
// # Create new channel and add user to channel
const channelName = 'new-channel';
cy.apiCreateChannel(testTeam.id, channelName, channelName).then(({channel}) => {
cy.apiGetUserByEmail(thor.email).then(({user}) => {
cy.apiAddUserToChannel(channel.id, user.id);
});
cy.visit(`/${testTeam.name}/channels/${channel.name}`);
});
// # Start an at mention that should return 2 users (in this case, the users share a last name)
cy.uiGetPostTextBox().
as('input').
clear().
type(`@${prefix}odinson`);
// * Thor should be a channel member
cy.uiVerifyAtMentionInSuggestionList(thor as Cypress.UserProfile, true);
// * Loki should NOT be a channel member
cy.uiVerifyAtMentionInSuggestionList(loki as Cypress.UserProfile, false);
}
export function doTestDMChannelSidebar(testUsers: Record<string, SimpleUser>) {
const thor = testUsers.thor;
// # Open of the add direct message modal
cy.uiAddDirectMessage().click({force: true});
// # Type username into input
cy.get('.more-direct-channels').
find('input').
should('exist').
type(thor.username, {force: true});
cy.intercept({
method: 'POST',
url: '/api/v4/users/search',
}).as('searchUsers');
cy.wait('@searchUsers').then((interception) => {
expect(interception.response.body.length === 1);
});
// * There should only be one result
cy.get('#moreDmModal').find('.more-modal__row').
as('result').
its('length').
should('equal', 1);
// * Result should have appropriate text
cy.get('@result').
find('.more-modal__name').
should('have.text', `@${thor.username} - ${thor.first_name} ${thor.last_name} (${thor.nickname})`);
cy.get('@result').
find('.more-modal__description').
should('have.text', thor.email);
// # Click on the result to add user
cy.get('@result').click({force: true});
// # Click "Go"
cy.uiGetButton('Go').click();
// # Should land on direct message channel for that user
cy.get('#channelHeaderTitle').should('have.text', thor.username + ' ');
}

Просмотреть файл

@@ -0,0 +1,113 @@
// 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.
// ***************************************************************
// Stage: @prod
// Group: @channels @autocomplete
import {getRandomLetter} from '../../../../utils';
import {doTestQuickChannelSwitcher} from '../common_test';
import {createSearchData} from '../helpers';
describe('Autocomplete with Database - Users', () => {
const prefix = getRandomLetter(3);
let testUsers;
before(() => {
cy.apiGetClientLicense().then(({isCloudLicensed}) => {
if (!isCloudLicensed) {
cy.shouldHaveElasticsearchDisabled();
}
});
createSearchData(prefix).then((searchData) => {
testUsers = searchData.users;
cy.apiLogin(searchData.sysadmin);
// # Navigate to the new teams town square
cy.visit(`/${searchData.team.name}/channels/town-square`);
// # Open quick channel switcher
cy.typeCmdOrCtrl().type('k');
cy.findByRole('textbox', {name: 'quick switch input'}).should('be.visible');
});
});
describe('search for user in channel switcher', () => {
describe('by @username', () => {
it('MM-T4071_1 Full username returns single user', () => {
doTestQuickChannelSwitcher(`@${prefix}ironman`, testUsers.ironman);
});
it('MM-T4071_2 Unique partial username returns single user', () => {
doTestQuickChannelSwitcher(`@${prefix}doc`, testUsers.doctorstrange);
});
it('MM-T4071_3 Partial username returns all users that match', () => {
doTestQuickChannelSwitcher(`@${prefix}i`, testUsers.ironman);
});
});
describe('by @firstname', () => {
it('MM-T4072_1 Full first name returns single user', () => {
doTestQuickChannelSwitcher(`@${prefix}tony`, testUsers.ironman);
});
it('MM-T4072_2 Unique partial first name returns single user', () => {
doTestQuickChannelSwitcher(`@${prefix}wa`, testUsers.deadpool);
});
it('MM-T4072_3 Partial first name returns all users that match', () => {
doTestQuickChannelSwitcher(`@${prefix}ste`, testUsers.captainamerica, testUsers.doctorstrange);
});
});
describe('by @lastname', () => {
it('MM-T4073_1 Full last name returns single user', () => {
doTestQuickChannelSwitcher(`@${prefix}stark`, testUsers.ironman);
});
it('MM-T4073_2 Unique partial last name returns single user', () => {
doTestQuickChannelSwitcher(`@${prefix}ban`, testUsers.hulk);
});
it('MM-T4073_3 Partial last name returns all users that match', () => {
doTestQuickChannelSwitcher(`@${prefix}ba`, testUsers.hawkeye, testUsers.hulk);
});
});
describe('by @nickname', () => {
it('MM-T4074_1 Full nickname returns single user', () => {
doTestQuickChannelSwitcher(`@${prefix}ronin`, testUsers.hawkeye);
});
it('MM-T4074_2 Unique partial nickname returns single user', () => {
doTestQuickChannelSwitcher(`@${prefix}gam`, testUsers.hulk);
});
it('MM-T4074_3 Partial nickname returns all users that match', () => {
doTestQuickChannelSwitcher(`@${prefix}pro`, testUsers.captainamerica, testUsers.ironman);
});
});
describe('special characters in usernames are returned', () => {
it('MM-T4075_1 Username with dot', () => {
doTestQuickChannelSwitcher(`@${prefix}dot.dot`, testUsers.dot);
});
it('MM-T4075_2 Username dash', () => {
doTestQuickChannelSwitcher(`@${prefix}dash-dash`, testUsers.dash);
});
it('MM-T4075_3 Username underscore', () => {
doTestQuickChannelSwitcher(`@${prefix}under_score`, testUsers.underscore);
});
});
});
});

Просмотреть файл

@@ -0,0 +1,109 @@
// 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.
// ***************************************************************
// Stage: @prod
// Group: @channels @autocomplete
import {getRandomLetter} from '../../../../utils';
import {doTestPostextbox} from '../common_test';
import {createSearchData} from '../helpers';
describe('Autocomplete with Database - Users', () => {
const prefix = getRandomLetter(3);
let testUsers;
before(() => {
cy.apiGetClientLicense().then(({isCloudLicensed}) => {
if (!isCloudLicensed) {
cy.shouldHaveElasticsearchDisabled();
}
});
createSearchData(prefix).then((searchData) => {
testUsers = searchData.users;
cy.apiLogin(searchData.sysadmin);
// # Navigate to the new teams town square
cy.visit(`/${searchData.team.name}/channels/town-square`);
});
});
describe('search for user in message input box', () => {
describe('by @username', () => {
it('MM-T4076_1 Full username returns single user', () => {
doTestPostextbox(`@${prefix}ironman`, testUsers.ironman);
});
it('MM-T4076_2 Unique partial username returns single user', () => {
doTestPostextbox(`@${prefix}doc`, testUsers.doctorstrange);
});
it('MM-T4076_3 Partial username returns all users that match', () => {
doTestPostextbox(`@${prefix}i`, testUsers.ironman);
});
});
describe('by @firstname', () => {
it('MM-T4077_1 Full first name returns single user', () => {
doTestPostextbox(`@${prefix}tony`, testUsers.ironman);
});
it('MM-T4077_2 Unique partial first name returns single user', () => {
doTestPostextbox(`@${prefix}wa`, testUsers.deadpool);
});
it('MM-T4077_3 Partial first name returns all users that match', () => {
doTestPostextbox(`@${prefix}ste`, testUsers.captainamerica, testUsers.doctorstrange);
});
});
describe('by @lastname', () => {
it('MM-T4078_1 Full last name returns single user', () => {
doTestPostextbox(`@${prefix}stark`, testUsers.ironman);
});
it('MM-T4078_2 Unique partial last name returns single user', () => {
doTestPostextbox(`@${prefix}ban`, testUsers.hulk);
});
it('MM-T4078_3 Partial last name returns all users that match', () => {
doTestPostextbox(`@${prefix}ba`, testUsers.hawkeye, testUsers.hulk);
});
});
describe('by @nickname', () => {
it('MM-T4079_1 Full nickname returns single user', () => {
doTestPostextbox(`@${prefix}ronin`, testUsers.hawkeye);
});
it('MM-T4079_2 Unique partial nickname returns single user', () => {
doTestPostextbox(`@${prefix}gam`, testUsers.hulk);
});
it('MM-T4079_3 Partial nickname returns all users that match', () => {
doTestPostextbox(`@${prefix}pro`, testUsers.captainamerica, testUsers.ironman);
});
});
describe('special characters in usernames are returned', () => {
it('MM-T4080_1 Username with dot', () => {
doTestPostextbox(`@${prefix}dot.dot`, testUsers.dot);
});
it('MM-T4080_2 Username with dash', () => {
doTestPostextbox(`@${prefix}dash-dash`, testUsers.dash);
});
it('MM-T4080_3 Username with underscore', () => {
doTestPostextbox(`@${prefix}under_score`, testUsers.underscore);
});
});
});
});

Просмотреть файл

@@ -0,0 +1,44 @@
// 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.
// ***************************************************************
// Stage: @prod
// Group: @channels @autocomplete
import {getRandomLetter} from '../../../../utils';
import {doTestDMChannelSidebar, doTestUserChannelSection} from '../common_test';
import {createSearchData} from '../helpers';
describe('Autocomplete with Database - Users', () => {
const prefix = getRandomLetter(3);
let testUsers;
let testTeam;
before(() => {
cy.apiGetClientLicense().then(({isCloudLicensed}) => {
if (!isCloudLicensed) {
cy.shouldHaveElasticsearchDisabled();
}
});
createSearchData(prefix).then((searchData) => {
testUsers = searchData.users;
testTeam = searchData.team;
cy.apiLogin(searchData.sysadmin);
});
});
it('MM-T4081 Users in correct in/out of channel sections', () => {
doTestUserChannelSection(prefix, testTeam, testUsers);
});
it('MM-T4082 DM can be opened with a user not on your team or in your DM channel sidebar', () => {
doTestDMChannelSidebar(testUsers);
});
});

Просмотреть файл

@@ -0,0 +1,300 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import * as TIMEOUTS from '../../../fixtures/timeouts';
import {getAdminAccount} from '../../../support/env';
export type SimpleUser = Pick<Cypress.UserProfile, 'username' | 'first_name' | 'last_name' | 'nickname' | 'password' | 'email'>;
function createPrivateChannel(teamId: string, userToAdd: Cypress.UserProfile = null) {
// # Create a private channel as sysadmin
return createChannel('P', teamId, userToAdd);
}
function createPublicChannel(teamId: string, userToAdd: Cypress.UserProfile = null) {
// # Create a public channel as sysadmin
return createChannel('O', teamId, userToAdd);
}
function createSearchData(prefix: string) {
return cy.apiCreateCustomAdmin({loginAfter: true, hideAdminTrialModal: true}).then(({sysadmin}) => {
const users = getTestUsers(prefix);
cy.apiLogin(sysadmin);
// # Create new team for tests
return cy.apiCreateTeam('search', 'Search').then(({team}) => {
// # Create pool of users for tests
Cypress._.forEach(users, (testUser) => {
cy.apiCreateUser({user: testUser}).then(({user}) => {
cy.apiAddUserToTeam(team.id, user.id);
});
});
return cy.wrap({sysadmin, team, users});
});
});
}
function enableElasticSearch() {
// # Enable elastic search via the API
cy.apiUpdateConfig({
ElasticsearchSettings: {
EnableAutocomplete: true,
EnableIndexing: true,
EnableSearching: true,
Sniff: false,
},
} as Cypress.AdminConfig);
// # Navigate to the elastic search setting page
cy.visit('/admin_console/environment/elasticsearch');
// * Test the connection and verify that we are successful
cy.contains('button', 'Test Connection').click();
cy.get('.alert-success').should('have.text', 'Test successful. Configuration saved.');
// # Index so we are up to date
cy.contains('button', 'Index Now').click();
// # Small wait to ensure new row is added
cy.wait(TIMEOUTS.ONE_SEC).get('.job-table__table').find('tbody > tr').eq(0).as('firstRow');
// * Newest row should eventually result in Success
const checkFirstRow = () => {
return cy.get('@firstRow').then((el) => {
return el.find('.status-icon-success').length > 0;
});
};
const options = {
timeout: TIMEOUTS.TWO_MIN,
interval: TIMEOUTS.TWO_SEC,
errorMsg: 'Reindex did not succeed in time',
};
cy.waitUntil(checkFirstRow, options);
}
function getTestUsers(prefix = ''): Record<string, SimpleUser> {
if (Cypress.env('searchTestUsers')) {
return JSON.parse(Cypress.env('searchTestUsers'));
}
return {
ironman: generatePrefixedUser({
username: 'ironman',
first_name: 'Tony',
last_name: 'Stark',
nickname: 'protoncannon',
}, prefix),
hulk: generatePrefixedUser({
username: 'hulk',
first_name: 'Bruce',
last_name: 'Banner',
nickname: 'gammaray',
}, prefix),
hawkeye: generatePrefixedUser({
username: 'hawkeye',
first_name: 'Clint',
last_name: 'Barton',
nickname: 'ronin',
}, prefix),
deadpool: generatePrefixedUser({
username: 'deadpool',
first_name: 'Wade',
last_name: 'Wilson',
nickname: 'merc',
}, prefix),
captainamerica: generatePrefixedUser({
username: 'captainamerica',
first_name: 'Steve',
last_name: 'Rogers',
nickname: 'professional',
}, prefix),
doctorstrange: generatePrefixedUser({
username: 'doctorstrange',
first_name: 'Stephen',
last_name: 'Strange',
nickname: 'sorcerersupreme',
}, prefix),
thor: generatePrefixedUser({
username: 'thor',
first_name: 'Thor',
last_name: 'Odinson',
nickname: 'mjolnir',
}, prefix),
loki: generatePrefixedUser({
username: 'loki',
first_name: 'Loki',
last_name: 'Odinson',
nickname: 'trickster',
}, prefix),
dot: generatePrefixedUser({
username: 'dot.dot',
first_name: 'z1First',
last_name: 'z1Last',
nickname: 'z1Nick',
}, prefix),
dash: generatePrefixedUser({
username: 'dash-dash',
first_name: 'z2First',
last_name: 'z2Last',
nickname: 'z2Nick',
}, prefix),
underscore: generatePrefixedUser({
username: 'under_score',
first_name: 'z3First',
last_name: 'z3Last',
nickname: 'z3Nick',
}, prefix),
};
}
function getPostTextboxInput() {
cy.wait(TIMEOUTS.HALF_SEC);
cy.uiGetPostTextBox().
as('input').
clear();
}
function getQuickChannelSwitcherInput() {
cy.findByRole('textbox', {name: 'quick switch input'}).
should('be.visible').
as('input').
clear();
}
function searchAndVerifyChannel(channel: Cypress.Channel, shouldExist = true) {
const name = channel.display_name;
searchForChannel(name);
if (shouldExist) {
// * Channel should appear in suggestions list
cy.get('#suggestionList').findByTestId(channel.name).should('be.visible');
} else {
// * Suggestion list and channel item should not appear
cy.get('#suggestionList').should('not.exist');
cy.findByTestId(channel.name).should('not.exist');
}
}
function searchAndVerifyUser(user: Cypress.UserProfile) {
// # Start @ mentions autocomplete with username
cy.uiGetPostTextBox().
as('input').
clear().
type(`@${user.username}`);
// * Suggestion list should appear
cy.get('#suggestionList', {timeout: TIMEOUTS.FIVE_SEC}).should('be.visible');
// * Verify user appears in results post-change
return cy.uiVerifyAtMentionSuggestion(user);
}
function searchForChannel(name: string) {
// # Open up channel switcher
cy.typeCmdOrCtrl().type('k').wait(TIMEOUTS.ONE_SEC);
// # Clear out and type in the name
cy.findByRole('textbox', {name: 'quick switch input'}).
should('be.visible').
as('input').
clear().
type(name);
}
function startAtMention(string: string) {
// # Get the expected input
cy.get('@input').clear().type(string);
// * Suggestion list should appear
cy.get('#suggestionList').should('be.visible');
}
function verifySuggestionAtPostTextbox(...expectedUsers: Cypress.UserProfile[]) {
expectedUsers.forEach((user) => {
cy.wait(TIMEOUTS.HALF_SEC);
cy.uiVerifyAtMentionSuggestion(user);
});
}
function verifySuggestionAtChannelSwitcher(...expectedUsers: Cypress.UserProfile[]) {
expectedUsers.forEach((user) => {
cy.findByTestId(user.username).
should('be.visible').
and('have.text', `${user.first_name} ${user.last_name} (${user.nickname})@${user.username}`);
});
}
function createChannel(channelType: string, teamId: string, userToAdd: Cypress.UserProfile = null) {
// # Create a channel as sysadmin
return cy.externalRequest({
user: getAdminAccount(),
method: 'POST',
path: 'channels',
data: {
team_id: teamId,
name: 'test-channel' + Date.now(),
display_name: 'Test Channel ' + Date.now(),
type: channelType,
header: '',
purpose: '',
},
}).then(({data: channel}) => {
if (userToAdd) {
// # Get user profile by email
return cy.apiGetUserByEmail(userToAdd.email).then(({user}) => {
// # Add user to team
cy.externalRequest({
user: getAdminAccount(),
method: 'post',
path: `channels/${channel.id}/members`,
data: {user_id: user.id},
}).then(() => {
// # Explicitly wait to give some time to index before searching
cy.wait(TIMEOUTS.TWO_SEC);
return cy.wrap(channel);
});
});
}
// # Explicitly wait to give some time to index before searching
cy.wait(TIMEOUTS.TWO_SEC);
return cy.wrap(channel);
});
}
function generatePrefixedUser(user: Omit<SimpleUser, 'password' | 'email'>, prefix: string) {
return {
username: withPrefix(user.username, prefix),
password: 'passwd',
first_name: withPrefix(user.first_name, prefix),
last_name: withPrefix(user.last_name, prefix),
email: createEmail(user.username, prefix),
nickname: withPrefix(user.nickname, prefix),
};
}
function withPrefix(name: string, prefix: string) {
return prefix + name;
}
function createEmail(name: string, prefix: string) {
return `${prefix}${name}@sample.mattermost.com`;
}
export {
createPrivateChannel,
createPublicChannel,
createSearchData,
enableElasticSearch,
getTestUsers,
getPostTextboxInput,
getQuickChannelSwitcherInput,
searchAndVerifyChannel,
searchAndVerifyUser,
searchForChannel,
startAtMention,
verifySuggestionAtChannelSwitcher,
verifySuggestionAtPostTextbox,
};