|
| 1 | +/* |
| 2 | +Copyright 2024 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import { test, expect } from "../../element-web-test"; |
| 18 | +import { Bot } from "../../pages/bot"; |
| 19 | + |
| 20 | +test.describe("Landmark navigation tests", () => { |
| 21 | + test.use({ |
| 22 | + displayName: "Alice", |
| 23 | + }); |
| 24 | + |
| 25 | + test("without any rooms", async ({ page, homeserver, app, user }) => { |
| 26 | + /** |
| 27 | + * Without any rooms, there is no tile in the roomlist to be focused. |
| 28 | + * So the next landmark in the list should be focused instead. |
| 29 | + */ |
| 30 | + |
| 31 | + // Pressing Control+F6 will first focus the space button |
| 32 | + await page.keyboard.press("ControlOrMeta+F6"); |
| 33 | + await expect(page.locator(".mx_SpaceButton_active")).toBeFocused(); |
| 34 | + |
| 35 | + // Pressing Control+F6 again will focus room search |
| 36 | + await page.keyboard.press("ControlOrMeta+F6"); |
| 37 | + await expect(page.locator(".mx_RoomSearch")).toBeFocused(); |
| 38 | + |
| 39 | + // Pressing Control+F6 again will focus the message composer |
| 40 | + await page.keyboard.press("ControlOrMeta+F6"); |
| 41 | + await expect(page.locator(".mx_HomePage")).toBeFocused(); |
| 42 | + |
| 43 | + // Pressing Control+F6 again will bring focus back to the space button |
| 44 | + await page.keyboard.press("ControlOrMeta+F6"); |
| 45 | + await expect(page.locator(".mx_SpaceButton_active")).toBeFocused(); |
| 46 | + |
| 47 | + // Now go back in the same order |
| 48 | + await page.keyboard.press("ControlOrMeta+Shift+F6"); |
| 49 | + await expect(page.locator(".mx_HomePage")).toBeFocused(); |
| 50 | + |
| 51 | + await page.keyboard.press("ControlOrMeta+Shift+F6"); |
| 52 | + await expect(page.locator(".mx_RoomSearch")).toBeFocused(); |
| 53 | + |
| 54 | + await page.keyboard.press("ControlOrMeta+Shift+F6"); |
| 55 | + await expect(page.locator(".mx_SpaceButton_active")).toBeFocused(); |
| 56 | + }); |
| 57 | + |
| 58 | + test("with an open room", async ({ page, homeserver, app, user }) => { |
| 59 | + const bob = new Bot(page, homeserver, { displayName: "Bob" }); |
| 60 | + await bob.prepareClient(); |
| 61 | + |
| 62 | + // create dm with bob |
| 63 | + await app.client.evaluate( |
| 64 | + async (cli, { bob }) => { |
| 65 | + const bobRoom = await cli.createRoom({ is_direct: true }); |
| 66 | + await cli.invite(bobRoom.room_id, bob); |
| 67 | + }, |
| 68 | + { |
| 69 | + bob: bob.credentials.userId, |
| 70 | + }, |
| 71 | + ); |
| 72 | + |
| 73 | + await app.viewRoomByName("Bob"); |
| 74 | + // confirm the room was loaded |
| 75 | + await expect(page.getByText("Bob joined the room")).toBeVisible(); |
| 76 | + |
| 77 | + // Pressing Control+F6 will first focus the space button |
| 78 | + await page.keyboard.press("ControlOrMeta+F6"); |
| 79 | + await expect(page.locator(".mx_SpaceButton_active")).toBeFocused(); |
| 80 | + |
| 81 | + // Pressing Control+F6 again will focus room search |
| 82 | + await page.keyboard.press("ControlOrMeta+F6"); |
| 83 | + await expect(page.locator(".mx_RoomSearch")).toBeFocused(); |
| 84 | + |
| 85 | + // Pressing Control+F6 again will focus the room tile in the room list |
| 86 | + await page.keyboard.press("ControlOrMeta+F6"); |
| 87 | + await expect(page.locator(".mx_RoomTile_selected")).toBeFocused(); |
| 88 | + |
| 89 | + // Pressing Control+F6 again will focus the message composer |
| 90 | + await page.keyboard.press("ControlOrMeta+F6"); |
| 91 | + await expect(page.locator(".mx_BasicMessageComposer_input")).toBeFocused(); |
| 92 | + |
| 93 | + // Pressing Control+F6 again will bring focus back to the space button |
| 94 | + await page.keyboard.press("ControlOrMeta+F6"); |
| 95 | + await expect(page.locator(".mx_SpaceButton_active")).toBeFocused(); |
| 96 | + |
| 97 | + // Now go back in the same order |
| 98 | + await page.keyboard.press("ControlOrMeta+Shift+F6"); |
| 99 | + await expect(page.locator(".mx_BasicMessageComposer_input")).toBeFocused(); |
| 100 | + |
| 101 | + await page.keyboard.press("ControlOrMeta+Shift+F6"); |
| 102 | + await expect(page.locator(".mx_RoomTile_selected")).toBeFocused(); |
| 103 | + |
| 104 | + await page.keyboard.press("ControlOrMeta+Shift+F6"); |
| 105 | + await expect(page.locator(".mx_RoomSearch")).toBeFocused(); |
| 106 | + |
| 107 | + await page.keyboard.press("ControlOrMeta+Shift+F6"); |
| 108 | + await expect(page.locator(".mx_SpaceButton_active")).toBeFocused(); |
| 109 | + }); |
| 110 | + |
| 111 | + test("without an open room", async ({ page, homeserver, app, user }) => { |
| 112 | + const bob = new Bot(page, homeserver, { displayName: "Bob" }); |
| 113 | + await bob.prepareClient(); |
| 114 | + |
| 115 | + // create a dm with bob |
| 116 | + await app.client.evaluate( |
| 117 | + async (cli, { bob }) => { |
| 118 | + const bobRoom = await cli.createRoom({ is_direct: true }); |
| 119 | + await cli.invite(bobRoom.room_id, bob); |
| 120 | + }, |
| 121 | + { |
| 122 | + bob: bob.credentials.userId, |
| 123 | + }, |
| 124 | + ); |
| 125 | + |
| 126 | + await app.viewRoomByName("Bob"); |
| 127 | + // confirm the room was loaded |
| 128 | + await expect(page.getByText("Bob joined the room")).toBeVisible(); |
| 129 | + |
| 130 | + // Close the room |
| 131 | + page.goto("/#/home"); |
| 132 | + |
| 133 | + // Pressing Control+F6 will first focus the space button |
| 134 | + await page.keyboard.press("ControlOrMeta+F6"); |
| 135 | + await expect(page.locator(".mx_SpaceButton_active")).toBeFocused(); |
| 136 | + |
| 137 | + // Pressing Control+F6 again will focus room search |
| 138 | + await page.keyboard.press("ControlOrMeta+F6"); |
| 139 | + await expect(page.locator(".mx_RoomSearch")).toBeFocused(); |
| 140 | + |
| 141 | + // Pressing Control+F6 again will focus the room tile in the room list |
| 142 | + await page.keyboard.press("ControlOrMeta+F6"); |
| 143 | + await expect(page.locator(".mx_RoomTile")).toBeFocused(); |
| 144 | + |
| 145 | + // Pressing Control+F6 again will focus the home section |
| 146 | + await page.keyboard.press("ControlOrMeta+F6"); |
| 147 | + await expect(page.locator(".mx_HomePage")).toBeFocused(); |
| 148 | + |
| 149 | + // Pressing Control+F6 will bring focus back to the space button |
| 150 | + await page.keyboard.press("ControlOrMeta+F6"); |
| 151 | + await expect(page.locator(".mx_SpaceButton_active")).toBeFocused(); |
| 152 | + |
| 153 | + // Now go back in same order |
| 154 | + await page.keyboard.press("ControlOrMeta+Shift+F6"); |
| 155 | + await expect(page.locator(".mx_HomePage")).toBeFocused(); |
| 156 | + |
| 157 | + await page.keyboard.press("ControlOrMeta+Shift+F6"); |
| 158 | + await expect(page.locator(".mx_RoomTile")).toBeFocused(); |
| 159 | + |
| 160 | + await page.keyboard.press("ControlOrMeta+Shift+F6"); |
| 161 | + await expect(page.locator(".mx_RoomSearch")).toBeFocused(); |
| 162 | + |
| 163 | + await page.keyboard.press("ControlOrMeta+Shift+F6"); |
| 164 | + await expect(page.locator(".mx_SpaceButton_active")).toBeFocused(); |
| 165 | + }); |
| 166 | +}); |
0 commit comments