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 all 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
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
26 changes: 17 additions & 9 deletions e2e/playwright/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

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

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);
Expand All @@ -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 All @@ -58,3 +59,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;
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.

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

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

import {expect, test} from '@e2e-support/test_fixture';
import SlashCommandSuggestions from 'support/components/slash_commands';
import {fillMessage, getTodoBotDMPageURL} 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}) => {
const dmURL = await getBotDMPageURL(teamName, botUserName);
await page.goto(dmURL, {waitUntil: 'load'});
});

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');
});
});
},
todo: () => {
const command = "/todo";

test(`${command}`, async ({page}) => {
const slash = new SlashCommandSuggestions(page.locator('#suggestionList'));

// # Type command to show suggestions
await fillMessage(command, 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');
rahulsuresh-git marked this conversation as resolved.
Show resolved Hide resolved
});
},

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(command, page);
rahulsuresh-git marked this conversation as resolved.
Show resolved Hide resolved

// # Grab the last post
const lastPost = await getLastPost(page);
rahulsuresh-git marked this conversation as resolved.
Show resolved Hide resolved

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