remove cypress tests of playbooks (#31128)

Этот коммит содержится в:
sabril
2025-05-21 16:37:01 +08:00
коммит произвёл GitHub
родитель 56c6d8a9ab
Коммит 1cb244e876
65 изменённых файлов: 0 добавлений и 18157 удалений

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

@@ -11,7 +11,6 @@ import './data_retention';
import './group';
import './keycloak';
import './ldap';
import './playbooks';
import './preference';
import './plugin';
import './role';

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

@@ -1,483 +0,0 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
const playbookRunsEndpoint = '/plugins/playbooks/api/v0/runs';
const StatusOK = 200;
const StatusCreated = 201;
/**
* Get all playbook runs directly via API
*/
Cypress.Commands.add('apiGetAllPlaybookRuns', (teamId) => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: '/plugins/playbooks/api/v0/runs',
qs: {team_id: teamId, per_page: 10000},
method: 'GET',
}).then((response) => {
expect(response.status).to.equal(StatusOK);
cy.wrap(response);
});
});
/**
* Get all InProgress playbook runs directly via API
*/
Cypress.Commands.add('apiGetAllInProgressPlaybookRuns', (teamId, userId = '') => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: '/plugins/playbooks/api/v0/runs',
qs: {team_id: teamId, status: 'InProgress', participant_id: userId},
method: 'GET',
}).then((response) => {
expect(response.status).to.equal(StatusOK);
cy.wrap(response);
});
});
/**
* Get playbook run by name directly via API
*/
Cypress.Commands.add('apiGetPlaybookRunByName', (teamId, name) => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: '/plugins/playbooks/api/v0/runs',
qs: {team_id: teamId, search_term: name},
method: 'GET',
}).then((response) => {
expect(response.status).to.equal(StatusOK);
cy.wrap(response);
});
});
/**
* Get a playbook run directly via API
* @param {String} playbookRunId
* All parameters required
*/
Cypress.Commands.add('apiGetPlaybookRun', (playbookRunId) => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: `${playbookRunsEndpoint}/${playbookRunId}`,
method: 'GET',
}).then((response) => {
expect(response.status).to.equal(StatusOK);
cy.wrap(response);
});
});
/**
* Start a playbook run directly via API.
*/
Cypress.Commands.add('apiRunPlaybook', (
{
teamId,
playbookId,
playbookRunName,
ownerUserId,
channelId,
description,
}, options) => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: playbookRunsEndpoint,
method: 'POST',
body: {
name: playbookRunName,
owner_user_id: ownerUserId,
team_id: teamId,
playbook_id: playbookId,
channel_id: channelId,
description,
},
failOnStatusCode: !(options?.expectedStatusCode),
}).then((response) => {
const statusCode = options?.expectedStatusCode || StatusCreated;
expect(response.status).to.equal(statusCode);
cy.wrap(response.body);
});
});
// Finish a playbook's run programmaticially. Uses currently logged in user, so that user must
// have edit permissions on the run
Cypress.Commands.add('apiFinishRun', (playbookRunId) => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: `${playbookRunsEndpoint}/${playbookRunId}/finish`,
method: 'PUT',
}).then((response) => {
expect(response.status).to.equal(StatusOK);
cy.wrap(response.body);
});
});
// Update a playbook run's status programmatically.
Cypress.Commands.add('apiUpdateStatus', (
{
playbookRunId,
message,
reminder = 300,
}) => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: `${playbookRunsEndpoint}/${playbookRunId}/status`,
method: 'POST',
body: {
message,
reminder,
},
}).then((response) => {
expect(response.status).to.equal(StatusOK);
cy.wrap(response.body);
});
});
/**
* Change the owner of a playbook run directly via API
* @param {String} playbookRunId
* @param {String} userId
* All parameters required
*/
Cypress.Commands.add('apiChangePlaybookRunOwner', (playbookRunId, userId) => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: playbookRunsEndpoint + '/' + playbookRunId + '/owner',
method: 'POST',
body: {
owner_id: userId,
},
}).then((response) => {
expect(response.status).to.equal(StatusOK);
cy.wrap(response);
});
});
/**
* Change the assignee of a checklist item directly via API
* @param {String} playbookRunId
* @param {String} checklistId
* @param {String} itemId
* @param {String} userId
* All parameters required
*/
Cypress.Commands.add('apiChangeChecklistItemAssignee', (playbookRunId, checklistId, itemId, userId) => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: playbookRunsEndpoint + `/${playbookRunId}/checklists/${checklistId}/item/${itemId}/assignee`,
method: 'PUT',
body: {
assignee_id: userId,
},
}).then((response) => {
expect(response.status).to.equal(StatusOK);
cy.wrap(response);
});
});
/**
* Check a checklist item directly via API
* @param {String} playbookRunId
* @param {String} checklistId
* @param {String} itemId
* @param {String} state ('' or 'closed')
*/
Cypress.Commands.add('apiSetChecklistItemState', (playbookRunId, checklistId, itemId, state) => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: playbookRunsEndpoint + `/${playbookRunId}/checklists/${checklistId}/item/${itemId}/state`,
method: 'PUT',
body: {
new_state: state,
},
}).then((response) => {
expect(response.status).to.equal(StatusOK);
cy.wrap(response);
});
});
// Verify playbook run is created
Cypress.Commands.add('verifyPlaybookRunActive', (teamId, playbookRunName, playbookRunDescription) => {
cy.apiGetPlaybookRunByName(teamId, playbookRunName).then((response) => {
const returnedPlaybookRuns = response.body;
const playbookRun = returnedPlaybookRuns.items.find((inc) => inc.name === playbookRunName);
assert.isDefined(playbookRun);
assert.equal(playbookRun.end_at, 0);
assert.equal(playbookRun.name, playbookRunName);
cy.log('test 1');
// Only check the description if provided. The server may supply a default depending
// on how the playbook run was started.
if (playbookRunDescription) {
assert.equal(playbookRun.description, playbookRunDescription);
}
});
});
// Verify playbook run exists but is not active
Cypress.Commands.add('verifyPlaybookRunEnded', (teamId, playbookRunName) => {
cy.apiGetPlaybookRunByName(teamId, playbookRunName).then((response) => {
const returnedPlaybookRuns = response.body;
const playbookRun = returnedPlaybookRuns.items.find((inc) => inc.name === playbookRunName);
assert.isDefined(playbookRun);
assert.notEqual(playbookRun.end_at, 0);
});
});
// Create a playbook programmatically.
Cypress.Commands.add('apiCreatePlaybook', (
{
teamId,
title,
description,
createPublicPlaybookRun,
createChannelMemberOnNewParticipant = true,
checklists,
memberIDs,
makePublic = true,
broadcastEnabled,
broadcastChannelIds,
reminderMessageTemplate,
reminderTimerDefaultSeconds = 24 * 60 * 60, // 24 hours
statusUpdateEnabled = true,
retrospectiveReminderIntervalSeconds,
retrospectiveTemplate,
retrospectiveEnabled = true,
invitedUserIds,
inviteUsersEnabled,
defaultOwnerId,
defaultOwnerEnabled,
announcementChannelId,
announcementChannelEnabled,
webhookOnCreationURLs,
webhookOnCreationEnabled,
webhookOnStatusUpdateURLs,
webhookOnStatusUpdateEnabled,
messageOnJoin,
messageOnJoinEnabled,
signalAnyKeywords,
signalAnyKeywordsEnabled,
channelNameTemplate,
runSummaryTemplate,
runSummaryTemplateEnabled,
channelMode = 'create_new_channel',
channelId = '',
metrics,
}) => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: '/plugins/playbooks/api/v0/playbooks',
method: 'POST',
body: {
title,
description,
team_id: teamId,
create_public_playbook_run: createPublicPlaybookRun,
create_channel_member_on_new_participant: createChannelMemberOnNewParticipant,
checklists,
public: makePublic,
members: memberIDs?.map((val) => ({user_id: val, roles: ['playbook_member', 'playbook_admin']})),
broadcast_enabled: broadcastEnabled,
broadcast_channel_ids: broadcastChannelIds,
reminder_message_template: reminderMessageTemplate,
reminder_timer_default_seconds: reminderTimerDefaultSeconds,
status_update_enabled: statusUpdateEnabled,
retrospective_reminder_interval_seconds: retrospectiveReminderIntervalSeconds,
retrospective_template: retrospectiveTemplate,
retrospective_enabled: retrospectiveEnabled,
invited_user_ids: invitedUserIds,
invite_users_enabled: inviteUsersEnabled,
default_owner_id: defaultOwnerId,
default_owner_enabled: defaultOwnerEnabled,
announcement_channel_id: announcementChannelId,
announcement_channel_enabled: announcementChannelEnabled,
webhook_on_creation_urls: webhookOnCreationURLs,
webhook_on_creation_enabled: webhookOnCreationEnabled,
webhook_on_status_update_urls: webhookOnStatusUpdateURLs,
webhook_on_status_update_enabled: webhookOnStatusUpdateEnabled,
message_on_join: messageOnJoin,
message_on_join_enabled: messageOnJoinEnabled,
signal_any_keywords: signalAnyKeywords,
signal_any_keywords_enabled: signalAnyKeywordsEnabled,
channel_name_template: channelNameTemplate,
run_summary_template: runSummaryTemplate,
run_summary_template_enabled: runSummaryTemplateEnabled,
channel_mode: channelMode,
channel_id: channelId,
metrics,
},
}).then((response) => {
expect(response.status).to.equal(201);
cy.wrap(response.headers.location);
}).then((location) => {
cy.request({
url: location,
method: 'GET',
}).then((response) => {
cy.wrap(response.body);
});
});
});
// Create a test playbook programmatically.
Cypress.Commands.add('apiCreateTestPlaybook', (
{
teamId,
title,
userId,
broadcastEnabled,
broadcastChannelIds,
reminderMessageTemplate,
checklists,
inviteUsersEnabled,
reminderTimerDefaultSeconds = 24 * 60 * 60, // 24 hours
otherMembers = [],
invitedUserIds = [],
channelNameTemplate = '',
}) => (
cy.apiCreatePlaybook({
teamId,
title,
checklists: checklists || [{
title: 'Stage 1',
items: [
{title: 'Step 1'},
{title: 'Step 2'},
],
}],
memberIDs: [
userId,
...otherMembers,
],
broadcastEnabled,
broadcastChannelIds,
reminderMessageTemplate,
reminderTimerDefaultSeconds,
invitedUserIds,
inviteUsersEnabled,
channelNameTemplate,
createChannelMemberOnNewParticipant: true,
removeChannelMemberOnRemovedParticipant: true,
})
));
// Verify that the playbook was created
Cypress.Commands.add('verifyPlaybookCreated', (teamId, playbookTitle) => (
cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: '/plugins/playbooks/api/v0/playbooks',
qs: {team_id: teamId, sort: 'title', direction: 'asc'},
method: 'GET',
}).then((response) => {
expect(response.status).to.equal(StatusOK);
const playbookResults = response.body;
const playbook = playbookResults.items.find((p) => p.title === playbookTitle);
assert.isDefined(playbook);
})
));
// Get a playbook
Cypress.Commands.add('apiGetPlaybook', (playbookId) => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: `/plugins/playbooks/api/v0/playbooks/${playbookId}`,
method: 'GET',
}).then((response) => {
expect(response.status).to.equal(StatusOK);
cy.wrap(response.body);
});
});
// Update a playbook
Cypress.Commands.add('apiUpdatePlaybook', (playbook, expectedHttpCode = StatusOK) => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: `/plugins/playbooks/api/v0/playbooks/${playbook.id}`,
method: 'PUT',
body: JSON.stringify(playbook),
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.equal(expectedHttpCode);
cy.wrap(response.body);
});
});
// Archive a playbook
Cypress.Commands.add('apiArchivePlaybook', (playbookId) => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: `/plugins/playbooks/api/v0/playbooks/${playbookId}`,
method: 'DELETE',
}).then((response) => {
expect(response.status).to.equal(204);
});
});
// Follow a playbook run
Cypress.Commands.add('apiFollowPlaybookRun', (playbookRunId) => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: `/plugins/playbooks/api/v0/runs/${playbookRunId}/followers`,
method: 'PUT',
}).then((response) => {
expect(response.status).to.equal(StatusOK);
cy.wrap(response.body);
});
});
// Unfollow a playbook run
Cypress.Commands.add('apiUnfollowPlaybookRun', (playbookRunId) => {
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: `/plugins/playbooks/api/v0/runs/${playbookRunId}/followers`,
method: 'DELETE',
}).then((response) => {
expect(response.status).to.equal(StatusOK);
cy.wrap(response.body);
});
});
//addUsersToRun
Cypress.Commands.add('apiAddUsersToRun', (playbookRunId, usersIds) => {
const query = `
mutation AddRunParticipants($runID: String!, $userIDs: [String!]!) {
addRunParticipants(runID: $runID, userIDs: $userIDs)
}
`;
const vars = {
runID: playbookRunId,
userIDs: usersIds,
};
return doGraphqlQuery(query, 'AddRunParticipants', vars).then((response) => {
expect(response.status).to.equal(StatusOK);
cy.wrap(response.body);
});
});
//updateRun
Cypress.Commands.add('apiUpdateRun', (playbookRunId, updates) => {
const query = `
mutation UpdateRun($id: String!, $updates: RunUpdates!) {
updateRun(id: $id, updates: $updates)
}
`;
const vars = {
id: playbookRunId,
updates,
};
return doGraphqlQuery(query, 'UpdateRun', vars).then((response) => {
expect(response.status).to.equal(StatusOK);
cy.wrap(response.body);
});
});
const doGraphqlQuery = (query, operationName, variables) => {
const payload = {query, operationName, variables};
return cy.request({
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: '/plugins/playbooks/api/v0/query',
body: JSON.stringify(payload),
method: 'POST',
});
};

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

@@ -19,7 +19,6 @@ import './login';
import './menu';
import './mfa';
import './modal';
import './playbooks';
import './post';
import './post_dropdown_menu';
import './search';

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

@@ -1,324 +0,0 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import * as TIMEOUTS from '../../fixtures/timeouts';
const playbookRunStartCommand = '/playbook run ';
Cypress.Commands.add('startPlaybookRun', (playbookName, playbookRunName) => {
cy.get('#interactiveDialogModal').should('exist').within(() => {
// # Select playbook
cy.selectPlaybookFromDropdown(playbookName);
// # Type playbook run name
cy.findByTestId('playbookRunNameinput').type(playbookRunName, {force: true});
// # Submit
cy.get('#interactiveDialogSubmit').click();
});
cy.get('#interactiveDialogModal').should('not.exist');
});
// Opens playbook run dialog using the `/playbook run` slash command
Cypress.Commands.add('openPlaybookRunDialogFromSlashCommand', () => {
cy.uiPostMessageQuickly(playbookRunStartCommand);
});
// Starts playbook run with the `/playbook run` slash command
Cypress.Commands.add('startPlaybookRunWithSlashCommand', (playbookName, playbookRunName) => {
cy.openPlaybookRunDialogFromSlashCommand();
cy.startPlaybookRun(playbookName, playbookRunName);
});
// Selects Playbooks icon in the App Bar
Cypress.Commands.add('getPlaybooksAppBarIcon', () => {
cy.get('#channel_view').should('be.visible');
return cy.get('.app-bar').find('#app-bar-icon-playbooks .app-bar__icon-inner');
});
// Starts playbook run from the playbook run RHS
Cypress.Commands.add('startPlaybookRunFromRHS', (playbookName, playbookRunName) => {
cy.get('#channel-header').within(() => {
// open flagged posts to ensure playbook run RHS is closed
cy.get('#channelHeaderFlagButton').click();
// open the playbook run RHS
cy.getPlaybooksAppBarIcon().should('exist').click();
});
cy.get('#rhsContainer').should('exist').within(() => {
cy.findByText('Run playbook').click();
});
cy.startPlaybookRun(playbookName, playbookRunName);
});
// Create a new task from the RHS
Cypress.Commands.add('addNewTaskFromRHS', (taskname) => {
// Click add new task
cy.findByTestId('add-new-task-0').click();
// Type a name
cy.findByTestId('checklist-item-textarea-title').type(taskname);
// Save task
cy.findByTestId('checklist-item-save-button').click();
});
// Starts playbook run from the post menu
Cypress.Commands.add('startPlaybookRunFromPostMenu', (playbookName, playbookRunName) => {
// post a message as user to avoid system message
cy.findByTestId('post_textbox').clear().type('new message here{enter}');
// post a second message because cypress has trouble finding latest post when there's only one message
cy.findByTestId('post_textbox').clear().type('another new message here{enter}');
cy.clickPostActionsMenu();
cy.findByTestId('playbookRunPostMenuIcon').click();
cy.startPlaybookRun(playbookName, playbookRunName);
});
// Create playbook
Cypress.Commands.add('createPlaybook', (teamName, playbookName) => {
cy.visit('/playbooks/playbooks/new');
cy.findByTestId('save_playbook', {timeout: TIMEOUTS.HALF_MIN}).should('exist');
// # Type playbook name
cy.get('#playbook-name .editable-trigger').click();
cy.get('#playbook-name .editable-input').type(playbookName);
cy.get('#playbook-name .editable-input').type('{enter}');
// # Save playbook
cy.findByTestId('save_playbook', {timeout: TIMEOUTS.HALF_MIN}).should('not.be.disabled').click();
cy.wait(TIMEOUTS.TWO_SEC);
cy.findByTestId('save_playbook', {timeout: TIMEOUTS.HALF_MIN}).should('not.be.disabled').click();
});
// Select the playbook from the dropdown menu
Cypress.Commands.add('selectPlaybookFromDropdown', (playbookName) => {
cy.findByTestId('autoCompleteSelector').should('exist').within(() => {
cy.get('input').click().type(playbookName.toLowerCase(), {force: true});
cy.get('#suggestionList').contains(playbookName).click({force: true});
});
});
Cypress.Commands.add('createPost', (message) => {
// post a message as user to avoid system message
cy.findByTestId('post_textbox').clear().type(`${message}{enter}`);
});
Cypress.Commands.add('addPostToTimelineUsingPostMenu', (playbookRunName, summary, postId) => {
cy.clickPostDotMenu(postId);
cy.findByTestId('playbookRunAddToTimeline').click();
cy.get('#interactiveDialogModal').should('exist').within(() => {
// # Select playbook run
cy.findByTestId('autoCompleteSelector').should('exist').within(() => {
cy.get('input').click().type(playbookRunName);
cy.get('#suggestionList').contains(playbookRunName).click({force: true});
});
// # Type playbook run name
cy.findByTestId('summaryinput').clear().type(summary, {force: true});
// # Submit
cy.get('#interactiveDialogSubmit').click();
});
cy.get('#interactiveDialogModal').should('not.exist');
});
Cypress.Commands.add('openSelector', () => {
cy.findByText('Search for people').click({force: true});
});
Cypress.Commands.add('addInvitedUser', (userName) => {
cy.get('.invite-users-selector__menu').within(() => {
cy.findByText(userName).click({force: true});
});
});
Cypress.Commands.add('selectOwner', (userName) => {
cy.get('.assign-owner-selector__menu').within(() => {
cy.findByText(userName).click({force: true});
});
});
Cypress.Commands.add('selectChannel', (channelName) => {
cy.get('#playbook-automation-broadcast .playbooks-rselect__menu').within(() => {
cy.findByText(channelName).click({force: true});
});
});
Cypress.Commands.add('openReminderSelector', () => {
cy.get('#reminder_timer_datetime input').click({force: true});
});
Cypress.Commands.add('selectReminderTime', (timeText) => {
cy.get('#reminder_timer_datetime .playbooks-rselect__menu').within(() => {
cy.findByText(timeText).click({force: true});
});
});
/**
* Update the status of the current playbook run through the slash command.
*/
Cypress.Commands.add('updateStatus', (message, reminderQuery) => {
// # Run the slash command to update status.
cy.uiPostMessageQuickly('/playbook update ');
// # Get the interactive dialog modal.
cy.getStatusUpdateDialog().within(() => {
// # remove what's there if applicable, and type the new update in the textbox.
cy.findByTestId('update_run_status_textbox').clear().type(message);
if (reminderQuery) {
cy.get('#reminder_timer_datetime').within(() => {
cy.get('input').type(reminderQuery, {delay: TIMEOUTS.TWO_HUNDRED_MILLIS, force: true}).wait(TIMEOUTS.ONE_SEC).type('{enter}');
});
}
// # Submit the dialog.
cy.get('button.confirm').click();
});
// * Verify that the interactive dialog has gone.
cy.getStatusUpdateDialog().should('not.exist');
// # Return the post ID of the status update.
return cy.getLastPostId();
});
/**
* Edit a post through the post dot menu.
* @param {String} postId - ID of the post to delete.
* @param {String} newMessage - New content of the post.
*/
Cypress.Commands.add('editPost', (postId, newMessage) => {
// # Open the post dot menu.
cy.clickPostDotMenu(postId);
// # Click on the Edit menu option.
cy.get(`#edit_post_${postId}`).click();
// # Overwrite the post content with the new message provided.
cy.get('#edit_textbox').clear().type(newMessage);
// # Confirm the edit in the dialog.
cy.get('#editButton').click();
});
Cypress.Commands.add('getStatusUpdateDialog', () => {
return cy.findByRole('dialog', {name: /post update/i});
});
Cypress.Commands.add('getStyledComponent', (className) => {
cy.get(`[class^="${className}-"]`);
});
/**
* Get the provided pseudo-class from the previous element and return the property passed as argument
* @param {String} pseudoClass - CSS pseudo class to get.
* @param {String} property - Property that will be returned.
*
* Stolen from https://stackoverflow.com/questions/55516990/cypress-testing-pseudo-css-class-before
*/
Cypress.Commands.add('cssPseudoClass', {prevSubject: 'element'}, (el, pseudoClass, property) => {
const win = el[0].ownerDocument.defaultView;
const pseudoElem = win.getComputedStyle(el[0], pseudoClass);
return pseudoElem.getPropertyValue(property).replace(/(^")|("$)/g, '');
});
/**
* Get the :before pseudo-class from the previous element and return the property passed as argument
* @param {String} property - Property that will be returned.
*/
Cypress.Commands.add('before', {prevSubject: 'element'}, (el, property) => {
return cy.wrap(el).cssPseudoClass('before', property);
});
/**
* Get the :after pseudo-class from the previous element and return the property passed as argument
* @param {String} property - Property that will be returned.
*/
Cypress.Commands.add('after', {prevSubject: 'element'}, (el, property) => {
return cy.wrap(el).cssPseudoClass('after', property);
});
function waitUntilPermanentPost() {
cy.get('#postListContent').should('exist');
cy.waitUntil(() => cy.findAllByTestId('postView').last().then((el) => !(el[0].id.includes(':'))));
}
Cypress.Commands.add('getFirstPostId', () => {
waitUntilPermanentPost();
cy.findAllByTestId('postView').first().should('have.attr', 'id').and('not.include', ':').
invoke('replace', 'post_', '');
});
Cypress.Commands.add('assertRunDetailsPageRenderComplete', (expectedRunOwner) => {
cy.findByTestId('lhs-navigation').should('be.visible').within(() => {
cy.contains('Playbooks').should('be.visible');
cy.contains('Runs').should('be.visible');
});
cy.get('#playbooks-sidebar-right').should('be.visible').within(() => {
cy.findByTestId('assignee-profile-selector').should('contain', expectedRunOwner);
cy.findAllByTestId('timeline-item', {exact: false}).should('have.length.of.at.least', 1);
cy.findAllByTestId('profile-option', {exact: false}).should('have.length.of.at.least', 1);
});
});
Cypress.Commands.add('interceptTelemetry', () => {
cy.intercept('/plugins/playbooks/api/v0/telemetry').as('telemetry');
});
const defaultExpectTelemetryToContainOptions = {
waitForCalls: 'auto',
};
// cy.expectTelemetryToContain expects to find the given telemetry events in the order given among the
// recorded telemetry. It doesn't fail if other telemetry events happen to occur in between.
Cypress.Commands.add('expectTelemetryToContain', (items, opts) => {
const options = {...defaultExpectTelemetryToContainOptions, ...opts};
// Wait for at least as many telemetry events as requested if auto, or explicit number if passed.
if (options.waitForCalls === 'auto') {
items.forEach(() => cy.wait('@telemetry'));
} else {
for (let i = 0; i < options.waitForCalls; i++) {
cy.wait('@telemetry');
}
}
// When additional telemetry events are emitted than what is expected, the ones we want may
// still be be pending, so wait a bit more to try to let requests settle.
cy.wait(TIMEOUTS.HALF_SEC);
cy.get('@telemetry.all').then((xhrs) => {
let xhrIndex = 0;
items.forEach((item) => {
while (xhrIndex < xhrs.length) {
const xhr = xhrs[xhrIndex];
// Advance to the next xhr element regardless of whether or not we find a match.
xhrIndex++;
if (xhr.request.body.name === item.name && xhr.request.body.type === item.type) {
// Validate only passed properties
if (item.properties) {
for (const [key, value] of Object.entries(item.properties)) {
expect(xhr.request.body.properties[key]).to.eq(value, `Property ${key} does not match for event ${item.name}`);
}
}
return;
}
}
throw new Error(`failed to find telemetry event '${item.type}' '${item.name}'`);
});
});
});