|
| 1 | +import { faker } from '@faker-js/faker'; |
| 2 | + |
| 3 | +import { Users } from '../fixtures/userStates'; |
| 4 | +import { HomeChannel } from '../page-objects'; |
| 5 | +import { preserveSettings } from '../utils/preserveSettings'; |
| 6 | +import { test, expect } from '../utils/test'; |
| 7 | + |
| 8 | +const settingsList = [ |
| 9 | + 'E2E_Enable', |
| 10 | + 'E2E_Allow_Unencrypted_Messages', |
| 11 | + 'E2E_Enabled_Default_DirectRooms', |
| 12 | + 'E2E_Enabled_Default_PrivateRooms', |
| 13 | +]; |
| 14 | + |
| 15 | +preserveSettings(settingsList); |
| 16 | + |
| 17 | +test.describe('E2EE Encrypted Channels', () => { |
| 18 | + let poHomeChannel: HomeChannel; |
| 19 | + |
| 20 | + test.use({ storageState: Users.userE2EE.state }); |
| 21 | + |
| 22 | + test.beforeAll(async ({ api }) => { |
| 23 | + await api.post('/settings/E2E_Enable', { value: true }); |
| 24 | + await api.post('/settings/E2E_Allow_Unencrypted_Messages', { value: true }); |
| 25 | + await api.post('/settings/E2E_Enabled_Default_DirectRooms', { value: false }); |
| 26 | + await api.post('/settings/E2E_Enabled_Default_PrivateRooms', { value: false }); |
| 27 | + await api.post('/im.delete', { username: 'user2' }); |
| 28 | + }); |
| 29 | + |
| 30 | + test.beforeEach(async ({ page }) => { |
| 31 | + poHomeChannel = new HomeChannel(page); |
| 32 | + await page.goto('/home'); |
| 33 | + }); |
| 34 | + |
| 35 | + test('expect create a private channel encrypted and send an encrypted message', async ({ page }) => { |
| 36 | + const channelName = faker.string.uuid(); |
| 37 | + |
| 38 | + await poHomeChannel.sidenav.createEncryptedChannel(channelName); |
| 39 | + |
| 40 | + await expect(page).toHaveURL(`/group/${channelName}`); |
| 41 | + |
| 42 | + await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeVisible(); |
| 43 | + |
| 44 | + await poHomeChannel.content.sendMessage('hello world'); |
| 45 | + |
| 46 | + await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('hello world'); |
| 47 | + await expect(poHomeChannel.content.lastUserMessage.locator('.rcx-icon--name-key')).toBeVisible(); |
| 48 | + |
| 49 | + await poHomeChannel.tabs.kebab.click({ force: true }); |
| 50 | + |
| 51 | + await expect(poHomeChannel.tabs.btnDisableE2E).toBeVisible(); |
| 52 | + await poHomeChannel.tabs.btnDisableE2E.click({ force: true }); |
| 53 | + await expect(page.getByRole('dialog', { name: 'Disable encryption' })).toBeVisible(); |
| 54 | + await page.getByRole('button', { name: 'Disable encryption' }).click(); |
| 55 | + await poHomeChannel.dismissToast(); |
| 56 | + await page.waitForTimeout(1000); |
| 57 | + |
| 58 | + await poHomeChannel.content.sendMessage('hello world not encrypted'); |
| 59 | + |
| 60 | + await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('hello world not encrypted'); |
| 61 | + await expect(poHomeChannel.content.lastUserMessage.locator('.rcx-icon--name-key')).not.toBeVisible(); |
| 62 | + |
| 63 | + await poHomeChannel.tabs.kebab.click({ force: true }); |
| 64 | + await expect(poHomeChannel.tabs.btnEnableE2E).toBeVisible(); |
| 65 | + await poHomeChannel.tabs.btnEnableE2E.click({ force: true }); |
| 66 | + await expect(page.getByRole('dialog', { name: 'Enable encryption' })).toBeVisible(); |
| 67 | + await page.getByRole('button', { name: 'Enable encryption' }).click(); |
| 68 | + await poHomeChannel.dismissToast(); |
| 69 | + await page.waitForTimeout(1000); |
| 70 | + |
| 71 | + await poHomeChannel.content.sendMessage('hello world encrypted again'); |
| 72 | + |
| 73 | + await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('hello world encrypted again'); |
| 74 | + await expect(poHomeChannel.content.lastUserMessage.locator('.rcx-icon--name-key')).toBeVisible(); |
| 75 | + }); |
| 76 | + |
| 77 | + test('expect create a private encrypted channel and send a encrypted thread message', async ({ page }) => { |
| 78 | + const channelName = faker.string.uuid(); |
| 79 | + |
| 80 | + await poHomeChannel.sidenav.createEncryptedChannel(channelName); |
| 81 | + |
| 82 | + await expect(page).toHaveURL(`/group/${channelName}`); |
| 83 | + |
| 84 | + await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeVisible(); |
| 85 | + |
| 86 | + await poHomeChannel.content.sendMessage('This is the thread main message.'); |
| 87 | + |
| 88 | + await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('This is the thread main message.'); |
| 89 | + await expect(poHomeChannel.content.lastUserMessage.locator('.rcx-icon--name-key')).toBeVisible(); |
| 90 | + |
| 91 | + await page.locator('[data-qa-type="message"]').last().hover(); |
| 92 | + await page.locator('role=button[name="Reply in thread"]').click(); |
| 93 | + |
| 94 | + await expect(page).toHaveURL(/.*thread/); |
| 95 | + |
| 96 | + await expect(poHomeChannel.content.mainThreadMessageText).toContainText('This is the thread main message.'); |
| 97 | + await expect(poHomeChannel.content.mainThreadMessageText.locator('.rcx-icon--name-key')).toBeVisible(); |
| 98 | + |
| 99 | + await poHomeChannel.content.toggleAlsoSendThreadToChannel(true); |
| 100 | + await page.getByRole('dialog').locator('[name="msg"]').last().fill('This is an encrypted thread message also sent in channel'); |
| 101 | + await page.keyboard.press('Enter'); |
| 102 | + await expect(poHomeChannel.content.lastThreadMessageText).toContainText('This is an encrypted thread message also sent in channel'); |
| 103 | + await expect(poHomeChannel.content.lastThreadMessageText.locator('.rcx-icon--name-key')).toBeVisible(); |
| 104 | + await expect(poHomeChannel.content.lastUserMessage).toContainText('This is an encrypted thread message also sent in channel'); |
| 105 | + await expect(poHomeChannel.content.mainThreadMessageText).toContainText('This is the thread main message.'); |
| 106 | + await expect(poHomeChannel.content.mainThreadMessageText.locator('.rcx-icon--name-key')).toBeVisible(); |
| 107 | + }); |
| 108 | + |
| 109 | + test('expect create a private encrypted channel and check disabled message menu actions on an encrypted message', async ({ page }) => { |
| 110 | + const channelName = faker.string.uuid(); |
| 111 | + |
| 112 | + await poHomeChannel.sidenav.createEncryptedChannel(channelName); |
| 113 | + |
| 114 | + await expect(page).toHaveURL(`/group/${channelName}`); |
| 115 | + |
| 116 | + await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeVisible(); |
| 117 | + |
| 118 | + await poHomeChannel.content.sendMessage('This is an encrypted message.'); |
| 119 | + |
| 120 | + await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('This is an encrypted message.'); |
| 121 | + await expect(poHomeChannel.content.lastUserMessage.locator('.rcx-icon--name-key')).toBeVisible(); |
| 122 | + |
| 123 | + await page.locator('[data-qa-type="message"]').last().hover(); |
| 124 | + await expect(page.locator('role=button[name="Forward message not available on encrypted content"]')).toBeDisabled(); |
| 125 | + |
| 126 | + await poHomeChannel.content.openLastMessageMenu(); |
| 127 | + |
| 128 | + await expect(page.locator('role=menuitem[name="Reply in direct message"]')).toHaveClass(/disabled/); |
| 129 | + await expect(page.locator('role=menuitem[name="Copy link"]')).toHaveClass(/disabled/); |
| 130 | + }); |
| 131 | + |
| 132 | + test('expect create a private channel, encrypt it and send an encrypted message', async ({ page }) => { |
| 133 | + const channelName = faker.string.uuid(); |
| 134 | + |
| 135 | + await poHomeChannel.sidenav.openNewByLabel('Channel'); |
| 136 | + await poHomeChannel.sidenav.inputChannelName.fill(channelName); |
| 137 | + await poHomeChannel.sidenav.btnCreate.click(); |
| 138 | + |
| 139 | + await expect(page).toHaveURL(`/group/${channelName}`); |
| 140 | + |
| 141 | + await expect(poHomeChannel.toastSuccess).toBeVisible(); |
| 142 | + |
| 143 | + await poHomeChannel.dismissToast(); |
| 144 | + |
| 145 | + await poHomeChannel.tabs.kebab.click(); |
| 146 | + await expect(poHomeChannel.tabs.btnEnableE2E).toBeVisible(); |
| 147 | + await poHomeChannel.tabs.btnEnableE2E.click(); |
| 148 | + await expect(page.getByRole('dialog', { name: 'Enable encryption' })).toBeVisible(); |
| 149 | + await page.getByRole('button', { name: 'Enable encryption' }).click(); |
| 150 | + await page.waitForTimeout(1000); |
| 151 | + |
| 152 | + await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeVisible(); |
| 153 | + |
| 154 | + await poHomeChannel.content.sendMessage('hello world'); |
| 155 | + |
| 156 | + await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('hello world'); |
| 157 | + await expect(poHomeChannel.content.lastUserMessage.locator('.rcx-icon--name-key')).toBeVisible(); |
| 158 | + }); |
| 159 | + |
| 160 | + test('expect create a encrypted private channel and mention user', async ({ page }) => { |
| 161 | + const channelName = faker.string.uuid(); |
| 162 | + |
| 163 | + await poHomeChannel.sidenav.createEncryptedChannel(channelName); |
| 164 | + |
| 165 | + await expect(page).toHaveURL(`/group/${channelName}`); |
| 166 | + |
| 167 | + await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeVisible(); |
| 168 | + |
| 169 | + await poHomeChannel.content.sendMessage('hello @user1'); |
| 170 | + |
| 171 | + const userMention = page.getByRole('button', { |
| 172 | + name: 'user1', |
| 173 | + }); |
| 174 | + |
| 175 | + await expect(userMention).toBeVisible(); |
| 176 | + }); |
| 177 | + |
| 178 | + test('expect create a encrypted private channel, mention a channel and navigate to it', async ({ page }) => { |
| 179 | + const channelName = faker.string.uuid(); |
| 180 | + |
| 181 | + await poHomeChannel.sidenav.createEncryptedChannel(channelName); |
| 182 | + |
| 183 | + await expect(page).toHaveURL(`/group/${channelName}`); |
| 184 | + |
| 185 | + await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeVisible(); |
| 186 | + |
| 187 | + await poHomeChannel.content.sendMessage('Are you in the #general channel?'); |
| 188 | + |
| 189 | + const channelMention = page.getByRole('button', { |
| 190 | + name: 'general', |
| 191 | + }); |
| 192 | + |
| 193 | + await expect(channelMention).toBeVisible(); |
| 194 | + |
| 195 | + await channelMention.click(); |
| 196 | + |
| 197 | + await expect(page).toHaveURL(`/channel/general`); |
| 198 | + }); |
| 199 | + |
| 200 | + test('expect create a encrypted private channel, mention a channel and user', async ({ page }) => { |
| 201 | + const channelName = faker.string.uuid(); |
| 202 | + |
| 203 | + await poHomeChannel.sidenav.createEncryptedChannel(channelName); |
| 204 | + |
| 205 | + await expect(page).toHaveURL(`/group/${channelName}`); |
| 206 | + |
| 207 | + await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeVisible(); |
| 208 | + |
| 209 | + await poHomeChannel.content.sendMessage('Are you in the #general channel, @user1 ?'); |
| 210 | + |
| 211 | + const channelMention = page.getByRole('button', { |
| 212 | + name: 'general', |
| 213 | + }); |
| 214 | + |
| 215 | + const userMention = page.getByRole('button', { |
| 216 | + name: 'user1', |
| 217 | + }); |
| 218 | + |
| 219 | + await expect(userMention).toBeVisible(); |
| 220 | + await expect(channelMention).toBeVisible(); |
| 221 | + }); |
| 222 | + |
| 223 | + test('expect create a private channel, send unecrypted messages, encrypt the channel and delete the last message and check the last message in the sidebar', async ({ |
| 224 | + page, |
| 225 | + }) => { |
| 226 | + const channelName = faker.string.uuid(); |
| 227 | + |
| 228 | + // Enable Sidebar Extended display mode |
| 229 | + await poHomeChannel.sidenav.setDisplayMode('Extended'); |
| 230 | + |
| 231 | + // Create private channel |
| 232 | + await poHomeChannel.sidenav.openNewByLabel('Channel'); |
| 233 | + await poHomeChannel.sidenav.inputChannelName.fill(channelName); |
| 234 | + await poHomeChannel.sidenav.btnCreate.click(); |
| 235 | + await expect(page).toHaveURL(`/group/${channelName}`); |
| 236 | + await expect(poHomeChannel.toastSuccess).toBeVisible(); |
| 237 | + await poHomeChannel.dismissToast(); |
| 238 | + |
| 239 | + // Send Unencrypted Messages |
| 240 | + await poHomeChannel.content.sendMessage('first unencrypted message'); |
| 241 | + await poHomeChannel.content.sendMessage('second unencrypted message'); |
| 242 | + |
| 243 | + // Encrypt channel |
| 244 | + await poHomeChannel.tabs.kebab.click({ force: true }); |
| 245 | + await expect(poHomeChannel.tabs.btnEnableE2E).toBeVisible(); |
| 246 | + await poHomeChannel.tabs.btnEnableE2E.click({ force: true }); |
| 247 | + await expect(page.getByRole('dialog', { name: 'Enable encryption' })).toBeVisible(); |
| 248 | + await page.getByRole('button', { name: 'Enable encryption' }).click(); |
| 249 | + await page.waitForTimeout(1000); |
| 250 | + await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeVisible(); |
| 251 | + |
| 252 | + // Send Encrypted Messages |
| 253 | + const encriptedMessage1 = 'first ENCRYPTED message'; |
| 254 | + const encriptedMessage2 = 'second ENCRYPTED message'; |
| 255 | + await poHomeChannel.content.sendMessage(encriptedMessage1); |
| 256 | + await poHomeChannel.content.sendMessage(encriptedMessage2); |
| 257 | + |
| 258 | + // Delete last message |
| 259 | + await expect(poHomeChannel.content.lastUserMessageBody).toHaveText(encriptedMessage2); |
| 260 | + await poHomeChannel.content.openLastMessageMenu(); |
| 261 | + await page.locator('role=menuitem[name="Delete"]').click(); |
| 262 | + await page.locator('#modal-root .rcx-button-group--align-end .rcx-button--danger').click(); |
| 263 | + |
| 264 | + // Check last message in the sidebar |
| 265 | + const sidebarChannel = poHomeChannel.sidenav.getSidebarItemByName(channelName); |
| 266 | + await expect(sidebarChannel).toBeVisible(); |
| 267 | + await expect(sidebarChannel.locator('span')).toContainText(encriptedMessage1); |
| 268 | + }); |
| 269 | + |
| 270 | + test('expect create a private encrypted channel and pin/star an encrypted message', async ({ page }) => { |
| 271 | + const channelName = faker.string.uuid(); |
| 272 | + |
| 273 | + await poHomeChannel.sidenav.createEncryptedChannel(channelName); |
| 274 | + |
| 275 | + await expect(page).toHaveURL(`/group/${channelName}`); |
| 276 | + |
| 277 | + await expect(poHomeChannel.content.encryptedRoomHeaderIcon).toBeVisible(); |
| 278 | + |
| 279 | + await poHomeChannel.content.sendMessage('This message should be pinned and stared.'); |
| 280 | + |
| 281 | + await expect(poHomeChannel.content.lastUserMessageBody).toHaveText('This message should be pinned and stared.'); |
| 282 | + await expect(poHomeChannel.content.lastUserMessage.locator('.rcx-icon--name-key')).toBeVisible(); |
| 283 | + |
| 284 | + await poHomeChannel.content.openLastMessageMenu(); |
| 285 | + await page.locator('role=menuitem[name="Star"]').click(); |
| 286 | + |
| 287 | + await expect(poHomeChannel.toastSuccess).toBeVisible(); |
| 288 | + await poHomeChannel.dismissToast(); |
| 289 | + |
| 290 | + await poHomeChannel.content.openLastMessageMenu(); |
| 291 | + await page.locator('role=menuitem[name="Pin"]').click(); |
| 292 | + await page.locator('#modal-root >> button:has-text("Yes, pin message")').click(); |
| 293 | + |
| 294 | + await expect(poHomeChannel.toastSuccess).toBeVisible(); |
| 295 | + await poHomeChannel.dismissToast(); |
| 296 | + |
| 297 | + await poHomeChannel.tabs.kebab.click(); |
| 298 | + await poHomeChannel.tabs.btnPinnedMessagesList.click(); |
| 299 | + |
| 300 | + await expect(page.getByRole('dialog', { name: 'Pinned Messages' })).toBeVisible(); |
| 301 | + |
| 302 | + const lastPinnedMessage = page.getByRole('dialog', { name: 'Pinned Messages' }).locator('[data-qa-type="message"]').last(); |
| 303 | + await expect(lastPinnedMessage).toContainText('This message should be pinned and stared.'); |
| 304 | + await lastPinnedMessage.hover(); |
| 305 | + await lastPinnedMessage.locator('role=button[name="More"]').waitFor(); |
| 306 | + await lastPinnedMessage.locator('role=button[name="More"]').click(); |
| 307 | + await expect(page.locator('role=menuitem[name="Copy link"]')).toHaveClass(/disabled/); |
| 308 | + |
| 309 | + await poHomeChannel.btnContextualbarClose.click(); |
| 310 | + |
| 311 | + await poHomeChannel.tabs.kebab.click(); |
| 312 | + await poHomeChannel.tabs.btnStarredMessageList.click(); |
| 313 | + |
| 314 | + const lastStarredMessage = page.getByRole('dialog', { name: 'Starred Messages' }).locator('[data-qa-type="message"]').last(); |
| 315 | + await expect(page.getByRole('dialog', { name: 'Starred Messages' })).toBeVisible(); |
| 316 | + await expect(lastStarredMessage).toContainText('This message should be pinned and stared.'); |
| 317 | + await lastStarredMessage.hover(); |
| 318 | + await lastStarredMessage.locator('role=button[name="More"]').waitFor(); |
| 319 | + await lastStarredMessage.locator('role=button[name="More"]').click(); |
| 320 | + await expect(page.locator('role=menuitem[name="Copy link"]')).toHaveClass(/disabled/); |
| 321 | + }); |
| 322 | +}); |
0 commit comments