forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
home-sidenav.ts
98 lines (78 loc) · 3.51 KB
/
home-sidenav.ts
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
import type { Locator, Page } from '@playwright/test';
import { expect } from '../../utils/test';
export class HomeSidenav {
private readonly page: Page;
constructor(page: Page) {
this.page = page;
}
get checkboxPrivateChannel(): Locator {
return this.page.locator(
'//*[@id="modal-root"]//*[contains(@class, "rcx-field") and contains(text(), "Private")]/../following-sibling::label/i',
);
}
get checkboxReadOnly(): Locator {
return this.page.locator(
'//*[@id="modal-root"]//*[contains(@class, "rcx-field") and contains(text(), "Read Only")]/../following-sibling::label/i',
);
}
get inputChannelName(): Locator {
return this.page.locator('#modal-root [data-qa="create-channel-modal"] [data-qa-type="channel-name-input"]');
}
get inputDirectUsername(): Locator {
return this.page.locator('#modal-root [data-qa="create-direct-modal"] [data-qa-type="user-auto-complete-input"]');
}
get btnCreate(): Locator {
return this.page.locator('//*[@id="modal-root"]//button[contains(text(), "Create")]');
}
async openAdministrationByLabel(text: string): Promise<void> {
await this.page.locator('role=button[name="Administration"]').click();
await this.page.locator(`li.rcx-option >> text="${text}"`).click();
}
async openNewByLabel(text: string): Promise<void> {
await this.page.locator('[data-qa="sidebar-create"]').click();
await this.page.locator(`li.rcx-option >> text="${text}"`).click();
}
async logout(): Promise<void> {
await this.page.locator('[data-qa="sidebar-avatar-button"]').click();
await this.page.locator('//*[contains(@class, "rcx-option__content") and contains(text(), "Logout")]').click();
}
async switchStatus(status: 'offline' | 'online'): Promise<void> {
await this.page.locator('[data-qa="sidebar-avatar-button"]').click();
await this.page.locator(`//li[@class="rcx-option"]//div[contains(text(), "${status}")]`).click();
}
async openChat(name: string): Promise<void> {
await this.page.locator('[data-qa="sidebar-search"]').click();
await this.page.locator('[data-qa="sidebar-search-input"]').type(name);
await this.page.locator(`[data-qa="sidebar-item-title"] >> text="${name}"`).first().click();
}
async switchOmnichannelStatus(status: 'offline' | 'online') {
// button has a id of "omnichannel-status-toggle"
const toggleButton = this.page.locator('#omnichannel-status-toggle');
expect(toggleButton).toBeVisible();
enum StatusTitleMap {
offline = 'Turn on answer chats',
online = 'Turn off answer chats',
}
const currentStatus: StatusTitleMap = (await toggleButton.getAttribute('data-tooltip')) as any;
if (status === 'offline') {
if (currentStatus === StatusTitleMap.online) {
await toggleButton.click();
}
} else if (currentStatus === StatusTitleMap.offline) {
await toggleButton.click();
}
await this.page.waitForTimeout(500);
const newStatus: StatusTitleMap = (await this.page.locator('#omnichannel-status-toggle').getAttribute('data-tooltip')) as any;
expect(newStatus).toBe(status === 'offline' ? StatusTitleMap.offline : StatusTitleMap.online);
}
// Note: this is a workaround for now since queued omnichannel chats are not searchable yet so we can't use openChat() :(
async openQueuedOmnichannelChat(name: string): Promise<void> {
await this.page.locator('[data-qa="sidebar-item-title"]', { hasText: name }).first().click();
}
async createPublicChannel(name: string) {
await this.openNewByLabel('Channel');
await this.checkboxPrivateChannel.click();
await this.inputChannelName.type(name);
await this.btnCreate.click();
}
}