diff --git a/lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.contains.js b/lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.contains.js new file mode 100644 index 000000000000..a3d6f28c1510 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.contains.js @@ -0,0 +1,172 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isString = require( '@stdlib/assert/is-string' ); +var Autosize = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Autosize, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the constructor returns an instance which has a `contains` property', function test( t ) { + var v; + + v = new Autosize(); + t.strictEqual( hasOwnProp( v, 'contains' ), false, 'returns expected value' ); + t.strictEqual( hasProp( v, 'contains' ), true, 'returns expected value' ); + t.strictEqual( isString( v.contains ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor throws an error if provided an invalid `contains` option', function test( t ) { + var values; + var i; + + values = [ + 'beep', + 'boop', + 'invalid', + 'CONTENT', + 'PADDING', + 5, + NaN, + null, + void 0, + true, + false, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var autosize = new Autosize({ // eslint-disable-line no-unused-vars + 'contains': value + }); + }; + } +}); + +tape( 'the constructor returns an instance having a `contains` property which throws an error if set to an invalid value', function test( t ) { + var values; + var i; + + values = [ + 'beep', + 'boop', + 'invalid', + 'CONTENT', + 'PADDING', + 5, + NaN, + null, + void 0, + true, + false, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var autosize = new Autosize(); + autosize.contains = value; + }; + } +}); + +tape( 'the constructor returns an instance having a `contains` property which returns the method for determining how a size calculation should be performed', function test( t ) { + var autosize; + + autosize = new Autosize(); + t.strictEqual( autosize.contains, 'content', 'returns expected value' ); + + autosize = new Autosize({ + 'contains': 'padding' + }); + t.strictEqual( autosize.contains, 'padding', 'returns expected value' ); + + autosize = new Autosize({ + 'contains': 'content' + }); + t.strictEqual( autosize.contains, 'content', 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `contains` property which can be set to a valid method', function test( t ) { + var autosize; + + autosize = new Autosize(); + + autosize.contains = 'padding'; + t.strictEqual( autosize.contains, 'padding', 'returns expected value' ); + + autosize.contains = 'content'; + t.strictEqual( autosize.contains, 'content', 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance which emits an event when the `contains` property is set to a new value', function test( t ) { + var autosize; + var count; + + autosize = new Autosize(); + count = 0; + + autosize.on( 'change', onChange ); + + autosize.contains = 'padding'; + t.strictEqual( count, 1, 'returns expected value' ); + + autosize.contains = 'content'; + t.strictEqual( count, 2, 'returns expected value' ); + + // Setting to the same value should not emit an event: + autosize.contains = 'content'; + t.strictEqual( count, 2, 'returns expected value' ); + + t.end(); + + function onChange() { + count += 1; + } +}); diff --git a/lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.js b/lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.js new file mode 100644 index 000000000000..f8bb9caf6152 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.js @@ -0,0 +1,181 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var Autosize = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Autosize, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var autosize = new Autosize(); + t.strictEqual( instanceOf( autosize, Autosize ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor does not require the `new` keyword', function test( t ) { + var autosize; + var ctor; + + ctor = Autosize; + autosize = ctor(); + t.strictEqual( instanceOf( autosize, Autosize ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor does not require the `new` keyword (options)', function test( t ) { + var autosize; + var ctor; + + ctor = Autosize; + autosize = ctor({ + 'type': 'fit' + }); + t.strictEqual( instanceOf( autosize, Autosize ), true, 'returns expected value' ); + t.strictEqual( autosize.type, 'fit', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + true, + false, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var autosize = new Autosize( value ); // eslint-disable-line no-unused-vars + }; + } +}); + +tape( 'the constructor has a read-only `name` property', function test( t ) { + t.strictEqual( Autosize.name, 'Autosize', 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toJSON` method for serializing an instance to JSON', function test( t ) { + var expected; + var autosize; + var json; + + autosize = new Autosize(); + json = autosize.toJSON(); + + expected = { + 'contains': 'content', + 'resize': false, + 'type': 'pad' + }; + t.deepEqual( json, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `toJSON` method for serializing an instance to JSON (options)', function test( t ) { + var expected; + var autosize; + var json; + + autosize = new Autosize({ + 'type': 'fit', + 'contains': 'padding', + 'resize': true + }); + json = autosize.toJSON(); + + expected = { + 'contains': 'padding', + 'resize': true, + 'type': 'fit' + }; + t.deepEqual( json, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `toJSON` method is implicitly invoked by `JSON.stringify`', function test( t ) { + var expected; + var autosize; + + autosize = new Autosize({ + 'type': 'none', + 'contains': 'content', + 'resize': false + }); + + expected = { + 'contains': 'content', + 'resize': false, + 'type': 'none' + }; + t.strictEqual( JSON.stringify( autosize ), JSON.stringify( expected ), 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance which inherits from EventEmitter', function test( t ) { + var autosize; + + autosize = new Autosize(); + + t.strictEqual( typeof autosize.on, 'function', 'returns expected value' ); + t.strictEqual( typeof autosize.emit, 'function', 'returns expected value' ); + t.strictEqual( typeof autosize.removeListener, 'function', 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor ignores unrecognized options', function test( t ) { + var autosize; + + autosize = new Autosize({ + 'type': 'fit', + 'beep': 'boop', + 'foo': 'bar' + }); + + t.strictEqual( autosize.type, 'fit', 'returns expected value' ); + t.strictEqual( hasOwnProp( autosize, 'beep' ), false, 'returns expected value' ); + t.strictEqual( hasOwnProp( autosize, 'foo' ), false, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.properties.js b/lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.properties.js new file mode 100644 index 000000000000..8224f9c55b1e --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.properties.js @@ -0,0 +1,77 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isArray = require( '@stdlib/assert/is-array' ); +var Autosize = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Autosize, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the constructor returns an instance which has a `properties` property', function test( t ) { + var v; + + v = new Autosize(); + t.strictEqual( hasOwnProp( v, 'properties' ), false, 'returns expected value' ); + t.strictEqual( hasProp( v, 'properties' ), true, 'returns expected value' ); + t.strictEqual( isArray( v.properties ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance having a `properties` property which returns a list of enumerable properties', function test( t ) { + var expected; + var autosize; + var props; + + autosize = new Autosize(); + props = autosize.properties; + + t.strictEqual( isArray( props ), true, 'returns expected value' ); + + expected = [ 'contains', 'resize', 'type' ]; + t.deepEqual( props, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `properties` property which returns a new array on each access', function test( t ) { + var autosize; + var props1; + var props2; + + autosize = new Autosize(); + props1 = autosize.properties; + props2 = autosize.properties; + + t.notEqual( props1, props2, 'returns expected value' ); + t.deepEqual( props1, props2, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.resize.js b/lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.resize.js new file mode 100644 index 000000000000..567d244c9336 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.resize.js @@ -0,0 +1,160 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ); +var Autosize = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Autosize, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the constructor returns an instance which has a `resize` property', function test( t ) { + var v; + + v = new Autosize(); + t.strictEqual( hasOwnProp( v, 'resize' ), false, 'returns expected value' ); + t.strictEqual( hasProp( v, 'resize' ), true, 'returns expected value' ); + t.strictEqual( isBoolean( v.resize ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor throws an error if provided an invalid `resize` option', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var autosize = new Autosize({ // eslint-disable-line no-unused-vars + 'resize': value + }); + }; + } +}); + +tape( 'the constructor returns an instance having a `resize` property which throws an error if set to a non-boolean value', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var autosize = new Autosize(); + autosize.resize = value; + }; + } +}); + +tape( 'the constructor returns an instance having a `resize` property which returns a boolean indicating whether to re-calculate an autosize layout on every view update', function test( t ) { + var autosize; + + autosize = new Autosize(); + t.strictEqual( autosize.resize, false, 'returns expected value' ); + + autosize = new Autosize({ + 'resize': true + }); + t.strictEqual( autosize.resize, true, 'returns expected value' ); + + autosize = new Autosize({ + 'resize': false + }); + t.strictEqual( autosize.resize, false, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `resize` property which can be set to a boolean', function test( t ) { + var autosize; + + autosize = new Autosize(); + + autosize.resize = true; + t.strictEqual( autosize.resize, true, 'returns expected value' ); + + autosize.resize = false; + t.strictEqual( autosize.resize, false, 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance which emits an event when the `resize` property is set to a new value', function test( t ) { + var autosize; + var count; + + autosize = new Autosize(); + count = 0; + + autosize.on( 'change', onChange ); + + autosize.resize = true; + t.strictEqual( count, 1, 'returns expected value' ); + + autosize.resize = false; + t.strictEqual( count, 2, 'returns expected value' ); + + // Setting to the same value should not emit an event: + autosize.resize = false; + t.strictEqual( count, 2, 'returns expected value' ); + + t.end(); + + function onChange() { + count += 1; + } +}); diff --git a/lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.type.js b/lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.type.js new file mode 100644 index 000000000000..3ec46745a9d6 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.type.js @@ -0,0 +1,191 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isString = require( '@stdlib/assert/is-string' ); +var Autosize = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Autosize, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the constructor returns an instance which has a `type` property', function test( t ) { + var v; + + v = new Autosize(); + t.strictEqual( hasOwnProp( v, 'type' ), false, 'returns expected value' ); + t.strictEqual( hasProp( v, 'type' ), true, 'returns expected value' ); + t.strictEqual( isString( v.type ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor throws an error if provided an invalid `type` option', function test( t ) { + var values; + var i; + + values = [ + 'beep', + 'boop', + 'invalid', + 'PAD', + 'FIT', + 5, + NaN, + null, + void 0, + true, + false, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var autosize = new Autosize({ // eslint-disable-line no-unused-vars + 'type': value + }); + }; + } +}); + +tape( 'the constructor returns an instance having a `type` property which throws an error if set to an invalid value', function test( t ) { + var values; + var i; + + values = [ + 'beep', + 'boop', + 'invalid', + 'PAD', + 'FIT', + 5, + NaN, + null, + void 0, + true, + false, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var autosize = new Autosize(); + autosize.type = value; + }; + } +}); + +tape( 'the constructor returns an instance having a `type` property which returns the autosize type', function test( t ) { + var autosize; + + autosize = new Autosize(); + t.strictEqual( autosize.type, 'pad', 'returns expected value' ); + + autosize = new Autosize({ + 'type': 'fit' + }); + t.strictEqual( autosize.type, 'fit', 'returns expected value' ); + + autosize = new Autosize({ + 'type': 'fit-x' + }); + t.strictEqual( autosize.type, 'fit-x', 'returns expected value' ); + + autosize = new Autosize({ + 'type': 'fit-y' + }); + t.strictEqual( autosize.type, 'fit-y', 'returns expected value' ); + + autosize = new Autosize({ + 'type': 'none' + }); + t.strictEqual( autosize.type, 'none', 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance having a `type` property which can be set to a valid autosize method', function test( t ) { + var autosize; + + autosize = new Autosize(); + + autosize.type = 'fit'; + t.strictEqual( autosize.type, 'fit', 'returns expected value' ); + + autosize.type = 'fit-x'; + t.strictEqual( autosize.type, 'fit-x', 'returns expected value' ); + + autosize.type = 'fit-y'; + t.strictEqual( autosize.type, 'fit-y', 'returns expected value' ); + + autosize.type = 'none'; + t.strictEqual( autosize.type, 'none', 'returns expected value' ); + + autosize.type = 'pad'; + t.strictEqual( autosize.type, 'pad', 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance which emits an event when the `type` property is set to a new value', function test( t ) { + var autosize; + var count; + + autosize = new Autosize(); + count = 0; + + autosize.on( 'change', onChange ); + + autosize.type = 'fit'; + t.strictEqual( count, 1, 'returns expected value' ); + + autosize.type = 'none'; + t.strictEqual( count, 2, 'returns expected value' ); + + // Setting to the same value should not emit an event: + autosize.type = 'none'; + t.strictEqual( count, 2, 'returns expected value' ); + + t.end(); + + function onChange() { + count += 1; + } +});