Skip to content

Commit

Permalink
MM-52487: fix more playbooks tests (mattermost#23475)
Browse files Browse the repository at this point in the history
* fix playbooks/channels/rhs/template_spec.js

* fix playbooks/channels/update_request_post_spec.js

* fix playbooks/runs/rdp_rhs_runinfo_spec.js

* fix playbooks/runs/rdp_rhs_statusupdates_spec.js

* remove enableexperimentalfeatures flag in e2e tests

* rdp_main_header_spec: simplify channel loaded assertion

* playbooks rhs participants: fix infinite fetch loop

* improved onboarding skipping

* simplify participants fetching
  • Loading branch information
lieut-data authored and sbishel committed Aug 15, 2023
1 parent f1d25d1 commit 2228f16
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 122 deletions.
Expand Up @@ -34,10 +34,6 @@ describe('channels > rhs > template', {testIsolation: true}, () => {
// # Switch to playbooks DM channel
cy.visit(`/${team1.name}/messages/@playbooks`);

// * Checking the bot badge as an indicator of page
// * stability / rendering finished
cy.findByText('BOT').should('be.visible');

// # Open playbooks RHS.
cy.getPlaybooksAppBarIcon().should('be.visible').click();

Expand All @@ -58,10 +54,6 @@ describe('channels > rhs > template', {testIsolation: true}, () => {
// # Switch to playbooks DM channel
cy.visit(`/${team1.name}/messages/@playbooks`);

// * Checking the bot badge as an indicator of page
// * stability / rendering finished
cy.findByText('BOT').should('be.visible');

// # Open playbooks RHS.
cy.getPlaybooksAppBarIcon().should('be.visible').click();

Expand Down
Expand Up @@ -19,6 +19,13 @@ describe('channels > update request post', {testIsolation: true}, () => {
let testPlaybookRun2;

before(() => {
cy.apiUpdateConfig({
ServiceSettings: {
ThreadAutoFollow: true,
CollapsedThreads: 'default_on',
},
});

cy.apiInitSetup().then(({team, user}) => {
testTeam = team;
testParticipant = user;
Expand Down
Expand Up @@ -40,34 +40,7 @@ describe('playbooks > feedback', {testIsolation: true}, () => {
});
});

it('playbooks shows prompt in global header, with experimental feature flag', () => {
// # Enable experimental feature flag
cy.apiAdminLogin().then(() => {
cy.apiEnsureFeatureFlag('enableexperimentalfeatures', true);

// # Login as testUser
cy.apiLogin(testUser);
});

// # Visit the playbooks product
cy.visit('/playbooks');

// # Verify Give Feedback link is configured to open in a new tab.
cy.findByText('Give feedback').invoke('attr', 'target').should('eq', '_blank');

// # Verify Give Feedback link href
cy.findByText('Give feedback').invoke('attr', 'href').should('match', /playbooks-feedback/);
});

it('playbooks shows prompt in global header, without experimental feature flag', () => {
// # Disable experimental feature flag
cy.apiAdminLogin().then(() => {
cy.apiEnsureFeatureFlag('enableexperimentalfeatures', false);

// # Login as testUser
cy.apiLogin(testUser);
});

it('playbooks shows prompt in global header', () => {
// # Visit the playbooks product
cy.visit('/playbooks');

Expand Down
Expand Up @@ -618,13 +618,8 @@ describe('runs > run details page > header', {testIsolation: true}, () => {
// # Navigate to the playbook run channel
cy.visit(`/${testTeam.name}/channels/${playbookRunChannelName}`);

// * Verify the user was added to the channel
cy.getFirstPostId().then((id) => {
cy.get(`#postMessageText_${id}`).within(() => {
cy.contains('You and');
cy.contains('joined the channel');
});
});
// # Verify channel loads
cy.get('#channelHeaderTitle').should('be.visible').should('contain', playbookRunName);

// * assert telemetry data
cy.expectTelemetryToContain([
Expand Down Expand Up @@ -681,13 +676,8 @@ describe('runs > run details page > header', {testIsolation: true}, () => {
// # Navigate to the playbook run channel
cy.visit(`/${testTeam.name}/channels/${playbookRunChannelName}`);

// * Verify that the user was added to the channel
cy.getFirstPostId().then((id) => {
cy.get(`#postMessageText_${id}`).within(() => {
cy.contains('You and');
cy.contains('joined the channel');
});
});
// # Verify channel loads
cy.get('#channelHeaderTitle').should('be.visible').should('contain', playbookRunName);
});
});
});
Expand Down Expand Up @@ -812,13 +802,8 @@ describe('runs > run details page > header', {testIsolation: true}, () => {
// # Navigate to the playbook run channel
cy.visit(`/${testTeam.name}/channels/${playbookRunChannelName}`);

// * Verify that the user was added to the channel
cy.getFirstPostId().then((id) => {
cy.get(`#postMessageText_${id}`).within(() => {
cy.contains('You and');
cy.contains('joined the channel');
});
});
// # Verify channel loads
cy.get('#channelHeaderTitle').should('be.visible').should('contain', playbookRunName);
});
});
});
Expand Down
Expand Up @@ -164,7 +164,7 @@ describe('runs > run details page > run info', {testIsolation: true}, () => {
from: 'run_details',
playbookrun_id: testRun.id,
},
], {waitForCalls: 3});
], {waitForCalls: 2});
});

it('click channel link navigates to run\'s channel', () => {
Expand Down
Expand Up @@ -100,13 +100,13 @@ describe('runs > run details page > status update', {testIsolation: true}, () =>
});

describe('as viewer', () => {
beforeEach(() => {
cy.apiLogin(testViewerUser).then(() => {
cy.visit(`/playbooks/runs/${testRun.id}`);
});
});

it('rhs can not be open when there is no updates', () => {
// * Log in as viewer user
cy.apiLogin(testViewerUser);

// * Browse to test run
cy.visit(`/playbooks/runs/${testRun.id}`);

// * Assert that the link is not present
cy.findByTestId('run-statusupdate-section').findByText('View all updates').should('not.exist');
});
Expand All @@ -125,22 +125,26 @@ describe('runs > run details page > status update', {testIsolation: true}, () =>
});
});

cy.apiLogin(testViewerUser).then(() => {
// # Click View all updates link
cy.findByTestId('run-statusupdate-section').findByText('View all updates').click();

// * Assert RHS is open and have the correct title/subtitle
getRHS().should('be.visible');
getRHS().findByTestId('rhs-title').contains('Status updates');
getRHS().findByTestId('rhs-subtitle').contains(testRun.name);

// * Assert that we have both updates in reverse order
getStatusUpdates().should('have.length', 2);
getStatusUpdates().eq(0).contains('message 2');
getStatusUpdates().eq(0).contains(testUser.username);
getStatusUpdates().eq(1).contains('message 1');
getStatusUpdates().eq(1).contains(testUser.username);
});
// * Log in as viewer user
cy.apiLogin(testViewerUser);

// * Browse to test run
cy.visit(`/playbooks/runs/${testRun.id}`);

// # Click View all updates link
cy.findByTestId('run-statusupdate-section').findByText('View all updates').click();

// * Assert RHS is open and have the correct title/subtitle
getRHS().should('be.visible');
getRHS().findByTestId('rhs-title').contains('Status updates');
getRHS().findByTestId('rhs-subtitle').contains(testRun.name);

// * Assert that we have both updates in reverse order
getStatusUpdates().should('have.length', 2);
getStatusUpdates().eq(0).contains('message 2');
getStatusUpdates().eq(0).contains(testUser.username);
getStatusUpdates().eq(1).contains('message 1');
getStatusUpdates().eq(1).contains(testUser.username);
});
});
});
Expand Up @@ -80,31 +80,7 @@ describe('Task Inbox >', {testIsolation: true}, () => {

const getRHS = () => cy.get('#playbooks-backstage-sidebar-right');

it('icon in global header, with experimental feature flag', () => {
// # Enable experimental feature flag
cy.apiAdminLogin().then(() => {
cy.apiEnsureFeatureFlag('enableexperimentalfeatures', true);

// # Login as testUser
cy.apiLogin(testUser);
});

// # Visit the playbooks product
cy.visit('/playbooks');

// # Verify icon present in global header icon to open
cy.findByTestId('header-task-inbox-icon').click();
});

it('icon in global header, without experimental feature flag', () => {
// # Disable experimental feature flag
cy.apiAdminLogin().then(() => {
cy.apiEnsureFeatureFlag('enableexperimentalfeatures', false);

// # Login as testUser
cy.apiLogin(testUser);
});

it('icon in global header', () => {
// # Visit the playbooks product
cy.visit('/playbooks');

Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/cypress/tests/support/api/user.js
Expand Up @@ -260,7 +260,7 @@ Cypress.Commands.add('apiCreateUser', ({
cy.apiSaveDraftsTourTipPreference(createdUser.id, true);

if (bypassTutorial) {
cy.apiSaveTutorialStep(createdUser.id, '999');
cy.apiDisableTutorials(createdUser.id);
}

if (hideActionsMenu) {
Expand Down
Expand Up @@ -6,10 +6,11 @@ import {useIntl} from 'react-intl';
import styled from 'styled-components';
import {AccountPlusOutlineIcon} from '@mattermost/compass-icons/components';
import {useDispatch, useSelector} from 'react-redux';
import {getProfilesByIds} from 'mattermost-redux/actions/users';
import {getMissingProfilesByIds} from 'mattermost-redux/actions/users';
import {UserProfile} from '@mattermost/types/users';
import {sortByUsername} from 'mattermost-redux/utils/user_utils';
import {getCurrentUser} from 'mattermost-redux/selectors/entities/users';
import {getUser} from 'mattermost-redux/selectors/entities/users';
import {GlobalState} from '@mattermost/types/store';

import Profile from 'src/components/profile/profile';
import Tooltip from 'src/components/widgets/tooltip';
Expand Down Expand Up @@ -44,8 +45,6 @@ export const Participants = ({playbookRun, role, teamName}: Props) => {
const {formatMessage} = useIntl();
const [manageMode, setManageMode] = useState(false);
const [searchTerm, setSearchTerm] = useState('');
const myUser = useSelector(getCurrentUser);
const [participantsProfiles, setParticipantsProfiles] = useState<UserProfile[]>([]);
const [showAddParticipantsModal, setShowAddParticipantsModal] = useState(false);

const {removeFromRun, changeRunOwner} = useManageRunMembership(playbookRun.id);
Expand All @@ -55,19 +54,14 @@ export const Participants = ({playbookRun, role, teamName}: Props) => {
return removeFromRun(userIDs);
};

const participantsProfiles = useSelector((state: GlobalState) => {
const profiles = playbookRun.participant_ids.map((id) => getUser(state, id));
return profiles.sort(sortByUsername);
});

useEffect(() => {
const profiles = dispatch(getProfilesByIds(playbookRun.participant_ids));

//@ts-ignore
profiles.then(({data}: { data: UserProfile[] }) => {
// getProfilesByIds doesn't return current user profile, so add it when a user is participant
if (role === Role.Participant) {
data.push(myUser);
}
data.sort(sortByUsername);
setParticipantsProfiles(data || []);
});
}, [dispatch, myUser, playbookRun.participant_ids, role]);
dispatch(getMissingProfilesByIds(playbookRun.participant_ids));
}, [dispatch, playbookRun.participant_ids]);

const includesTerm = (user: UserProfile) => {
const userInfo = user.first_name + ';' + user.last_name + ';' + user.nickname + ';' + user.username;
Expand Down

0 comments on commit 2228f16

Please sign in to comment.