Skip to content

Commit

Permalink
feat: enable/disable LinkedIn Sales Navigator
Browse files Browse the repository at this point in the history
Resolves #611
  • Loading branch information
amtrack committed Feb 9, 2024
1 parent fe69d9d commit 6b0c41f
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,5 +34,6 @@ export {
reportsAndDashboards,
salesforceToSalesforce,
security,
companyInformation
companyInformation,
linkedInSalesNavigatorSettings
};
8 changes: 8 additions & 0 deletions src/plugins/linkedin-sales-navigator-settings/disable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "../schema.json",
"settings": {
"linkedInSalesNavigatorSettings": {
"enabled": false
}
}
}
8 changes: 8 additions & 0 deletions src/plugins/linkedin-sales-navigator-settings/enable.json
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 src/plugins/linkedin-sales-navigator-settings/index.e2e-spec.ts
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' });
});
});
20 changes: 20 additions & 0 deletions src/plugins/linkedin-sales-navigator-settings/index.ts
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);
}
}
43 changes: 43 additions & 0 deletions src/plugins/linkedin-sales-navigator-settings/page.ts
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();
}
}
13 changes: 13 additions & 0 deletions src/plugins/linkedin-sales-navigator-settings/schema.json
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"
}
}
}

0 comments on commit 6b0c41f

Please sign in to comment.