-
Notifications
You must be signed in to change notification settings - Fork 20
/
Notification.ts
185 lines (166 loc) · 4.85 KB
/
Notification.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import { ChainablePromiseElement } from 'webdriverio'
import {
BasePage, IPageDecorator, PageDecorator, VSCodeLocatorMap
} from '../utils.js'
import { Notification as NotificationLocators } from '../../locators/1.73.0.js'
/**
* Available types of notifications
* @hidden
*/
export enum NotificationType {
Info = 'info',
Warning = 'warning',
Error = 'error',
Any = 'any'
}
interface NotificationButton extends IPageDecorator<typeof NotificationLocators> {}
/**
* Notification button
*
* @category Workbench
*/
class NotificationButton extends BasePage<typeof NotificationLocators> {
/**
* @private
*/
public locatorKey = 'Notification' as const
private title: string
constructor (
locators: VSCodeLocatorMap,
title: string
) {
super(locators, (locators.Notification.buttonConstructor as Function)(title) as string)
this.title = title
}
getTitle (): string {
return this.title
}
}
export interface Notification extends IPageDecorator<typeof NotificationLocators> {}
/**
* Abstract element representing a notification
*
* @category Workbench
*/
export abstract class Notification extends BasePage<typeof NotificationLocators> {
/**
* Get the message of the notification
* @returns Promise resolving to notification message
*/
getMessage (): Promise<string> {
return this.message$.getText()
}
/**
* Get the type of the notification
* @returns Promise resolving to NotificationType
*/
async getType (): Promise<NotificationType> {
const iconType = await this.icon$.getAttribute('class')
if (iconType.indexOf('icon-info') > -1) {
return NotificationType.Info
} if (iconType.indexOf('icon-warning') > -1) {
return NotificationType.Warning
}
return NotificationType.Error
}
/**
* Get the source of the notification as text
* @returns Promise resolving to notification source
*/
async getSource (): Promise<string> {
await this.expand()
return this.source$.getAttribute('title')
}
/**
* Find whether the notification has an active progress bar
* @returns Promise resolving to true/false
*/
async hasProgress (): Promise<boolean> {
const klass = await this.progress$.getAttribute('class')
return klass.indexOf('done') < 0
}
/**
* Dismiss the notification
* @returns Promise resolving when notification is dismissed
*/
async dismiss (): Promise<void> {
const btn = await this.dismiss$
/**
* make button interactable given they only contain
* text on hover
*/
await browser.execute(
(btnSection) => { btnSection.style.display = 'block' },
await this.btnSection$ as any as HTMLLinkElement
)
await btn.click()
}
/**
* Get the action buttons of the notification as an array
* of NotificationButton objects
* @returns Promise resolving to array of NotificationButton objects
*/
async getActions (): Promise<NotificationButton[]> {
const buttons: NotificationButton[] = []
const elements = await this.actions$
.$$(this.locators.action)
for (const button of elements) {
buttons.push(await new NotificationButton(
this.locatorMap,
await button.getAttribute(this.locators.actionLabel)
).wait())
}
return buttons
}
/**
* Click on an action button with the given title
* @param title title of the action/button
* @returns Promise resolving when the select button is pressed
*/
async takeAction (title: string): Promise<void> {
await new NotificationButton(
this.locatorMap,
title
).elem.click()
}
/**
* Expand the notification if possible
*/
async expand (): Promise<void> {
await this.elem.moveTo()
const exp = await this.expand$$
if (exp[0]) {
await exp[0].click()
}
}
}
/**
* Notification displayed on its own in the notifications-toasts container
*
* @category Workbench
*/
@PageDecorator(NotificationLocators)
export class StandaloneNotification extends Notification {
/**
* @private
*/
public locatorKey = 'Notification' as const
constructor (
locators: VSCodeLocatorMap,
notification: ChainablePromiseElement<WebdriverIO.Element>
) {
super(locators, notification, locators.Notification.standaloneContainer as string)
}
}
/**
* Notification displayed within the notifications center
*
* @category Workbench
*/
@PageDecorator(NotificationLocators)
export class CenterNotification extends Notification {
/**
* @private
*/
public locatorKey = 'Notification' as const
}