Skip to content

Commit

Permalink
MM-20904 Add E2E tests for custom categories (mattermost#5981)
Browse files Browse the repository at this point in the history
* MM-20904 Add E2E tests for custom categories

 * Tests for create, delete and rename categories

* MM-20904 fix types

* Update e2e/cypress/integration/channel_sidebar/custom_categories_spec.js

Co-authored-by: Guillermo Vayá <[email protected]>

* Update e2e/cypress/integration/channel_sidebar/custom_categories_spec.js

Co-authored-by: Harrison Healey <[email protected]>

* Update e2e/cypress/integration/channel_sidebar/custom_categories_spec.js

Co-authored-by: Guillermo Vayá <[email protected]>

* Update PR

* Update e2e/cypress/integration/channel_sidebar/custom_categories_spec.js

Co-authored-by: Jelena Gilliam <[email protected]>

* Update e2e/cypress/integration/channel_sidebar/custom_categories_spec.js

Co-authored-by: Jelena Gilliam <[email protected]>

* Update e2e/cypress/integration/channel_sidebar/custom_categories_spec.js

Co-authored-by: Jelena Gilliam <[email protected]>

* Update e2e/cypress/integration/channel_sidebar/custom_categories_spec.js

Co-authored-by: Jelena Gilliam <[email protected]>

* Update e2e/cypress/integration/channel_sidebar/custom_categories_spec.js

Co-authored-by: Jelena Gilliam <[email protected]>

* update snapshots

Co-authored-by: Guillermo Vayá <[email protected]>
Co-authored-by: Harrison Healey <[email protected]>
Co-authored-by: Jelena Gilliam <[email protected]>
  • Loading branch information
4 people committed Sep 25, 2020
1 parent d5dc814 commit cb13baa
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 0 deletions.
3 changes: 3 additions & 0 deletions components/__snapshots__/generic_modal.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ exports[`components/GenericModal should match snapshot for base case 1`] = `
dialogClassName="a11y__modal GenericModal"
dialogComponentClass={[Function]}
enforceFocus={true}
id="genericModal"
keyboard={true}
manager={
ModalManager {
Expand Down Expand Up @@ -71,6 +72,7 @@ exports[`components/GenericModal should match snapshot with both buttons 1`] = `
dialogClassName="a11y__modal GenericModal"
dialogComponentClass={[Function]}
enforceFocus={true}
id="genericModal"
keyboard={true}
manager={
ModalManager {
Expand Down Expand Up @@ -153,6 +155,7 @@ exports[`components/GenericModal should match snapshot with disabled confirm but
dialogClassName="a11y__modal GenericModal"
dialogComponentClass={[Function]}
enforceFocus={true}
id="genericModal"
keyboard={true}
manager={
ModalManager {
Expand Down
1 change: 1 addition & 0 deletions components/edit_category_modal/edit_category_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default class EditCategoryModal extends React.PureComponent<Props, State>
handleCancel={this.handleCancel}
confirmButtonText={editButtonText}
isConfirmDisabled={this.isConfirmDisabled()}
id='editCategoryModal'
>
<QuickInput
autoFocus={true}
Expand Down
3 changes: 3 additions & 0 deletions components/generic_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Props = {
confirmButtonClassName?: string;
cancelButtonText?: React.ReactNode;
isConfirmDisabled?: boolean;
id: string;
autoCloseOnCancelButton?: boolean;
autoCloseOnConfirmButton?: boolean;
};
Expand All @@ -30,6 +31,7 @@ type State = {
export default class GenericModal extends React.PureComponent<Props, State> {
static defaultProps: Partial<Props> = {
show: true,
id: 'genericModal',
autoCloseOnCancelButton: true,
autoCloseOnConfirmButton: true,
};
Expand Down Expand Up @@ -126,6 +128,7 @@ export default class GenericModal extends React.PureComponent<Props, State> {
restoreFocus={true}
role='dialog'
aria-labelledby='genericModalLabel'
id={this.props.id}
>
<Modal.Header
closeButton={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports[`ProductNoticesModal Match snapshot for single notice 1`] = `
</span>
}
handleConfirm={[Function]}
id="genericModal"
modalHeaderText={
<span>
title
Expand Down Expand Up @@ -60,6 +61,7 @@ exports[`ProductNoticesModal Match snapshot for user notice 1`] = `
}
handleCancel={[Function]}
handleConfirm={[Function]}
id="genericModal"
modalHeaderText={
<span>
title
Expand Down Expand Up @@ -128,6 +130,7 @@ exports[`ProductNoticesModal Should match snapshot for system admin notice 1`] =
</React.Fragment>
}
handleConfirm={[Function]}
id="genericModal"
modalHeaderText={
<span>
for sysadmin
Expand Down
141 changes: 141 additions & 0 deletions e2e/cypress/integration/channel_sidebar/custom_categories_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// 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: @channel_sidebar

import {getRandomId} from '../../utils';

describe('Channel sidebar', () => {
before(() => {
// # Enable channel sidebar organization
cy.apiUpdateConfig({
ServiceSettings: {
ExperimentalChannelSidebarOrganization: 'default_on',
},
});

// # Login as test user and visit town-square
cy.apiInitSetup({loginAfter: true}).then(({team}) => {
cy.visit(`/${team.name}/channels/town-square`);
});

// # Close "What's new" modal
cy.uiCloseWhatsNewModal();
});

it('MM-T3161_1 should create a new category from sidebar menu', () => {
const categoryName = createCategoryFromSidebarMenu();

// * check if the category exists
cy.get(`button[aria-label='${categoryName}']`).should('contain', categoryName);
});

it('MM-T3161_2 should create a new category from category menu', () => {
const categoryName = createCategoryFromSidebarMenu();

// # create a category from category menu
cy.get(`button[aria-label='${categoryName}']`).parents('.SidebarChannelGroup').within(() => {
cy.get('.SidebarMenu').invoke('show').get('.SidebarMenu_menuButton').click();
cy.get('.icon-folder-plus-outline').parents('button').click();
});

const newCategoryName = `category-${getRandomId()}`;
cy.get('#editCategoryModal input').type(newCategoryName).type('{enter}');

// * check if the newly created category exists
cy.get(`button[aria-label='${newCategoryName}']`).should('contain', newCategoryName);
});

it('MM-T3161_3 move an existing channel to a new category', () => {
const newCategoryName = `category-${getRandomId()}`;

// # move to a new category
cy.get('#sidebarItem_off-topic').parent().then((element) => {
// # get id of the channel
const id = element[0].getAttribute('data-rbd-draggable-id');
cy.get('#sidebarItem_off-topic').parent('li').within(() => {
// # open dropown next to channel name
cy.get('.SidebarMenu').invoke('show').get('.SidebarMenu_menuButton').click();

// # open sub menu
cy.get(`#moveTo-${id}`).parent('.SubMenuItem').trigger('mouseover');

// # click on move to new category
cy.get(`#moveToNewCategory-${id}`).parent('.SubMenuItem').click();
});
});
cy.get('#editCategoryModal input').type(newCategoryName).type('{enter}');

// * check if the newly created category exists
cy.get(`button[aria-label='${newCategoryName}']`).should('contain', newCategoryName);
});

it('MM-T3163 Rename a category', () => {
const categoryName = createCategoryFromSidebarMenu();
cy.get(`button[aria-label='${categoryName}']`).should('contain', categoryName);
cy.get(`button[aria-label='${categoryName}']`).parents('.SidebarChannelGroup').then((element) => {
// # get id of the category
const id = element[0].getAttribute('data-rbd-draggable-id');
cy.get(`button[aria-label='${categoryName}']`).parents('.SidebarChannelGroup').within(() => {
cy.get('.SidebarMenu').invoke('show').get('.SidebarMenu_menuButton').click();

// # click on rename menu item
cy.get(`#rename-${id}`).click();
});

const renameCategory = `category-${getRandomId()}`;

// # rename category
cy.get('#editCategoryModal input').clear().type(renameCategory).type('{enter}');

// * check if the previous category exist
cy.get(`button[aria-label='${categoryName}']`).should('not.exist');

// * check if the renamed category exists
cy.get(`button[aria-label='${renameCategory}']`).should('contain', renameCategory);
});
});

it('MM-T3165 Delete a category', () => {
const categoryName = createCategoryFromSidebarMenu();
cy.get(`button[aria-label='${categoryName}']`).should('contain', categoryName);
cy.get(`button[aria-label='${categoryName}']`).parents('.SidebarChannelGroup').then((element) => {
// # get id of the category
const id = element[0].getAttribute('data-rbd-draggable-id');
cy.get(`button[aria-label='${categoryName}']`).parents('.SidebarChannelGroup').within(() => {
cy.get('.SidebarMenu').invoke('show').get('.SidebarMenu_menuButton').click();

// # click on delete menu item
cy.get(`#delete-${id}`).click();
});

// # click on delete button
cy.get('.GenericModal__button.delete').click();

// * check if the deleted category exists
cy.get(`button[aria-label='${categoryName}']`).should('not.exist');
});
});
});

function createCategoryFromSidebarMenu() {
// # Start with a new category
const categoryName = `category-${getRandomId()}`;

// # Click on the siebar menu dropdown
cy.get('.AddChannelDropdown_dropdownButton').click();

// # Click on create category link
cy.get('#createCategory').click();

// # Enter category name and hit enter
cy.get('#editCategoryModal input').type(categoryName).type('{enter}');
return categoryName;
}

0 comments on commit cb13baa

Please sign in to comment.