diff --git a/src/plugins/index.ts b/src/plugins/index.ts index b7f89725..dd88d161 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -15,6 +15,7 @@ import { ReportsAndDashboards as reportsAndDashboards } from './reports-and-dash import { SalesforceToSalesforce as salesforceToSalesforce } from './salesforce-to-salesforce'; import { Security as security } from './security'; import { CompanyInformation as companyInformation } from './company-information'; +import { LinkedInSalesNavigatorSettings as linkedInSalesNavigatorSettings } from './linkedin-sales-navigator-settings'; export { activitySettings, @@ -33,5 +34,6 @@ export { reportsAndDashboards, salesforceToSalesforce, security, - companyInformation + companyInformation, + linkedInSalesNavigatorSettings }; diff --git a/src/plugins/linkedin-sales-navigator-settings/disable.json b/src/plugins/linkedin-sales-navigator-settings/disable.json new file mode 100644 index 00000000..a31912f0 --- /dev/null +++ b/src/plugins/linkedin-sales-navigator-settings/disable.json @@ -0,0 +1,8 @@ +{ + "$schema": "../schema.json", + "settings": { + "linkedInSalesNavigatorSettings": { + "enabled": false + } + } +} diff --git a/src/plugins/linkedin-sales-navigator-settings/enable.json b/src/plugins/linkedin-sales-navigator-settings/enable.json new file mode 100644 index 00000000..bbda4c25 --- /dev/null +++ b/src/plugins/linkedin-sales-navigator-settings/enable.json @@ -0,0 +1,8 @@ +{ + "$schema": "../schema.json", + "settings": { + "linkedInSalesNavigatorSettings": { + "enabled": true + } + } +} diff --git a/src/plugins/linkedin-sales-navigator-settings/index.e2e-spec.ts b/src/plugins/linkedin-sales-navigator-settings/index.e2e-spec.ts new file mode 100644 index 00000000..fc95fe83 --- /dev/null +++ b/src/plugins/linkedin-sales-navigator-settings/index.e2e-spec.ts @@ -0,0 +1,31 @@ +import assert from 'assert'; +import { Config, LinkedInSalesNavigatorSettings } from '.'; + +describe(LinkedInSalesNavigatorSettings.name, function () { + let plugin: LinkedInSalesNavigatorSettings; + before(() => { + plugin = new LinkedInSalesNavigatorSettings(global.bf); + }); + + const configEnabled: Config = { + enabled: true + }; + const configDisabled: Config = { + enabled: false + }; + + it('should enable', async () => { + await plugin.run(configEnabled); + }); + it('should already be enabled', async () => { + const res = await plugin.run(configEnabled); + assert.deepStrictEqual(res, { message: 'no action necessary' }); + }); + it('should disable', async () => { + await plugin.run(configDisabled); + }); + it('should already be disabled', async () => { + const res = await plugin.run(configDisabled); + assert.deepStrictEqual(res, { message: 'no action necessary' }); + }); +}); diff --git a/src/plugins/linkedin-sales-navigator-settings/index.ts b/src/plugins/linkedin-sales-navigator-settings/index.ts new file mode 100644 index 00000000..f69a9856 --- /dev/null +++ b/src/plugins/linkedin-sales-navigator-settings/index.ts @@ -0,0 +1,20 @@ +import { BrowserforcePlugin } from '../../plugin'; +import { LinkedInSalesNavigatorPage } from './page'; + +export type Config = { + enabled: boolean; +}; + +export class LinkedInSalesNavigatorSettings extends BrowserforcePlugin { + public async retrieve(definition?: Config): Promise { + const result = { enabled: false }; + const page = new LinkedInSalesNavigatorPage(await this.browserforce.openPage(LinkedInSalesNavigatorPage.getUrl())); + result.enabled = await page.getStatus(); + return result; + } + + public async apply(config: Config): Promise { + const page = new LinkedInSalesNavigatorPage(await this.browserforce.openPage(LinkedInSalesNavigatorPage.getUrl())); + await page.setStatus(config.enabled); + } +} diff --git a/src/plugins/linkedin-sales-navigator-settings/page.ts b/src/plugins/linkedin-sales-navigator-settings/page.ts new file mode 100644 index 00000000..78e3cecc --- /dev/null +++ b/src/plugins/linkedin-sales-navigator-settings/page.ts @@ -0,0 +1,43 @@ +import { Page } from 'puppeteer'; +import { throwPageErrors } from '../../browserforce'; + +const ENABLE_TOGGLE = 'div[data-aura-class="setup_sales_linkedinLinkedInSetupRow"] input[type="checkbox"]'; +const CONFIRM_CHECKBOX = + 'pierce/lightning-primitive-input-checkbox input[name="LinkedIn Sales Navigator Integration Acceptance Checkbox"]'; +const ACCEPT_BUTTON = + 'section[data-aura-class="setup_sales_linkedinLinkedInSetupAcceptTermsModal"] div div button:not(:disabled):nth-child(2)'; + +export class LinkedInSalesNavigatorPage { + private page: Page; + + constructor(page: Page) { + this.page = page; + } + + public static getUrl(): string { + return 'lightning/setup/LinkedInSalesNavigatorPage/home'; + } + + public async getStatus(): Promise { + await this.page.waitForSelector(ENABLE_TOGGLE, { visible: true }); + const isEnabled = await this.page.$eval(ENABLE_TOGGLE, (el: HTMLInputElement) => el.checked); + await this.page.close(); + return isEnabled; + } + + public async setStatus(enable: boolean): Promise { + await this.page.waitForSelector(ENABLE_TOGGLE, { visible: true }); + await this.page.click(ENABLE_TOGGLE); + + if (enable) { + await this.page.waitForSelector(CONFIRM_CHECKBOX, { visible: true }); + const checkbox = await this.page.$(CONFIRM_CHECKBOX); + await checkbox?.evaluate((input: HTMLInputElement) => input.click()); + await this.page.waitForSelector(ACCEPT_BUTTON, { visible: true }); + await this.page.click(ACCEPT_BUTTON); + } + + await throwPageErrors(this.page); + await this.page.close(); + } +} diff --git a/src/plugins/linkedin-sales-navigator-settings/schema.json b/src/plugins/linkedin-sales-navigator-settings/schema.json new file mode 100644 index 00000000..9958ddc3 --- /dev/null +++ b/src/plugins/linkedin-sales-navigator-settings/schema.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "https://github.com/amtrack/sfdx-browserforce-plugin/src/plugins/linkedin-sales-navigator-settings/schema.json", + "title": "LinkedIn Sales Navigator Settings", + "description": "", + "type": "object", + "properties": { + "enabled": { + "title": "Enable LinkedIn Sales Navigator", + "type": "boolean" + } + } +}