Unverified Commit 32a1844c authored by Saturnino Abril's avatar Saturnino Abril Committed by GitHub
Browse files

Cypress test for MM-T621 Override username and profile picture - remove...

Cypress test for MM-T621 Override username and profile picture - remove overrides from payload (#5892)

Automatic Merge
parent 701e3ff6
......@@ -9,12 +9,15 @@
// Group: @incoming_webhook
import {getRandomId} from '../../../utils';
import * as TIMEOUTS from '../../../fixtures/timeouts';
describe('Incoming webhook', () => {
const inAppUsername = 'in-app';
const inAppIconURL = 'https://pbs.twimg.com/profile_images/3303520670/4da3468b30495a5d73e6f31df068e5c9.jpeg';
let testTeam;
let testChannel;
let siteName;
let sysadmin;
let incomingWebhook;
......@@ -28,8 +31,6 @@ describe('Incoming webhook', () => {
EnablePostUsernameOverride: true,
EnablePostIconOverride: true,
},
}).then(({config}) => {
siteName = config.TeamSettings.SiteName;
});
// # Create and visit new channel and create incoming webhook
......@@ -46,84 +47,124 @@ describe('Incoming webhook', () => {
cy.apiCreateWebhook(newIncomingHook).then((hook) => {
incomingWebhook = hook;
editIncomingWebhook(incomingWebhook.id, team.name, inAppUsername, inAppIconURL);
});
});
});
beforeEach(() => {
cy.visit(`/${testTeam.name}/channels/town-square`);
});
it('MM-T620 Payload username and profile picture override in-app settings', () => {
// # Edit incoming webhook
cy.visit(`/${testTeam.name}/integrations/incoming_webhooks/edit?id=${incomingWebhook.id}`);
cy.get('.backstage-header', {timeout: TIMEOUTS.ONE_MIN}).should('be.visible').within(() => {
cy.findByText('Incoming Webhooks').should('be.visible');
cy.findByText('Edit').should('be.visible');
});
// # Post an incoming webhook with username and profile icon URL
const payload = getPayload(testChannel, true);
cy.postIncomingWebhook({url: incomingWebhook.url, data: payload});
// # Enter username and profile icon URL
const inAppUsername = 'in-app';
const inAppIconURL = 'https://pbs.twimg.com/profile_images/3303520670/4da3468b30495a5d73e6f31df068e5c9.jpeg';
cy.findByLabelText('Username').should('exist').type(inAppUsername);
cy.findByLabelText('Profile Picture').should('exist').type(inAppIconURL);
// # Click test channel on sidebar
cy.get(`#sidebarItem_${testChannel.name}`).should('be.visible').click();
// # CLick update and verify ot redirects to incoming webhook page
cy.findByText('Update').click();
cy.url().should('include', `/${testTeam.name}/integrations/incoming_webhooks`).wait(TIMEOUTS.ONE_SEC);
// # Wait for the webhook message to get posted
cy.waitUntil(() => cy.getLastPost().then((el) => {
const postedMessageEl = el.find('.post-message__text > p')[0];
return Boolean(postedMessageEl && postedMessageEl.textContent.includes(payload.text));
}));
// # Click back to site and verify that it redirects to town-square channel
cy.findByText(`Back to ${siteName}`).click();
cy.url().should('include', `/${testTeam.name}/channels/town-square`);
// * Verify that the username and profile icon are overridden per webhook payload
verifyLastPost(sysadmin, payload.username, payload.icon_url);
});
// # Post an incoming webhook
const payload = getPayload(testChannel);
it('MM-T621 Override username and profile picture - remove overrides from payload', () => {
// # Post an incoming webhook without username and profile icon URL
const payload = getPayload(testChannel, false);
cy.postIncomingWebhook({url: incomingWebhook.url, data: payload});
// # Click test channel and verify last post
// # Click test channel on sidebar
cy.get(`#sidebarItem_${testChannel.name}`).should('be.visible').click();
cy.getLastPost().within(() => {
// * Verify that the username is overridden per webhook payload
cy.get('.post__header').find('.user-popover').as('usernameForPopover').should('have.text', payload.username);
// * Verify that the user icon is overridden per webhook payload
const baseUrl = Cypress.config('baseUrl');
const encodedIconUrl = encodeURIComponent(payload.icon_url);
cy.get('.profile-icon > img').as('profileIconForPopover').should('have.attr', 'src', `${baseUrl}/api/v4/image?url=${encodedIconUrl}`);
// # Wait for the webhook message to get posted
cy.waitUntil(() => cy.getLastPost().then((el) => {
const postedMessageEl = el.find('.post-message__text > p')[0];
return Boolean(postedMessageEl && postedMessageEl.textContent.includes(payload.text));
}));
// * Verify that the BOT label appears
cy.get('.Badge').should('be.visible').and('have.text', 'BOT');
// * Verify that the username and profile icon are based from webhook settings
verifyLastPost(sysadmin, inAppUsername, inAppIconURL);
});
});
// * Verify that there's no status indicator
cy.get('.status').should('not.exist');
});
function editIncomingWebhook(incomingWebhookId, teamName, inAppUsername, inAppIconURL) {
// # Edit incoming webhook
cy.visit(`/${teamName}/integrations/incoming_webhooks/edit?id=${incomingWebhookId}`);
cy.get('.backstage-header', {timeout: TIMEOUTS.ONE_MIN}).should('be.visible').within(() => {
cy.findByText('Incoming Webhooks').should('be.visible');
cy.findByText('Edit').should('be.visible');
});
// # Click on username and verify profile popover
cy.get('@usernameForPopover').click();
verifyProfilePopover(sysadmin, payload);
// # Enter username and profile icon URL
cy.findByLabelText('Username').should('exist').type(inAppUsername);
cy.findByLabelText('Profile Picture').should('exist').type(inAppIconURL);
// # Click away to close propfile popover
cy.get('body').click();
// # Click update and verify it redirects to incoming webhook page
cy.findByText('Update').click();
cy.url().should('include', `/${teamName}/integrations/incoming_webhooks`).wait(TIMEOUTS.ONE_SEC);
}
// # Click on profile icon and verify profile popover
cy.get('@profileIconForPopover').click();
verifyProfilePopover(sysadmin, payload);
});
});
function getPayload(channel, withUsernameAndProfileIcon) {
const payload = {
channel: channel.name,
text: `${getRandomId()} - this is from incoming webhook`,
};
if (!withUsernameAndProfileIcon) {
return payload;
}
function getPayload(channel) {
return {
channel: channel.name,
...payload,
username: 'payload_username',
text: 'This is from incoming webhook',
icon_url: 'http://www.mattermost.org/wp-content/uploads/2016/04/icon_WS.png',
};
}
function verifyProfilePopover(owner, payload) {
function verifyLastPost(owner, username, iconUrl) {
cy.getLastPost().within(() => {
// * Verify username in post header
cy.get('.post__header').find('.user-popover').as('usernameForPopover').should('have.text', username);
// * Verify profile icon in post header
const baseUrl = Cypress.config('baseUrl');
const encodedIconUrl = encodeURIComponent(iconUrl);
cy.get('.profile-icon > img').as('profileIconForPopover').should('have.attr', 'src', `${baseUrl}/api/v4/image?url=${encodedIconUrl}`);
// * Verify that the BOT label appears
cy.get('.Badge').should('be.visible').and('have.text', 'BOT');
// * Verify that there's no status indicator
cy.get('.status').should('not.exist');
});
// # Click on username and verify profile popover
cy.get('@usernameForPopover').click();
verifyProfilePopover(owner, username, iconUrl);
// # Click away to close propfile popover
cy.get('body').click();
// # Click on profile icon and verify profile popover
cy.get('@profileIconForPopover').click();
verifyProfilePopover(owner, username, iconUrl);
}
function verifyProfilePopover(owner, username, iconUrl) {
// * Verify that the profile popover is shown
cy.get('#user-profile-popover').should('be.visible').within(() => {
// * Verify username from payload
cy.get('.user-popover__username').should('be.visible').and('have.text', payload.username);
cy.get('.user-popover__username').should('be.visible').and('have.text', username);
// * Verify icon URL from payload
cy.get('.Avatar').should('have.attr', 'src', payload.icon_url);
cy.get('.Avatar').should('have.attr', 'src', iconUrl);
// * Verify that it matches with correct footer
cy.get('.popover__row').should('be.visible').and('have.text', `This post was created by an integration from @${owner.username}`);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment