-
Notifications
You must be signed in to change notification settings - Fork 20
/
ActivityBar.ts
98 lines (92 loc) · 3.57 KB
/
ActivityBar.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 { ViewControl, ActionsControl } from '../index.js'
import { PageDecorator, IPageDecorator, ElementWithContextMenu } from '../utils.js'
import { ActivityBar as ActivityBarLocators } from '../../locators/1.73.0.js'
export interface ActivityBar extends IPageDecorator<typeof ActivityBarLocators> {}
/**
* Page object representing the left side activity bar in VS Code
*
* @category ActivityBar
*/
@PageDecorator(ActivityBarLocators)
export class ActivityBar extends ElementWithContextMenu<typeof ActivityBarLocators> {
/**
* @private
*/
public locatorKey = 'ActivityBar' as const
/**
* Find all view containers displayed in the activity bar
* @returns Promise resolving to array of ViewControl objects
*/
async getViewControls (): Promise<ViewControl[]> {
const views: ViewControl[] = []
const viewContainer = await this.viewContainer$
for (const element of await viewContainer.$$(this.locators.actionItem)) {
views.push(await new ViewControl(
this.locatorMap,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
element as any,
this
).wait())
}
return views
}
/**
* Find a view container with a given title
* @param name title of the view
* @returns Promise resolving to ViewControl object representing the view selector, undefined if not found
*/
async getViewControl (name: string): Promise<ViewControl | undefined> {
const controls = await this.getViewControls()
const names = await Promise.all(
controls.map(async (item) => item.getTitle())
)
const index = names.findIndex((value) => value.indexOf(name) > -1)
if (index > -1) {
return controls[index]
}
return undefined
}
/**
* Returns selected view control
* @returns Promise resolving to selected ViewControl object
*/
async getSelectedViewAction (): Promise<ViewControl> {
const element = await this.viewContainer$.$(this.locators.actionItemSelected)
return new ViewControl(
this.locatorMap,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
element as any,
this
).wait()
}
/**
* Find all global action controls displayed on the bottom of the activity bar
* @returns Promise resolving to array of ActionsControl objects
*/
async getGlobalActions (): Promise<ActionsControl[]> {
const actions: ActionsControl[] = []
const actionContainer = await this.actionsContainer$
for (const element of await actionContainer.$$(this.locators.actionItem)) {
actions.push(await new ActionsControl(
this.locatorMap,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
element as any
).wait())
}
return actions
}
/**
* Find an action control with a given title
* @param name title of the global action
* @returns Promise resolving to ActionsControl object representing the action selector, undefined if not found
*/
async getGlobalAction (name: string): Promise<ActionsControl | undefined> {
const actions = await this.getGlobalActions()
const names = await Promise.all(actions.map(async (item) => item.getTitle()))
const index = names.findIndex((value) => value.indexOf(name) > -1)
if (index > -1) {
return actions[index]
}
return undefined
}
}