forked from GetStream/stream-chat-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThread.ts
More file actions
112 lines (107 loc) Β· 3.88 KB
/
Thread.ts
File metadata and controls
112 lines (107 loc) Β· 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* eslint-disable jest/no-standalone-expect */
import type { Page } from '@playwright/test';
import selectors from '../../selectors';
import { expect } from '@playwright/test';
import { getMessage } from '../Message/MessageSimple';
export function composeThreadSelector(prependSelectors?: string) {
return `${prependSelectors || ''} ${selectors.threadMessageList}`;
}
export default (page: Page) => ({
click: {
close() {
return page.click(selectors.buttonCloseThread);
},
open(text: string, nth = 0) {
return page
.locator(`${selectors.messageRepliesButton} >> nth=${nth} `, { hasText: text })
.click();
},
async openFor(messageText: string, nth = 0) {
await page
.locator(selectors.message, { hasText: messageText })
.locator(selectors.messageRepliesButton)
.nth(nth)
.click();
},
},
get: (prependSelectors?: string) =>
page.locator(composeThreadSelector(prependSelectors)),
see: {
empty() {
const replies = page.locator(`${selectors.threadReplyList} ${selectors.message}`);
return expect(replies).toHaveCount(1);
},
inViewport: {
async nthMessage(text: string, nth?: number) {
const isThread = true;
await expect(getMessage(page, text, nth, isThread)).toBeVisible();
// todo: playwright's toBeVisible() does not differ, whether the element is in viewport or not
// => needed custom function to determine
// await page.waitForSelector(getMessageSelector(text, nth, isThread))
// const threadMsgListBox = await page.locator(selectors.threadMessageList).boundingBox();
// const msgBox = await getMessage(page, text, nth, isThread).boundingBox();
// expect(isVisible(msgBox, threadMsgListBox)).toBeTruthy();
},
},
async isScrolledToBottom(selector: string) {
await page.waitForTimeout(500);
expect(
await page.evaluate(
([selector]) => {
const messageList = document.querySelector(selector);
if (!messageList) return false;
return (
messageList.scrollTop + messageList.clientHeight ===
messageList.scrollHeight
);
},
[selector],
),
).toBeTruthy();
},
not: {
empty() {
const replies = page.locator(selectors.threadReplyListWithReplies);
return expect(replies).not.toBeEmpty();
},
inDOM: {
nthMessage(text: string, nth?: number) {
const isThread = true;
const msgLocator = getMessage(page, text, nth, isThread);
return expect(msgLocator).toHaveCount(0);
},
},
inViewport: {
nthMessage(text: string, nth?: number) {
const isThread = true;
const msgLocator = getMessage(page, text, nth, isThread);
return expect(msgLocator).not.toBeVisible();
// todo: playwright's toBeVisible() does not differ, whether the element is in viewport or not
// => needed custom function to determine
// await expect(msgLocator).toBeVisible();
// const threadMsgListBox = await page.locator(selectors.threadMessageList).boundingBox();
// const msgBox = await msgLocator.boundingBox();
// expect(isVisible(msgBox, threadMsgListBox)).toBeFalsy();
},
},
async isScrolledToBottom(selector: string) {
expect(
await page.evaluate(
([selector]) => {
const messageList = document.querySelector(selector);
if (!messageList) return false;
return (
messageList.scrollTop + messageList.clientHeight ===
messageList.scrollHeight
);
},
[selector],
),
).toBeFalsy();
},
},
start() {
return expect(page.locator(selectors.threadStart)).toBeVisible();
},
},
});