-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(e2e, playwright): added playwright e2e tests for /todo add, list and help commands #254
base: master
Are you sure you want to change the base?
Changes from all commits
861f546
b88c7d0
72396b4
201c38a
5a49d44
0f78845
4d5aa70
dedc5ef
985cba8
49d90b9
37abad1
7b53add
b07e0cd
b0c2d52
9680eff
93e0490
18e5802
dbc8524
65707b4
53e705a
2eda538
c62b16a
0efc671
9b17b5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import core from './todo_plugin.spec'; | ||
import {test} from "@e2e-support/test_fixture"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can probably keep the styling of things as single quotes. I wonder why CI linting didn't catch these changes |
||
import commands from "./todo_plugin.spec"; | ||
|
||
import '../support/init_test'; | ||
import "../support/init_test"; | ||
|
||
core.connected(); | ||
// Test if plugin shows the correct suggestions for command autocomplete | ||
test.describe("command autocomplete", commands.autocomplete); | ||
|
||
// Test `/todo add` commands | ||
test.describe("commands/add", commands.add); | ||
|
||
// Test `/todo list` commands | ||
test.describe("commands/list", commands.list); | ||
|
||
// Test `/todo help` commands | ||
test.describe("commands/help", commands.help); |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -6,35 +6,114 @@ | |||
// - [*] indicates an assertion (e.g. * Check the title) | ||||
// *************************************************************** | ||||
|
||||
import {expect, test} from '@e2e-support/test_fixture'; | ||||
import SlashCommandSuggestions from 'support/components/slash_commands'; | ||||
import {fillMessage, getTodoBotDMPageURL} from 'support/utils'; | ||||
import {expect, test} from "@e2e-support/test_fixture"; | ||||
import SlashCommandSuggestions from "support/components/slash_commands"; | ||||
import { | ||||
fillMessage, | ||||
getBotDMPageURL, | ||||
getLastPost, | ||||
getTeamName, | ||||
postMessage, | ||||
} from "support/utils"; | ||||
|
||||
const botUserName = "todo"; | ||||
let teamName = ""; | ||||
|
||||
test.beforeAll(async ({ pw }) => { | ||||
const { adminClient, adminUser } = await pw.getAdminClient(); | ||||
if (adminUser === null) { | ||||
Comment on lines
+16
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's inconsistent indentation in this file. Another thing the linter should be noticing. I'm thinking we should converge on 4 spaces for indenting |
||||
throw new Error("can not get adminUser"); | ||||
} | ||||
if (teamName === "") { | ||||
teamName = await getTeamName(adminClient, adminUser.id); | ||||
} | ||||
}); | ||||
|
||||
test.beforeEach(async ({ page }) => { | ||||
const dmURL = await getBotDMPageURL(teamName, botUserName); | ||||
await page.goto(dmURL, { waitUntil: "load" }); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking we should clear the bot DMs before each test, since we're using the same channel for each test. We can use the function defined here for this:
|
||||
}); | ||||
|
||||
export default { | ||||
connected: () => { | ||||
test.describe('available commands', () => { | ||||
test('with just the main command', async ({page, pw}) => { | ||||
autocomplete: () => { | ||||
test('/todo', async ({ page }) => { | ||||
const slash = new SlashCommandSuggestions( | ||||
page.locator("#suggestionList") | ||||
); | ||||
|
||||
// # Type command to show suggestions | ||||
await fillMessage('/todo', page); | ||||
|
||||
// * Assert suggestions are visible | ||||
await expect(slash.container).toBeVisible(); | ||||
|
||||
// * Assert todo [command] is visible | ||||
await expect(slash.getItemTitleNth(0)).toHaveText("todo [command]"); | ||||
|
||||
await expect(slash.getItemDescNth(0)).toContainText( | ||||
"Available commands:" | ||||
); | ||||
}); | ||||
}, | ||||
|
||||
help: () => { | ||||
test('/todo help', async ({ page }) => { | ||||
// # Run command to trigger help | ||||
await postMessage('/todo help', page); | ||||
|
||||
// # Get ephemeral post response from todo help command | ||||
const lastPost = await getLastPost(page); | ||||
|
||||
// * Assert "help" is in the post body | ||||
await expect(lastPost).toContainText("help"); | ||||
|
||||
// * Assert if length of content shown is greater than 10 lines | ||||
const postBody = await lastPost.textContent(); | ||||
const postBodyLines = postBody ? postBody.split('\n') : []; | ||||
expect(postBodyLines.length).toBeGreaterThanOrEqual(10); | ||||
}); | ||||
}, | ||||
|
||||
add: () => { | ||||
test("/todo add <message>", async ({ page }) => { | ||||
const todoMessage = "Don't forget to be awesome"; | ||||
|
||||
// # Run command to add todo | ||||
await postMessage(`/todo add ${todoMessage}`, page); | ||||
|
||||
// # Get ephemeral post response from todo add command | ||||
const post = await getLastPost(page); | ||||
|
||||
await expect(post).toBeVisible(); | ||||
|
||||
await expect(post).toContainText("Added Todo. Todo List:"); | ||||
await expect(post).toContainText(todoMessage); | ||||
|
||||
// * Assert added todo is visible | ||||
await expect(post).toContainText(todoMessage); | ||||
Comment on lines
+90
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two lines are duplicated |
||||
}); | ||||
}, | ||||
|
||||
list: () => { | ||||
test("/todo list", async ({ page }) => { | ||||
const todoMessage = "Don't forget to be awesome"; | ||||
|
||||
const {adminClient, adminUser} = await pw.getAdminClient(); | ||||
if (adminUser === null) { | ||||
throw new Error('can not get adminUser'); | ||||
} | ||||
const dmURL = await getTodoBotDMPageURL(adminClient, '', adminUser.id); | ||||
await page.goto(dmURL, {waitUntil: 'load'}); | ||||
// # Run command to add todo | ||||
await postMessage(`/todo add ${todoMessage}`, page); | ||||
|
||||
const slash = new SlashCommandSuggestions(page.locator('#suggestionList')); | ||||
// # Type command to list todo | ||||
await postMessage('/todo list', page); | ||||
|
||||
// # Run incomplete command to trigger help | ||||
await fillMessage('/todo', page); | ||||
// # Get ephemeral post response from todo list command | ||||
const post = await getLastPost(page); | ||||
|
||||
// * Assert suggestions are visible | ||||
await expect(slash.container).toBeVisible(); | ||||
await expect(post).toBeVisible(); | ||||
|
||||
// * Assert help is visible | ||||
await expect(slash.getItemTitleNth(0)).toHaveText('todo [command]'); | ||||
await expect(post).toContainText("Todo List:"); | ||||
await expect(post).toContainText(todoMessage); | ||||
|
||||
await expect(slash.getItemDescNth(0)).toHaveText('Available commands: list, add, pop, send, settings, help'); | ||||
}); | ||||
}); | ||||
}, | ||||
// * Assert added todo is visible | ||||
await expect(post).toContainText(todoMessage); | ||||
Comment on lines
+113
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, two lines are duplicated |
||||
}); | ||||
}, | ||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need the
@
symbol here right? Interesting how things are passing without this