-
Notifications
You must be signed in to change notification settings - Fork 48
feat: add Einstein Bots plugin to enable/disable Einstein Bots #735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "$schema": "../schema.json", | ||
| "settings": { | ||
| "einsteinBots": { | ||
| "enabled": false | ||
| } | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "$schema": "../schema.json", | ||
| "settings": { | ||
| "einsteinBots": { | ||
| "enabled": true | ||
| } | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import assert from 'assert'; | ||
| import { EinsteinBots } from './index.js'; | ||
|
|
||
| describe(EinsteinBots.name, function () { | ||
| this.timeout('10m'); | ||
| let plugin: EinsteinBots; | ||
| before(() => { | ||
| plugin = new EinsteinBots(global.browserforce); | ||
| }); | ||
|
|
||
| const configEnabled = { | ||
| enabled: true, | ||
| }; | ||
| const configDisabled = { | ||
| enabled: false, | ||
| }; | ||
|
|
||
| it('should enable Einstein Bots', async () => { | ||
| await plugin.run(configEnabled); | ||
| }); | ||
|
|
||
| it('should verify Einstein Bots is enabled', async () => { | ||
| const res = await plugin.retrieve(); | ||
| assert.deepStrictEqual(res, configEnabled); | ||
| }); | ||
|
|
||
| it('should disable Einstein Bots', async () => { | ||
| await plugin.run(configDisabled); | ||
| }); | ||
|
|
||
| it('should verify Einstein Bots is disabled', async () => { | ||
| const res = await plugin.retrieve(); | ||
| assert.deepStrictEqual(res, configDisabled); | ||
| }); | ||
| }); | ||
|
|
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,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 }); | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the click event on the input is not working. Please consider clicking on the parent
|
||||||
|
|
||||||
| // 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); | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sleeping is not a good practice.
Suggested change
|
||||||
| } | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,14 @@ | ||||||||||
| { | ||||||||||
| "$schema": "http://json-schema.org/draft-07/schema", | ||||||||||
| "$id": "https://github.com/amtrack/sfdx-browserforce-plugin/src/plugins/einstein-bots/schema.json", | ||||||||||
| "title": "Einstein Bots", | ||||||||||
| "type": "object", | ||||||||||
| "properties": { | ||||||||||
| "enabled": { | ||||||||||
| "title": "Einstein Bots", | ||||||||||
| "description": "Enable or disable Einstein Bots. Setup -> Einstein Bots -> Einstein Bots toggle.", | ||||||||||
|
Comment on lines
+8
to
+9
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please include the reason why this is necessary.
Suggested change
|
||||||||||
| "type": "boolean" | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.