Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
MM-26035 Remove "cy.apiCreateNewUser" in favor new "cy.apiInitSetup" (#…
Browse files Browse the repository at this point in the history
…5737)

* remove apiCreateNewUser

* update per new testing-library api

* updatetimeout constants and per comments

* fix failing lint

Co-authored-by: Saturnino Abril <[email protected]>
  • Loading branch information
saturninoabril and Saturnino Abril committed Jun 19, 2020
1 parent 8880deb commit 9f25729
Show file tree
Hide file tree
Showing 30 changed files with 1,019 additions and 836 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,32 @@

// Group: @enterprise @elasticsearch @autocomplete

import users from '../../../fixtures/users.json';
import {getAdminAccount} from '../../../support/env';

import {
createEmail,
createPrivateChannel,
enableElasticSearch,
searchForChannel,
withTimestamp,
} from './helpers';

describe('Autocomplete with Elasticsearch - Channel', () => {
const timestamp = Date.now();
let team = {};
let user;
const admin = getAdminAccount();
let testTeam;
let testUser;

before(() => {
// * Check if server has license for Elasticsearch
cy.requireLicenseForFeature('Elasticsearch');

// # Create new team to run tests against
cy.apiCreateTeam(`elastic-${timestamp}`, `elastic-${timestamp}`).then((response) => {
team = response.body;

const daredevil = {
username: withTimestamp('daredevil', timestamp),
firstName: 'Matt',
lastName: 'Murdock',
email: createEmail('daredevil', timestamp),
nickname: withTimestamp('attorney', timestamp),
};

// # Setup new channel and user
cy.apiCreateNewUser(daredevil, [team.id]).as('newUser');
});

// # Enable Elasticsearch
enableElasticSearch();
cy.apiLogout();

// # Login and navigate to team with new user
cy.get('@newUser').then((newUser) => {
user = newUser;
cy.apiLogin(user.username, user.password);
cy.visit(`/${team.name}`);
// # Login as test user and go to town-square
cy.apiInitSetup({loginAfter: true}).then(({team, user}) => {
testUser = user;
testTeam = team;

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

Expand All @@ -61,7 +44,7 @@ describe('Autocomplete with Elasticsearch - Channel', () => {

it("private channel I don't belong to does not appear", () => {
// # Create private channel, do not add new user to it (sets @privateChannel alias)
createPrivateChannel(team.id).then((channel) => {
createPrivateChannel(testTeam.id).then((channel) => {
// # Go to off-topic channel to partially reload the page
cy.get('#sidebarChannelContainer').should('be.visible').within(() => {
cy.findAllByText('Off-Topic').should('be.visible').click();
Expand All @@ -78,7 +61,7 @@ describe('Autocomplete with Elasticsearch - Channel', () => {

it('private channel I do belong to appears', () => {
// # Create private channel and add new user to it (sets @privateChannel alias)
createPrivateChannel(team.id, user).then((channel) => {
createPrivateChannel(testTeam.id, testUser).then((channel) => {
// # Go to off-topic channel to partially reload the page
cy.get('#sidebarChannelContainer').should('be.visible').within(() => {
cy.findAllByText('Off-Topic').should('be.visible').click();
Expand All @@ -102,7 +85,7 @@ describe('Autocomplete with Elasticsearch - Channel', () => {

// # As admin, create a new team that the new user is not a member of
cy.task('externalRequest', {
user: users.sysadmin,
user: admin,
path: 'teams',
baseUrl,
method: 'post',
Expand Down Expand Up @@ -137,12 +120,12 @@ describe('Autocomplete with Elasticsearch - Channel', () => {
before(() => {
// # Login as admin
cy.apiAdminLogin();
cy.visit(`/${team.name}`);
cy.visit(`/${testTeam.name}`);

const name = 'hellothere';

// # Create a new channel
cy.apiCreateChannel(team.id, name, name).then((channelResponse) => {
cy.apiCreateChannel(testTeam.id, name, name).then((channelResponse) => {
channelId = channelResponse.body.id;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,78 +60,89 @@ module.exports = {
return {
ironman: {
username: withTimestamp('ironman', reverseTimeStamp),
firstName: 'Tony',
lastName: 'Stark',
password: 'passwd',
first_name: 'Tony',
last_name: 'Stark',
email: createEmail('ironman', reverseTimeStamp),
nickname: withTimestamp('protoncannon', reverseTimeStamp),
},
hulk: {
username: withTimestamp('hulk', reverseTimeStamp),
firstName: 'Bruce',
lastName: 'Banner',
password: 'passwd',
first_name: 'Bruce',
last_name: 'Banner',
email: createEmail('hulk', reverseTimeStamp),
nickname: withTimestamp('gammaray', reverseTimeStamp),
},
hawkeye: {
username: withTimestamp('hawkeye', reverseTimeStamp),
firstName: 'Clint',
lastName: 'Barton',
password: 'passwd',
first_name: 'Clint',
last_name: 'Barton',
email: createEmail('hawkeye', reverseTimeStamp),
nickname: withTimestamp('ronin', reverseTimeStamp),
},
deadpool: {
username: withTimestamp('deadpool', reverseTimeStamp),
firstName: 'Wade',
lastName: 'Wilson',
password: 'passwd',
first_name: 'Wade',
last_name: 'Wilson',
email: createEmail('deadpool', reverseTimeStamp),
nickname: withTimestamp('merc', reverseTimeStamp),
},
captainamerica: {
username: withTimestamp('captainamerica', reverseTimeStamp),
firstName: 'Steve',
lastName: 'Rogers',
password: 'passwd',
first_name: 'Steve',
last_name: 'Rogers',
email: createEmail('captainamerica', reverseTimeStamp),
nickname: withTimestamp('professional', reverseTimeStamp),
},
doctorstrange: {
username: withTimestamp('doctorstrange', reverseTimeStamp),
firstName: 'Stephen',
lastName: 'Strange',
password: 'passwd',
first_name: 'Stephen',
last_name: 'Strange',
email: createEmail('doctorstrange', reverseTimeStamp),
nickname: withTimestamp('sorcerersupreme', reverseTimeStamp),
},
thor: {
username: withTimestamp('thor', reverseTimeStamp),
firstName: 'Thor',
lastName: 'Odinson',
password: 'passwd',
first_name: 'Thor',
last_name: 'Odinson',
email: createEmail('thor', reverseTimeStamp),
nickname: withTimestamp('mjolnir', reverseTimeStamp),
},
loki: {
username: withTimestamp('loki', reverseTimeStamp),
firstName: 'Loki',
lastName: 'Odinson',
password: 'passwd',
first_name: 'Loki',
last_name: 'Odinson',
email: createEmail('loki', reverseTimeStamp),
nickname: withTimestamp('trickster', reverseTimeStamp),
},
dot: {
username: withTimestamp('dot.dot', reverseTimeStamp),
firstName: 'z1First',
lastName: 'z1Last',
password: 'passwd',
first_name: 'z1First',
last_name: 'z1Last',
email: createEmail('dot', reverseTimeStamp),
nickname: 'z1Nick',
},
dash: {
username: withTimestamp('dash-dash', reverseTimeStamp),
firstName: 'z2First',
lastName: 'z2Last',
password: 'passwd',
first_name: 'z2First',
last_name: 'z2Last',
email: createEmail('dash', reverseTimeStamp),
nickname: 'z2Nick',
},
underscore: {
username: withTimestamp('under_score', reverseTimeStamp),
firstName: 'z3First',
lastName: 'z3Last',
password: 'passwd',
first_name: 'z3First',
last_name: 'z3Last',
email: createEmail('undercore', reverseTimeStamp),
nickname: 'z3Nick',
},
Expand Down Expand Up @@ -231,7 +242,7 @@ module.exports = {
// # Verify user appears in results post-change
return cy.findByTestId(`mentionSuggestion_${user.username}`, {exact: false}).within((name) => {
cy.wrap(name).find('.mention--align').should('have.text', `@${user.username}`);
cy.wrap(name).find('.ml-2').should('have.text', `${user.firstName} ${user.lastName} (${user.nickname})`);
cy.wrap(name).find('.ml-2').should('have.text', `${user.first_name} ${user.last_name} (${user.nickname})`);
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,47 @@ import {

describe('Autocomplete with Elasticsearch - Renaming', () => {
const timestamp = Date.now();
let team;
let testTeam;

before(() => {
cy.apiSaveTeammateNameDisplayPreference('username');

// * Check if server has license for Elasticsearch
cy.requireLicenseForFeature('Elasticsearch');

// # Create new team for tests
cy.apiCreateTeam(`elastic-${timestamp}`, `elastic-${timestamp}`).then((response) => {
team = response.body;
testTeam = response.body;
});

// # Enable elastic search
// # Enable Elasticsearch
enableElasticSearch();
});

it('renamed user appears in message input box', () => {
const spiderman = {
username: withTimestamp('spiderman', timestamp),
firstName: 'Peter',
lastName: 'Parker',
password: 'passwd',
first_name: 'Peter',
last_name: 'Parker',
email: createEmail('spiderman', timestamp),
nickname: withTimestamp('friendlyneighborhood', timestamp),
};

// # Create a new user
cy.apiCreateNewUser(spiderman, [team.id]).then((userResponse) => {
const user = userResponse;
cy.visit(`/${team.name}`);
cy.apiCreateUser({user: spiderman}).then(({user}) => {
cy.apiAddUserToTeam(testTeam.id, user.id).then(() => {
cy.visit(`/${testTeam.name}/channels/town-square`);

// # Verify user appears in search results pre-change
searchAndVerifyUser(user);
// # Verify user appears in search results pre-change
searchAndVerifyUser(user);

// # Rename a user
const newName = withTimestamp('webslinger', timestamp);
cy.apiPatchUser(user.id, {username: newName}).then(() => {
user.username = newName;
// # Rename a user
const newName = withTimestamp('webslinger', timestamp);
cy.apiPatchUser(user.id, {username: newName}).then(() => {
user.username = newName;

// # Verify user appears in search results post-change
searchAndVerifyUser(user);
// # Verify user appears in search results post-change
searchAndVerifyUser(user);
});
});
});
});
Expand All @@ -69,7 +69,7 @@ describe('Autocomplete with Elasticsearch - Renaming', () => {
const newChannelName = 'updatedchannel' + Date.now();

// # Create a new channel
cy.apiCreateChannel(team.id, channelName, channelName).then((channelResponse) => {
cy.apiCreateChannel(testTeam.id, channelName, channelName).then((channelResponse) => {
const channel = channelResponse.body;

// # Channel should appear in search results pre-change
Expand All @@ -87,54 +87,59 @@ describe('Autocomplete with Elasticsearch - Renaming', () => {
});

describe('renamed team', () => {
let user;
let channel;
let testUser;
let testChannel;

before(() => {
const punisher = {
username: withTimestamp('punisher', timestamp),
firstName: 'Frank',
lastName: 'Castle',
password: 'passwd',
first_name: 'Frank',
last_name: 'Castle',
email: createEmail('punisher', timestamp),
nickname: withTimestamp('lockednloaded', timestamp),
};

// # Setup new channel and user
cy.apiCreateNewUser(punisher, [team.id]).then((userResponse) => {
user = userResponse;
cy.apiCreateUser({user: punisher}).then(({user}) => {
testUser = user;

// # Hit escape to close and lingering modals
cy.get('body').type('{esc}');
cy.apiAddUserToTeam(testTeam.id, testUser.id).then(() => {
cy.visit(`/${testTeam.name}/channels/town-square`);

// # Verify user appears in search results pre-change
searchAndVerifyUser(user);
// # Hit escape to close and lingering modals
cy.get('body').type('{esc}');

// # Verify user appears in search results pre-change
searchAndVerifyUser(testUser);
});
});

const channelName = 'another-channel' + Date.now();

// # Create a new channel
cy.apiCreateChannel(team.id, channelName, channelName).then((channelResponse) => {
channel = channelResponse.body;
cy.apiCreateChannel(testTeam.id, channelName, channelName).then((channelResponse) => {
testChannel = channelResponse.body;

// # Channel should appear in search results pre-change
searchAndVerifyChannel(channel);
searchAndVerifyChannel(testChannel);

// # Hit escape to close the modal
cy.get('body').type('{esc}');
});

// # Rename the channel
cy.apiPatchTeam(team.id, {name: 'updatedteam' + timestamp});
// # Rename the team
cy.apiPatchTeam(testTeam.id, {name: 'updatedteam' + timestamp});
});

it('correctly searches for user', () => {
cy.get('body').type('{esc}');
searchAndVerifyUser(user);
searchAndVerifyUser(testUser);
});

it('correctly searches for channel', () => {
cy.get('body').type('{esc}');
searchAndVerifyChannel(channel);
searchAndVerifyChannel(testChannel);
});
});
});
Loading

0 comments on commit 9f25729

Please sign in to comment.