forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MM-15887] E2E: add test for interactive menus - basic options (matte…
…rmost#3063) * E2E: add test for interactive menus - basic options * check status after initiating Cypress task both for postIncomingWebhook and postMessageAs
- Loading branch information
1 parent
09bab23
commit f4eb2bc
Showing
13 changed files
with
778 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"attachments": [{ | ||
"pretext": "This is the attachment pretext.", | ||
"text": "This is the attachment text.", | ||
"actions": [{ | ||
"name": "Select an option...", | ||
"integration": { | ||
"url": "http:https://localhost:3000/message_menus", | ||
"context": { | ||
"action": "do_something" | ||
} | ||
}, | ||
"type": "select", | ||
"options": [{ | ||
"text": "Option 1", | ||
"value": "option1" | ||
}, { | ||
"text": "Option 2", | ||
"value": "option2" | ||
}, { | ||
"text": "Option 3", | ||
"value": "option3" | ||
}] | ||
}] | ||
}] | ||
} |
17 changes: 17 additions & 0 deletions
17
e2e/cypress/fixtures/hooks/message_menus_with_datasource.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"attachments": [{ | ||
"pretext": "This is the attachment pretext.", | ||
"text": "This is the attachment text.", | ||
"actions": [{ | ||
"name": "Select an option...", | ||
"integration": { | ||
"url": "http:https://localhost:3000/message_menus_datasource", | ||
"context": { | ||
"action": "do_something" | ||
} | ||
}, | ||
"type": "select", | ||
"data_source": "channels" | ||
}] | ||
}] | ||
} |
165 changes: 165 additions & 0 deletions
165
e2e/cypress/integration/interactive_menu/basic_options.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
// 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. | ||
// *************************************************************** | ||
|
||
/** | ||
* Note: This test requires webhook server running. Initiate `npm run start:webhook` to start. | ||
*/ | ||
|
||
import * as TIMEOUTS from '../../fixtures/timeouts'; | ||
import users from '../../fixtures/users.json'; | ||
import {getMessageMenusPayload} from '../../utils'; | ||
|
||
const options = [ | ||
{text: 'Option 1', value: 'option1'}, | ||
{text: 'Option 2', value: 'option2'}, | ||
{text: 'Option 3', value: 'option3'}, | ||
]; | ||
const payload = getMessageMenusPayload({options}); | ||
|
||
let channelId; | ||
let incomingWebhook; | ||
|
||
describe('MM-15887 Interactive menus - basic options', () => { | ||
before(() => { | ||
if (process.env.NODE_ENV !== 'qa') { | ||
// Set AllowedUntrustedInternalConnections to localhost if running in development | ||
const newSettings = { | ||
ServiceSettings: {AllowedUntrustedInternalConnections: 'localhost'}, | ||
}; | ||
cy.apiUpdateConfig(newSettings); | ||
} | ||
|
||
// # Login as sysadmin and ensure that teammate name display setting us set to default 'username' | ||
cy.apiLogin('sysadmin'); | ||
cy.apiSaveTeammateNameDisplayPreference('username'); | ||
|
||
// # Visit '/' and create incoming webhook | ||
cy.visit('/'); | ||
cy.getCurrentChannelId().then((id) => { | ||
channelId = id; | ||
|
||
const newIncomingHook = { | ||
channel_id: id, | ||
channel_locked: true, | ||
description: 'Incoming webhook interactive menu', | ||
display_name: 'menuIn' + Date.now(), | ||
}; | ||
|
||
cy.apiCreateWebhook(newIncomingHook).then((hook) => { | ||
incomingWebhook = hook; | ||
}); | ||
}); | ||
}); | ||
|
||
it('matches elements', () => { | ||
// # Post an incoming webhook | ||
cy.task('postIncomingWebhook', {url: incomingWebhook.url, data: payload}). | ||
its('status'). | ||
should('be.equal', 200); | ||
|
||
// # Get message attachment from the last post | ||
cy.getLastPostId().then((postId) => { | ||
cy.get(`#messageAttachmentList_${postId}`).as('messageAttachmentList'); | ||
}); | ||
|
||
// * Verify each element of message attachment list | ||
cy.get('@messageAttachmentList').within(() => { | ||
cy.get('.attachment__thumb-pretext').should('be.visible').and('have.text', 'This is attachment pretext with basic options'); | ||
cy.get('.post-message__text-container').should('be.visible').and('have.text', 'This is attachment text with basic options'); | ||
cy.get('.attachment-actions').should('be.visible'); | ||
cy.get('.select-suggestion-container').should('be.visible'); | ||
cy.get('.select-suggestion-container > input').should('be.visible').and('have.attr', 'placeholder', 'Select an option...'); | ||
|
||
cy.get('#suggestionList').should('not.be.visible'); | ||
cy.get('.select-suggestion-container > input').click(); | ||
cy.get('#suggestionList').should('be.visible').children().should('have.length', options.length); | ||
|
||
cy.get('#suggestionList').children().each(($el, index) => { | ||
cy.wrap($el).should('have.text', options[index].text); | ||
}); | ||
|
||
// * Close suggestion list by clicking on other element | ||
cy.get('.attachment__thumb-pretext').click(); | ||
}); | ||
}); | ||
|
||
it('displays selected option and posts ephemeral message', () => { | ||
// # Post an incoming webhook | ||
cy.task('postIncomingWebhook', {url: incomingWebhook.url, data: payload}). | ||
its('status'). | ||
should('be.equal', 200); | ||
|
||
// # Get message attachment from the last post | ||
cy.getLastPostId().then((postId) => { | ||
cy.get(`#messageAttachmentList_${postId}`).as('messageAttachmentList'); | ||
}); | ||
|
||
cy.get('@messageAttachmentList').within(() => { | ||
// # Select option 1 by typing exact text and press enter | ||
cy.get('.select-suggestion-container > input').click().clear().type(`${options[0].text}{enter}`); | ||
|
||
// * Verify that the input is updated with the selected option | ||
cy.get('.select-suggestion-container > input').should('be.visible').and('have.attr', 'value', options[0].text); | ||
}); | ||
|
||
cy.wait(TIMEOUTS.SMALL); | ||
|
||
cy.getLastPostId().then((postId) => { | ||
// * Verify that ephemeral message is posted, visible to observer and contains an exact message | ||
cy.get(`#${postId}_message`).should('be.visible').and('have.class', 'post--ephemeral'); | ||
cy.get('.post__visibility').should('be.visible').and('have.text', '(Only visible to you)'); | ||
cy.get(`#postMessageText_${postId}`).should('be.visible').and('have.text', 'Ephemeral | select option: option1'); | ||
}); | ||
}); | ||
|
||
it('displays reply in center channel with "commented on [user\'s] message: [text]"', () => { | ||
const user1 = users['user-1']; | ||
|
||
// # Post an incoming webhook | ||
cy.task('postIncomingWebhook', {url: incomingWebhook.url, data: payload}). | ||
its('status'). | ||
should('be.equal', 200); | ||
|
||
// # Get last post | ||
cy.getLastPostId().then((parentMessageId) => { | ||
const baseUrl = Cypress.config('baseUrl'); | ||
|
||
// # Post another message | ||
cy.task('postMessageAs', {sender: user1, message: 'Just another message', channelId, baseUrl}). | ||
its('status'). | ||
should('be.equal', 201); | ||
|
||
// # Click comment icon to open RHS | ||
cy.clickPostCommentIcon(parentMessageId); | ||
|
||
// * Check that the RHS is open | ||
cy.get('#rhsContainer').should('be.visible'); | ||
|
||
// # Have another user reply to the webhook message | ||
cy.task('postMessageAs', {sender: user1, message: 'Reply to webhook', channelId, rootId: parentMessageId, baseUrl}). | ||
its('status'). | ||
should('be.equal', 201); | ||
|
||
// # Get the latest post | ||
cy.getLastPostId().then((replyMessageId) => { | ||
// * Verify that the reply is in the channel view with matching text | ||
cy.get(`#post_${replyMessageId}`).within(() => { | ||
cy.get('.post__link').should('be.visible').and('have.text', 'Commented on sysadmin\'s message: This is attachment pretext with basic options'); | ||
cy.get(`#postMessageText_${replyMessageId}`).should('be.visible').and('have.text', 'Reply to webhook'); | ||
}); | ||
|
||
// * Verify that the reply is in the RHS with matching text | ||
cy.get(`#rhsPost_${replyMessageId}`).within(() => { | ||
cy.get('.post__link').should('not.be.visible'); | ||
cy.get(`#postMessageText_${replyMessageId}`).should('be.visible').and('have.text', 'Reply to webhook'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
const axios = require('axios'); | ||
|
||
module.exports = async ({url, data}) => { | ||
let response; | ||
|
||
try { | ||
response = await axios({method: 'post', url, data}); | ||
} catch (err) { | ||
if (err.response) { | ||
response = err.response; | ||
} | ||
} | ||
|
||
return {status: response.status, data: response.data}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.