Skip to content

Commit

Permalink
Merge pull request #180 from amtrack/feat/ui-density-settings
Browse files Browse the repository at this point in the history
feat: add User Interface -> Density Settings
  • Loading branch information
amtrack authored Oct 21, 2019
2 parents 610c53f + 4e3f3b1 commit 6dda85a
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/plugins/density-settings/comfy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "../schema.json",
"settings": {
"densitySettings": {
"density": "Comfy"
}
}
}
8 changes: 8 additions & 0 deletions src/plugins/density-settings/compact.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "../schema.json",
"settings": {
"densitySettings": {
"density": "Compact"
}
}
}
79 changes: 79 additions & 0 deletions src/plugins/density-settings/index.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import * as assert from 'assert';
import * as child from 'child_process';
import * as path from 'path';
import DensitySettings from '.';

describe(DensitySettings.name, () => {
it('should set to Compact', function() {
this.timeout(1000 * 90);
this.slow(1000 * 30);
const setCompactCommand = child.spawnSync(path.resolve('bin', 'run'), [
'browserforce:apply',
'-f',
path.resolve(path.join(__dirname, 'compact.json'))
]);
assert.deepEqual(
setCompactCommand.status,
0,
setCompactCommand.output.toString()
);
assert(
/to '"Compact"'/.test(setCompactCommand.output.toString()),
setCompactCommand.output.toString()
);
});
it('should already be set to Compact', function() {
this.timeout(1000 * 90);
this.slow(1000 * 30);
const setCompactCommand2 = child.spawnSync(path.resolve('bin', 'run'), [
'browserforce:apply',
'-f',
path.resolve(path.join(__dirname, 'compact.json'))
]);
assert.deepEqual(
setCompactCommand2.status,
0,
setCompactCommand2.output.toString()
);
assert(
/no action necessary/.test(setCompactCommand2.output.toString()),
setCompactCommand2.output.toString()
);
});
it('should set to Comfy', function() {
this.timeout(1000 * 90);
this.slow(1000 * 30);
const setComfyCommand = child.spawnSync(path.resolve('bin', 'run'), [
'browserforce:apply',
'-f',
path.resolve(path.join(__dirname, 'comfy.json'))
]);
assert.deepEqual(
setComfyCommand.status,
0,
setComfyCommand.output.toString()
);
assert(
/to '"Comfy"'/.test(setComfyCommand.output.toString()),
setComfyCommand.output.toString()
);
});
it('should already be set to Comfy', function() {
this.timeout(1000 * 90);
this.slow(1000 * 30);
const setComfyCommand2 = child.spawnSync(path.resolve('bin', 'run'), [
'browserforce:apply',
'-f',
path.resolve(path.join(__dirname, 'comfy.json'))
]);
assert.deepEqual(
setComfyCommand2.status,
0,
setComfyCommand2.output.toString()
);
assert(
/no action necessary/.test(setComfyCommand2.output.toString()),
setComfyCommand2.output.toString()
);
});
});
95 changes: 95 additions & 0 deletions src/plugins/density-settings/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { BrowserforcePlugin } from '../../plugin';

const PATHS = {
BASE: 'lightning/setup/DensitySetup/home'
};

const domWaitForPickerItems = () => {
return (
document.querySelector('one-density-visual-picker') &&
document.querySelector('one-density-visual-picker').shadowRoot &&
document
.querySelector('one-density-visual-picker')
.shadowRoot.querySelectorAll('one-density-visual-picker-item').length >
1 &&
document
.querySelector('one-density-visual-picker')
.shadowRoot.querySelectorAll('one-density-visual-picker-item')[1]
.shadowRoot &&
document
.querySelector('one-density-visual-picker')
.shadowRoot.querySelectorAll('one-density-visual-picker-item')[1]
.shadowRoot.querySelector('input')
);
};

const domGetPickerItemInputs = () => {
return Array.from(
document
.querySelector('one-density-visual-picker')
.shadowRoot.querySelectorAll('one-density-visual-picker-item')
).map(item => {
return item.shadowRoot.querySelector('input');
});
};

export default class DensitySettings extends BrowserforcePlugin {
public async retrieve() {
const response = {
density: ''
};
const page = await this.browserforce.openPage(PATHS.BASE, {
waitUntil: ['load', 'domcontentloaded', 'networkidle0']
});
await page.waitForFunction(domWaitForPickerItems);
const inputJsHandle = await page.evaluateHandle(domGetPickerItemInputs);
// convert JSHandle.getProperties (Map) to Array
const inputs = Array.from((await inputJsHandle.getProperties()).values());
const checkedRadio = await page.evaluate((...inputElements) => {
return inputElements
.map(input => {
return {
value: input.value,
checked: input.checked
};
})
.find(input => input.checked);
}, ...inputs);
if (checkedRadio && checkedRadio.value) {
response.density = checkedRadio.value;
}
return response;
}

public async apply(config) {
const page = await this.browserforce.openPage(PATHS.BASE, {
waitUntil: ['load', 'domcontentloaded', 'networkidle0']
});
await page.waitForFunction(domWaitForPickerItems);
const inputJsHandle = await page.evaluateHandle(domGetPickerItemInputs);
// convert JSHandle.getProperties (Map) to Array
const inputs = Array.from((await inputJsHandle.getProperties()).values());
await Promise.all([
page.waitForResponse(
response =>
response
.url()
.includes(
'UserSettings.DensityUserSettings.setDefaultDensitySetting=1'
) && response.status() === 200
),
page.evaluate(
(targetValue, ...inputElements) => {
const targetInput = inputElements.find(
input => input.value === targetValue
);
if (targetInput) {
targetInput.click();
}
},
config.density,
...inputs
)
]);
}
}
14 changes: 14 additions & 0 deletions src/plugins/density-settings/schema.json
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/density-settings/schema.json",
"title": "Density Settings",
"type": "object",
"properties": {
"density": {
"title": "Density",
"description": "Choose the default display setting for your org",
"type": "string",
"enum": ["Comfy", "Compact"]
}
}
}
2 changes: 2 additions & 0 deletions src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as communities from './communities';
import * as companySettings from './company-settings';
import * as customerPortal from './customer-portal';
import * as densitySettings from './density-settings';
import * as homePageLayouts from './home-page-layouts';
import * as reportsAndDashboards from './reports-and-dashboards';
import * as salesforceToSalesforce from './salesforce-to-salesforce';
Expand All @@ -9,6 +10,7 @@ export {
communities,
companySettings,
customerPortal,
densitySettings,
homePageLayouts,
reportsAndDashboards,
salesforceToSalesforce,
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"customerPortal": {
"$ref": "./customer-portal/schema.json"
},
"densitySettings": {
"$ref": "./density-settings/schema.json"
},
"homePageLayouts": {
"$ref": "./home-page-layouts/schema.json"
},
Expand Down

0 comments on commit 6dda85a

Please sign in to comment.