-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathindex.ts
More file actions
48 lines (40 loc) · 1.82 KB
/
index.ts
File metadata and controls
48 lines (40 loc) · 1.82 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
import { BrowserforcePlugin } from '../../plugin.js';
const BASE_PATH = '/lightning/setup/EinsteinBots/home';
// The checkbox input element (for reading state and clicking)
const TOGGLE_INPUT_SELECTOR = 'input[type="checkbox"][aria-label*="Einstein Bots"]';
type Config = {
enabled: boolean;
};
export class EinsteinBots extends BrowserforcePlugin {
public async retrieve(): Promise<Config> {
await using page = await this.browserforce.openPage(BASE_PATH);
await page.locator(TOGGLE_INPUT_SELECTOR).waitFor();
const response = {
enabled: await page.locator(TOGGLE_INPUT_SELECTOR).isChecked(),
};
return response;
}
public async apply(config: Config): Promise<void> {
await using page = await this.browserforce.openPage(BASE_PATH);
await page.locator(TOGGLE_INPUT_SELECTOR).waitFor();
const currentState = await page.locator(TOGGLE_INPUT_SELECTOR).isChecked();
// Only click if the state needs to change
if (currentState !== config.enabled) {
if (!config.enabled) {
// When disabling, click the toggle and wait for the confirmation dialog
await page.locator(TOGGLE_INPUT_SELECTOR).click({ force: true });
// Wait for the "Disable Einstein Bots" dialog and click Yes
const disableDialog = page.getByRole('dialog', { name: 'Disable Einstein Bots' });
await disableDialog.waitFor({ timeout: 5000 });
await disableDialog.getByRole('button', { name: 'Yes' }).click();
// Wait for the dialog to close (this is when the save happens)
await disableDialog.waitFor({ state: 'hidden', timeout: 10000 });
} else {
// When enabling, just click the toggle
await page.locator(TOGGLE_INPUT_SELECTOR).click({ force: true });
}
// Wait for the save to complete
await page.waitForTimeout(2000);
}
}
}