Skip to content

Commit 3a78ee8

Browse files
Added keyboard navigation tests
1 parent f028070 commit 3a78ee8

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import React from 'react';
5+
import { expect } from '@playwright/experimental-ct-react';
6+
import { test as betaTest } from './FlavoredBaseTest';
7+
import { COMPONENT_LOCALE_EN_US } from '../../src';
8+
import {
9+
FluentChatMessageComponentWrapperProps,
10+
FluentChatMessageComponent
11+
} from '../../src/components/ChatMessage/MessageComponents/FluentChatMessageComponent';
12+
13+
betaTest.describe('FluentChatMessageComponent keyboard navigation tests', () => {
14+
const localeStrings = COMPONENT_LOCALE_EN_US.strings;
15+
16+
const props: FluentChatMessageComponentWrapperProps = {
17+
key: '1',
18+
statusToRender: undefined,
19+
shouldOverlapAvatarAndMessage: false,
20+
onActionButtonClick: () => {},
21+
strings: localeStrings.messageThread,
22+
onRenderMessageStatus: undefined,
23+
styles: undefined,
24+
defaultStatusRenderer: () => <></>,
25+
message: {
26+
content: 'Hello World!',
27+
messageId: '1',
28+
attached: true,
29+
messageType: 'chat',
30+
contentType: 'html',
31+
createdOn: new Date(),
32+
mine: false
33+
},
34+
userId: '1'
35+
};
36+
37+
betaTest('User can navigate to message using keyboard', async ({ mount, page }) => {
38+
const component = await mount(<FluentChatMessageComponent {...props} />);
39+
40+
await page.keyboard.press('Tab');
41+
const messageBody = component.getByTestId('chat-composite-message');
42+
await expect(messageBody).toBeVisible();
43+
await expect(messageBody).toBeFocused();
44+
45+
// check that focus stays on the message and not moved anywhere after additional Enter key press
46+
await page.keyboard.press('Enter');
47+
await expect(messageBody).toBeFocused();
48+
});
49+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import React from 'react';
5+
import { expect } from '@playwright/experimental-ct-react';
6+
import { test as betaTest } from './FlavoredBaseTest';
7+
import { COMPONENT_LOCALE_EN_US } from '../../src';
8+
import { Locator, Page } from 'playwright-core';
9+
import { FluentChatMyMessageComponent } from '../../src/components/ChatMessage/MyMessageComponents/FluentChatMyMessageComponent';
10+
import { FluentChatMessageComponentWrapperProps } from '../../src/components/ChatMessage/MessageComponents/FluentChatMessageComponent';
11+
12+
betaTest.describe('FluentChatMyMessageComponent keyboard navigation tests', () => {
13+
const localeStrings = COMPONENT_LOCALE_EN_US.strings;
14+
15+
const props: FluentChatMessageComponentWrapperProps = {
16+
key: '1',
17+
statusToRender: undefined,
18+
shouldOverlapAvatarAndMessage: false,
19+
onActionButtonClick: () => {},
20+
strings: localeStrings.messageThread,
21+
onRenderMessageStatus: undefined,
22+
styles: undefined,
23+
defaultStatusRenderer: () => <></>,
24+
message: {
25+
content: 'Hello World!',
26+
messageId: '1',
27+
attached: true,
28+
messageType: 'chat',
29+
contentType: 'html',
30+
createdOn: new Date(),
31+
mine: true
32+
},
33+
userId: '1'
34+
};
35+
36+
betaTest('User can navigate to message and edit message using keyboard', async ({ mount, page }) => {
37+
const component = await mount(<FluentChatMyMessageComponent {...props} />);
38+
39+
await showMoreMenuButton(component, page);
40+
await openMoreMenu(component, page);
41+
42+
// start editing
43+
await page.keyboard.press('Enter');
44+
await expect(component.getByTestId('chat-message-edit-box-cancel-button')).toBeVisible();
45+
await expect(component.getByTestId('chat-message-edit-box-submit-button')).toBeVisible();
46+
47+
await page.keyboard.press('Tab');
48+
await expect(component.getByTestId('chat-message-edit-box-cancel-button')).toBeFocused();
49+
await page.keyboard.press('Tab');
50+
await expect(component.getByTestId('chat-message-edit-box-submit-button')).toBeFocused();
51+
await page.keyboard.press('Enter');
52+
53+
const messageBody = component.getByTestId('chat-composite-message');
54+
await expect(messageBody).toBeVisible();
55+
await expect(messageBody).toBeFocused();
56+
57+
await expect(component.getByTestId('chat-composite-message-action-icon')).toBeVisible();
58+
});
59+
60+
betaTest('User can navigate to message and cancel message editing using keyboard', async ({ mount, page }) => {
61+
const component = await mount(<FluentChatMyMessageComponent {...props} />);
62+
63+
await showMoreMenuButton(component, page);
64+
await openMoreMenu(component, page);
65+
66+
// start editing
67+
await page.keyboard.press('Enter');
68+
await expect(component.getByTestId('chat-message-edit-box-cancel-button')).toBeVisible();
69+
await expect(component.getByTestId('chat-message-edit-box-submit-button')).toBeVisible();
70+
71+
await page.keyboard.press('Tab');
72+
await expect(component.getByTestId('chat-message-edit-box-cancel-button')).toBeFocused();
73+
await page.keyboard.press('Enter');
74+
75+
const messageBody = component.getByTestId('chat-composite-message');
76+
await expect(messageBody).toBeVisible();
77+
await expect(messageBody).toBeFocused();
78+
79+
await expect(component.getByTestId('chat-composite-message-action-icon')).toBeVisible();
80+
});
81+
});
82+
83+
const showMoreMenuButton = async (component: Locator, page: Page): Promise<void> => {
84+
await component.evaluate(() => document.fonts.ready);
85+
const messageBody = component.getByTestId('chat-composite-message');
86+
await expect(messageBody).toBeVisible();
87+
await page.keyboard.press('Tab');
88+
89+
await expect(messageBody).toBeFocused();
90+
91+
await expect(component.getByTestId('chat-composite-message-action-icon')).toBeVisible();
92+
};
93+
94+
const openMoreMenu = async (component: Locator, page: Page): Promise<void> => {
95+
// navigate to message menu
96+
await page.keyboard.press('Enter');
97+
await expect(component.getByTestId('chat-composite-message-action-icon')).toBeFocused();
98+
99+
// open message menu
100+
await page.keyboard.press('Enter');
101+
102+
// page is used here as more menu is not part of the component
103+
const editButton = page.getByTestId('chat-composite-message-contextual-menu-edit-action');
104+
await expect(editButton).toBeVisible();
105+
await expect(page.getByTestId('chat-composite-message-contextual-menu-remove-action')).toBeVisible();
106+
await expect(editButton).toBeFocused();
107+
};

0 commit comments

Comments
 (0)