Skip to content

Commit

Permalink
Merge pull request #25 from DGB-UNAM-FOLIO/UNAM
Browse files Browse the repository at this point in the history
Add story Primary Currency Setting
  • Loading branch information
zburke authored Jun 11, 2019
2 parents d21953e + 5c77576 commit d488e22
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Change history for ui-organization
## [2.10.1]
* Primary Currency Setting. Refs UIU-1040.

## [2.10.0](https://github.com/folio-org/ui-organization/tree/v2.10.0) (2019-06-10)
[Full Changelog](https://github.com/folio-org/ui-organization/compare/v2.9.1...v2.10.0)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
"@folio/eslint-config-stripes": "^3.2.1",
"@folio/stripes": "^2.7.0",
"@folio/stripes-cli": "^1.8.0",
"@folio/stripes-core": "^3.5.1",
"@folio/stripes-core": "^3.6.0",
"babel-polyfill": "^6.26.0",
"babel-eslint": "^9.0.0",
"chai": "^4.2.0",
Expand Down
30 changes: 23 additions & 7 deletions src/settings/Locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { Field } from 'redux-form';
import { ConfigManager } from '@folio/stripes/smart-components';
import { Col, Row, Select } from '@folio/stripes/components';
import { Col, Row, Select, CurrencySelect } from '@folio/stripes/components';
import timezones from '../util/timezones';

const timeZonesList = timezones.map(timezone => (
Expand Down Expand Up @@ -39,6 +39,7 @@ class Locale extends React.Component {
}).isRequired,
setLocale: PropTypes.func.isRequired,
setTimezone: PropTypes.func.isRequired,
setCurrency: PropTypes.func.isRequired,
}).isRequired,
label: PropTypes.node.isRequired,
};
Expand All @@ -54,7 +55,7 @@ class Locale extends React.Component {
// eslint-disable-next-line class-methods-use-this
getInitialValues(settings) {
const value = settings.length === 0 ? '' : settings[0].value;
const defaultConfig = { locale: 'en-US', timezone: 'UTC' };
const defaultConfig = { locale: 'en-US', timezone: 'UTC', currency: 'USD' };
let config;

try {
Expand All @@ -68,17 +69,18 @@ class Locale extends React.Component {

setLocaleSettings(setting) {
const localeValues = JSON.parse(setting.value);
const { locale, timezone } = localeValues;
const { locale, timezone, currency } = localeValues;
setTimeout(() => {
if (locale) this.props.stripes.setLocale(locale);
if (timezone) this.props.stripes.setTimezone(timezone);
if (currency) this.props.stripes.setCurrency(currency);
}, 2000);
}

// eslint-disable-next-line class-methods-use-this
beforeSave(data) {
const { locale, timezone } = data;
return JSON.stringify({ locale, timezone });
const { locale, timezone, currency } = data;
return JSON.stringify({ locale, timezone, currency });
}

render() {
Expand All @@ -92,7 +94,7 @@ class Locale extends React.Component {
onAfterSave={this.setLocaleSettings}
>
<Row>
<Col xs={12}>
<Col xs={12} id="select-locale">
<div>
<FormattedMessage id="ui-tenant-settings.settings.localization" />
</div>
Expand All @@ -107,7 +109,7 @@ class Locale extends React.Component {
</Col>
</Row>
<Row>
<Col xs={12}>
<Col xs={12} id="select-timezone">
<div>
<FormattedMessage id="ui-tenant-settings.settings.timeZonePicker" />
</div>
Expand All @@ -121,6 +123,20 @@ class Locale extends React.Component {
/>
</Col>
</Row>
<Row>
<Col xs={12} id="select-currency">
<div>
<FormattedMessage id="ui-tenant-settings.settings.primaryCurrency" />
</div>
<br />
<Field
component={CurrencySelect}
id="currency"
name="currency"
placeholder="---"
/>
</Col>
</Row>
</this.configManager>
);
}
Expand Down
20 changes: 20 additions & 0 deletions test/bigtest/interactors/language-and-localization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
clickable,
collection,
interactor,
text,
} from '@bigtest/interactor';

// eslint-disable-next-line import/no-extraneous-dependencies
import SelectInteractor from '@folio/stripes-components/lib/Select/tests/interactor';

@interactor class LanguageAndLocalization {
title = text('#config-form [class*=paneTitle---]');
settings = collection('[class*=row--]', SelectInteractor);
save = clickable('#clickable-save-config');
selectLocale = new SelectInteractor('#select-locale');
selectTimeZone = new SelectInteractor('#select-timezone');
selectCurrency = new SelectInteractor('#select-currency');
}

export default LanguageAndLocalization;
10 changes: 10 additions & 0 deletions test/bigtest/network/factories/configs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

import { Factory, faker } from '@bigtest/mirage';

export default Factory.extend({
id: faker.random.uuid,
module: 'ORG',
configName: 'localeSettings',
enabled: 'true',
value: '{ currency: "USD" }'
});
3 changes: 3 additions & 0 deletions test/bigtest/network/models/configs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Model } from '@bigtest/mirage';

export default Model.extend();
18 changes: 18 additions & 0 deletions test/bigtest/network/scenarios/language-and-localization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* istanbul ignore file */

export default (server) => {
server.get('/configurations/entries', (schema) => {
return schema.configs.all();
});

server.post('/configurations/entries', (schema, request) => {
const body = JSON.parse(request.requestBody);
return schema.configs.create(body);
});

server.put('/configurations/entries/:id', ({ configs }, request) => {
const matching = configs.find(request.params.id);
const body = JSON.parse(request.requestBody);
return matching.update(body);
});
};
49 changes: 49 additions & 0 deletions test/bigtest/tests/language-and-localization-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { beforeEach, describe, it } from '@bigtest/mocha';
import { expect } from 'chai';
import setupApplication from '../helpers/setup-application';
import LanguageAndLocalization from '../interactors/language-and-localization';

describe('Language and localization', () => {
setupApplication({ scenarios: ['language-and-localization'] });
const lal = new LanguageAndLocalization();

beforeEach(function () {
this.visit('/settings/tenant-settings/locale');
});

it('should be present', () => {
expect(lal.title).to.equal('Language and localization');
});
describe('Test primary currency', () => {
beforeEach(async function () {
await lal.selectCurrency.selectAndBlur('Canadian Dollar (CAD)');
await lal.save();
});

it('should be present', () => {
expect(lal.selectCurrency.val).to.equal('CAD');
}).timeout(2000);
});

describe('Test primary locale', () => {
beforeEach(async function () {
await lal.selectLocale.selectAndBlur('Arabic');
await lal.save();
});

it('should be present', () => {
expect(lal.selectLocale.val).to.equal('ar-AR');
}).timeout(2000);
});

describe('Test primary timezone', () => {
beforeEach(async function () {
await lal.selectTimeZone.selectAndBlur('UTC');
await lal.save();
});

it('should be present', () => {
expect(lal.selectTimeZone.val).to.equal('UTC');
}).timeout(2000);
});
});
1 change: 1 addition & 0 deletions translations/ui-tenant-settings/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"settings.keyBindings": "Edit key bindings as JSON.",
"settings.localization": "Locale (for language display, date format etc.)",
"settings.timeZonePicker": "Time zone (time zone used when showing date time information)",
"settings.primaryCurrency": "Primary currency (for currency symbol to display)",
"settings.updated": "Settings were successfully updated.",

"settings.saml.validate.fillIn": "Please fill this in to continue",
Expand Down

0 comments on commit d488e22

Please sign in to comment.