|
1 | 1 | /* eslint-disable jest/no-done-callback */ |
2 | 2 | /* eslint-disable jest/require-top-level-describe */ |
3 | | -import { expect, Page, test } from '@playwright/test'; |
4 | | - |
5 | | -function getPreview(page: Page) { |
6 | | - return page.locator('*data-testid=channel-preview-button >> text=add-message'); |
7 | | -} |
8 | | - |
9 | | -test.describe('add a message', () => { |
10 | | - test.beforeEach(async ({ baseURL, page }) => { |
11 | | - await page.goto(`${baseURL}/?story=connected-user--user1`); |
12 | | - await page.waitForSelector('[data-storyloaded]'); |
13 | | - // Select correct channel |
14 | | - const preview = getPreview(page); |
15 | | - await preview.click(); |
| 3 | +import selectors from './user/selectors'; |
| 4 | +import { test } from './user/test'; |
| 5 | + |
| 6 | +const CHANNEL_NAME = 'add-message' as const; |
| 7 | +const ADDED_MESSAGE_MAIN_LIST = 'Hello world!' as const; |
| 8 | +const ADDED_MESSAGE_THREAD = 'Hello world back!' as const; |
| 9 | + |
| 10 | +test.describe('add text message', () => { |
| 11 | + |
| 12 | + test.beforeEach(async ({controller, user}) => { |
| 13 | + await controller.openStory('add-message--user1', selectors.channelPreviewButton); |
| 14 | + await user.clicks.ChannelPreview.text(CHANNEL_NAME); |
16 | 15 | }); |
17 | 16 |
|
18 | | - test('message list should clear', async ({ page }) => { |
19 | | - await page.click('data-testid=truncate'); |
20 | | - const list = page.locator('.str-chat__list'); |
21 | | - await expect(list).toBeEmpty(); |
| 17 | + test('message list and preview button should be clear', async ({controller, user}) => { |
| 18 | + await controller.clearChannel() |
| 19 | + await user.sees.MessageList.empty(); |
| 20 | + await user.sees.ChannelPreview(CHANNEL_NAME).empty(); |
22 | 21 | }); |
23 | 22 |
|
24 | | - test('channel list preview should be cleared', async ({ page }) => { |
25 | | - const preview = getPreview(page); |
26 | | - await expect(preview).toContainText('Nothing yet...'); |
| 23 | + test('message list should update for current user', async ({controller, user}) => { |
| 24 | + await controller.sendMessage(); |
| 25 | + |
| 26 | + await user.sees.MessageList.not.empty(); |
| 27 | + await user.sees.MessageList.contains.nthMessage(ADDED_MESSAGE_MAIN_LIST); |
| 28 | + await user.sees.ChannelPreview(CHANNEL_NAME).contains.lastMessage(ADDED_MESSAGE_MAIN_LIST); |
27 | 29 | }); |
| 30 | +}); |
28 | 31 |
|
29 | | - test('message list should update for current user', async ({ page }) => { |
30 | | - await page.click('data-testid=add-message'); |
31 | | - const list = page.locator('.str-chat__list'); |
32 | | - await expect(list).not.toBeEmpty(); |
33 | | - const newMessage = page.locator('.str-chat__message').first(); |
34 | | - await expect(newMessage).toContainText('Hello world!'); |
| 32 | +test.describe('receive a message', () => { |
| 33 | + |
| 34 | + test.beforeEach(async ({controller, user}) => { |
| 35 | + await controller.openStory('add-message--user1', selectors.channelPreviewButton); |
| 36 | + |
| 37 | + await user.clicks.ChannelPreview.text(CHANNEL_NAME); |
| 38 | + |
| 39 | + await controller.sendMessage(); |
| 40 | + |
| 41 | + await controller.openStory('add-message--user2', selectors.channelPreviewButton); |
35 | 42 | }); |
36 | 43 |
|
37 | | - test('channel list should update for current user', async ({ page }) => { |
38 | | - const preview = getPreview(page); |
39 | | - await expect(preview).toContainText('Hello world!'); |
| 44 | + test('channel list should update for channel members and show unread', async ({user}) => { |
| 45 | + await user.sees.ChannelPreview(CHANNEL_NAME).not.read(); |
| 46 | + await user.sees.ChannelPreview(CHANNEL_NAME).contains.lastMessage(ADDED_MESSAGE_MAIN_LIST); |
| 47 | + }); |
| 48 | + |
| 49 | + test('message list should update for different users on the channel', async ({user, page}) => { |
| 50 | + await Promise.all([ |
| 51 | + page.waitForResponse((r) => r.url().includes('/read') && r.ok()), |
| 52 | + user.clicks.ChannelPreview.text(CHANNEL_NAME) |
| 53 | + ]); |
| 54 | + await user.sees.MessageList.not.empty(); |
| 55 | + await user.sees.ChannelPreview(CHANNEL_NAME).read(); |
| 56 | + await user.sees.MessageList.contains.nthMessage(ADDED_MESSAGE_MAIN_LIST); |
40 | 57 | }); |
41 | 58 | }); |
42 | 59 |
|
43 | | -test.describe('receive a message', () => { |
44 | | - test.beforeEach(async ({ baseURL, page }) => { |
45 | | - await page.goto(`${baseURL}/?story=connected-user--user2`); |
46 | | - await page.waitForSelector('[data-storyloaded]'); |
| 60 | + |
| 61 | +test.describe('reply to a message', () => { |
| 62 | + test.beforeEach(async ({controller, user}) => { |
| 63 | + await controller.openStory('add-message--user1', selectors.channelPreviewButton); |
| 64 | + await user.clicks.ChannelPreview.text(CHANNEL_NAME); |
| 65 | + }); |
| 66 | + |
| 67 | + test.afterEach(async ({user}) => { |
| 68 | + await user.clicks.Thread.close(); |
| 69 | + }) |
| 70 | + |
| 71 | + test('thread with no replies contains only parent message', async ({controller, user}) => { |
| 72 | + await controller.clearChannel(); |
| 73 | + await controller.sendMessage(); |
| 74 | + await user.clicks.MessageActions.reply(ADDED_MESSAGE_MAIN_LIST); |
| 75 | + await user.sees.Thread.empty(); |
| 76 | + }); |
| 77 | + |
| 78 | + test('reply to a message should appear at the bottom of the thread and in channel preview', async ({ user}) => { |
| 79 | + await user.clicks.MessageActions.reply(ADDED_MESSAGE_MAIN_LIST); |
| 80 | + await user.submits.MessageInput.reply(ADDED_MESSAGE_THREAD); |
| 81 | + await user.sees.Thread.not.empty(); |
| 82 | + await user.sees.Thread.inViewport.nthMessage(ADDED_MESSAGE_THREAD, -1); |
| 83 | + // todo: channel preview does not reflect new messages from thread |
| 84 | + // await user.sees.ChannelPreview(CHANNEL_NAME).contains.lastMessage(ADDED_MESSAGE_THREAD); |
47 | 85 | }); |
| 86 | +}) |
48 | 87 |
|
49 | | - test('channel list should update for channel members and show unread', async ({ page }) => { |
50 | | - const preview = getPreview(page); |
51 | | - await expect(preview).toHaveClass(/str-chat__channel-preview-messenger--unread/); |
52 | | - await expect(preview).toContainText('Hello world!'); |
| 88 | +test.describe('receive the reply', () => { |
| 89 | + test.beforeEach(async ({controller, user: user1, page}) => { |
| 90 | + await controller.openStory('add-message--user1', selectors.channelPreviewButton); |
| 91 | + await user1.clicks.ChannelPreview.text(CHANNEL_NAME); |
| 92 | + await controller.clearChannel(); |
| 93 | + await controller.sendMessage(); |
| 94 | + await user1.clicks.MessageActions.reply(ADDED_MESSAGE_MAIN_LIST); |
| 95 | + await Promise.all([ |
| 96 | + page.waitForResponse((r) => r.url().includes('/message') && r.ok()), |
| 97 | + user1.submits.MessageInput.reply(ADDED_MESSAGE_THREAD) |
| 98 | + ]) |
| 99 | + await controller.openStory('add-message--user2', selectors.channelPreviewButton); |
53 | 100 | }); |
54 | 101 |
|
55 | | - test('message list should update for different users on the channel', async ({ page }) => { |
56 | | - const preview = getPreview(page); |
57 | | - await preview.click(); |
58 | | - await expect(preview).not.toHaveClass(/str-chat__channel-preview-messenger--unread/); |
| 102 | + // todo: channel preview does not reflect new messages from thread |
| 103 | + // test('for the other user channel preview displays correct last message showed unread', async ({user: user2}) => { |
| 104 | + // await user2.sees.ChannelPreview(CHANNEL_NAME).not.read(); |
| 105 | + // await user2.sees.ChannelPreview(CHANNEL_NAME).contains.lastMessage(ADDED_MESSAGE_THREAD); |
| 106 | + // }); |
| 107 | + |
| 108 | + test('the other user sees that reply to a message appeared at the bottom of the thread and in channel preview', async ({user: user2, page}) => { |
| 109 | + await Promise.all([ |
| 110 | + page.waitForResponse((r) => r.url().includes('/read') && r.ok()), |
| 111 | + user2.clicks.ChannelPreview.text(CHANNEL_NAME) |
| 112 | + ]); |
| 113 | + |
| 114 | + await Promise.all([ |
| 115 | + page.waitForResponse((r) => r.url().includes('/replies') && r.ok()), |
| 116 | + user2.clicks.MessageActions.reply(ADDED_MESSAGE_MAIN_LIST), |
| 117 | + ]); |
59 | 118 |
|
60 | | - const list = page.locator('.str-chat__list'); |
61 | | - await expect(list).not.toBeEmpty(); |
62 | | - const newMessage = page.locator('.str-chat__message').first(); |
63 | | - await expect(newMessage).toContainText('Hello world!'); |
| 119 | + await user2.sees.Thread.not.empty(); |
| 120 | + await user2.sees.ChannelPreview(CHANNEL_NAME).read(); |
| 121 | + await user2.sees.Thread.inViewport.nthMessage(ADDED_MESSAGE_THREAD, -1); |
64 | 122 | }); |
65 | 123 | }); |
0 commit comments