-
Notifications
You must be signed in to change notification settings - Fork 11
/
Tab.ts
73 lines (63 loc) · 1.89 KB
/
Tab.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
import * as playwright from "playwright";
import { RethrownError } from "../utils/RethrownError";
import { EnsureXrmGetter } from "./Global";
import { XrmUiTest } from "./XrmUITest";
/**
* State of a tab
*/
export interface TabState {
/**
* Whether the tab is currently visible
*/
isVisible: boolean;
}
/**
* Module for interacting with D365 Tabs
*/
export class Tab {
private _page: playwright.Page;
constructor(private xrmUiTest: XrmUiTest) {
this._page = xrmUiTest.page;
this.xrmUiTest = xrmUiTest;
}
/**
* Opens the specified tab on the form
*
* @param tabName Name of the tab to open
* @returns Promise which fulfills with the current control state
*/
open = async (tabName: string) => {
try {
await EnsureXrmGetter(this._page);
await this._page.evaluate((tabName: string) => {
const xrm = window.oss_FindXrm();
xrm.Page.ui.tabs.get(tabName).setDisplayState("expanded");
}, tabName);
await this.xrmUiTest.waitForIdleness();
}
catch (e) {
throw new RethrownError(`Error when opening tab '${tabName}'`, e);
}
}
/**
* Gets the state of the specified tab
*
* @param name Name of the tab to retrieve
* @returns Promise which fulfills with the current tab state
*/
get = async (name: string): Promise<TabState> => {
try {
await EnsureXrmGetter(this._page);
return this._page.evaluate((tabName: string) => {
const xrm = window.oss_FindXrm();
const tab = xrm.Page.ui.tabs.get(tabName);
return {
isVisible: tab.getVisible()
};
}, name);
}
catch (e) {
throw new RethrownError(`Error when getting tab '${name}'`, e);
}
}
}