From 861f546af6b609dcf7f649f9ec3b47f1f2a3b196 Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Sun, 3 Dec 2023 13:14:54 -0600 Subject: [PATCH 01/22] did some cleanup in existing code --- e2e/playwright/package.json | 1 + e2e/playwright/tests/test.list.ts | 8 +-- e2e/playwright/tests/todo_plugin.spec.ts | 62 ++++++++++++------------ 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/e2e/playwright/package.json b/e2e/playwright/package.json index 18aac110..d9b3fdd5 100644 --- a/e2e/playwright/package.json +++ b/e2e/playwright/package.json @@ -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 -- --ui --project=chrome --config='../../../mattermost-plugin-todo/e2e/playwright/playwright.config.ts'", "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", diff --git a/e2e/playwright/tests/test.list.ts b/e2e/playwright/tests/test.list.ts index 732baaf3..9b9d3f38 100644 --- a/e2e/playwright/tests/test.list.ts +++ b/e2e/playwright/tests/test.list.ts @@ -1,9 +1,9 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {test} from '@playwright/test'; -import core from './todo_plugin.spec'; +import { test } from "@playwright/test"; +import core from "./todo_plugin.spec"; -import '../support/init_test'; +import "../support/init_test"; -test.describe(core.connected); +test.describe("setup", core.setup); diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index 745e6bb6..01f55346 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -6,37 +6,37 @@ // - [*] 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, getTodoBotDMPageURL } from "support/utils"; export default { - connected: () => { - test.describe('available commands', () => { - test('with just the main command', async ({pages, page, pw}) => { - - 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'}); - - const c = new pages.ChannelsPage(page); - const slash = new SlashCommandSuggestions(page.locator('#suggestionList')); - - // # Run incomplete command to trigger help - await fillMessage('/todo', page); - - // * Assert suggestions are visible - await expect(slash.container).toBeVisible(); - - // * Assert help is visible - await expect(slash.getItemTitleNth(0)).toHaveText('todo [command]'); - - await expect(slash.getItemDescNth(0)).toHaveText('Available commands: list, add, pop, send, settings, help'); - }); - }); - }, + setup: () => { + test("checking available commands", async ({ pages, page, pw }) => { + 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" }); + + const c = new pages.ChannelsPage(page); + const slash = new SlashCommandSuggestions( + page.locator("#suggestionList") + ); + + // # Run incomplete command to trigger help + await fillMessage("/todo", page); + + // * Assert suggestions are visible + await expect(slash.container).toBeVisible(); + + // * Assert help is visible + await expect(slash.getItemTitleNth(0)).toHaveText("todo [command]"); + + await expect(slash.getItemDescNth(0)).toHaveText( + "Available commands: list, add, pop, send, settings, help" + ); + }); + }, }; - From b88c7d02acd28991c01d896850579dd6b045b1cc Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Sun, 3 Dec 2023 14:49:09 -0600 Subject: [PATCH 02/22] wrote test for help command --- e2e/playwright/package.json | 2 +- e2e/playwright/tests/test.list.ts | 4 + e2e/playwright/tests/todo_plugin.spec.ts | 95 +++++++++++++++++++----- 3 files changed, 82 insertions(+), 19 deletions(-) diff --git a/e2e/playwright/package.json b/e2e/playwright/package.json index d9b3fdd5..133a4525 100644 --- a/e2e/playwright/package.json +++ b/e2e/playwright/package.json @@ -2,7 +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 -- --ui --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", diff --git a/e2e/playwright/tests/test.list.ts b/e2e/playwright/tests/test.list.ts index 9b9d3f38..b3925947 100644 --- a/e2e/playwright/tests/test.list.ts +++ b/e2e/playwright/tests/test.list.ts @@ -6,4 +6,8 @@ import core from "./todo_plugin.spec"; import "../support/init_test"; +// Test if plugin is setup correctly test.describe("setup", core.setup); + +// Test various plugin actions +test.describe("actions", core.actions); diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index 01f55346..dc7126e4 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -7,36 +7,95 @@ // *************************************************************** import { expect, test } from "@e2e-support/test_fixture"; +import Client4 from "@mattermost/client/client4"; +import { UserProfile } from "@mattermost/types/users"; import SlashCommandSuggestions from "support/components/slash_commands"; import { fillMessage, getTodoBotDMPageURL } from "support/utils"; +let adminClient: Client4, adminUser: UserProfile | null; + +test.beforeEach(async ({ page, pw }) => { + const data = await pw.getAdminClient(); + adminClient = data.adminClient; + adminUser = data.adminUser; + if (adminUser === null) { + throw new Error("can not get adminUser"); + } + const dmURL = await getTodoBotDMPageURL(adminClient, "", adminUser.id); + await page.goto(dmURL, { waitUntil: "load" }); +}); + export default { setup: () => { test("checking available commands", async ({ pages, page, pw }) => { - const { adminClient, adminUser } = await pw.getAdminClient(); - if (adminUser === null) { - throw new Error("can not get adminUser"); + if (adminUser) { + const dmURL = await getTodoBotDMPageURL(adminClient, "", adminUser.id); + await page.goto(dmURL, { waitUntil: "load" }); + const c = new pages.ChannelsPage(page); + const slash = new SlashCommandSuggestions( + page.locator("#suggestionList") + ); + + // # Run command to trigger todo + 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)).toHaveText( + "Available commands: list, add, pop, send, settings, help" + ); } - const dmURL = await getTodoBotDMPageURL(adminClient, "", adminUser.id); - await page.goto(dmURL, { waitUntil: "load" }); + }); + }, + actions: () => { + test("help action", async ({ pages, page, pw }) => { + if (adminUser) { + const dmURL = await getTodoBotDMPageURL(adminClient, "", adminUser.id); + await page.goto(dmURL, { waitUntil: "load" }); + const c = new pages.ChannelsPage(page); + const slash = new SlashCommandSuggestions( + page.locator("#suggestionList") + ); + + // # Run command to trigger help + await c.postMessage("/todo help"); + + // # Grab the last post + const post = await c.getLastPost(); + const postBody = post.container.locator( + ".post-message__text-container" + ); + + // * Assert /todo add [message] command is visible + await expect(postBody).toContainText(`add [message]`); - const c = new pages.ChannelsPage(page); - const slash = new SlashCommandSuggestions( - page.locator("#suggestionList") - ); + // * Assert /todo list command is visible + await expect(postBody).toContainText("list"); - // # Run incomplete command to trigger help - await fillMessage("/todo", page); + // * Assert /todo list [listName] command is visible + await expect(postBody).toContainText("list [listName]"); - // * Assert suggestions are visible - await expect(slash.container).toBeVisible(); + // * Assert /todo pop command is visible + await expect(postBody).toContainText("pop"); - // * Assert help is visible - await expect(slash.getItemTitleNth(0)).toHaveText("todo [command]"); + // * Assert /todo send [user] [message] command is visible + await expect(postBody).toContainText("send [user] [message]"); - await expect(slash.getItemDescNth(0)).toHaveText( - "Available commands: list, add, pop, send, settings, help" - ); + // * Assert /todo settings summary [on, off] command is visible + await expect(postBody).toContainText("settings summary [on, off]"); + + // * Assert /todo settings allow_incoming_task_requests [on, off] command is visible + await expect(postBody).toContainText( + "settings allow_incoming_task_requests [on, off]" + ); + + // * Assert /todo help command is visible + await expect(postBody).toContainText("help"); + } }); }, }; From 72396b4ca9fb760eb4065031bbb2feaf37df5963 Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Sun, 3 Dec 2023 16:19:18 -0600 Subject: [PATCH 03/22] code cleanup --- e2e/playwright/tests/todo_plugin.spec.ts | 106 ++++++++++------------- 1 file changed, 45 insertions(+), 61 deletions(-) diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index dc7126e4..ba7a419f 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -7,17 +7,11 @@ // *************************************************************** import { expect, test } from "@e2e-support/test_fixture"; -import Client4 from "@mattermost/client/client4"; -import { UserProfile } from "@mattermost/types/users"; import SlashCommandSuggestions from "support/components/slash_commands"; import { fillMessage, getTodoBotDMPageURL } from "support/utils"; -let adminClient: Client4, adminUser: UserProfile | null; - test.beforeEach(async ({ page, pw }) => { - const data = await pw.getAdminClient(); - adminClient = data.adminClient; - adminUser = data.adminUser; + const { adminClient, adminUser } = await pw.getAdminClient(); if (adminUser === null) { throw new Error("can not get adminUser"); } @@ -28,74 +22,64 @@ test.beforeEach(async ({ page, pw }) => { export default { setup: () => { test("checking available commands", async ({ pages, page, pw }) => { - if (adminUser) { - const dmURL = await getTodoBotDMPageURL(adminClient, "", adminUser.id); - await page.goto(dmURL, { waitUntil: "load" }); - const c = new pages.ChannelsPage(page); - const slash = new SlashCommandSuggestions( - page.locator("#suggestionList") - ); - - // # Run command to trigger todo - 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)).toHaveText( - "Available commands: list, add, pop, send, settings, help" - ); - } + const c = new pages.ChannelsPage(page); + const slash = new SlashCommandSuggestions( + page.locator("#suggestionList") + ); + + // # Run command to trigger todo + 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)).toHaveText( + "Available commands: list, add, pop, send, settings, help" + ); }); }, actions: () => { test("help action", async ({ pages, page, pw }) => { - if (adminUser) { - const dmURL = await getTodoBotDMPageURL(adminClient, "", adminUser.id); - await page.goto(dmURL, { waitUntil: "load" }); - const c = new pages.ChannelsPage(page); - const slash = new SlashCommandSuggestions( - page.locator("#suggestionList") - ); + const c = new pages.ChannelsPage(page); + const slash = new SlashCommandSuggestions( + page.locator("#suggestionList") + ); - // # Run command to trigger help - await c.postMessage("/todo help"); + // # Run command to trigger help + await c.postMessage("/todo help"); - // # Grab the last post - const post = await c.getLastPost(); - const postBody = post.container.locator( - ".post-message__text-container" - ); + // # Grab the last post + const post = await c.getLastPost(); + const postBody = post.container.locator(".post-message__text-container"); - // * Assert /todo add [message] command is visible - await expect(postBody).toContainText(`add [message]`); + // * Assert /todo add [message] command is visible + await expect(postBody).toContainText(`add [message]`); - // * Assert /todo list command is visible - await expect(postBody).toContainText("list"); + // * Assert /todo list command is visible + await expect(postBody).toContainText("list"); - // * Assert /todo list [listName] command is visible - await expect(postBody).toContainText("list [listName]"); + // * Assert /todo list [listName] command is visible + await expect(postBody).toContainText("list [listName]"); - // * Assert /todo pop command is visible - await expect(postBody).toContainText("pop"); + // * Assert /todo pop command is visible + await expect(postBody).toContainText("pop"); - // * Assert /todo send [user] [message] command is visible - await expect(postBody).toContainText("send [user] [message]"); + // * Assert /todo send [user] [message] command is visible + await expect(postBody).toContainText("send [user] [message]"); - // * Assert /todo settings summary [on, off] command is visible - await expect(postBody).toContainText("settings summary [on, off]"); + // * Assert /todo settings summary [on, off] command is visible + await expect(postBody).toContainText("settings summary [on, off]"); - // * Assert /todo settings allow_incoming_task_requests [on, off] command is visible - await expect(postBody).toContainText( - "settings allow_incoming_task_requests [on, off]" - ); + // * Assert /todo settings allow_incoming_task_requests [on, off] command is visible + await expect(postBody).toContainText( + "settings allow_incoming_task_requests [on, off]" + ); - // * Assert /todo help command is visible - await expect(postBody).toContainText("help"); - } + // * Assert /todo help command is visible + await expect(postBody).toContainText("help"); }); }, }; From 201c38ac4f1dd8fe6c63793a619bbdc69a64817d Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Sun, 3 Dec 2023 16:23:56 -0600 Subject: [PATCH 04/22] removed unused code --- e2e/playwright/tests/todo_plugin.spec.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index ba7a419f..eefa13b2 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -22,7 +22,6 @@ test.beforeEach(async ({ page, pw }) => { export default { setup: () => { test("checking available commands", async ({ pages, page, pw }) => { - const c = new pages.ChannelsPage(page); const slash = new SlashCommandSuggestions( page.locator("#suggestionList") ); @@ -44,9 +43,6 @@ export default { actions: () => { test("help action", async ({ pages, page, pw }) => { const c = new pages.ChannelsPage(page); - const slash = new SlashCommandSuggestions( - page.locator("#suggestionList") - ); // # Run command to trigger help await c.postMessage("/todo help"); From 5a49d446fdf845ff376829548999b964b7081cb2 Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Sun, 3 Dec 2023 17:01:00 -0600 Subject: [PATCH 05/22] added test for /todo add --- e2e/playwright/tests/todo_plugin.spec.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index eefa13b2..10d25d27 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -77,5 +77,26 @@ export default { // * Assert /todo help command is visible await expect(postBody).toContainText("help"); }); + + test("add action", async ({ pages, page, pw }) => { + const c = new pages.ChannelsPage(page); + const slash = new SlashCommandSuggestions( + page.locator("#suggestionList") + ); + const todoMessage = "Don't forget to be awesome"; + + // # Run command to add todo + await c.postMessage(`/todo add ${todoMessage}`); + + // # Grab the last post + const post = await c.getLastPost(); + const postBody = post.container.locator(".post-message__text-container"); + + // * Assert post body has correct title + await expect(postBody).toContainText("Added Todo. Todo List:"); + + // * Assert added todo is visible + await expect(postBody).toContainText(todoMessage); + }); }, }; From 0f78845a305d8d4570c18555843429d2fad846c9 Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Sun, 3 Dec 2023 19:50:31 -0600 Subject: [PATCH 06/22] fixed tsc errors and added helper function in support utils --- e2e/playwright/support/utils.ts | 76 +++++++++++++++--------- e2e/playwright/tests/todo_plugin.spec.ts | 13 ++-- 2 files changed, 56 insertions(+), 33 deletions(-) diff --git a/e2e/playwright/support/utils.ts b/e2e/playwright/support/utils.ts index b13ce154..7e707688 100644 --- a/e2e/playwright/support/utils.ts +++ b/e2e/playwright/support/utils.ts @@ -1,60 +1,78 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import type {Page} from '@playwright/test'; +import type { Page } from "@playwright/test"; -import {UserProfile} from '@mattermost/types/users'; -import Client4 from '@mattermost/client/client4'; +import Client4 from "@mattermost/client/client4"; +import { UserProfile } from "@mattermost/types/users"; export const waitForNewMessages = async (page: Page) => { - await page.waitForTimeout(1000); + await page.waitForTimeout(1000); - // This should be able to be waited based on locators instead of pure time-based - // The following code work "almost" always. Commented for now to have green tests. - // await page.locator('#postListContent').getByTestId('NotificationSeparator').getByText('New Messages').waitFor(); + // This should be able to be waited based on locators instead of pure time-based + // The following code work "almost" always. Commented for now to have green tests. + // 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 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 fillTextField = async (name: string, value: string, page: Page) => { - await page.getByTestId(`${name}`).fill(value); +export const fillTextField = async ( + name: string, + value: string, + page: Page +) => { + await page.getByTestId(`${name}`).fill(value); }; export const submitDialog = async (page: Page) => { - await page.click('#interactiveDialogSubmit'); + await page.click("#interactiveDialogSubmit"); }; 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) => { - await fillMessage(message, page) - await page.getByTestId('SendMessageButton').click(); + await fillMessage(message, page); + await page.getByTestId("SendMessageButton").click(); }; -export const cleanUpBotDMs = async (client: Client4, userId: UserProfile['id'], botUsername: string) => { - const bot = await client.getUserByUsername(botUsername); +export const cleanUpBotDMs = async ( + client: Client4, + userId: UserProfile["id"], + botUsername: string +) => { + const bot = await client.getUserByUsername(botUsername); - const userIds = [userId, bot.id]; - const channel = await client.createDirectChannel(userIds); - const posts = await client.getPosts(channel.id); + const userIds = [userId, bot.id]; + const channel = await client.createDirectChannel(userIds); + const posts = await client.getPosts(channel.id); - const deletePostPromises = Object.keys(posts.posts).map(client.deletePost); - await Promise.all(deletePostPromises); + const deletePostPromises = Object.keys(posts.posts).map(client.deletePost); + await Promise.all(deletePostPromises); }; export const getSlackAttachmentLocatorId = (postId: string) => { - return `#post_${postId} .attachment__body`; + return `#post_${postId} .attachment__body`; }; export const getPostMessageLocatorId = (postId: string) => { - return `#post_${postId} .post-message`; + return `#post_${postId} .post-message`; +}; + +export const getLastPost = async (page: Page) => { + const lastPost = page.getByTestId("postView").last(); + await lastPost.waitFor(); + return lastPost; }; diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index eefa13b2..64834b46 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -8,7 +8,12 @@ import { expect, test } from "@e2e-support/test_fixture"; import SlashCommandSuggestions from "support/components/slash_commands"; -import { fillMessage, getTodoBotDMPageURL } from "support/utils"; +import { + fillMessage, + getLastPost, + getTodoBotDMPageURL, + postMessage, +} from "support/utils"; test.beforeEach(async ({ page, pw }) => { const { adminClient, adminUser } = await pw.getAdminClient(); @@ -45,11 +50,11 @@ export default { const c = new pages.ChannelsPage(page); // # Run command to trigger help - await c.postMessage("/todo help"); + postMessage("/todo help", page); // # Grab the last post - const post = await c.getLastPost(); - const postBody = post.container.locator(".post-message__text-container"); + const post = await getLastPost(page); + const postBody = post.locator(".post-message__text-container"); // * Assert /todo add [message] command is visible await expect(postBody).toContainText(`add [message]`); From 4d5aa7055ae479d85a2c9ac18350624c712af621 Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Sun, 3 Dec 2023 20:12:05 -0600 Subject: [PATCH 07/22] reverted prettier changes --- e2e/playwright/support/utils.ts | 4 ++-- e2e/playwright/tests/test.list.ts | 2 +- e2e/playwright/tests/todo_plugin.spec.ts | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/e2e/playwright/support/utils.ts b/e2e/playwright/support/utils.ts index 7e707688..f5aeb2a3 100644 --- a/e2e/playwright/support/utils.ts +++ b/e2e/playwright/support/utils.ts @@ -1,10 +1,10 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import type { Page } from "@playwright/test"; +import type {Page} from "@playwright/test"; import Client4 from "@mattermost/client/client4"; -import { UserProfile } from "@mattermost/types/users"; +import {UserProfile} from "@mattermost/types/users"; export const waitForNewMessages = async (page: Page) => { await page.waitForTimeout(1000); diff --git a/e2e/playwright/tests/test.list.ts b/e2e/playwright/tests/test.list.ts index b3925947..e245f86d 100644 --- a/e2e/playwright/tests/test.list.ts +++ b/e2e/playwright/tests/test.list.ts @@ -1,7 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import { test } from "@playwright/test"; +import {test} from "@playwright/test"; import core from "./todo_plugin.spec"; import "../support/init_test"; diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index 64834b46..9e726a46 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -6,13 +6,13 @@ // - [*] indicates an assertion (e.g. * Check the title) // *************************************************************** -import { expect, test } from "@e2e-support/test_fixture"; +import {expect, test} from "@e2e-support/test_fixture"; import SlashCommandSuggestions from "support/components/slash_commands"; import { - fillMessage, - getLastPost, - getTodoBotDMPageURL, - postMessage, + fillMessage, + getLastPost, + getTodoBotDMPageURL, + postMessage, } from "support/utils"; test.beforeEach(async ({ page, pw }) => { From dedc5efd29392dbd3a96ed676c92e68a764ecab2 Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Mon, 4 Dec 2023 17:40:35 -0600 Subject: [PATCH 08/22] prettier changes reverted --- e2e/playwright/support/utils.ts | 71 ++++++++++-------------- e2e/playwright/tests/test.list.ts | 6 +- e2e/playwright/tests/todo_plugin.spec.ts | 54 ++++++++---------- 3 files changed, 56 insertions(+), 75 deletions(-) diff --git a/e2e/playwright/support/utils.ts b/e2e/playwright/support/utils.ts index f5aeb2a3..ae929391 100644 --- a/e2e/playwright/support/utils.ts +++ b/e2e/playwright/support/utils.ts @@ -1,74 +1,63 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import type {Page} from "@playwright/test"; +import type {Page} from '@playwright/test'; + +import Client4 from '@mattermost/client/client4'; +import {UserProfile} from '@mattermost/types/users'; -import Client4 from "@mattermost/client/client4"; -import {UserProfile} from "@mattermost/types/users"; export const waitForNewMessages = async (page: Page) => { - await page.waitForTimeout(1000); + await page.waitForTimeout(1000); - // This should be able to be waited based on locators instead of pure time-based - // The following code work "almost" always. Commented for now to have green tests. - // await page.locator('#postListContent').getByTestId('NotificationSeparator').getByText('New Messages').waitFor(); + // This should be able to be waited based on locators instead of pure time-based + // The following code work "almost" always. Commented for now to have green tests. + // 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 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 fillTextField = async ( - name: string, - value: string, - page: Page -) => { - await page.getByTestId(`${name}`).fill(value); +export const fillTextField = async (name: string, value: string, page: Page) => { + await page.getByTestId(`${name}`).fill(value); }; export const submitDialog = async (page: Page) => { - await page.click("#interactiveDialogSubmit"); + await page.click('#interactiveDialogSubmit'); }; 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) => { - await fillMessage(message, page); - await page.getByTestId("SendMessageButton").click(); + await fillMessage(message, page) + await page.getByTestId('SendMessageButton').click(); }; -export const cleanUpBotDMs = async ( - client: Client4, - userId: UserProfile["id"], - botUsername: string -) => { - const bot = await client.getUserByUsername(botUsername); +export const cleanUpBotDMs = async (client: Client4, userId: UserProfile['id'], botUsername: string) => { + const bot = await client.getUserByUsername(botUsername); - const userIds = [userId, bot.id]; - const channel = await client.createDirectChannel(userIds); - const posts = await client.getPosts(channel.id); + const userIds = [userId, bot.id]; + const channel = await client.createDirectChannel(userIds); + const posts = await client.getPosts(channel.id); - const deletePostPromises = Object.keys(posts.posts).map(client.deletePost); - await Promise.all(deletePostPromises); + const deletePostPromises = Object.keys(posts.posts).map(client.deletePost); + await Promise.all(deletePostPromises); }; export const getSlackAttachmentLocatorId = (postId: string) => { - return `#post_${postId} .attachment__body`; + return `#post_${postId} .attachment__body`; }; export const getPostMessageLocatorId = (postId: string) => { - return `#post_${postId} .post-message`; + return `#post_${postId} .post-message`; }; export const getLastPost = async (page: Page) => { diff --git a/e2e/playwright/tests/test.list.ts b/e2e/playwright/tests/test.list.ts index e245f86d..ae2f53a5 100644 --- a/e2e/playwright/tests/test.list.ts +++ b/e2e/playwright/tests/test.list.ts @@ -1,10 +1,10 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {test} from "@playwright/test"; -import core from "./todo_plugin.spec"; +import {test} from '@playwright/test'; +import core from './todo_plugin.spec'; -import "../support/init_test"; +import '../support/init_test'; // Test if plugin is setup correctly test.describe("setup", core.setup); diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index 9e726a46..9358dedd 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -6,81 +6,73 @@ // - [*] 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, - getLastPost, - getTodoBotDMPageURL, - postMessage, -} from "support/utils"; +import {expect, test} from '@e2e-support/test_fixture'; +import SlashCommandSuggestions from 'support/components/slash_commands'; +import {fillMessage, getLastPost, getTodoBotDMPageURL, postMessage, } from 'support/utils'; test.beforeEach(async ({ page, pw }) => { - const { adminClient, adminUser } = await pw.getAdminClient(); + const {adminClient, adminUser} = await pw.getAdminClient(); if (adminUser === null) { - throw new Error("can not get adminUser"); + throw new Error('can not get adminUser'); } - const dmURL = await getTodoBotDMPageURL(adminClient, "", adminUser.id); - await page.goto(dmURL, { waitUntil: "load" }); + const dmURL = await getTodoBotDMPageURL(adminClient, '', adminUser.id); + await page.goto(dmURL, {waitUntil: 'load'}); }); export default { setup: () => { - test("checking available commands", async ({ pages, page, pw }) => { - const slash = new SlashCommandSuggestions( - page.locator("#suggestionList") - ); + test('checking available commands', async ({ page }) => { + const slash = new SlashCommandSuggestions(page.locator('#suggestionList')); // # Run command to trigger todo - await fillMessage("/todo", page); + 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.getItemTitleNth(0)).toHaveText('todo [command]'); - await expect(slash.getItemDescNth(0)).toHaveText( - "Available commands: list, add, pop, send, settings, help" - ); + await expect(slash.getItemDescNth(0)).toHaveText('Available commands: list, add, pop, send, settings, help'); }); }, actions: () => { - test("help action", async ({ pages, page, pw }) => { + test('help action', async ({ pages, page, pw }) => { const c = new pages.ChannelsPage(page); // # Run command to trigger help - postMessage("/todo help", page); + postMessage('/todo help', page); // # Grab the last post const post = await getLastPost(page); - const postBody = post.locator(".post-message__text-container"); + const postBody = post.locator('.post-message__text-container'); // * Assert /todo add [message] command is visible await expect(postBody).toContainText(`add [message]`); // * Assert /todo list command is visible - await expect(postBody).toContainText("list"); + await expect(postBody).toContainText('list'); // * Assert /todo list [listName] command is visible - await expect(postBody).toContainText("list [listName]"); + await expect(postBody).toContainText('list [listName]'); // * Assert /todo pop command is visible - await expect(postBody).toContainText("pop"); + await expect(postBody).toContainText('pop'); // * Assert /todo send [user] [message] command is visible - await expect(postBody).toContainText("send [user] [message]"); + await expect(postBody).toContainText('send [user] [message]'); // * Assert /todo settings summary [on, off] command is visible - await expect(postBody).toContainText("settings summary [on, off]"); + await expect(postBody).toContainText('settings summary [on, off]'); // * Assert /todo settings allow_incoming_task_requests [on, off] command is visible await expect(postBody).toContainText( - "settings allow_incoming_task_requests [on, off]" + 'settings allow_incoming_task_requests [on, off]' ); // * Assert /todo help command is visible - await expect(postBody).toContainText("help"); + await expect(postBody).toContainText('help'); }); }, }; + From 985cba83a70987b3a1edbf808d7f0421378b2289 Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Mon, 4 Dec 2023 17:42:02 -0600 Subject: [PATCH 09/22] addressed PR comments --- e2e/playwright/tests/todo_plugin.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index 9358dedd..d8c29d86 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -36,8 +36,8 @@ export default { await expect(slash.getItemDescNth(0)).toHaveText('Available commands: list, add, pop, send, settings, help'); }); }, - actions: () => { - test('help action', async ({ pages, page, pw }) => { + commands: () => { + test('help', async ({ pages, page, pw }) => { const c = new pages.ChannelsPage(page); // # Run command to trigger help @@ -48,7 +48,7 @@ export default { const postBody = post.locator('.post-message__text-container'); // * Assert /todo add [message] command is visible - await expect(postBody).toContainText(`add [message]`); + await expect(postBody).toContainText('add [message]'); // * Assert /todo list command is visible await expect(postBody).toContainText('list'); From 49d90b9b8e864809a9381a6f421eb51c1a869d51 Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Mon, 4 Dec 2023 17:42:37 -0600 Subject: [PATCH 10/22] removed extra line --- e2e/playwright/support/utils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/e2e/playwright/support/utils.ts b/e2e/playwright/support/utils.ts index ae929391..65bc7b1c 100644 --- a/e2e/playwright/support/utils.ts +++ b/e2e/playwright/support/utils.ts @@ -6,7 +6,6 @@ import type {Page} from '@playwright/test'; import Client4 from '@mattermost/client/client4'; import {UserProfile} from '@mattermost/types/users'; - export const waitForNewMessages = async (page: Page) => { await page.waitForTimeout(1000); From 37abad14a15f8bfb60196d4b403625744c360a49 Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Mon, 4 Dec 2023 18:17:43 -0600 Subject: [PATCH 11/22] fixed issue with incorrect import --- e2e/playwright/tests/test.list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/playwright/tests/test.list.ts b/e2e/playwright/tests/test.list.ts index ae2f53a5..78b2abe0 100644 --- a/e2e/playwright/tests/test.list.ts +++ b/e2e/playwright/tests/test.list.ts @@ -10,4 +10,4 @@ import '../support/init_test'; test.describe("setup", core.setup); // Test various plugin actions -test.describe("actions", core.actions); +test.describe("actions", core.commands); From 7b53add8294a447ca3bc34b465bd7567016ed338 Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Fri, 8 Dec 2023 10:56:54 -0600 Subject: [PATCH 12/22] fixing test names and invocation methods --- e2e/playwright/tests/test.list.ts | 6 +++--- e2e/playwright/tests/todo_plugin.spec.ts | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/e2e/playwright/tests/test.list.ts b/e2e/playwright/tests/test.list.ts index 78b2abe0..dca2dc64 100644 --- a/e2e/playwright/tests/test.list.ts +++ b/e2e/playwright/tests/test.list.ts @@ -2,12 +2,12 @@ // See LICENSE.txt for license information. import {test} from '@playwright/test'; -import core from './todo_plugin.spec'; +import commands from './todo_plugin.spec'; import '../support/init_test'; // Test if plugin is setup correctly -test.describe("setup", core.setup); +test.describe("setup", commands.setup); // Test various plugin actions -test.describe("actions", core.commands); +test.describe("testing help command", commands.help); diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index d8c29d86..36625a04 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -10,7 +10,7 @@ import {expect, test} from '@e2e-support/test_fixture'; import SlashCommandSuggestions from 'support/components/slash_commands'; import {fillMessage, getLastPost, getTodoBotDMPageURL, postMessage, } from 'support/utils'; -test.beforeEach(async ({ page, pw }) => { +test.beforeEach(async ({page, pw}) => { const {adminClient, adminUser} = await pw.getAdminClient(); if (adminUser === null) { throw new Error('can not get adminUser'); @@ -21,7 +21,7 @@ test.beforeEach(async ({ page, pw }) => { export default { setup: () => { - test('checking available commands', async ({ page }) => { + test('checking available commands', async ({page}) => { const slash = new SlashCommandSuggestions(page.locator('#suggestionList')); // # Run command to trigger todo @@ -36,8 +36,9 @@ export default { await expect(slash.getItemDescNth(0)).toHaveText('Available commands: list, add, pop, send, settings, help'); }); }, - commands: () => { - test('help', async ({ pages, page, pw }) => { + + help: () => { + test('help', async ({pages, page, pw}) => { const c = new pages.ChannelsPage(page); // # Run command to trigger help @@ -73,6 +74,6 @@ export default { // * Assert /todo help command is visible await expect(postBody).toContainText('help'); }); - }, + } }; From b07e0cd05a4809eb7b4713023591bf505e31b8aa Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Fri, 8 Dec 2023 15:43:36 -0600 Subject: [PATCH 13/22] refactored code to get DM URL and teamName --- e2e/playwright/support/utils.ts | 23 ++++++++++++----------- e2e/playwright/tests/todo_plugin.spec.ts | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/e2e/playwright/support/utils.ts b/e2e/playwright/support/utils.ts index 65bc7b1c..0725ffba 100644 --- a/e2e/playwright/support/utils.ts +++ b/e2e/playwright/support/utils.ts @@ -14,13 +14,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 (client: Client4, userId: string, teamName: string, botUsername: string) => { + return `${teamName}/messages/${botUsername}`; }; export const fillTextField = async (name: string, value: string, page: Page) => { @@ -32,7 +33,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) => { @@ -60,7 +61,7 @@ export const getPostMessageLocatorId = (postId: string) => { }; export const getLastPost = async (page: Page) => { - const lastPost = page.getByTestId("postView").last(); - await lastPost.waitFor(); - return lastPost; + const lastPost = page.getByTestId("postView").last(); + await lastPost.waitFor(); + return lastPost; }; diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index 36625a04..dba785e7 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -8,14 +8,27 @@ import {expect, test} from '@e2e-support/test_fixture'; import SlashCommandSuggestions from 'support/components/slash_commands'; -import {fillMessage, getLastPost, getTodoBotDMPageURL, postMessage, } from 'support/utils'; +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) { + throw new Error('can not get adminUser'); + } + if (teamName === '') { + teamName = await getTeamName(adminClient, adminUser.id) + } +}); test.beforeEach(async ({page, pw}) => { const {adminClient, adminUser} = await pw.getAdminClient(); if (adminUser === null) { throw new Error('can not get adminUser'); } - const dmURL = await getTodoBotDMPageURL(adminClient, '', adminUser.id); + const dmURL = await getBotDMPageURL(adminClient, adminUser.id, teamName, botUserName); await page.goto(dmURL, {waitUntil: 'load'}); }); From b0c2d52f9a1697bb850a9020fa016b48d6d980ec Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Fri, 8 Dec 2023 15:49:31 -0600 Subject: [PATCH 14/22] refactored getLastPost method --- e2e/playwright/support/utils.ts | 3 ++- e2e/playwright/tests/todo_plugin.spec.ts | 19 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/e2e/playwright/support/utils.ts b/e2e/playwright/support/utils.ts index 0725ffba..d895e529 100644 --- a/e2e/playwright/support/utils.ts +++ b/e2e/playwright/support/utils.ts @@ -63,5 +63,6 @@ export const getPostMessageLocatorId = (postId: string) => { export const getLastPost = async (page: Page) => { const lastPost = page.getByTestId("postView").last(); await lastPost.waitFor(); - return lastPost; + const postBody = lastPost.locator('.post-message__text-container'); + return postBody; }; diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index dba785e7..b4509d75 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -58,34 +58,33 @@ export default { postMessage('/todo help', page); // # Grab the last post - const post = await getLastPost(page); - const postBody = post.locator('.post-message__text-container'); + const lastPost = await getLastPost(page); // * Assert /todo add [message] command is visible - await expect(postBody).toContainText('add [message]'); + await expect(lastPost).toContainText('add [message]'); // * Assert /todo list command is visible - await expect(postBody).toContainText('list'); + await expect(lastPost).toContainText('list'); // * Assert /todo list [listName] command is visible - await expect(postBody).toContainText('list [listName]'); + await expect(lastPost).toContainText('list [listName]'); // * Assert /todo pop command is visible - await expect(postBody).toContainText('pop'); + await expect(lastPost).toContainText('pop'); // * Assert /todo send [user] [message] command is visible - await expect(postBody).toContainText('send [user] [message]'); + await expect(lastPost).toContainText('send [user] [message]'); // * Assert /todo settings summary [on, off] command is visible - await expect(postBody).toContainText('settings summary [on, off]'); + await expect(lastPost).toContainText('settings summary [on, off]'); // * Assert /todo settings allow_incoming_task_requests [on, off] command is visible - await expect(postBody).toContainText( + await expect(lastPost).toContainText( 'settings allow_incoming_task_requests [on, off]' ); // * Assert /todo help command is visible - await expect(postBody).toContainText('help'); + await expect(lastPost).toContainText('help'); }); } }; From 9680eff26b7c95611ef11d552cc6d580468be569 Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Fri, 8 Dec 2023 16:05:13 -0600 Subject: [PATCH 15/22] refactored comments and test names --- e2e/playwright/tests/test.list.ts | 6 ++--- e2e/playwright/tests/todo_plugin.spec.ts | 32 ++++++++---------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/e2e/playwright/tests/test.list.ts b/e2e/playwright/tests/test.list.ts index dca2dc64..82fecacd 100644 --- a/e2e/playwright/tests/test.list.ts +++ b/e2e/playwright/tests/test.list.ts @@ -6,8 +6,8 @@ import commands from './todo_plugin.spec'; import '../support/init_test'; -// Test if plugin is setup correctly -test.describe("setup", commands.setup); +// Test if plugin shows the correct suggestions +test.describe("testing todo command", commands.todo); -// Test various plugin actions +// Test if plugin actions work correctly test.describe("testing help command", commands.help); diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index b4509d75..e836930e 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -33,12 +33,14 @@ test.beforeEach(async ({page, pw}) => { }); export default { - setup: () => { - test('checking available commands', async ({page}) => { + todo: () => { + const command = "/todo"; + + test(`${command}`, async ({page}) => { const slash = new SlashCommandSuggestions(page.locator('#suggestionList')); - // # Run command to trigger todo - await fillMessage('/todo', page); + // # Type command to show suggestions + await fillMessage(command, page); // * Assert suggestions are visible await expect(slash.container).toBeVisible(); @@ -51,39 +53,27 @@ export default { }, help: () => { - test('help', async ({pages, page, pw}) => { + const command = "/todo help"; + + test(`${command}`, async ({pages, page, pw}) => { const c = new pages.ChannelsPage(page); // # Run command to trigger help - postMessage('/todo help', page); + postMessage(command, page); // # Grab the last post const lastPost = await getLastPost(page); - // * Assert /todo add [message] command is visible + // * Assert all commands are shown in the help text output await expect(lastPost).toContainText('add [message]'); - - // * Assert /todo list command is visible await expect(lastPost).toContainText('list'); - - // * Assert /todo list [listName] command is visible await expect(lastPost).toContainText('list [listName]'); - - // * Assert /todo pop command is visible await expect(lastPost).toContainText('pop'); - - // * Assert /todo send [user] [message] command is visible await expect(lastPost).toContainText('send [user] [message]'); - - // * Assert /todo settings summary [on, off] command is visible await expect(lastPost).toContainText('settings summary [on, off]'); - - // * Assert /todo settings allow_incoming_task_requests [on, off] command is visible await expect(lastPost).toContainText( 'settings allow_incoming_task_requests [on, off]' ); - - // * Assert /todo help command is visible await expect(lastPost).toContainText('help'); }); } From 93e0490db569d4e3dd288d389351712199457cd2 Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Sat, 9 Dec 2023 07:43:13 -0600 Subject: [PATCH 16/22] fixed getBotDMPageURL arguments --- e2e/playwright/support/utils.ts | 2 +- e2e/playwright/tests/todo_plugin.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/playwright/support/utils.ts b/e2e/playwright/support/utils.ts index d895e529..74c2afd6 100644 --- a/e2e/playwright/support/utils.ts +++ b/e2e/playwright/support/utils.ts @@ -20,7 +20,7 @@ export const getTeamName = async (client: Client4, userId: string) => { return team; }; -export const getBotDMPageURL = async (client: Client4, userId: string, teamName: string, botUsername: string) => { +export const getBotDMPageURL = async (teamName: string, botUsername: string) => { return `${teamName}/messages/${botUsername}`; }; diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index e836930e..3ce4f607 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -28,7 +28,7 @@ test.beforeEach(async ({page, pw}) => { if (adminUser === null) { throw new Error('can not get adminUser'); } - const dmURL = await getBotDMPageURL(adminClient, adminUser.id, teamName, botUserName); + const dmURL = await getBotDMPageURL(teamName, botUserName); await page.goto(dmURL, {waitUntil: 'load'}); }); From 18e5802839e5fc0d4c8da03e26282f0f174d5cb1 Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Sat, 9 Dec 2023 07:46:39 -0600 Subject: [PATCH 17/22] cleaned up before test functions: --- e2e/playwright/tests/todo_plugin.spec.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index 3ce4f607..27923628 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -23,11 +23,7 @@ test.beforeAll(async ({pw}) => { } }); -test.beforeEach(async ({page, pw}) => { - const {adminClient, adminUser} = await pw.getAdminClient(); - if (adminUser === null) { - throw new Error('can not get adminUser'); - } +test.beforeEach(async ({page}) => { const dmURL = await getBotDMPageURL(teamName, botUserName); await page.goto(dmURL, {waitUntil: 'load'}); }); From 65707b4af11e41ace50159728346f16c5bb30743 Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Sun, 19 May 2024 14:18:22 -0500 Subject: [PATCH 18/22] fixed test import in test.list.ts --- e2e/playwright/tests/test.list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/playwright/tests/test.list.ts b/e2e/playwright/tests/test.list.ts index 4371d64e..3f973b88 100644 --- a/e2e/playwright/tests/test.list.ts +++ b/e2e/playwright/tests/test.list.ts @@ -1,7 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import { test } from "@playwright/test"; +import { test } from "@e2e-support/test_fixture"; import commands from "./todo_plugin.spec"; import "../support/init_test"; From 2eda53897dda2b0dd7d673d581f8251050ccccef Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Sun, 19 May 2024 18:16:31 -0500 Subject: [PATCH 19/22] fixed addTodo test --- e2e/playwright/tests/test.list.ts | 3 +++ e2e/playwright/tests/todo_plugin.spec.ts | 28 +++++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/e2e/playwright/tests/test.list.ts b/e2e/playwright/tests/test.list.ts index 3f973b88..8043d152 100644 --- a/e2e/playwright/tests/test.list.ts +++ b/e2e/playwright/tests/test.list.ts @@ -9,5 +9,8 @@ import "../support/init_test"; // Test if plugin shows the correct suggestions test.describe("testing todo command", commands.todo); +// Test if adding todo works correctly +test.describe("testing add todo command", commands.addTodo); + // Test if plugin actions work correctly test.describe("testing help command", commands.help); diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index fe2376f1..e04f4344 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -61,9 +61,7 @@ export default { help: () => { const command = "/todo help"; - test(`${command}`, async ({ pages, page, pw }) => { - const c = new pages.ChannelsPage(page); - + test(`${command}`, async ({ page }) => { // # Run command to trigger help postMessage(command, page); @@ -82,26 +80,26 @@ export default { ); await expect(lastPost).toContainText("help"); }); + }, - test("add action", async ({ pages, page, pw }) => { - const c = new pages.ChannelsPage(page); - const slash = new SlashCommandSuggestions( - page.locator("#suggestionList") - ); - const todoMessage = "Don't forget to be awesome"; + addTodo: () => { + const todoMessage = "Don't forget to be awesome"; + const command = `/todo add ${todoMessage}`; + test("/todo add ", async ({ page }) => { // # Run command to add todo - await c.postMessage(`/todo add ${todoMessage}`); + postMessage(command, page); // # Grab the last post - const post = await c.getLastPost(); - const postBody = post.container.locator(".post-message__text-container"); + const post = await getLastPost(page); + + await expect(post).toBeVisible(); - // * Assert post body has correct title - await expect(postBody).toContainText("Added Todo. Todo List:"); + await expect(post).toContainText("Added Todo. Todo List:"); + await expect(post).toContainText(todoMessage); // * Assert added todo is visible - await expect(postBody).toContainText(todoMessage); + await expect(post).toContainText(todoMessage); }); }, }; From c62b16a1a37ca1d98d34096d47c815d53697cdcb Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Sun, 19 May 2024 18:29:17 -0500 Subject: [PATCH 20/22] added /todo list test --- e2e/playwright/tests/test.list.ts | 9 +++++--- e2e/playwright/tests/todo_plugin.spec.ts | 27 ++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/e2e/playwright/tests/test.list.ts b/e2e/playwright/tests/test.list.ts index 8043d152..5f804d5b 100644 --- a/e2e/playwright/tests/test.list.ts +++ b/e2e/playwright/tests/test.list.ts @@ -7,10 +7,13 @@ import commands from "./todo_plugin.spec"; import "../support/init_test"; // Test if plugin shows the correct suggestions -test.describe("testing todo command", commands.todo); +// test.describe("testing todo command", commands.todo); // Test if adding todo works correctly -test.describe("testing add todo command", commands.addTodo); +// test.describe("testing add todo command", commands.addTodo); + +// Test if listing todo works correctly +test.describe("testing list todo command", commands.listTodo); // Test if plugin actions work correctly -test.describe("testing help command", commands.help); +// test.describe("testing help command", commands.help); diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index e04f4344..5dd9ba6e 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -63,7 +63,7 @@ export default { test(`${command}`, async ({ page }) => { // # Run command to trigger help - postMessage(command, page); + await postMessage(command, page); // # Grab the last post const lastPost = await getLastPost(page); @@ -88,7 +88,7 @@ export default { test("/todo add ", async ({ page }) => { // # Run command to add todo - postMessage(command, page); + await postMessage(command, page); // # Grab the last post const post = await getLastPost(page); @@ -102,4 +102,27 @@ export default { await expect(post).toContainText(todoMessage); }); }, + + listTodo: () => { + const todoMessage = "Don't forget to be awesome"; + + test("/todo list", async ({ page }) => { + // # Run command to add todo + await postMessage(`/todo add ${todoMessage}`, page); + + // # Type command to list todo + await postMessage(`/todo list`, page); + + // # Grab the last post + const post = await getLastPost(page); + + await expect(post).toBeVisible(); + + await expect(post).toContainText("Todo List:"); + await expect(post).toContainText(todoMessage); + + // * Assert added todo is visible + await expect(post).toContainText(todoMessage); + }); + }, }; From 0efc671208287e5f1bbf3687a1a50742f377f5bc Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Sun, 19 May 2024 21:05:48 -0500 Subject: [PATCH 21/22] comment fixes from original PRs --- e2e/playwright/tests/test.list.ts | 18 +++--- e2e/playwright/tests/todo_plugin.spec.ts | 77 +++++++++++------------- 2 files changed, 43 insertions(+), 52 deletions(-) diff --git a/e2e/playwright/tests/test.list.ts b/e2e/playwright/tests/test.list.ts index 5f804d5b..ec397b64 100644 --- a/e2e/playwright/tests/test.list.ts +++ b/e2e/playwright/tests/test.list.ts @@ -1,19 +1,19 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import { test } from "@e2e-support/test_fixture"; +import {test} from "@e2e-support/test_fixture"; import commands from "./todo_plugin.spec"; import "../support/init_test"; -// Test if plugin shows the correct suggestions -// test.describe("testing todo command", commands.todo); +// Test if plugin shows the correct suggestions for command autocomplete +test.describe("command autocomplete", commands.autocomplete); -// Test if adding todo works correctly -// test.describe("testing add todo command", commands.addTodo); +// Test `/todo add` commands +// test.describe("commands/add", commands.add); -// Test if listing todo works correctly -test.describe("testing list todo command", commands.listTodo); +// Test `/todo list` commands +// test.describe("commands/list", commands.list); -// Test if plugin actions work correctly -// test.describe("testing help command", commands.help); +// Test `/todo help` commands +// test.describe("commands/help", commands.help); diff --git a/e2e/playwright/tests/todo_plugin.spec.ts b/e2e/playwright/tests/todo_plugin.spec.ts index 5dd9ba6e..5036dd29 100644 --- a/e2e/playwright/tests/todo_plugin.spec.ts +++ b/e2e/playwright/tests/todo_plugin.spec.ts @@ -6,14 +6,14 @@ // - [*] indicates an assertion (e.g. * Check the title) // *************************************************************** -import { expect, test } from "@e2e-support/test_fixture"; +import {expect, test} from "@e2e-support/test_fixture"; import SlashCommandSuggestions from "support/components/slash_commands"; import { - fillMessage, - getBotDMPageURL, - getLastPost, - getTeamName, - postMessage, + fillMessage, + getBotDMPageURL, + getLastPost, + getTeamName, + postMessage, } from "support/utils"; const botUserName = "todo"; @@ -35,16 +35,14 @@ test.beforeEach(async ({ page }) => { }); export default { - todo: () => { - const command = "/todo"; - - test(`${command}`, async ({ page }) => { + autocomplete: () => { + test('/todo', async ({ page }) => { const slash = new SlashCommandSuggestions( page.locator("#suggestionList") ); // # Type command to show suggestions - await fillMessage(command, page); + await fillMessage('/todo', page); // * Assert suggestions are visible await expect(slash.container).toBeVisible(); @@ -52,45 +50,38 @@ export default { // * Assert todo [command] is visible await expect(slash.getItemTitleNth(0)).toHaveText("todo [command]"); - await expect(slash.getItemDescNth(0)).toHaveText( - "Available commands: list, add, pop, send, settings, help" + await expect(slash.getItemDescNth(0)).toContainText( + "Available commands:" ); }); }, help: () => { - const command = "/todo help"; - - test(`${command}`, async ({ page }) => { + test('/todo help', async ({ page }) => { // # Run command to trigger help - await postMessage(command, page); - - // # Grab the last post - const lastPost = await getLastPost(page); - - // * Assert all commands are shown in the help text output - await expect(lastPost).toContainText("add [message]"); - await expect(lastPost).toContainText("list"); - await expect(lastPost).toContainText("list [listName]"); - await expect(lastPost).toContainText("pop"); - await expect(lastPost).toContainText("send [user] [message]"); - await expect(lastPost).toContainText("settings summary [on, off]"); - await expect(lastPost).toContainText( - "settings allow_incoming_task_requests [on, off]" - ); - await expect(lastPost).toContainText("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); }); }, - addTodo: () => { - const todoMessage = "Don't forget to be awesome"; - const command = `/todo add ${todoMessage}`; - + add: () => { test("/todo add ", async ({ page }) => { + const todoMessage = "Don't forget to be awesome"; + // # Run command to add todo - await postMessage(command, page); + await postMessage(`/todo add ${todoMessage}`, page); - // # Grab the last post + // # Get ephemeral post response from todo add command const post = await getLastPost(page); await expect(post).toBeVisible(); @@ -103,17 +94,17 @@ export default { }); }, - listTodo: () => { - const todoMessage = "Don't forget to be awesome"; - + list: () => { test("/todo list", async ({ page }) => { + const todoMessage = "Don't forget to be awesome"; + // # Run command to add todo await postMessage(`/todo add ${todoMessage}`, page); // # Type command to list todo - await postMessage(`/todo list`, page); + await postMessage('/todo list', page); - // # Grab the last post + // # Get ephemeral post response from todo list command const post = await getLastPost(page); await expect(post).toBeVisible(); From 9b17b5e4ba0f8696c26b8bd99e13a5bc682c911c Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Sun, 19 May 2024 21:16:20 -0500 Subject: [PATCH 22/22] uncommented lines in test.list.ts --- e2e/playwright/support/utils.ts | 3 +-- e2e/playwright/tests/test.list.ts | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/e2e/playwright/support/utils.ts b/e2e/playwright/support/utils.ts index 74c2afd6..03229014 100644 --- a/e2e/playwright/support/utils.ts +++ b/e2e/playwright/support/utils.ts @@ -2,9 +2,8 @@ // See LICENSE.txt for license information. import type {Page} from '@playwright/test'; - -import Client4 from '@mattermost/client/client4'; import {UserProfile} from '@mattermost/types/users'; +import Client4 from '@mattermost/client/client4'; export const waitForNewMessages = async (page: Page) => { await page.waitForTimeout(1000); diff --git a/e2e/playwright/tests/test.list.ts b/e2e/playwright/tests/test.list.ts index ec397b64..d88a0f8a 100644 --- a/e2e/playwright/tests/test.list.ts +++ b/e2e/playwright/tests/test.list.ts @@ -10,10 +10,10 @@ import "../support/init_test"; test.describe("command autocomplete", commands.autocomplete); // Test `/todo add` commands -// test.describe("commands/add", commands.add); +test.describe("commands/add", commands.add); // Test `/todo list` commands -// test.describe("commands/list", commands.list); +test.describe("commands/list", commands.list); // Test `/todo help` commands -// test.describe("commands/help", commands.help); +test.describe("commands/help", commands.help);