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