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 e2e test for /todo help command #238

Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
24 changes: 13 additions & 11 deletions e2e/playwright/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (teamName: string, botUsername: string) => {
return `${teamName}/messages/${botUsername}`;
};

export const fillTextField = async (name: string, value: string, page: Page) => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -60,7 +61,8 @@ 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();
const postBody = lastPost.locator('.post-message__text-container');
return postBody;
Comment on lines +66 to +67
Copy link
Contributor

Choose a reason for hiding this comment

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

Sometimes we'll want to parse other things from the post and not just the body. Maybe we can create a separate function getLastPostBody or getLastPostText and have it call getLastPost.

I'm mainly trying to be weary of any changes to the "meaning" of functions that are already in files being shared among the plugin projects. That's one of the main focuses on the e2e framework. This is essentially an externally facing API for other plugins to use.

};
10 changes: 5 additions & 5 deletions e2e/playwright/tests/test.list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 if plugin shows the correct suggestions
test.describe("testing todo command", commands.todo);

// Test various plugin actions
test.describe("actions", core.commands);
// Test if plugin actions work correctly
test.describe("testing help command", commands.help);
rahulsuresh-git marked this conversation as resolved.
Show resolved Hide resolved
73 changes: 36 additions & 37 deletions e2e/playwright/tests/todo_plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,35 @@

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';

test.beforeEach(async ({ page, pw }) => {
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');
}
const dmURL = await getTodoBotDMPageURL(adminClient, '', adminUser.id);
if (teamName === '') {
teamName = await getTeamName(adminClient, adminUser.id)
}
});

test.beforeEach(async ({page}) => {
const dmURL = await getBotDMPageURL(teamName, botUserName);
await page.goto(dmURL, {waitUntil: 'load'});
});

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();
Expand All @@ -36,43 +47,31 @@ export default {
await expect(slash.getItemDescNth(0)).toHaveText('Available commands: list, add, pop, send, settings, help');
rahulsuresh-git marked this conversation as resolved.
Show resolved Hide resolved
});
},
commands: () => {
test('help', async ({ pages, page, pw }) => {

help: () => {
const command = "/todo help";

test(`${command}`, async ({pages, page, pw}) => {
rahulsuresh-git marked this conversation as resolved.
Show resolved Hide resolved
const c = new pages.ChannelsPage(page);

// # Run command to trigger help
postMessage('/todo help', page);
postMessage(command, page);
rahulsuresh-git marked this conversation as resolved.
Show resolved Hide resolved

// # Grab the last post
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]');

// * 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 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 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(
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]');
rahulsuresh-git marked this conversation as resolved.
Show resolved Hide resolved
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');
});
},
}
};