woocommerce/plugins/woocommerce-blocks/assets/js/base/components/price-slider/test/constrain-range-slider-valu...

40 lines
2.0 KiB
JavaScript
Raw Normal View History

/**
* Internal dependencies
*/
import { constrainRangeSliderValues } from '../constrain-range-slider-values';
describe( 'constrainRangeSliderValues', () => {
test.each`
Add @woocommerce/eslint-plugin dependency (https://github.com/woocommerce/woocommerce-blocks/pull/3115) * convert eslint config to use @woocommerce/eslint-plugin - removes unnecessary dependencies - adds e2e-tests/specs to eslint ignore (they are automatically generated) - turns off rules that will be handled in subsequent pulls (to avoid a mammoth changeset for review). - NOTE: prettier config needs left in because of a bug with the existing version of `@wordpress/eslint-plugin` pulled in (fixed in https://github.com/WordPress/gutenberg/pull/25068) so I left the file for now. * prettier fixes. * remove obsolete plugin and fixes for eslint update This branch brings an update to eslint which also changes some syntax with plugins. So this commit: - fixes featuer-flag plugin syntax. - removed obsolete dependency-group plugin (which is now in the `@woocommerce/eslint-plugin` configuration. * add to-do comment * fixes for test runs - this also converts our e2e test scripts to use `wp-script test:e2e`, an advantage of this is it will load CHROMIUM on demand for the e2e test run. * fixes for test runs - this also converts our e2e test scripts to use `wp-script test:e2e`, an advantage of this is it will load CHROMIUM on demand for the e2e test run. * include prettier alias as a dependency This has to be done because prettier is installed with storybook and thus the alias setup in `@wordpress/scripts` is over-ridden by the storybook import. * another attempt at e2e-test-fix * add some debugging and temporarily just add one e2e config test for travis * more debugging * try installing full puppeteer and see if fixes * fix package-lock? * setupSettings separately from other fixture loading * add debugging of files * add another console.log (hopefully trigger travis) * split out blockPage creation to it’s own as well * fixed! remove debugging and re-enable travis configs for entire test suite * fix config and rename e2e-tests to e2e - fixes the failing product-search test - tests/e2e-tests was redundant, I changed to `tests/e2e` (this follows a file pattern change made in woocommerce core as well). * add todo for some eslint properties * remove unnecessary early function execution * revert earlier commit and remove duplicate call to createBlockPages
2020-09-07 17:31:10 +00:00
values | min | max | step | isMin | expected
${ [ 20, 60 ] } | ${ 0 } | ${ 70 } | ${ 10 } | ${ true } | ${ [ 20, 60 ] }
${ [ 20, 60 ] } | ${ 20 } | ${ 60 } | ${ 10 } | ${ true } | ${ [ 20, 60 ] }
${ [ 20, 60 ] } | ${ 30 } | ${ 50 } | ${ 10 } | ${ true } | ${ [ 30, 50 ] }
${ [ 50, 50 ] } | ${ 20 } | ${ 60 } | ${ 10 } | ${ true } | ${ [ 50, 60 ] }
${ [ 50, 50 ] } | ${ 20 } | ${ 60 } | ${ 10 } | ${ false } | ${ [ 40, 50 ] }
${ [ 20, 60 ] } | ${ null } | ${ null } | ${ 10 } | ${ true } | ${ [ 20, 60 ] }
${ [ null, null ] } | ${ 20 } | ${ 60 } | ${ 10 } | ${ true } | ${ [ 20, 60 ] }
${ [ '20', '60' ] } | ${ 30 } | ${ 50 } | ${ 10 } | ${ true } | ${ [ 30, 50 ] }
${ [ -60, -20 ] } | ${ -70 } | ${ 0 } | ${ 10 } | ${ true } | ${ [ -60, -20 ] }
${ [ -60, -20 ] } | ${ -60 } | ${ -20 } | ${ 10 } | ${ true } | ${ [ -60, -20 ] }
${ [ -60, -20 ] } | ${ -50 } | ${ -30 } | ${ 10 } | ${ true } | ${ [ -50, -30 ] }
${ [ -50, -50 ] } | ${ -60 } | ${ -20 } | ${ 10 } | ${ true } | ${ [ -50, -40 ] }
${ [ -50, -50 ] } | ${ -60 } | ${ -20 } | ${ 10 } | ${ false } | ${ [ -60, -50 ] }
${ [ -60, -20 ] } | ${ null } | ${ null } | ${ 10 } | ${ true } | ${ [ -60, -20 ] }
${ [ null, null ] } | ${ -60 } | ${ -20 } | ${ 10 } | ${ true } | ${ [ -60, -20 ] }
${ [ '-60', '-20' ] } | ${ -50 } | ${ -30 } | ${ 10 } | ${ true } | ${ [ -50, -30 ] }
`(
`correctly sets prices to its constraints with arguments values: $values, min: $min, max: $max, step: $step and isMin: $isMin`,
( { values, min, max, step, isMin, expected } ) => {
const constrainedValues = constrainRangeSliderValues(
values,
min,
max,
step,
isMin
);
expect( constrainedValues ).toEqual( expected );
}
);
} );