From 861f546af6b609dcf7f649f9ec3b47f1f2a3b196 Mon Sep 17 00:00:00 2001 From: Rahul Suresh Date: Sun, 3 Dec 2023 13:14:54 -0600 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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); + }); }, };