-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable/disable LinkedIn Sales Navigator
Resolves #611
- Loading branch information
Showing
7 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "../schema.json", | ||
"settings": { | ||
"linkedInSalesNavigatorSettings": { | ||
"enabled": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "../schema.json", | ||
"settings": { | ||
"linkedInSalesNavigatorSettings": { | ||
"enabled": true | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/plugins/linkedin-sales-navigator-settings/index.e2e-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Config> { | ||
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<void> { | ||
const page = new LinkedInSalesNavigatorPage(await this.browserforce.openPage(LinkedInSalesNavigatorPage.getUrl())); | ||
await page.setStatus(config.enabled); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<boolean> { | ||
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<void> { | ||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
} |