Skip to content

Commit

Permalink
Quick fix on flaky E2E specs (mattermost#2699)
Browse files Browse the repository at this point in the history
* fix flaky e2e specs

* updated test
  • Loading branch information
saturninoabril committed Apr 26, 2019
1 parent 0afcde5 commit 155e1d5
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports[`components/team_members_dropdown should match snapshot for team_members
<button
aria-expanded="true"
className="dropdown-toggle theme color--link style--none"
id="teamMembersDropdown_username2"
type="button"
>
<span>
Expand Down Expand Up @@ -55,6 +56,7 @@ exports[`components/team_members_dropdown should match snapshot opening dropdown
<button
aria-expanded="true"
className="dropdown-toggle theme color--link style--none"
id="teamMembersDropdown_username2"
type="button"
>
<span>
Expand Down Expand Up @@ -102,6 +104,7 @@ exports[`components/team_members_dropdown should match snapshot with group-const
<button
aria-expanded="true"
className="dropdown-toggle theme color--link style--none"
id="teamMembersDropdown_username2"
type="button"
>
<span>
Expand Down
5 changes: 3 additions & 2 deletions components/team_members_dropdown/team_members_dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ export default class TeamMembersDropdown extends React.Component {
showMakeAdmin = false;
}

const canRemoveFromTeam = this.props.user.id !== me.id && !currentTeam.group_constrained;
const canRemoveFromTeam = user.id !== me.id && !currentTeam.group_constrained;

let makeDemoteModal = null;
if (this.props.user.id === me.id) {
if (user.id === me.id) {
const title = (
<FormattedMessage
id='team_members_dropdown.confirmDemoteRoleTitle'
Expand Down Expand Up @@ -231,6 +231,7 @@ export default class TeamMembersDropdown extends React.Component {
return (
<MenuWrapper>
<button
id={`teamMembersDropdown_${user.username}`}
className='dropdown-toggle theme color--link style--none'
type='button'
aria-expanded='true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import TeamMembersDropdown from 'components/team_members_dropdown/team_members_d
describe('components/team_members_dropdown', () => {
const user = {
id: 'user-1',
username: 'username1',
roles: 'team_admin',
};

const user2 = {
id: 'user-2',
username: 'username2',
roles: 'team_admin',
};

Expand Down
2 changes: 2 additions & 0 deletions cypress/integration/channel/header_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ describe('Header', () => {

// * Check that no elippsis is present
cy.get('#header-popover > div.popover-content').should('have.html', `<blockquote>\n<p>${header}</p>\n</blockquote>`);

cy.apiSaveMessageDisplayPreference();
});
});
31 changes: 26 additions & 5 deletions cypress/integration/channel/message_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@

/*eslint max-nested-callbacks: ["error", 3]*/

function shouldHavePostProfileImageVisible(isVisible = true) {
cy.getLastPostIdWithRetry().then((postID) => {
const target = `#post_${postID}`;
if (isVisible) {
cy.get(target).invoke('attr', 'class').
should('contain', 'current--user').
and('contain', 'other--root');

cy.get(`${target} > #postContent > .post__img`).should('be.visible');
} else {
cy.get(target).invoke('attr', 'class').
should('contain', 'current--user').
and('contain', 'same--user').
and('contain', 'same--root');

cy.get(`${target} > #postContent > .post__img`).
should('be.visible').
and('be.empty');
}
});
}

describe('Message', () => {
it('M13701 Consecutive message does not repeat profile info', () => {
// 1. Login as sysadmin and go to /
Expand All @@ -26,19 +48,19 @@ describe('Message', () => {
cy.postMessage('One');

// * Check profile image is visible
cy.get('#postListContent > .post.current--user > .post__content > .post__img').last().should('be.visible').find('span > img').should('be.visible');
shouldHavePostProfileImageVisible(true);

// 5. Post message "Two"
cy.postMessage('Two');

// * Check profile image is not visible
cy.get('#postListContent > .post.current--user > .post__content > .post__img').last().should('be.visible').should('be.empty');
shouldHavePostProfileImageVisible(false);

// 6. Post message "Three"
cy.postMessage('Three');

// * Check profile image is not visible
cy.get('#postListContent > .post.current--user > .post__content > .post__img').last().should('be.visible').should('be.empty');
shouldHavePostProfileImageVisible(false);
});

it('M14012 Focus move to main input box when a character key is selected', () => {
Expand All @@ -59,8 +81,7 @@ describe('Message', () => {
cy.get('#post_textbox').type('A');

// 5. Open the "..." menu on a post in the main to move the focus out of the main input box
cy.get(divPostId).trigger('mouseover');
cy.get(`#CENTER_dropdown_${postId} .dropdown-toggle`).click({force: true});
cy.clickPostDotMenu(postId);

// 6. Push a character key such as "A"
cy.get('#post_textbox').type('A');
Expand Down
6 changes: 3 additions & 3 deletions cypress/integration/system_console/demoted_user_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const sysadmin = users.sysadmin;
describe('System Console', () => {
it('SC14734 Demoted user cannot continue to view System Console', () => {
// 1. Login and navigate to the app as user
cy.login(user.username);
cy.apiLogin(user.username);

// 2. Get MMUSERID cookie to use userId later
cy.getCookie('MMUSERID').as('userId');
Expand All @@ -31,9 +31,9 @@ describe('System Console', () => {
});

// 4. Visit a page on the system console
cy.visit('/admin_console/general/configuration');
cy.visit('/admin_console/about/license');
cy.get('#adminConsoleWrapper').should('be.visible');
cy.url().should('include', '/admin_console/general');
cy.url().should('include', '/admin_console/about/license');

// 5. Change the role of the user back to user
cy.get('@userId').then((userId) => {
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/team/teams_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('Teams Suite', () => {
cy.getLastPost().should('contain', 'System').and('contain', `${user.username} added to the channel by you.`);

// 7. Logout
cy.logout();
cy.apiLogout();

// 8. Login as user added to Team
cy.apiLogin(user.username);
Expand All @@ -107,7 +107,7 @@ describe('Teams Suite', () => {
cy.getLastPost().should('contain', 'System').and('contain', 'You were added to the channel by @sysadmin.');

// 9. Remove user from team
cy.removeTeamMember(teamURL, user.firstName);
cy.removeTeamMember(teamURL, user.username);
});

it('TS14633 Leave all teams', () => {
Expand Down
5 changes: 3 additions & 2 deletions cypress/support/ui_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,14 @@ Cypress.Commands.add('createNewTeam', (teamName, teamURL) => {
});

Cypress.Commands.add('removeTeamMember', (teamURL, username) => {
cy.logout();
cy.apiLogout();
cy.apiLogin('sysadmin');
cy.visit(`/${teamURL}`);
cy.get('#sidebarHeaderDropdownButton').click();
cy.get('#manageMembers').click();
cy.focused().type(username, {force: true});
cy.get('#removeFromTeam').click({force: true});
cy.get(`#teamMembersDropdown_${username}`).click();
cy.get('#removeFromTeam').click();
cy.get('.modal-header .close').click();
});

Expand Down

0 comments on commit 155e1d5

Please sign in to comment.