Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/jsxc/jsxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorsualko <klaus@jsxc.org>2019-02-08 19:02:49 +0300
committersualko <klaus@jsxc.org>2019-02-08 19:02:49 +0300
commit74946465cb20a850156b395e2ec80afc0b000cd9 (patch)
tree0f76e2fae591e1d6f410ba59745c0aeb14fca1e7 /test
parent0f5750dea45a2e47be2831b2abefd7a343b7737c (diff)
fix: option merge
Diffstat (limited to 'test')
-rw-r--r--test/Options.spec.ts30
-rw-r--r--test/util/Utils.spec.ts51
2 files changed, 75 insertions, 6 deletions
diff --git a/test/Options.spec.ts b/test/Options.spec.ts
index 8fcaad97..3c689a95 100644
--- a/test/Options.spec.ts
+++ b/test/Options.spec.ts
@@ -40,7 +40,7 @@ describe('Options', function() {
});
it('should return stored options', function() {
- const STORED_VALUE = 'foo';
+ const STORED_VALUE = new Date();
let store = {};
for (let name in defaultOptions) {
@@ -50,10 +50,28 @@ describe('Options', function() {
storage.getItem = sinon.stub().returns(store);
for (let name in defaultOptions) {
- expect(options.get(name)).equals(STORED_VALUE);
+ expect(options.get(name), `Option name: ${name}`).equals(STORED_VALUE);
}
});
+ it('should return merged objects, if only single values were changed', function() {
+ storage.getItem = sinon.stub().returns({
+ notification: {
+ mute: 'foobar'
+ }
+ });
+
+ let notificationOptions = options.get('notification');
+
+ for (let name in defaultOptions.notification) {
+ if (name === 'mute') {
+ expect(notificationOptions[name]).equals('foobar');
+ } else {
+ expect(notificationOptions[name]).equals(defaultOptions.notification[name]);
+ }
+ }
+ })
+
it('should return correct values for chained keys', function() {
const STORED_VALUE = 'foo';
let store = {
@@ -77,7 +95,7 @@ describe('Options', function() {
it('should return overwritten defaults', function() {
storage.getItem = sinon.stub().returns({});
- const KEY = 'onLogin';
+ const KEY = 'rosterAppend';
const VALUE = 'foo';
Options.overwriteDefaults({
@@ -102,11 +120,11 @@ describe('Options', function() {
Options.overwriteDefaults({
newOption: 'new',
- onLogin: 'foobar',
+ rosterAppend: 'div',
});
expect(options.get('newOption')).equals(undefined);
- expect(options.get('onLogin')).equals(defaultOptions.onLogin);
+ expect(options.get('rosterAppend')).equals(defaultOptions.rosterAppend);
});
it('should update the value in the store', function() {
@@ -145,7 +163,7 @@ describe('Options', function() {
})
it('should trigger registered hooks', function() {
- const KEY = 'onLogin';
+ const KEY = 'rosterAppend';
const VALUE = 'foobar';
const OLD_VALUE = 'old_foobar';
diff --git a/test/util/Utils.spec.ts b/test/util/Utils.spec.ts
index f87130b0..288b40d1 100644
--- a/test/util/Utils.spec.ts
+++ b/test/util/Utils.spec.ts
@@ -17,4 +17,55 @@ describe('Utils', () => {
it('should escape the following characters: &<>', () => {
expect(Utils.escapeHTML('<>&&amp;&lt;&gt;')).equals('&lt;&gt;&amp;&amp;&lt;&gt;');
})
+
+ it('should detect property objects', () => {
+ expect(Utils.isObject({}), 'Empty object').equals(true);
+ expect(Utils.isObject({a: 1}), 'Object').equals(true);
+
+ expect(Utils.isObject(undefined), 'Undefined').equals(false);
+ expect(Utils.isObject(0), 'Number 0').equals(false);
+ expect(Utils.isObject(1), 'Number 1').equals(false);
+ expect(Utils.isObject(true), 'True boolean').equals(false);
+ expect(Utils.isObject(false), 'False boolean').equals(false);
+ expect(Utils.isObject([]), 'Empty array').equals(false);
+ expect(Utils.isObject(['foo']), 'Array').equals(false);
+ expect(Utils.isObject(''), 'Empty string').equals(false);
+ expect(Utils.isObject('foo'), 'String').equals(false);
+ expect(Utils.isObject(new Date()), 'Date object').equals(false);
+ })
+
+ it('should deep merge objects', () => {
+ let date = new Date();
+ let target: any = {
+ a: {
+ b: 'bar',
+ },
+ b: 'foobar',
+ c: 'bar',
+ };
+ let source1 = {
+ a: {
+ a: 'new',
+ b: 'foobar',
+ },
+ c: 'foobar',
+ d: date,
+ };
+ let source2 = {
+ a: {
+ c: 'foobar',
+ },
+ e: 'foobar',
+ }
+ let returnValue = Utils.mergeDeep(target, source1, source2);
+
+ expect(returnValue).equals(target);
+ expect(target.a.a, 'target.a.a').equals('new');
+ expect(target.a.b, 'target.a.b').equals('foobar');
+ expect(target.a.c, 'target.a.c').equals('foobar');
+ expect(target.b, 'target.b').equals('foobar');
+ expect(target.c, 'target.c').equals('foobar');
+ expect(target.d, 'target.d').equals(date);
+ expect(target.e, 'target.e').equals('foobar');
+ });
});