-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
test: add tests for Axis constructor and properties #10414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Sachinn-64
wants to merge
1
commit into
stdlib-js:refactor/plot
Choose a base branch
from
Sachinn-64:test-plot-vega-axis
base: refactor/plot
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+14,379
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
181 changes: 181 additions & 0 deletions
181
lib/node_modules/@stdlib/plot/vega/axis/ctor/test/test.aria.js
This file contains hidden or 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,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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); | ||
| var hasProp = require( '@stdlib/assert/has-property' ); | ||
| var isBoolean = require( '@stdlib/assert/is-boolean' ); | ||
| var Axis = require( './../lib' ); | ||
|
|
||
|
|
||
| // TESTS // | ||
|
|
||
| tape( 'main export is a function', function test( t ) { | ||
| t.ok( true, __filename ); | ||
| t.strictEqual( typeof Axis, 'function', 'main export is a function' ); | ||
| t.end(); | ||
| }); | ||
|
|
||
| tape( 'the constructor returns an instance which has a `aria` property', function test( t ) { | ||
| var v; | ||
|
|
||
| v = new Axis({ | ||
| 'scale': 'xScale', | ||
| 'orient': 'bottom' | ||
| }); | ||
| t.strictEqual( hasOwnProp( v, 'aria' ), false, 'returns expected value' ); | ||
| t.strictEqual( hasProp( v, 'aria' ), true, 'returns expected value' ); | ||
| t.strictEqual( isBoolean( v.aria ), true, 'returns expected value' ); | ||
| t.end(); | ||
| }); | ||
|
|
||
| tape( 'the constructor throws an error if provided an invalid `aria` 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 axis = new Axis({ // eslint-disable-line no-unused-vars | ||
| 'scale': 'xScale', | ||
| 'orient': 'bottom', | ||
| 'aria': value | ||
| }); | ||
| }; | ||
| } | ||
| }); | ||
|
|
||
| tape( 'the constructor returns an instance having a `aria` 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 axis = new Axis({ | ||
| 'scale': 'xScale', | ||
| 'orient': 'bottom' | ||
| }); | ||
| axis.aria = value; | ||
| }; | ||
| } | ||
| }); | ||
|
|
||
| tape( 'the constructor returns an instance having a `aria` property', function test( t ) { | ||
| var axis; | ||
|
|
||
| axis = new Axis({ | ||
| 'scale': 'xScale', | ||
| 'orient': 'bottom' | ||
| }); | ||
| t.strictEqual( axis.aria, true, 'returns expected value' ); | ||
|
|
||
| axis = new Axis({ | ||
| 'scale': 'xScale', | ||
| 'orient': 'bottom', | ||
| 'aria': false | ||
| }); | ||
| t.strictEqual( axis.aria, false, 'returns expected value' ); | ||
|
|
||
| axis = new Axis({ | ||
| 'scale': 'xScale', | ||
| 'orient': 'bottom', | ||
| 'aria': true | ||
| }); | ||
| t.strictEqual( axis.aria, true, 'returns expected value' ); | ||
|
|
||
| t.end(); | ||
| }); | ||
|
|
||
| tape( 'the constructor returns an instance having a `aria` property which can be set to a boolean', function test( t ) { | ||
| var axis; | ||
|
|
||
| axis = new Axis({ | ||
| 'scale': 'xScale', | ||
| 'orient': 'bottom' | ||
| }); | ||
|
|
||
| axis.aria = true; | ||
| t.strictEqual( axis.aria, true, 'returns expected value' ); | ||
|
|
||
| axis.aria = false; | ||
| t.strictEqual( axis.aria, false, 'returns expected value' ); | ||
|
|
||
| t.end(); | ||
| }); | ||
|
|
||
| tape( 'the constructor returns an instance which emits an event when the `aria` property is set to a new value', function test( t ) { | ||
| var axis; | ||
| var count; | ||
|
|
||
| axis = new Axis({ | ||
| 'scale': 'xScale', | ||
| 'orient': 'bottom' | ||
| }); | ||
| count = 0; | ||
|
|
||
| axis.on( 'change', onChange ); | ||
|
|
||
| axis.aria = false; | ||
| t.strictEqual( count, 1, 'returns expected value' ); | ||
|
|
||
| axis.aria = true; | ||
| t.strictEqual( count, 2, 'returns expected value' ); | ||
|
|
||
| // Setting to the same value should not emit an event: | ||
| axis.aria = true; | ||
| t.strictEqual( count, 2, 'returns expected value' ); | ||
|
|
||
| t.end(); | ||
|
|
||
| function onChange() { | ||
| count += 1; | ||
| } | ||
| }); | ||
182 changes: 182 additions & 0 deletions
182
lib/node_modules/@stdlib/plot/vega/axis/ctor/test/test.band_position.js
This file contains hidden or 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,182 @@ | ||||||||||||||||
| /** | ||||||||||||||||
| * @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 isUndefined = require( '@stdlib/assert/is-undefined' ); | ||||||||||||||||
| var hasProp = require( '@stdlib/assert/has-property' ); | ||||||||||||||||
| var isNumber = require( '@stdlib/assert/is-number' ); | ||||||||||||||||
| var Axis = require( './../lib' ); | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| // TESTS // | ||||||||||||||||
|
|
||||||||||||||||
| tape( 'main export is a function', function test( t ) { | ||||||||||||||||
| t.ok( true, __filename ); | ||||||||||||||||
| t.strictEqual( typeof Axis, 'function', 'main export is a function' ); | ||||||||||||||||
| t.end(); | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| tape( 'the constructor returns an instance which has a `bandPosition` property', function test( t ) { | ||||||||||||||||
| var v; | ||||||||||||||||
|
|
||||||||||||||||
| v = new Axis({ | ||||||||||||||||
| 'scale': 'xScale', | ||||||||||||||||
| 'orient': 'bottom' | ||||||||||||||||
| }); | ||||||||||||||||
| t.strictEqual( hasOwnProp( v, 'bandPosition' ), false, 'returns expected value' ); | ||||||||||||||||
| t.strictEqual( hasProp( v, 'bandPosition' ), true, 'returns expected value' ); | ||||||||||||||||
| t.strictEqual( isUndefined( v.bandPosition ), true, 'returns expected value' ); | ||||||||||||||||
|
|
||||||||||||||||
| v = new Axis({ | ||||||||||||||||
| 'scale': 'xScale', | ||||||||||||||||
| 'orient': 'bottom', | ||||||||||||||||
| 'bandPosition': 0.5 | ||||||||||||||||
| }); | ||||||||||||||||
| t.strictEqual( isNumber( v.bandPosition ), true, 'returns expected value' ); | ||||||||||||||||
|
|
||||||||||||||||
| t.end(); | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| tape( 'the constructor throws an error if provided an invalid `bandPosition` option', function test( t ) { | ||||||||||||||||
| var values; | ||||||||||||||||
| var i; | ||||||||||||||||
|
|
||||||||||||||||
| values = [ | ||||||||||||||||
| 'beep', | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
| -0.1, | ||||||||||||||||
| 1.1, | ||||||||||||||||
| NaN, | ||||||||||||||||
| {}, | ||||||||||||||||
| 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 axis = new Axis({ // eslint-disable-line no-unused-vars | ||||||||||||||||
| 'scale': 'xScale', | ||||||||||||||||
| 'orient': 'bottom', | ||||||||||||||||
| 'bandPosition': value | ||||||||||||||||
| }); | ||||||||||||||||
| }; | ||||||||||||||||
| } | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| tape( 'the constructor returns an instance having a `bandPosition` property which throws an error if set to an invalid value', function test( t ) { | ||||||||||||||||
| var values; | ||||||||||||||||
| var i; | ||||||||||||||||
|
|
||||||||||||||||
| values = [ | ||||||||||||||||
| 'beep', | ||||||||||||||||
| -0.1, | ||||||||||||||||
| 1.1, | ||||||||||||||||
| NaN, | ||||||||||||||||
| {}, | ||||||||||||||||
| 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 axis = new Axis({ | ||||||||||||||||
| 'scale': 'xScale', | ||||||||||||||||
| 'orient': 'bottom' | ||||||||||||||||
| }); | ||||||||||||||||
| axis.bandPosition = value; | ||||||||||||||||
| }; | ||||||||||||||||
| } | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| tape( 'the constructor returns an instance having a `bandPosition` property', function test( t ) { | ||||||||||||||||
| var axis; | ||||||||||||||||
|
|
||||||||||||||||
| axis = new Axis({ | ||||||||||||||||
| 'scale': 'xScale', | ||||||||||||||||
| 'orient': 'bottom' | ||||||||||||||||
| }); | ||||||||||||||||
| t.strictEqual( isUndefined( axis.bandPosition ), true, 'returns expected value' ); | ||||||||||||||||
|
|
||||||||||||||||
| axis = new Axis({ | ||||||||||||||||
| 'scale': 'xScale', | ||||||||||||||||
| 'orient': 'bottom', | ||||||||||||||||
| 'bandPosition': 0.5 | ||||||||||||||||
| }); | ||||||||||||||||
| t.strictEqual( axis.bandPosition, 0.5, 'returns expected value' ); | ||||||||||||||||
|
|
||||||||||||||||
| t.end(); | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| tape( 'the constructor returns an instance having a `bandPosition` property which can be set to a valid value', function test( t ) { | ||||||||||||||||
| var axis; | ||||||||||||||||
|
|
||||||||||||||||
| axis = new Axis({ | ||||||||||||||||
| 'scale': 'xScale', | ||||||||||||||||
| 'orient': 'bottom' | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| axis.bandPosition = 0.5; | ||||||||||||||||
| t.strictEqual( axis.bandPosition, 0.5, 'returns expected value' ); | ||||||||||||||||
|
|
||||||||||||||||
| axis.bandPosition = 0; | ||||||||||||||||
| t.strictEqual( axis.bandPosition, 0, 'returns expected value' ); | ||||||||||||||||
|
|
||||||||||||||||
| axis.bandPosition = 1; | ||||||||||||||||
| t.strictEqual( axis.bandPosition, 1, 'returns expected value' ); | ||||||||||||||||
|
|
||||||||||||||||
| t.end(); | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| tape( 'the constructor returns an instance which emits an event when the `bandPosition` property is set to a new value', function test( t ) { | ||||||||||||||||
| var axis; | ||||||||||||||||
| var count; | ||||||||||||||||
|
|
||||||||||||||||
| axis = new Axis({ | ||||||||||||||||
| 'scale': 'xScale', | ||||||||||||||||
| 'orient': 'bottom' | ||||||||||||||||
| }); | ||||||||||||||||
| count = 0; | ||||||||||||||||
|
|
||||||||||||||||
| axis.on( 'change', onChange ); | ||||||||||||||||
|
|
||||||||||||||||
| axis.bandPosition = 0.5; | ||||||||||||||||
| t.strictEqual( count, 1, 'returns expected value' ); | ||||||||||||||||
|
|
||||||||||||||||
| axis.bandPosition = 0.3; | ||||||||||||||||
| t.strictEqual( count, 2, 'returns expected value' ); | ||||||||||||||||
|
|
||||||||||||||||
| // Setting to the same value should not emit an event: | ||||||||||||||||
| axis.bandPosition = 0.3; | ||||||||||||||||
| t.strictEqual( count, 2, 'returns expected value' ); | ||||||||||||||||
|
|
||||||||||||||||
| t.end(); | ||||||||||||||||
|
|
||||||||||||||||
| function onChange() { | ||||||||||||||||
| count += 1; | ||||||||||||||||
| } | ||||||||||||||||
| }); | ||||||||||||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.