-
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.
Merge pull request #180 from amtrack/feat/ui-density-settings
feat: add User Interface -> Density Settings
- Loading branch information
Showing
7 changed files
with
209 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "../schema.json", | ||
"settings": { | ||
"densitySettings": { | ||
"density": "Comfy" | ||
} | ||
} | ||
} |
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": { | ||
"densitySettings": { | ||
"density": "Compact" | ||
} | ||
} | ||
} |
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,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() | ||
); | ||
}); | ||
}); |
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,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 | ||
) | ||
]); | ||
} | ||
} |
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,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"] | ||
} | ||
} | ||
} |
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