|
@@ -26,13 +26,16 @@ beforeEach( () => {
|
|
|
|
|
|
|
|
describe( 'constructor', () => {
|
|
describe( 'constructor', () => {
|
|
|
it( 'should set configurations', () => {
|
|
it( 'should set configurations', () => {
|
|
|
- expect( config ).to.have.property( 'creator' ).to.equal( 'inline' );
|
|
|
|
|
- expect( config ).to.have.property( 'language' ).to.equal( 'pl' );
|
|
|
|
|
- expect( config ).to.have.property( 'resize' ).to.have.property( 'minheight' ).to.equal( 300 );
|
|
|
|
|
- expect( config ).to.have.property( 'resize' ).to.have.property( 'maxheight' ).to.equal( 800 );
|
|
|
|
|
- expect( config ).to.have.property( 'resize' ).to.have.property( 'icon' )
|
|
|
|
|
- .to.have.property( 'path' ).to.equal( 'xyz' );
|
|
|
|
|
- expect( config ).to.have.property( 'toolbar' ).to.equal( 'top' );
|
|
|
|
|
|
|
+ expect( config.get( 'creator' ) ).to.equal( 'inline' );
|
|
|
|
|
+ expect( config.get( 'language' ) ).to.equal( 'pl' );
|
|
|
|
|
+ expect( config.get( 'resize' ) ).to.deep.equal( {
|
|
|
|
|
+ minheight: 300,
|
|
|
|
|
+ maxheight: 800,
|
|
|
|
|
+ icon: {
|
|
|
|
|
+ path: 'xyz'
|
|
|
|
|
+ }
|
|
|
|
|
+ } );
|
|
|
|
|
+ expect( config.get( 'toolbar' ) ).to.equal( 'top' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should work with no parameters', () => {
|
|
it( 'should work with no parameters', () => {
|
|
@@ -42,11 +45,6 @@ describe( 'constructor', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
describe( 'set', () => {
|
|
describe( 'set', () => {
|
|
|
- it( 'should create Config instances for objects', () => {
|
|
|
|
|
- expect( config.resize ).to.be.an.instanceof( Config );
|
|
|
|
|
- expect( config.resize.icon ).to.be.an.instanceof( Config );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
it( 'should set configurations when passing objects', () => {
|
|
it( 'should set configurations when passing objects', () => {
|
|
|
config.set( {
|
|
config.set( {
|
|
|
option1: 1,
|
|
option1: 1,
|
|
@@ -55,32 +53,53 @@ describe( 'set', () => {
|
|
|
}
|
|
}
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- expect( config )
|
|
|
|
|
- .to.have.property( 'option1' ).to.equal( 1 );
|
|
|
|
|
-
|
|
|
|
|
- expect( config )
|
|
|
|
|
- .to.have.property( 'option2' )
|
|
|
|
|
- .to.have.property( 'suboption21' ).to.equal( 21 );
|
|
|
|
|
|
|
+ expect( config.get( 'option1' ) ).to.equal( 1 );
|
|
|
|
|
+ expect( config.get( 'option2.suboption21' ) ).to.equal( 21 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should set configurations when passing name and value', () => {
|
|
it( 'should set configurations when passing name and value', () => {
|
|
|
config.set( 'something', 'anything' );
|
|
config.set( 'something', 'anything' );
|
|
|
|
|
|
|
|
- expect( config ).to.have.property( 'something' ).to.equal( 'anything' );
|
|
|
|
|
|
|
+ expect( config.get( 'something' ) ).to.equal( 'anything' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should set configurations when passing name.with.deep and value', () => {
|
|
it( 'should set configurations when passing name.with.deep and value', () => {
|
|
|
config.set( 'color.red', 'f00' );
|
|
config.set( 'color.red', 'f00' );
|
|
|
config.set( 'background.color.blue', '00f' );
|
|
config.set( 'background.color.blue', '00f' );
|
|
|
|
|
|
|
|
- expect( config )
|
|
|
|
|
- .to.have.property( 'color' )
|
|
|
|
|
- .to.have.property( 'red' ).to.equal( 'f00' );
|
|
|
|
|
|
|
+ expect( config.get( 'color.red' ) ).to.equal( 'f00' );
|
|
|
|
|
+ expect( config.get( 'background.color.blue' ) ).to.equal( '00f' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should replace a simple entry with an object', () => {
|
|
|
|
|
+ config.set( 'test', 1 );
|
|
|
|
|
+ config.set( 'test', {
|
|
|
|
|
+ prop: 1
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ expect( config.get( 'test' ) ).to.be.an( 'object' );
|
|
|
|
|
+ expect( config.get( 'test.prop' ) ).to.equal( 1 );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should replace a simple entry with an object when passing only object', () => {
|
|
|
|
|
+ config.set( 'test', 1 );
|
|
|
|
|
+ config.set( {
|
|
|
|
|
+ test: {
|
|
|
|
|
+ prop: 1
|
|
|
|
|
+ }
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- expect( config )
|
|
|
|
|
- .to.have.property( 'background' )
|
|
|
|
|
- .to.have.property( 'color' )
|
|
|
|
|
- .to.have.property( 'blue' ).to.equal( '00f' );
|
|
|
|
|
|
|
+ expect( config.get( 'test' ) ).to.be.an( 'object' );
|
|
|
|
|
+ expect( config.get( 'test.prop' ) ).to.equal( 1 );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should replace a simple entry with an object when passing a name.with.deep', () => {
|
|
|
|
|
+ config.set( 'test.prop', 1 );
|
|
|
|
|
+ config.set( 'test.prop.value', 1 );
|
|
|
|
|
+
|
|
|
|
|
+ expect( config.get( 'test' ) ).to.be.an( 'object' );
|
|
|
|
|
+ expect( config.get( 'test.prop' ) ).to.be.an( 'object' );
|
|
|
|
|
+ expect( config.get( 'test.prop.value' ) ).to.equal( 1 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should override and expand deep configurations', () => {
|
|
it( 'should override and expand deep configurations', () => {
|
|
@@ -95,64 +114,142 @@ describe( 'set', () => {
|
|
|
}
|
|
}
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- expect( config ).to.have.property( 'resize' );
|
|
|
|
|
- expect( config.resize ).to.have.property( 'minheight' ).to.equal( 400 );
|
|
|
|
|
- expect( config.resize ).to.have.property( 'maxheight' ).to.equal( 800 ); // Not touched
|
|
|
|
|
- expect( config.resize ).to.have.property( 'hidden' ).to.equal( true );
|
|
|
|
|
|
|
+ expect( config.get( 'resize' ) ).to.be.deep.equal( {
|
|
|
|
|
+ minheight: 400, // Overridden
|
|
|
|
|
+ maxheight: 800, // The same
|
|
|
|
|
+ hidden: true, // Expanded
|
|
|
|
|
+ icon: {
|
|
|
|
|
+ path: 'abc', // Overridden
|
|
|
|
|
+ url: true // Expanded
|
|
|
|
|
+ }
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should override and expand object when passing an object', () => {
|
|
|
|
|
+ config.set( 'resize', {
|
|
|
|
|
+ minHeight: 400, // Override
|
|
|
|
|
+ hidden: true, // Expand
|
|
|
|
|
+ icon: {
|
|
|
|
|
+ path: 'abc', // Override
|
|
|
|
|
+ url: true // Expand
|
|
|
|
|
+ }
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- expect( config.resize ).to.have.property( 'icon' );
|
|
|
|
|
- expect( config.resize.icon ).to.have.property( 'path' ).to.equal( 'abc' );
|
|
|
|
|
- expect( config.resize.icon ).to.have.property( 'url' ).to.equal( true );
|
|
|
|
|
|
|
+ expect( config.get( 'resize' ) ).to.deep.equal( {
|
|
|
|
|
+ minheight: 400, // Overridden
|
|
|
|
|
+ maxheight: 800, // The same
|
|
|
|
|
+ hidden: true, // Expanded
|
|
|
|
|
+ icon: {
|
|
|
|
|
+ path: 'abc', // Overridden
|
|
|
|
|
+ url: true // Expanded
|
|
|
|
|
+ }
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should replace a simple entry with a Config instance', () => {
|
|
|
|
|
- config.set( 'test', 1 );
|
|
|
|
|
- config.set( 'test', {
|
|
|
|
|
- prop: 1
|
|
|
|
|
|
|
+ it( 'should not create object for non-pure objects', () => {
|
|
|
|
|
+ function SomeClass() {}
|
|
|
|
|
+
|
|
|
|
|
+ config.set( 'date', new Date() );
|
|
|
|
|
+ config.set( {
|
|
|
|
|
+ instance: new SomeClass()
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- expect( config.test ).to.be.an.instanceof( Config );
|
|
|
|
|
- expect( config.test.prop ).to.equal( 1 );
|
|
|
|
|
|
|
+ expect( config.get( 'date' ) ).to.be.an.instanceof( Date );
|
|
|
|
|
+ expect( config.get( 'instance' ) ).to.be.an.instanceof( SomeClass );
|
|
|
} );
|
|
} );
|
|
|
|
|
+} );
|
|
|
|
|
|
|
|
- it( 'should replace a simple entry with a Config instance when passing an object', () => {
|
|
|
|
|
- config.set( 'test', 1 );
|
|
|
|
|
|
|
+describe( 'define', () => {
|
|
|
|
|
+ it( 'should set configurations when passing objects', () => {
|
|
|
config.set( {
|
|
config.set( {
|
|
|
- test: {
|
|
|
|
|
- prop: 1
|
|
|
|
|
|
|
+ option1: 1,
|
|
|
|
|
+ option2: {
|
|
|
|
|
+ subOption21: 21
|
|
|
}
|
|
}
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- expect( config.test ).to.be.an.instanceof( Config );
|
|
|
|
|
- expect( config.test.prop ).to.equal( 1 );
|
|
|
|
|
|
|
+ expect( config.get( 'option1' ) ).to.equal( 1 );
|
|
|
|
|
+ expect( config.get( 'option2.suboption21' ) ).to.equal( 21 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should replace a simple entry with a Config instance when passing a name.with.deep', () => {
|
|
|
|
|
- config.set( 'test.prop', 1 );
|
|
|
|
|
- config.set( 'test.prop.value', 1 );
|
|
|
|
|
|
|
+ it( 'should set configurations when passing name and value', () => {
|
|
|
|
|
+ config.set( 'something', 'anything' );
|
|
|
|
|
|
|
|
- expect( config.test ).to.be.an.instanceof( Config );
|
|
|
|
|
- expect( config.test.prop ).to.be.an.instanceof( Config );
|
|
|
|
|
- expect( config.test.prop.value ).to.equal( 1 );
|
|
|
|
|
|
|
+ expect( config.get( 'something' ) ).to.equal( 'anything' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should not create Config instances for non-pure objects', () => {
|
|
|
|
|
- function SomeClass() {}
|
|
|
|
|
|
|
+ it( 'should set configurations when passing name.with.deep and value', () => {
|
|
|
|
|
+ config.set( 'color.red', 'f00' );
|
|
|
|
|
+ config.set( 'background.color.blue', '00f' );
|
|
|
|
|
|
|
|
- config.set( 'date', new Date() );
|
|
|
|
|
- config.set( {
|
|
|
|
|
- instance: new SomeClass()
|
|
|
|
|
|
|
+ expect( config.get( 'color.red' ) ).to.equal( 'f00' );
|
|
|
|
|
+ expect( config.get( 'background.color.blue' ) ).to.equal( '00f' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should not replace already defined values', () => {
|
|
|
|
|
+ config.define( 'language', 'en' );
|
|
|
|
|
+ config.define( 'resize.minHeight', 400 );
|
|
|
|
|
+ config.define( 'resize.icon', 'some value' );
|
|
|
|
|
+
|
|
|
|
|
+ expect( config.get( 'language' ) ).to.equal( 'pl' );
|
|
|
|
|
+ expect( config.get( 'resize.icon' ) ).to.be.an( 'object' );
|
|
|
|
|
+ expect( config.get( 'resize.minheight' ) ).to.equal( 300 );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should expand but not override deep configurations', () => {
|
|
|
|
|
+ config.define( {
|
|
|
|
|
+ resize: {
|
|
|
|
|
+ minHeight: 400, // No override
|
|
|
|
|
+ hidden: true, // Expand
|
|
|
|
|
+ icon: {
|
|
|
|
|
+ path: 'abc', // No override
|
|
|
|
|
+ url: true // Expand
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- expect( config.date ).to.be.an.instanceof( Date );
|
|
|
|
|
- expect( config.instance ).to.be.an.instanceof( SomeClass );
|
|
|
|
|
|
|
+ expect( config.get( 'resize' ) ).to.be.deep.equal( {
|
|
|
|
|
+ minheight: 300, // The same
|
|
|
|
|
+ maxheight: 800, // The same
|
|
|
|
|
+ hidden: true, // Expanded
|
|
|
|
|
+ icon: {
|
|
|
|
|
+ path: 'xyz', // The same
|
|
|
|
|
+ url: true // Expanded
|
|
|
|
|
+ }
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should expand but not override when passing an object', () => {
|
|
|
|
|
+ config.define( 'resize', {
|
|
|
|
|
+ minHeight: 400, // No override
|
|
|
|
|
+ hidden: true, // Expand
|
|
|
|
|
+ icon: {
|
|
|
|
|
+ path: 'abc', // No override
|
|
|
|
|
+ url: true // Expand
|
|
|
|
|
+ }
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ expect( config.get( 'resize' ) ).to.be.deep.equal( {
|
|
|
|
|
+ minheight: 300, // The same
|
|
|
|
|
+ maxheight: 800, // The same
|
|
|
|
|
+ hidden: true, // Expanded
|
|
|
|
|
+ icon: {
|
|
|
|
|
+ path: 'xyz', // The same
|
|
|
|
|
+ url: true // Expanded
|
|
|
|
|
+ }
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should set `null` for undefined value', () => {
|
|
|
|
|
- config.set( 'test' );
|
|
|
|
|
|
|
+ it( 'should not create an object for non-pure objects', () => {
|
|
|
|
|
+ function SomeClass() {}
|
|
|
|
|
+
|
|
|
|
|
+ config.define( 'date', new Date() );
|
|
|
|
|
+ config.define( {
|
|
|
|
|
+ instance: new SomeClass()
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- expect( config.test ).to.be.null;
|
|
|
|
|
- expect( config.get( 'test' ) ).to.be.null;
|
|
|
|
|
|
|
+ expect( config.get( 'date' ) ).to.be.an.instanceof( Date );
|
|
|
|
|
+ expect( config.get( 'instance' ) ).to.be.an.instanceof( SomeClass );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -166,16 +263,15 @@ describe( 'get', () => {
|
|
|
expect( config.get( 'resize.icon.path' ) ).to.equal( 'xyz' );
|
|
expect( config.get( 'resize.icon.path' ) ).to.equal( 'xyz' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should retrieve a subset of the configuration', () => {
|
|
|
|
|
- let resizeConfig = config.get( 'resize' );
|
|
|
|
|
-
|
|
|
|
|
- expect( resizeConfig ).to.have.property( 'minheight' ).to.equal( 300 );
|
|
|
|
|
- expect( resizeConfig ).to.have.property( 'maxheight' ).to.equal( 800 );
|
|
|
|
|
- expect( resizeConfig ).to.have.property( 'icon' ).to.have.property( 'path' ).to.equal( 'xyz' );
|
|
|
|
|
|
|
+ it( 'should retrieve a object of the configuration', () => {
|
|
|
|
|
+ let resize = config.get( 'resize' );
|
|
|
|
|
|
|
|
- let iconConfig = resizeConfig.get( 'icon' );
|
|
|
|
|
|
|
+ expect( resize ).to.be.an( 'object' );
|
|
|
|
|
+ expect( resize.minheight ).equal( 300 );
|
|
|
|
|
+ expect( resize.maxheight ).to.equal( 800 );
|
|
|
|
|
+ expect( resize.icon ).to.be.an( 'object' );
|
|
|
|
|
|
|
|
- expect( iconConfig ).to.have.property( 'path' ).to.equal( 'xyz' );
|
|
|
|
|
|
|
+ expect( resize.icon ).to.be.an( 'object' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should retrieve values case-insensitively', () => {
|
|
it( 'should retrieve values case-insensitively', () => {
|
|
@@ -189,50 +285,21 @@ describe( 'get', () => {
|
|
|
expect( config.get( 'invalid' ) ).to.be.undefined;
|
|
expect( config.get( 'invalid' ) ).to.be.undefined;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should return undefined for non existing deep configuration', () => {
|
|
|
|
|
- expect( config.get( 'resize.invalid.value' ) ).to.be.undefined;
|
|
|
|
|
- } );
|
|
|
|
|
-} );
|
|
|
|
|
-
|
|
|
|
|
-describe( 'define', () => {
|
|
|
|
|
- it( 'should create the definition property', () => {
|
|
|
|
|
- expect( config ).to.not.have.property( 'definition' );
|
|
|
|
|
-
|
|
|
|
|
- config.define( 'test', 1 );
|
|
|
|
|
-
|
|
|
|
|
- expect( config ).to.have.property( 'definition' );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should set configurations in the definition property', () => {
|
|
|
|
|
- config.define( 'test1', 1 );
|
|
|
|
|
-
|
|
|
|
|
- // This is for Code Coverage to ensure that it works when `definition` is already defined.
|
|
|
|
|
- config.define( 'test2', 2 );
|
|
|
|
|
-
|
|
|
|
|
- expect( config.definition ).to.have.property( 'test1' ).to.equal( 1 );
|
|
|
|
|
- expect( config.definition ).to.have.property( 'test2' ).to.equal( 2 );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should set configurations passed as object in the definition property', () => {
|
|
|
|
|
- config.define( {
|
|
|
|
|
- test: 1
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ it( 'should return undefined for empty configuration', () => {
|
|
|
|
|
+ config = new Config();
|
|
|
|
|
|
|
|
- expect( config.definition ).to.have.property( 'test' ).to.equal( 1 );
|
|
|
|
|
|
|
+ expect( config.get( 'invalid' ) ).to.be.undefined;
|
|
|
|
|
+ expect( config.get( 'deep.invalid' ) ).to.be.undefined;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should not define main config properties but still be retrieved with get()', () => {
|
|
|
|
|
- config.define( 'test', 1 );
|
|
|
|
|
-
|
|
|
|
|
- expect( config ).to.not.have.property( 'test' );
|
|
|
|
|
- expect( config.get( 'test' ) ).to.equal( 1 );
|
|
|
|
|
|
|
+ it( 'should return undefined for non existing deep configuration', () => {
|
|
|
|
|
+ expect( config.get( 'resize.invalid.value' ) ).to.be.undefined;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should be overridden by set()', () => {
|
|
|
|
|
- config.define( 'test', 1 );
|
|
|
|
|
- config.set( 'test', 2 );
|
|
|
|
|
-
|
|
|
|
|
- expect( config ).to.have.property( 'test' ).to.equal( 2 );
|
|
|
|
|
- expect( config.get( 'test' ) ).to.equal( 2 );
|
|
|
|
|
|
|
+ it( 'should not be possible to retrieve value directly from config object', () => {
|
|
|
|
|
+ expect( config.creator ).to.be.undefined;
|
|
|
|
|
+ expect( () => {
|
|
|
|
|
+ config.resize.maxheight;
|
|
|
|
|
+ } ).to.throw();
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|