-
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: add Company Information > Currency Locale
This plugins allows changing the default currency locale. Configuration example: ```json "companyInformation": { "defaultCurrencyIsoCode": "English (Ireland) - EUR" } ```
- Loading branch information
Showing
10 changed files
with
181 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ | |
node_modules | ||
/.sfdx | ||
/.sf | ||
coverage/ | ||
.yarn/ | ||
.yarnrc.yml | ||
|
||
.vscode/settings.json | ||
|
||
|
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,7 @@ | ||
{ | ||
"settings": { | ||
"companyInformation": { | ||
"defaultCurrencyIsoCode": "Invalid Currency" | ||
} | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"settings": { | ||
"companyInformation": { | ||
"defaultCurrencyIsoCode": "English (Ireland) - EUR" | ||
} | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"settings": { | ||
"companyInformation": { | ||
"defaultCurrencyIsoCode": "English (South Africa) - ZAR" | ||
} | ||
} | ||
} |
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,62 @@ | ||
import assert from 'assert'; | ||
import * as child from 'child_process'; | ||
import * as path from 'path'; | ||
import { CompanyInformation } from '.'; | ||
import Os from 'os'; | ||
|
||
describe(CompanyInformation.name, function () { | ||
this.slow('30s'); | ||
this.timeout('2m'); | ||
|
||
const execStr = path.resolve('bin', Os.platform().startsWith('win') ? 'run.cmd' : 'run'); | ||
|
||
it('should set the currency to "English (South Africa) - ZAR" for next steps', () => { | ||
const bffile = path.join(__dirname, 'currency-zar.json'); | ||
const apply = child.spawnSync(execStr, [ | ||
'browserforce:apply', | ||
'-f', | ||
bffile | ||
]); | ||
assert.deepStrictEqual(apply.status, 0, apply.output.toString()); | ||
// no additional assertions are done here as this is a preparation for the followup tests | ||
}); | ||
it('should change currency to "English (Ireland) - EUR"', () => { | ||
const bffile = path.join(__dirname, 'currency-ireland.json'); | ||
const apply = child.spawnSync(execStr, [ | ||
'browserforce:apply', | ||
'-f', | ||
bffile | ||
]); | ||
assert.deepStrictEqual(apply.status, 0, apply.output.toString()); | ||
assert.ok( | ||
/to '"English \(Ireland\) - EUR"'/.test(apply.output.toString()), | ||
apply.output.toString() | ||
); | ||
}); | ||
it('should respond to no action necessary for currency change', () => { | ||
const bffile = path.join(__dirname, 'currency-ireland.json'); | ||
const apply = child.spawnSync(execStr, [ | ||
'browserforce:apply', | ||
'-f', | ||
bffile | ||
]); | ||
assert.deepStrictEqual(apply.status, 0, apply.output.toString()); | ||
assert.ok( | ||
/no action necessary/.test(apply.output.toString()), | ||
apply.output.toString() | ||
); | ||
}); | ||
it('should error on invalid input for invalid currency', () => { | ||
const bffile = path.join(__dirname, 'currency-invalid.json'); | ||
const apply = child.spawnSync(execStr, [ | ||
'browserforce:apply', | ||
'-f', | ||
bffile | ||
]); | ||
assert.notDeepStrictEqual(apply.status, 0, apply.output.toString()); | ||
assert.ok( | ||
/Invalid currency provided/.test(apply.output.toString()), | ||
apply.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,73 @@ | ||
import { BrowserforcePlugin } from '../../plugin'; | ||
|
||
const PATHS = (orgId: string) => ({ | ||
BASE: `/${orgId}/e` | ||
}); | ||
const SELECTORS = { | ||
BASE: 'div.pbBody', | ||
CURRENCY_DROPDOWN: '#DefaultCurrencyIsoCode', | ||
SAVE_BUTTON: 'input[class="btn"][type="submit"][name="save"]' | ||
}; | ||
|
||
type Config = { | ||
defaultCurrencyIsoCode?: string; | ||
}; | ||
|
||
export class CompanyInformation extends BrowserforcePlugin { | ||
public async retrieve(): Promise<Config> { | ||
const path = PATHS(this.org.getOrgId()); | ||
const page = await this.browserforce.openPage(path.BASE); | ||
await page.waitForSelector(SELECTORS.CURRENCY_DROPDOWN); | ||
|
||
const response = { | ||
defaultCurrencyIsoCode: '' | ||
}; | ||
const selectedOptions = await page.$$eval( | ||
`${SELECTORS.CURRENCY_DROPDOWN} > option[selected]`, | ||
options => options.map(option => option.textContent) | ||
); | ||
if (!selectedOptions) { | ||
throw new Error('No available existing value'); | ||
} | ||
response.defaultCurrencyIsoCode = selectedOptions[0]; | ||
return response; | ||
} | ||
|
||
public async apply(config: Config): Promise<void> { | ||
if (config.defaultCurrencyIsoCode?.length > 0) { | ||
const path = PATHS(this.org.getOrgId()); | ||
const page = await this.browserforce.openPage(path.BASE); | ||
|
||
// wait for selectors | ||
await page.waitForSelector(SELECTORS.CURRENCY_DROPDOWN); | ||
const selectElem = await page.$(SELECTORS.CURRENCY_DROPDOWN); | ||
await page.waitForSelector(SELECTORS.SAVE_BUTTON); | ||
|
||
// apply changes | ||
// await page.click(SELECTORS.CURRENCY_DROPDOWN); | ||
const optionList = await page.$$eval( | ||
`${SELECTORS.CURRENCY_DROPDOWN} > option`, | ||
options => options.map(option => ({ | ||
value: (option as HTMLOptionElement).value, | ||
textContent: option.textContent | ||
})) | ||
); | ||
const toBeSelectedOption = optionList.find(option => option.textContent == config.defaultCurrencyIsoCode); | ||
if (!toBeSelectedOption) { | ||
throw new Error(`Invalid currency provided. '${config.defaultCurrencyIsoCode}' is not a valid option available for currencies. Please use the exact name as it appears in the list.`); | ||
} | ||
await selectElem.select(toBeSelectedOption.value); | ||
|
||
// auto accept the dialog when it appears | ||
page.on("dialog", (dialog) => { | ||
dialog.accept(); | ||
}); | ||
|
||
// save | ||
await Promise.all([ | ||
page.waitForNavigation(), | ||
page.click(SELECTORS.SAVE_BUTTON) | ||
]); | ||
} | ||
} | ||
} |
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/home-page-layouts/schema.json", | ||
"title": "Company Information", | ||
"description": "", | ||
"type": "object", | ||
"properties": { | ||
"defaultCurrencyIsoCode": { | ||
"title": "Default Currency", | ||
"type": "string" | ||
} | ||
} | ||
} |
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