Skip to content
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

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
861f546
did some cleanup in existing code
rahulsuresh-git Dec 3, 2023
b88c7d0
wrote test for help command
rahulsuresh-git Dec 3, 2023
72396b4
code cleanup
rahulsuresh-git Dec 3, 2023
201c38a
removed unused code
rahulsuresh-git Dec 3, 2023
5a49d44
added test for /todo add
rahulsuresh-git Dec 3, 2023
0f78845
fixed tsc errors and added helper function in support utils
rahulsuresh-git Dec 4, 2023
4d5aa70
reverted prettier changes
rahulsuresh-git Dec 4, 2023
dedc5ef
prettier changes reverted
rahulsuresh-git Dec 4, 2023
985cba8
addressed PR comments
rahulsuresh-git Dec 4, 2023
49d90b9
removed extra line
rahulsuresh-git Dec 4, 2023
37abad1
fixed issue with incorrect import
rahulsuresh-git Dec 5, 2023
7b53add
fixing test names and invocation methods
rahulsuresh-git Dec 8, 2023
b07e0cd
refactored code to get DM URL and teamName
rahulsuresh-git Dec 8, 2023
b0c2d52
refactored getLastPost method
rahulsuresh-git Dec 8, 2023
9680eff
refactored comments and test names
rahulsuresh-git Dec 8, 2023
93e0490
fixed getBotDMPageURL arguments
rahulsuresh-git Dec 9, 2023
18e5802
cleaned up before test functions:
rahulsuresh-git Dec 9, 2023
dbc8524
merged feat/todo-help-e2e-test
rahulsuresh-git May 19, 2024
65707b4
fixed test import in test.list.ts
rahulsuresh-git May 19, 2024
53e705a
Merge branch 'feat/todo-add-e2e-test' of https://github.com/rahulsure…
rahulsuresh-git May 19, 2024
2eda538
fixed addTodo test
rahulsuresh-git May 19, 2024
c62b16a
added /todo list test
rahulsuresh-git May 19, 2024
0efc671
comment fixes from original PRs
rahulsuresh-git May 20, 2024
9b17b5e
uncommented lines in test.list.ts
rahulsuresh-git May 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions e2e/playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "plugin-e2e-tests",
"scripts": {
"test": "PW_SLOMO=200 npm run test --prefix ../../../mattermost/e2e-tests/playwright -- --project=chrome --config='../../../mattermost-plugin-todo/e2e/playwright/playwright.config.ts'",
"test-ui": "PW_SLOMO=200 npm run test --prefix ../../../mattermost/e2e-tests/playwright -- --project=chrome --config='../../../mattermost-plugin-todo/e2e/playwright/playwright.config.ts' --ui",
"test-ci": "PW_HEADLESS=true npm test",
"test-slomo": "npm run test-slomo --prefix ../../../mattermost/e2e-tests/playwright -- --project=chrome --config='../../../mattermost-plugin-todo/e2e/playwright/playwright.config.ts",
"debug": "npm test -- --debug",
Expand Down
25 changes: 16 additions & 9 deletions e2e/playwright/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// See LICENSE.txt for license information.

import type {Page} from '@playwright/test';

import {UserProfile} from '@mattermost/types/users';
import Client4 from '@mattermost/client/client4';

Expand All @@ -14,13 +13,14 @@ export const waitForNewMessages = async (page: Page) => {
// await page.locator('#postListContent').getByTestId('NotificationSeparator').getByText('New Messages').waitFor();
};

export const getTodoBotDMPageURL = async (client: Client4, teamName: string, userId: string) => {
let team = teamName;
if (team === '') {
const teams = await client.getTeamsForUser(userId);
team = teams[0].name;
}
return `${team}/messages/@todo`;
export const getTeamName = async (client: Client4, userId: string) => {
const teams = await client.getTeamsForUser(userId);
const team = teams[0].name;
return team;
};

export const getBotDMPageURL = async (teamName: string, botUsername: string) => {
return `${teamName}/messages/${botUsername}`;
Copy link
Contributor

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

Suggested change
return `${teamName}/messages/${botUsername}`;
return `${teamName}/messages/@${botUsername}`;

};

export const fillTextField = async (name: string, value: string, page: Page) => {
Expand All @@ -32,7 +32,7 @@ export const submitDialog = async (page: Page) => {
};

export const fillMessage = async (message: string, page: Page) => {
await fillTextField('post_textbox', message, page )
await fillTextField('post_textbox', message, page)
};

export const postMessage = async (message: string, page: Page) => {
Expand All @@ -58,3 +58,10 @@ export const getSlackAttachmentLocatorId = (postId: string) => {
export const getPostMessageLocatorId = (postId: string) => {
return `#post_${postId} .post-message`;
};

export const getLastPost = async (page: Page) => {
const lastPost = page.getByTestId("postView").last();
await lastPost.waitFor();
const postBody = lastPost.locator('.post-message__text-container');
return postBody;
};
17 changes: 14 additions & 3 deletions e2e/playwright/tests/test.list.ts
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";
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
125 changes: 102 additions & 23 deletions e2e/playwright/tests/todo_plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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" });
Copy link
Contributor

Choose a reason for hiding this comment

The 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 const cleanUpBotDMs = async (client: Client4, userId: UserProfile['id'], botUsername: string) => {

});

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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, two lines are duplicated

});
},
};
Loading