From 01916c805eccac0f1cdf16be3d9a765e4f09d7a6 Mon Sep 17 00:00:00 2001 From: apeltier <26309854+a-peltier@users.noreply.github.com> Date: Thu, 28 May 2020 22:45:39 +0200 Subject: [PATCH 1/6] Add eslint-plugin-jest and enforce recommended rules --- .eslintrc | 4 +- packages/react-vis/package.json | 1 + .../tests/components/treemap-tests.js | 8 --- packages/react-vis/tests/test-utils.js | 1 + yarn.lock | 56 ++++++++++++++++++- 5 files changed, 60 insertions(+), 10 deletions(-) diff --git a/.eslintrc b/.eslintrc index c3f618247..64bf74a38 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,6 +2,7 @@ "extends": [ "eslint:recommended", "plugin:react/recommended", + "plugin:jest/recommended", "prettier", "prettier/react" ], @@ -10,7 +11,8 @@ "react", "prettier", "babel", - "no-only-tests" + "no-only-tests", + "jest" ], "ignorePatterns": [ "node_modules", diff --git a/packages/react-vis/package.json b/packages/react-vis/package.json index 2d5d7c789..99af88d90 100644 --- a/packages/react-vis/package.json +++ b/packages/react-vis/package.json @@ -70,6 +70,7 @@ "canvas-prebuilt": "^1.6.11", "enzyme": "^3.11.0", "enzyme-adapter-react-16": "^1.15.2", + "eslint-plugin-jest":"^23.13.2", "jest":"^25.5.4", "jsdom": "^9.9.1", "node-sass": "^4.9.3", diff --git a/packages/react-vis/tests/components/treemap-tests.js b/packages/react-vis/tests/components/treemap-tests.js index aee52dc40..6c15cd42c 100644 --- a/packages/react-vis/tests/components/treemap-tests.js +++ b/packages/react-vis/tests/components/treemap-tests.js @@ -155,14 +155,6 @@ test('Treemap: Hide Root Node', () => { }); }); -test('Treemap: Empty treemap', () => { - const $ = mount(); - // 1 is the empty root node - expect($.find('.rv-treemap__leaf').length).toBe(1); - expect($.find('.rv-treemap').text()).toBe(''); - expect($.find('div.little-nested-tree-example').length).toBe(1); -}); - test('Treemap: SimpleTreemap', () => { const $ = mount(); [ diff --git a/packages/react-vis/tests/test-utils.js b/packages/react-vis/tests/test-utils.js index 544077ef8..806953abb 100644 --- a/packages/react-vis/tests/test-utils.js +++ b/packages/react-vis/tests/test-utils.js @@ -1,3 +1,4 @@ +/* eslint-disable jest/no-export */ import React from 'react'; import {mount} from 'enzyme'; diff --git a/yarn.lock b/yarn.lock index 306dc8a9d..8ebf76a63 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1847,6 +1847,11 @@ "@types/istanbul-lib-coverage" "*" "@types/istanbul-lib-report" "*" +"@types/json-schema@^7.0.3": + version "7.0.4" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339" + integrity sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA== + "@types/minimatch@*": version "3.0.3" resolved "https://registry.yarnpkg.com/@types%2fminimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" @@ -1984,6 +1989,29 @@ dependencies: "@types/yargs-parser" "*" +"@typescript-eslint/experimental-utils@^2.5.0": + version "2.34.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.34.0.tgz#d3524b644cdb40eebceca67f8cf3e4cc9c8f980f" + integrity sha512-eS6FTkq+wuMJ+sgtuNTtcqavWXqsflWcfBnlYhg/nS4aZ1leewkXGbvBhaapn1q6qf4M71bsR1tez5JTRMuqwA== + dependencies: + "@types/json-schema" "^7.0.3" + "@typescript-eslint/typescript-estree" "2.34.0" + eslint-scope "^5.0.0" + eslint-utils "^2.0.0" + +"@typescript-eslint/typescript-estree@2.34.0": + version "2.34.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.34.0.tgz#14aeb6353b39ef0732cc7f1b8285294937cf37d5" + integrity sha512-OMAr+nJWKdlVM9LOqCqh3pQQPwxHAN7Du8DR6dmwCrAmxtiXQnhHJ6tBNtf+cggqfo51SG/FCwnKhXCIM7hnVg== + dependencies: + debug "^4.1.1" + eslint-visitor-keys "^1.1.0" + glob "^7.1.6" + is-glob "^4.0.1" + lodash "^4.17.15" + semver "^7.3.2" + tsutils "^3.17.1" + "@webassemblyjs/ast@1.9.0": version "1.9.0" resolved "https://registry.yarnpkg.com/@webassemblyjs%2fast/-/ast-1.9.0.tgz#bd850604b4042459a5a41cd7d338cbed695ed964" @@ -6553,6 +6581,13 @@ eslint-plugin-babel@^5.3.0: dependencies: eslint-rule-composer "^0.3.0" +eslint-plugin-jest@^23.13.2: + version "23.13.2" + resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-23.13.2.tgz#7b7993b4e09be708c696b02555083ddefd7e4cc7" + integrity sha512-qZit+moTXTyZFNDqSIR88/L3rdBlTU7CuW6XmyErD2FfHEkdoLgThkRbiQjzgYnX6rfgLx3Ci4eJmF4Ui5v1Cw== + dependencies: + "@typescript-eslint/experimental-utils" "^2.5.0" + eslint-plugin-no-only-tests@^2.4.0: version "2.4.0" resolved "https://registry.yarnpkg.com/eslint-plugin-no-only-tests/-/eslint-plugin-no-only-tests-2.4.0.tgz#7d565434aa7d16ccc7eea957c391d98f827332ca" @@ -6629,6 +6664,13 @@ eslint-utils@^1.4.3: dependencies: eslint-visitor-keys "^1.1.0" +eslint-utils@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-2.0.0.tgz#7be1cc70f27a72a76cd14aa698bcabed6890e1cd" + integrity sha512-0HCPuJv+7Wv1bACm8y5/ECVfYdfsAm9xmVb7saeFlxjPYALefjhbYoCkBjPdPzGH8wWyTpAez82Fh3VKYEZ8OA== + dependencies: + eslint-visitor-keys "^1.1.0" + eslint-visitor-keys@^1.0.0, eslint-visitor-keys@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2" @@ -13856,6 +13898,11 @@ semver@^6.0.0, semver@^6.1.2, semver@^6.3.0: resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" integrity sha1-7gpkyK9ejO6mdoexM3YeG+y9HT0= +semver@^7.3.2: + version "7.3.2" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938" + integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ== + semver@~5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f" @@ -15420,11 +15467,18 @@ ts-pnp@^1.1.2: resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.2.0.tgz#a500ad084b0798f1c3071af391e65912c86bca92" integrity sha1-pQCtCEsHmPHDBxrzkeZZEshrypI= -tslib@^1.10.0, tslib@^1.9.0, tslib@^1.9.3: +tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3: version "1.13.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.13.0.tgz#c881e13cc7015894ed914862d276436fa9a47043" integrity sha1-yIHhPMcBWJTtkUhi0nZDb6mkcEM= +tsutils@^3.17.1: + version "3.17.1" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.17.1.tgz#ed719917f11ca0dee586272b2ac49e015a2dd759" + integrity sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g== + dependencies: + tslib "^1.8.1" + tty-browserify@0.0.0: version "0.0.0" resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6" From cf674b64bb4c85ab7feac32ba7b1769255499b14 Mon Sep 17 00:00:00 2001 From: apeltier <26309854+a-peltier@users.noreply.github.com> Date: Thu, 28 May 2020 23:24:05 +0200 Subject: [PATCH 2/6] Add top-level describe block to all tests and enforce related lint rule --- .eslintrc | 1 + .../tests/components/animation-tests.js | 32 +- .../tests/components/arc-series-tests.js | 14 +- .../tests/components/area-series-tests.js | 54 +- .../react-vis/tests/components/axes-tests.js | 212 ++-- .../components/axis-tick-format-tests.js | 88 +- .../tests/components/axis-title-tests.js | 68 +- .../tests/components/bar-series-tests.js | 169 ++-- .../tests/components/borders-tests.js | 10 +- .../components/circular-grid-lines-tests.js | 12 +- .../tests/components/color-article-tests.js | 166 ++-- .../tests/components/contour-series-tests.js | 14 +- .../tests/components/crosshair-tests.js | 40 +- .../components/custom-svg-series-tests.js | 66 +- .../tests/components/data-article-tests.js | 8 +- .../tests/components/decorative-axis-tests.js | 36 +- .../tests/components/gradient-tests.js | 26 +- .../tests/components/grid-lines-tests.js | 56 +- .../tests/components/heatmap-tests.js | 66 +- .../tests/components/hexbin-series-tests.js | 118 +-- .../tests/components/highlight-tests.js | 230 ++--- .../react-vis/tests/components/hints-tests.js | 20 +- .../components/interaction-article-tests.js | 32 +- .../tests/components/label-series-tests.js | 38 +- .../tests/components/legends-tests.js | 232 ++--- .../components/line-series-canvas-test.js | 88 +- .../tests/components/line-series-tests.js | 332 ++++--- .../components/make-vis-flexible-tests.js | 26 +- .../tests/components/mark-series-tests.js | 103 +- .../components/parallel-coordinates-tests.js | 131 +-- .../tests/components/polygon-series-tests.js | 12 +- .../tests/components/radar-chart-tests.js | 159 +-- .../tests/components/radial-tests.js | 127 +-- .../tests/components/rect-series-tests.js | 31 +- .../tests/components/sankey-tests.js | 202 ++-- .../tests/components/sunburst-tests.js | 118 +-- .../tests/components/treemap-tests.js | 290 +++--- .../tests/components/voronoi-tests.js | 72 +- .../tests/components/whisker-series-tests.js | 14 +- .../tests/components/xy-plot-tests.js | 508 +++++----- packages/react-vis/tests/test-utils.js | 1 + .../react-vis/tests/utils/axis-utils-tests.js | 250 ++--- .../tests/utils/chart-utils-tests.js | 38 +- .../react-vis/tests/utils/data-utils-tests.js | 34 +- .../tests/utils/react-utils-tests.js | 6 +- .../tests/utils/scales-utils-tests.js | 939 +++++++++--------- .../tests/utils/series-utils-tests.js | 470 ++++----- .../tests/utils/styling-utils-tests.js | 54 +- 48 files changed, 2966 insertions(+), 2847 deletions(-) diff --git a/.eslintrc b/.eslintrc index 64bf74a38..3adc4006a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -37,6 +37,7 @@ "object-curly-spacing": 0, "babel/object-curly-spacing": 2, "no-only-tests/no-only-tests": 2, + "jest/require-top-level-describe":"error", "react/prop-types": "off", "prettier/prettier": "warn" } diff --git a/packages/react-vis/tests/components/animation-tests.js b/packages/react-vis/tests/components/animation-tests.js index c9b7302bb..d5a82623c 100644 --- a/packages/react-vis/tests/components/animation-tests.js +++ b/packages/react-vis/tests/components/animation-tests.js @@ -27,21 +27,23 @@ import AxisTicks from 'plot/axis/axis-ticks'; import VerticalBarSeries from 'plot/series/vertical-bar-series'; import XYPlot from 'plot/xy-plot'; -test('Animation interpolates xDomain when specified', () => { - const wrapper = mount( - - - - - ); +describe('Animation', () => { + test('interpolates xDomain when specified', () => { + const wrapper = mount( + + + + + ); - const renderedAnimationWrapper = wrapper.find(Animation); + const renderedAnimationWrapper = wrapper.find(Animation); - expect(renderedAnimationWrapper.find(AxisTicks).prop('xDomain')).toEqual([ - 'Black' - ]); + expect(renderedAnimationWrapper.find(AxisTicks).prop('xDomain')).toEqual([ + 'Black' + ]); + }); }); diff --git a/packages/react-vis/tests/components/arc-series-tests.js b/packages/react-vis/tests/components/arc-series-tests.js index 2953eb721..26cbc3c0b 100644 --- a/packages/react-vis/tests/components/arc-series-tests.js +++ b/packages/react-vis/tests/components/arc-series-tests.js @@ -6,10 +6,12 @@ import ArcSeriesExample from '../../../showcase/radial-chart/arc-series-example' testRenderWithProps(ArcSeries, GENERIC_XYPLOT_SERIES_PROPS); -test('ArcSeries: Showcase Example - ArcSeriesExample', () => { - const $ = mount(); - expect($.text()).toBe('UPDATE-4-2024-4-2024'); - // multiplied by two to account for shadow listeners - expect($.find('.rv-xy-plot__series--arc').length).toBe(4); - expect($.find('.rv-xy-plot__series--arc path').length).toBe(2 * 8); +describe('ArcSeries', () => { + test('Showcase Example - ArcSeriesExample', () => { + const $ = mount(); + expect($.text()).toBe('UPDATE-4-2024-4-2024'); + // multiplied by two to account for shadow listeners + expect($.find('.rv-xy-plot__series--arc').length).toBe(4); + expect($.find('.rv-xy-plot__series--arc path').length).toBe(2 * 8); + }); }); diff --git a/packages/react-vis/tests/components/area-series-tests.js b/packages/react-vis/tests/components/area-series-tests.js index 076eeacf5..993d488e3 100644 --- a/packages/react-vis/tests/components/area-series-tests.js +++ b/packages/react-vis/tests/components/area-series-tests.js @@ -19,33 +19,35 @@ const AREA_PROPS = { ] }; -test('AreaSeries: basic rendering', () => { - const $ = mount( - - - - ); - expect($.find('.rv-xy-plot__series').length).toBe(1); - expect($.find('path.rv-xy-plot__series').length).toBe(1); - expect($.find('path.area-chart-example').length).toBe(1); +describe('AreaSeries', () => { + test('basic rendering', () => { + const $ = mount( + + + + ); + expect($.find('.rv-xy-plot__series').length).toBe(1); + expect($.find('path.rv-xy-plot__series').length).toBe(1); + expect($.find('path.area-chart-example').length).toBe(1); - $.setProps({children: }); - expect($.find('.rv-xy-plot__series').length).toBe(0); - expect($.find('.rv-xy-plot__series path').length).toBe(0); - expect($.find('.area-chart-example').length).toBe(0); -}); + $.setProps({children: }); + expect($.find('.rv-xy-plot__series').length).toBe(0); + expect($.find('.rv-xy-plot__series path').length).toBe(0); + expect($.find('.area-chart-example').length).toBe(0); + }); -test('AreaSeries: Showcase Example - AreaChart', () => { - const $ = mount(); - expect($.find('.rv-xy-plot__series').length).toBe(1); - expect($.find('path.rv-xy-plot__series').length).toBe(1); - expect($.find('path.area-series-example').length).toBe(1); -}); + test('AreaSeries: Showcase Example - AreaChart', () => { + const $ = mount(); + expect($.find('.rv-xy-plot__series').length).toBe(1); + expect($.find('path.rv-xy-plot__series').length).toBe(1); + expect($.find('path.area-series-example').length).toBe(1); + }); -test('AreaSeries: Showcase Example - AreaChartElevated', () => { - const $ = mount(); - expect($.find('.rv-xy-plot__series').length).toBe(5); - expect($.find('path.rv-xy-plot__series').length).toBe(3); - expect($.find('path.area-elevated-series-1').length).toBe(1); - expect($.find('path.area-elevated-series-2').length).toBe(1); + test('AreaSeries: Showcase Example - AreaChartElevated', () => { + const $ = mount(); + expect($.find('.rv-xy-plot__series').length).toBe(5); + expect($.find('path.rv-xy-plot__series').length).toBe(3); + expect($.find('path.area-elevated-series-1').length).toBe(1); + expect($.find('path.area-elevated-series-2').length).toBe(1); + }); }); diff --git a/packages/react-vis/tests/components/axes-tests.js b/packages/react-vis/tests/components/axes-tests.js index 90fc4cbe4..8b1787c5d 100644 --- a/packages/react-vis/tests/components/axes-tests.js +++ b/packages/react-vis/tests/components/axes-tests.js @@ -8,110 +8,114 @@ import CustomAxesOrientation from '../../../showcase/axes/custom-axes-orientatio import AxisWithTurnedLabels from '../../../showcase/plot/axis-with-turned-labels'; import AxisOn0 from '../../../showcase/axes/axis-on-0'; -test('Axis: Showcase Example - CustomAxesOrientation', () => { - const $ = mount(); - expect($.text()).toBe('1.01.52.02.53.03.54.0X Axis246810Y Axis'); - expect($.find('.rv-xy-plot__series--line').length).toBe(2); - expect($.find('line').length).toBe(26); -}); - -test('Axis: Showcase Example - Custom axis', () => { - const $ = mount(); - expect($.text()).toBe('1.01.52.03.0X'); - expect($.find('.rv-xy-plot__series--line').length).toBe(1); - expect($.find('line').length).toBe(15); - - const titleStyle = $.find('.rv-xy-plot__axis__title text').prop('style'); - expect(titleStyle.fontSize).toBe('16px'); -}); - -test('Axis: Showcase Example - Even more Custom axes', () => { - const $ = mount(); - expect($.text()).toBe( - '01345XValue is 0Value is 1Value is 2Value is 3Value is 4Value is 501491625cooldogskateboardwowsuchMultilinedogs' - ); - expect($.find('line').length).toBe(26); -}); - -test('Axis: Showcase Example - AxisWithTurnedLabels', () => { - const $ = mount(); - expect($.text()).toBe('ApplesBananasCranberries02468101214'); - expect($.find('rect').length).toBe(6); - expect($.find('line').length).toBe(24); -}); - -test('Axis: Showcase Example - Padded', () => { - const $ = mount(); - expect($.find('.rv-xy-plot__series--line').length).toBe(4); - expect($.find('line').length > 30).toBeTruthy(); -}); - -test('Axis: axis crosses on 0', () => { - // vertical axes - const $0 = mount( - - ).render(); - - const xOfGridlines0 = $0.find('.rv-xy-plot__grid-lines line')[0].attribs.x1; - const xOfAxisSetOn0 = translateToXY( - $0.find('.rv-xy-plot__axis.rv-xy-plot__axis--vertical')[0].attribs.transform - )[0]; - - expect(xOfGridlines0).toBe(xOfAxisSetOn0); - - const $1 = mount( - - ).render(); - - const xOfAxisNotSetOn0 = $1 - .find('.rv-xy-plot__axis.rv-xy-plot__axis--vertical')[0] - .attribs.transform.replace('translate(', '') - .split(',')[0]; - - expect(xOfGridlines0 !== xOfAxisNotSetOn0).toBeTruthy(); - - // horizontal axes - const $2 = mount( - - ).render(); - const gridlinesY = Number( - translateToXY($2.find('.rv-xy-plot__grid-lines')[0].attribs.transform)[1] - ); - const yOfGridlines0 = String( - gridlinesY + Number($2.find('.rv-xy-plot__grid-lines__line')[0].attribs.y1) - ); - const yOfAxisSetOn0 = translateToXY( - $2.find('.rv-xy-plot__axis.rv-xy-plot__axis--horizontal')[0].attribs - .transform - )[1]; - - expect(yOfAxisSetOn0).toBe(yOfGridlines0); - - const $3 = mount( - - ).render(); - - const yOfAxisNotSetOn0 = translateToXY( - $3.find('.rv-xy-plot__axis.rv-xy-plot__axis--horizontal')[0].attribs - .transform - )[1]; - expect(yOfAxisNotSetOn0 !== yOfGridlines0).toBeTruthy(); +describe('Axis', () => { + test('Showcase Example - CustomAxesOrientation', () => { + const $ = mount(); + expect($.text()).toBe('1.01.52.02.53.03.54.0X Axis246810Y Axis'); + expect($.find('.rv-xy-plot__series--line').length).toBe(2); + expect($.find('line').length).toBe(26); + }); + + test('Showcase Example - Custom axis', () => { + const $ = mount(); + expect($.text()).toBe('1.01.52.03.0X'); + expect($.find('.rv-xy-plot__series--line').length).toBe(1); + expect($.find('line').length).toBe(15); + + const titleStyle = $.find('.rv-xy-plot__axis__title text').prop('style'); + expect(titleStyle.fontSize).toBe('16px'); + }); + + test('Showcase Example - Even more Custom axes', () => { + const $ = mount(); + expect($.text()).toBe( + '01345XValue is 0Value is 1Value is 2Value is 3Value is 4Value is 501491625cooldogskateboardwowsuchMultilinedogs' + ); + expect($.find('line').length).toBe(26); + }); + + test('Showcase Example - AxisWithTurnedLabels', () => { + const $ = mount(); + expect($.text()).toBe('ApplesBananasCranberries02468101214'); + expect($.find('rect').length).toBe(6); + expect($.find('line').length).toBe(24); + }); + + test('Showcase Example - Padded', () => { + const $ = mount(); + expect($.find('.rv-xy-plot__series--line').length).toBe(4); + expect($.find('line').length > 30).toBeTruthy(); + }); + + test('axis crosses on 0', () => { + // vertical axes + const $0 = mount( + + ).render(); + + const xOfGridlines0 = $0.find('.rv-xy-plot__grid-lines line')[0].attribs.x1; + const xOfAxisSetOn0 = translateToXY( + $0.find('.rv-xy-plot__axis.rv-xy-plot__axis--vertical')[0].attribs + .transform + )[0]; + + expect(xOfGridlines0).toBe(xOfAxisSetOn0); + + const $1 = mount( + + ).render(); + + const xOfAxisNotSetOn0 = $1 + .find('.rv-xy-plot__axis.rv-xy-plot__axis--vertical')[0] + .attribs.transform.replace('translate(', '') + .split(',')[0]; + + expect(xOfGridlines0 !== xOfAxisNotSetOn0).toBeTruthy(); + + // horizontal axes + const $2 = mount( + + ).render(); + const gridlinesY = Number( + translateToXY($2.find('.rv-xy-plot__grid-lines')[0].attribs.transform)[1] + ); + const yOfGridlines0 = String( + gridlinesY + + Number($2.find('.rv-xy-plot__grid-lines__line')[0].attribs.y1) + ); + const yOfAxisSetOn0 = translateToXY( + $2.find('.rv-xy-plot__axis.rv-xy-plot__axis--horizontal')[0].attribs + .transform + )[1]; + + expect(yOfAxisSetOn0).toBe(yOfGridlines0); + + const $3 = mount( + + ).render(); + + const yOfAxisNotSetOn0 = translateToXY( + $3.find('.rv-xy-plot__axis.rv-xy-plot__axis--horizontal')[0].attribs + .transform + )[1]; + expect(yOfAxisNotSetOn0 !== yOfGridlines0).toBeTruthy(); + }); }); function translateToXY(translate) { diff --git a/packages/react-vis/tests/components/axis-tick-format-tests.js b/packages/react-vis/tests/components/axis-tick-format-tests.js index 08ccd72ba..131c8f1be 100644 --- a/packages/react-vis/tests/components/axis-tick-format-tests.js +++ b/packages/react-vis/tests/components/axis-tick-format-tests.js @@ -3,46 +3,54 @@ import {mount} from 'enzyme'; import CustomAxisTickElement from '../../../showcase/axes/custom-axis-tick-element'; -test('Axis Format: correctly renders return values from tickFormat', () => { - const element = mount(); - const ticks = element.find( - '.rv-xy-plot__axis--horizontal .rv-xy-plot__axis__tick' - ); - expect(ticks.map(tick => tick.find('text').length)).toEqual([0, 0, 1, 0, 1]); - expect( - ticks - .at(2) - .find('text') - .find('tspan').length - ).toBe(1); - expect( - ticks - .at(4) - .find('text') - .text() - ).toBe('Label'); -}); - -test('Axis Format: passes props to custom element', () => { - const CustomLabel = props => { - expect(Object.keys(props).sort()).toEqual([ - 'containerWidth', - 'dy', - 'textAnchor', - 'tickCount', - 'transform' +describe('Axis Format', () => { + test('correctly renders return values from tickFormat', () => { + const element = mount(); + const ticks = element.find( + '.rv-xy-plot__axis--horizontal .rv-xy-plot__axis__tick' + ); + expect(ticks.map(tick => tick.find('text').length)).toEqual([ + 0, + 0, + 1, + 0, + 1 ]); - return Custom Label; - }; - const element = mount(); - element.setState({ - data: [...element.state().data, {x: 5, y: 600, label: }] + expect( + ticks + .at(2) + .find('text') + .find('tspan').length + ).toBe(1); + expect( + ticks + .at(4) + .find('text') + .text() + ).toBe('Label'); + }); + + test('passes props to custom element', () => { + const CustomLabel = props => { + expect(Object.keys(props).sort()).toEqual([ + 'containerWidth', + 'dy', + 'textAnchor', + 'tickCount', + 'transform' + ]); + return Custom Label; + }; + const element = mount(); + element.setState({ + data: [...element.state().data, {x: 5, y: 600, label: }] + }); + expect( + element + .find('.rv-xy-plot__axis--horizontal .rv-xy-plot__axis__tick') + .at(5) + .find('text') + .text() + ).toBe('Custom Label'); }); - expect( - element - .find('.rv-xy-plot__axis--horizontal .rv-xy-plot__axis__tick') - .at(5) - .find('text') - .text() - ).toBe('Custom Label'); }); diff --git a/packages/react-vis/tests/components/axis-title-tests.js b/packages/react-vis/tests/components/axis-title-tests.js index b36afcf51..6b83119ec 100644 --- a/packages/react-vis/tests/components/axis-title-tests.js +++ b/packages/react-vis/tests/components/axis-title-tests.js @@ -11,44 +11,46 @@ const baseProps = { title: 'Title' }; -test('AxisTitle: horizontal bottom axis title', () => { - const props = Object.assign({}, baseProps, { - orientation: BOTTOM +describe('AxisTitle', () => { + test('horizontal bottom axis title', () => { + const props = Object.assign({}, baseProps, { + orientation: BOTTOM + }); + const $ = mount(); + const innerGroupHtml = $.find('g > g').html(); + expect(innerGroupHtml.includes('text-anchor: end')).toBeTruthy(); + expect($.find('text').text()).toBe(baseProps.title); }); - const $ = mount(); - const innerGroupHtml = $.find('g > g').html(); - expect(innerGroupHtml.includes('text-anchor: end')).toBeTruthy(); - expect($.find('text').text()).toBe(baseProps.title); -}); -test('AxisTitle: horizontal top axis title', () => { - const props = Object.assign({}, baseProps, { - orientation: TOP, - position: 'start' + test('horizontal top axis title', () => { + const props = Object.assign({}, baseProps, { + orientation: TOP, + position: 'start' + }); + const $ = mount(); + const innerGroupHtml = $.find('g > g').html(); + expect(innerGroupHtml.includes('text-anchor: start')).toBeTruthy(); + expect($.find('text').text()).toBe(baseProps.title); }); - const $ = mount(); - const innerGroupHtml = $.find('g > g').html(); - expect(innerGroupHtml.includes('text-anchor: start')).toBeTruthy(); - expect($.find('text').text()).toBe(baseProps.title); -}); -test('AxisTitle: vertical left title', () => { - const props = Object.assign({}, baseProps, { - orientation: LEFT + test('vertical left title', () => { + const props = Object.assign({}, baseProps, { + orientation: LEFT + }); + const $ = mount(); + const innerGroupHtml = $.find('g > g').html(); + expect(innerGroupHtml.includes('text-anchor: end')).toBeTruthy(); + expect($.find('text').text()).toBe(baseProps.title); }); - const $ = mount(); - const innerGroupHtml = $.find('g > g').html(); - expect(innerGroupHtml.includes('text-anchor: end')).toBeTruthy(); - expect($.find('text').text()).toBe(baseProps.title); -}); -test('AxisTitle: vertical right title', () => { - const props = Object.assign({}, baseProps, { - orientation: RIGHT, - position: 'start' + test('vertical right title', () => { + const props = Object.assign({}, baseProps, { + orientation: RIGHT, + position: 'start' + }); + const $ = mount(); + const innerGroupHtml = $.find('g > g').html(); + expect(innerGroupHtml.includes('text-anchor: start')).toBeTruthy(); + expect($.find('text').text()).toBe(baseProps.title); }); - const $ = mount(); - const innerGroupHtml = $.find('g > g').html(); - expect(innerGroupHtml.includes('text-anchor: start')).toBeTruthy(); - expect($.find('text').text()).toBe(baseProps.title); }); diff --git a/packages/react-vis/tests/components/bar-series-tests.js b/packages/react-vis/tests/components/bar-series-tests.js index 965b34160..319a51ce8 100644 --- a/packages/react-vis/tests/components/bar-series-tests.js +++ b/packages/react-vis/tests/components/bar-series-tests.js @@ -11,98 +11,101 @@ import BigBaseBarChart from '../../../showcase/plot/big-base-bar-chart'; import ClusteredStackedVerticalBarChart from '../../../showcase/plot/clustered-stacked-bar-chart'; import DifferenceChart from '../../../showcase/plot/difference-chart'; -testRenderWithProps(HorizontalBarSeries, GENERIC_XYPLOT_SERIES_PROPS); -testRenderWithProps(VerticalBarSeries, GENERIC_XYPLOT_SERIES_PROPS); +describe('BarSeries', () => { + testRenderWithProps(HorizontalBarSeries, GENERIC_XYPLOT_SERIES_PROPS); -test('BarSeries: Showcase Example - BarChart', () => { - const $ = mount(); - expect($.text()).toBe('TOGGLE TO CANVASABC02468101214ABC'); - expect($.find('.rv-xy-plot__series--bar rect').length).toBe(6); - expect($.find('g.vertical-bar-series-example').length).toBe(1); + testRenderWithProps(VerticalBarSeries, GENERIC_XYPLOT_SERIES_PROPS); - $.find('.showcase-button').simulate('click'); - expect($.find('rect.rv-xy-plot__series--bar').length).toBe(0); - expect($.find('.rv-xy-canvas canvas').length).toBe(1); -}); + test('Showcase Example - BarChart', () => { + const $ = mount(); + expect($.text()).toBe('TOGGLE TO CANVASABC02468101214ABC'); + expect($.find('.rv-xy-plot__series--bar rect').length).toBe(6); + expect($.find('g.vertical-bar-series-example').length).toBe(1); -test('BarSeries: Showcase Example - StackedHorizontalBarChart & StackedVerticalBarChart', () => { - [StackedHorizontalBarChart, StackedVerticalBarChart].forEach( - (Component, i) => { - const $ = mount(); - const textContent = ['0510152025', '12345']; - const expectedContent = `TOGGLE TO CANVAS${(i === 1 - ? textContent.reverse() - : textContent - ).join('')}`; - expect($.text()).toBe(expectedContent); - expect($.find('.rv-xy-plot__series--bar rect').length).toBe(6); - $.find('.showcase-button').simulate('click'); - expect($.find('.rv-xy-plot__series--bar rect').length).toBe(0); - expect($.find('.rv-xy-canvas canvas').length).toBe(1); - } - ); -}); + $.find('.showcase-button').simulate('click'); + expect($.find('rect.rv-xy-plot__series--bar').length).toBe(0); + expect($.find('.rv-xy-canvas canvas').length).toBe(1); + }); -test('BarSeries: Ordinal Y-Axis HorizontalBarSeries', () => { - const $ = mount( - - - - ); - expect($.find('.rv-xy-plot__series--bar rect').length).toBe(3); - expect( - $.find('.rv-xy-plot__series--bar rect') - .at(0) - .prop('height') > 0 - ).toBe(true); -}); + test('Showcase Example - StackedHorizontalBarChart & StackedVerticalBarChart', () => { + [StackedHorizontalBarChart, StackedVerticalBarChart].forEach( + (Component, i) => { + const $ = mount(); + const textContent = ['0510152025', '12345']; + const expectedContent = `TOGGLE TO CANVAS${(i === 1 + ? textContent.reverse() + : textContent + ).join('')}`; + expect($.text()).toBe(expectedContent); + expect($.find('.rv-xy-plot__series--bar rect').length).toBe(6); + $.find('.showcase-button').simulate('click'); + expect($.find('.rv-xy-plot__series--bar rect').length).toBe(0); + expect($.find('.rv-xy-canvas canvas').length).toBe(1); + } + ); + }); -test('BarSeries: No data', () => { - const $ = mount( - - - - ); - expect($.find('.rv-xy-plot__series--bar rect').length).toBe(0); -}); + test('Ordinal Y-Axis HorizontalBarSeries', () => { + const $ = mount( + + + + ); + expect($.find('.rv-xy-plot__series--bar rect').length).toBe(3); + expect( + $.find('.rv-xy-plot__series--bar rect') + .at(0) + .prop('height') > 0 + ).toBe(true); + }); -test('BarSeries: Showcase Example - ClusteredStackedVerticalBarChart', () => { - const $ = mount(); - expect($.text()).toBe('TOGGLE TO CANVASQ1Q2Q3Q40102030ApplesOranges'); - expect($.find('.rv-xy-plot__series--bar rect').length).toBe(16); - expect($.find('.rv-xy-plot__series').length).toBe(4); + test('No data', () => { + const $ = mount( + + + + ); + expect($.find('.rv-xy-plot__series--bar rect').length).toBe(0); + }); - $.find('.showcase-button').simulate('click'); - expect($.find('.rv-xy-plot__series--bar rect').length).toBe(0); - expect($.find('.rv-xy-canvas canvas').length).toBe(1); -}); + test('Showcase Example - ClusteredStackedVerticalBarChart', () => { + const $ = mount(); + expect($.text()).toBe('TOGGLE TO CANVASQ1Q2Q3Q40102030ApplesOranges'); + expect($.find('.rv-xy-plot__series--bar rect').length).toBe(16); + expect($.find('.rv-xy-plot__series').length).toBe(4); -test('BarSeries: Showcase Example - BigBaseBarChart', () => { - const $ = mount(); - expect($.text()).toBe( - 'TOGGLE TO CANVAS:38:39:40:41199,800199,900200,000200,100200,200200,300200,400' - ); - expect($.find('.rv-xy-plot__series--bar rect').length).toBe(15); - expect($.find('.rv-xy-plot__series').length).toBe(1); + $.find('.showcase-button').simulate('click'); + expect($.find('.rv-xy-plot__series--bar rect').length).toBe(0); + expect($.find('.rv-xy-canvas canvas').length).toBe(1); + }); - $.find('.showcase-button').simulate('click'); - expect($.find('.rv-xy-plot__series--bar rect').length).toBe(0); - expect($.find('.rv-xy-canvas canvas').length).toBe(1); -}); + test('Showcase Example - BigBaseBarChart', () => { + const $ = mount(); + expect($.text()).toBe( + 'TOGGLE TO CANVAS:38:39:40:41199,800199,900200,000200,100200,200200,300200,400' + ); + expect($.find('.rv-xy-plot__series--bar rect').length).toBe(15); + expect($.find('.rv-xy-plot__series').length).toBe(1); + + $.find('.showcase-button').simulate('click'); + expect($.find('.rv-xy-plot__series--bar rect').length).toBe(0); + expect($.find('.rv-xy-canvas canvas').length).toBe(1); + }); -test('BarSeries: Showcase Example - DifferenceChart', () => { - const $ = mount(); - expect($.text()).toBe('TOGGLE TO CANVAS02468101214-4-20246810'); - expect($.find('.rv-xy-plot__series--bar rect').length).toBe(15); - expect($.find('.rv-xy-plot__series').length).toBe(1); + test('Showcase Example - DifferenceChart', () => { + const $ = mount(); + expect($.text()).toBe('TOGGLE TO CANVAS02468101214-4-20246810'); + expect($.find('.rv-xy-plot__series--bar rect').length).toBe(15); + expect($.find('.rv-xy-plot__series').length).toBe(1); - $.find('.showcase-button').simulate('click'); - expect($.find('.rv-xy-plot__series--bar rect').length).toBe(0); - expect($.find('.rv-xy-canvas canvas').length).toBe(1); + $.find('.showcase-button').simulate('click'); + expect($.find('.rv-xy-plot__series--bar rect').length).toBe(0); + expect($.find('.rv-xy-canvas canvas').length).toBe(1); + }); }); diff --git a/packages/react-vis/tests/components/borders-tests.js b/packages/react-vis/tests/components/borders-tests.js index 3ce956826..5572886af 100644 --- a/packages/react-vis/tests/components/borders-tests.js +++ b/packages/react-vis/tests/components/borders-tests.js @@ -6,8 +6,10 @@ import GradientExample from '../../../showcase/misc/gradient-example'; testRenderWithProps(Borders, GENERIC_XYPLOT_SERIES_PROPS); -test('Borders: GradientExample', () => { - const $ = mount(); - expect($.find('.rv-xy-plot__borders').length).toBe(1); - expect($.find('.rv-xy-plot__borders rect').length).toBe(4); +describe('Borders', () => { + test('GradientExample', () => { + const $ = mount(); + expect($.find('.rv-xy-plot__borders').length).toBe(1); + expect($.find('.rv-xy-plot__borders rect').length).toBe(4); + }); }); diff --git a/packages/react-vis/tests/components/circular-grid-lines-tests.js b/packages/react-vis/tests/components/circular-grid-lines-tests.js index 60fd060d8..7af6c1af2 100644 --- a/packages/react-vis/tests/components/circular-grid-lines-tests.js +++ b/packages/react-vis/tests/components/circular-grid-lines-tests.js @@ -4,10 +4,12 @@ import CircularGridLines from 'plot/circular-grid-lines'; import {testRenderWithProps, GENERIC_XYPLOT_SERIES_PROPS} from '../test-utils'; import FauxRadialScatterplot from '../../../showcase/plot/faux-radial-scatterplot'; -testRenderWithProps(CircularGridLines, GENERIC_XYPLOT_SERIES_PROPS); +describe('CircularGridLines', () => { + testRenderWithProps(CircularGridLines, GENERIC_XYPLOT_SERIES_PROPS); -test('CircularGridLines: Showcase Example - FauxRadialScatterplot', () => { - const $ = mount(); - expect($.text()).toBe('-3-2-10123-3-2-10123'); - expect($.find('.rv-xy-plot__circular-grid-lines__line').length).toBe(7); + test('Showcase Example - FauxRadialScatterplot', () => { + const $ = mount(); + expect($.text()).toBe('-3-2-10123-3-2-10123'); + expect($.find('.rv-xy-plot__circular-grid-lines__line').length).toBe(7); + }); }); diff --git a/packages/react-vis/tests/components/color-article-tests.js b/packages/react-vis/tests/components/color-article-tests.js index a061452e6..2ffb93e20 100644 --- a/packages/react-vis/tests/components/color-article-tests.js +++ b/packages/react-vis/tests/components/color-article-tests.js @@ -22,94 +22,96 @@ import { CustomPalette } from '../../../showcase/color/mini-color-examples'; -test('Color Article Test: #generateCharts', () => { - [ - {name: 'SensibleDefaults', Item: SensibleDefaults}, - {name: 'ColorInXYPlot', Item: ColorInXYPlot}, - {name: 'LiteralColorAtSeriesLevel', Item: LiteralColorAtSeriesLevel}, - {name: 'LinearColorAtSeriesLevel', Item: LinearColorAtSeriesLevel}, - {name: 'CategoryColorAtSeriesLevel', Item: CategoryColorAtSeriesLevel}, - {name: 'LiteralColorAtMarkLevel', Item: LiteralColorAtMarkLevel}, - {name: 'CategoryColorAtMarkLevel', Item: CategoryColorAtMarkLevel}, - { - name: 'CategoryColorAtMarkLevelCustomPalette', - Item: CategoryColorAtMarkLevelCustomPalette - }, - { - name: 'CategoryColorAtMarkLevelFixedStroke', - Item: CategoryColorAtMarkLevelFixedStroke - }, - { - name: 'LinearColorAtMarkLevelNoPalette', - Item: LinearColorAtMarkLevelNoPalette - }, - {name: 'LinearColorAtMarkLevel', Item: LinearColorAtMarkLevel} - ].forEach(obj => { - const {Item} = obj; - const $ = mount(); - expect($.find('.rv-xy-plot').length).toBe(3); - expect($.find('.rv-xy-plot__series--bar rect').length).toBe(30); - expect($.find('path.rv-xy-plot__series--line').length).toBe(3); - expect($.find('.rv-xy-plot__series--mark circle').length).toBe(30); +describe('Color Article Test', () => { + test('generateCharts', () => { + [ + {name: 'SensibleDefaults', Item: SensibleDefaults}, + {name: 'ColorInXYPlot', Item: ColorInXYPlot}, + {name: 'LiteralColorAtSeriesLevel', Item: LiteralColorAtSeriesLevel}, + {name: 'LinearColorAtSeriesLevel', Item: LinearColorAtSeriesLevel}, + {name: 'CategoryColorAtSeriesLevel', Item: CategoryColorAtSeriesLevel}, + {name: 'LiteralColorAtMarkLevel', Item: LiteralColorAtMarkLevel}, + {name: 'CategoryColorAtMarkLevel', Item: CategoryColorAtMarkLevel}, + { + name: 'CategoryColorAtMarkLevelCustomPalette', + Item: CategoryColorAtMarkLevelCustomPalette + }, + { + name: 'CategoryColorAtMarkLevelFixedStroke', + Item: CategoryColorAtMarkLevelFixedStroke + }, + { + name: 'LinearColorAtMarkLevelNoPalette', + Item: LinearColorAtMarkLevelNoPalette + }, + {name: 'LinearColorAtMarkLevel', Item: LinearColorAtMarkLevel} + ].forEach(obj => { + const {Item} = obj; + const $ = mount(); + expect($.find('.rv-xy-plot').length).toBe(3); + expect($.find('.rv-xy-plot__series--bar rect').length).toBe(30); + expect($.find('path.rv-xy-plot__series--line').length).toBe(3); + expect($.find('.rv-xy-plot__series--mark circle').length).toBe(30); + }); }); -}); -test('Color Article Test: GradientCharts', () => { - const $ = mount(); + test('GradientCharts', () => { + const $ = mount(); - expect($.find('.rv-xy-plot').length).toBe(3); - expect($.find('.rv-xy-plot__series--bar rect').length).toBe(10); - expect($.find('path.rv-xy-plot__series--line').length).toBe(1); - expect($.find('.rv-xy-plot__series--mark circle').length).toBe(10); -}); + expect($.find('.rv-xy-plot').length).toBe(3); + expect($.find('.rv-xy-plot__series--bar rect').length).toBe(10); + expect($.find('path.rv-xy-plot__series--line').length).toBe(1); + expect($.find('.rv-xy-plot__series--mark circle').length).toBe(10); + }); -test('Color Article Test: ColorSpecificity', () => { - const $ = mount(); + test('ColorSpecificity', () => { + const $ = mount(); - expect($.find('.rv-xy-plot').length).toBe(3); - expect($.find('.rv-xy-plot__series--bar rect').length).toBe(10); - expect($.find('path.rv-xy-plot__series--line').length).toBe(3); - expect($.find('.rv-xy-plot__series--mark circle').length).toBe(30); -}); + expect($.find('.rv-xy-plot').length).toBe(3); + expect($.find('.rv-xy-plot__series--bar rect').length).toBe(10); + expect($.find('path.rv-xy-plot__series--line').length).toBe(3); + expect($.find('.rv-xy-plot__series--mark circle').length).toBe(30); + }); -test('Color Article Test: generatePalette', () => { - [ - { - name: 'ReactVis5', - Item: ReactVis5, - expectedText: '#12939A#79C7E3#1A3177#FF9833#EF5D28', - numberOfBoxes: 5 - }, - { - name: 'ReactVis20', - Item: ReactVis20, - expectedText: - '#19CDD7#DDB27C#88572C#FF991F#F15C17#223F9A#DA70BF#125C77#4DC19C#776E57#12939A#17B8BE#F6D18A#B7885E#FFCB99#F89570#829AE3#E79FD5#1E96BE#89DAC1#B3AD9E', - numberOfBoxes: 21 - }, - { - name: 'Continuous', - Item: Continuous, - expectedText: '#EF5D28#FF9833', - numberOfBoxes: 2 - }, - { - name: 'CustomPalette', - Item: CustomPalette, - expectedText: - '#cd3b54#59b953#ba4fb9#99b53e#7f61d3#c9a83a#626dbc#e08b39#5ea0d8#cf4d2a#4fb79b#d24691#528240#c388d2#80742b#9c4a6d#caaa70#e0829f#9d5d30#dc7666', - numberOfBoxes: 20 - } - ].forEach(obj => { - const {Item, expectedText, numberOfBoxes} = obj; - const $ = mount(); - expect($.find('.color-box').length).toBe(numberOfBoxes); - expect($.text()).toBe(expectedText); + test('generatePalette', () => { + [ + { + name: 'ReactVis5', + Item: ReactVis5, + expectedText: '#12939A#79C7E3#1A3177#FF9833#EF5D28', + numberOfBoxes: 5 + }, + { + name: 'ReactVis20', + Item: ReactVis20, + expectedText: + '#19CDD7#DDB27C#88572C#FF991F#F15C17#223F9A#DA70BF#125C77#4DC19C#776E57#12939A#17B8BE#F6D18A#B7885E#FFCB99#F89570#829AE3#E79FD5#1E96BE#89DAC1#B3AD9E', + numberOfBoxes: 21 + }, + { + name: 'Continuous', + Item: Continuous, + expectedText: '#EF5D28#FF9833', + numberOfBoxes: 2 + }, + { + name: 'CustomPalette', + Item: CustomPalette, + expectedText: + '#cd3b54#59b953#ba4fb9#99b53e#7f61d3#c9a83a#626dbc#e08b39#5ea0d8#cf4d2a#4fb79b#d24691#528240#c388d2#80742b#9c4a6d#caaa70#e0829f#9d5d30#dc7666', + numberOfBoxes: 20 + } + ].forEach(obj => { + const {Item, expectedText, numberOfBoxes} = obj; + const $ = mount(); + expect($.find('.color-box').length).toBe(numberOfBoxes); + expect($.text()).toBe(expectedText); + }); }); -}); -test('Color Article Test: LineSeriesMarkSeries', () => { - const $ = mount(); - expect($.find('path.rv-xy-plot__series--line').length).toBe(3); - expect($.find('.rv-xy-plot__series--mark circle').length).toBe(30); + test('LineSeriesMarkSeries', () => { + const $ = mount(); + expect($.find('path.rv-xy-plot__series--line').length).toBe(3); + expect($.find('.rv-xy-plot__series--mark circle').length).toBe(30); + }); }); diff --git a/packages/react-vis/tests/components/contour-series-tests.js b/packages/react-vis/tests/components/contour-series-tests.js index 51de6bfb1..2b620b599 100644 --- a/packages/react-vis/tests/components/contour-series-tests.js +++ b/packages/react-vis/tests/components/contour-series-tests.js @@ -4,11 +4,13 @@ import ContourSeries from 'plot/series/contour-series'; import {testRenderWithProps, GENERIC_XYPLOT_SERIES_PROPS} from '../test-utils'; import ContourSeriesExample from '../../../showcase/plot/contour-series-example'; -testRenderWithProps(ContourSeries, GENERIC_XYPLOT_SERIES_PROPS); +describe('ContourSeries', () => { + testRenderWithProps(ContourSeries, GENERIC_XYPLOT_SERIES_PROPS); -test('ContourSeries: Showcase Example - ContourSeriesExample', () => { - const $ = mount(); - expect($.text()).toBe('4045505560657075808590951002345678UPDATE'); - expect($.find('.rv-xy-plot__series--contour').length).toBe(1); - expect($.find('.rv-xy-plot__series--contour-line').length).toBe(28); + test('Showcase Example - ContourSeriesExample', () => { + const $ = mount(); + expect($.text()).toBe('4045505560657075808590951002345678UPDATE'); + expect($.find('.rv-xy-plot__series--contour').length).toBe(1); + expect($.find('.rv-xy-plot__series--contour-line').length).toBe(28); + }); }); diff --git a/packages/react-vis/tests/components/crosshair-tests.js b/packages/react-vis/tests/components/crosshair-tests.js index 818b73dfc..5186ce424 100644 --- a/packages/react-vis/tests/components/crosshair-tests.js +++ b/packages/react-vis/tests/components/crosshair-tests.js @@ -3,26 +3,28 @@ import {mount} from 'enzyme'; import DynamicCrosshair from '../../../showcase/axes/dynamic-crosshair'; -test('Crosshair: Dynamic Crosshair - Example', () => { - const $ = mount(); - simulateMouseMove(100); - expect($.find('.rv-crosshair').hasClass('test-class-name')).toBe(true); +describe('Crosshair', () => { + test('Dynamic Crosshair - Example', () => { + const $ = mount(); + simulateMouseMove(100); + expect($.find('.rv-crosshair').hasClass('test-class-name')).toBe(true); - function simulateMouseMove(x) { - $.find('.rv-xy-plot__inner').simulate('mousemove', { - nativeEvent: {clientX: x, clientY: 150} - }); - } -}); + function simulateMouseMove(x) { + $.find('.rv-xy-plot__inner').simulate('mousemove', { + nativeEvent: {clientX: x, clientY: 150} + }); + } + }); -test('Crosshair: Dynamic Crosshair - Touch Example', () => { - const $ = mount(); - simulateMouseMove(100); - expect($.find('.rv-crosshair').hasClass('test-class-name')).toBe(true); + test('Dynamic Crosshair - Touch Example', () => { + const $ = mount(); + simulateMouseMove(100); + expect($.find('.rv-crosshair').hasClass('test-class-name')).toBe(true); - function simulateMouseMove(x) { - $.find('.rv-xy-plot__inner').simulate('touchmove', { - nativeEvent: {type: 'touchmove', touches: [{pageX: x, pageY: 150}]} - }); - } + function simulateMouseMove(x) { + $.find('.rv-xy-plot__inner').simulate('touchmove', { + nativeEvent: {type: 'touchmove', touches: [{pageX: x, pageY: 150}]} + }); + } + }); }); diff --git a/packages/react-vis/tests/components/custom-svg-series-tests.js b/packages/react-vis/tests/components/custom-svg-series-tests.js index 9dfc9c661..92cb61edc 100644 --- a/packages/react-vis/tests/components/custom-svg-series-tests.js +++ b/packages/react-vis/tests/components/custom-svg-series-tests.js @@ -8,39 +8,41 @@ import CustomSVGRootLevelComponent from '../../../showcase/plot/custom-svg-root- testRenderWithProps(CustomSVGSeries, GENERIC_XYPLOT_SERIES_PROPS); -test('CustomSVGSeries: Showcase Example - CustomSVGExample', () => { - const $ = mount(); - expect($.text()).toBe('1.01.52.02.53.068101214x: 187.5y: 200'); - expect($.find('.rv-xy-plot__series--custom-svg').length).toBe(5); - expect($.find('.rv-xy-plot__series--custom-svg polygon').length).toBe(0); - expect($.find('.rv-xy-plot__series--custom-svg circle').length).toBe(2); - expect($.find('.rv-xy-plot__series--custom-svg rect').length).toBe(3); -}); +describe('CustomSVGSeries', () => { + test('Showcase Example - CustomSVGExample', () => { + const $ = mount(); + expect($.text()).toBe('1.01.52.02.53.068101214x: 187.5y: 200'); + expect($.find('.rv-xy-plot__series--custom-svg').length).toBe(5); + expect($.find('.rv-xy-plot__series--custom-svg polygon').length).toBe(0); + expect($.find('.rv-xy-plot__series--custom-svg circle').length).toBe(2); + expect($.find('.rv-xy-plot__series--custom-svg rect').length).toBe(3); + }); -test('CustomSVGSeries: Showcase Example - CustomSVGRootLevelComponent', () => { - const $ = mount(); - expect($.text()).toBe( - '1.01.52.02.53.068101214x: 0y: 125x: 87.5y: 75.00000000000001x: 125y: 250x: 250y: 0x: 187.5y: 200' - ); - expect($.find('.rv-xy-plot__series--custom-svg').length).toBe(5); - expect($.find('.rv-xy-plot__series--custom-svg polygon').length).toBe(0); - expect($.find('.rv-xy-plot__series--custom-svg circle').length).toBe(5); - expect($.find('.rv-xy-plot__series--custom-svg rect').length).toBe(0); - expect($.find('.rv-xy-plot__series--custom-svg text').length).toBe(5); -}); + test('Showcase Example - CustomSVGRootLevelComponent', () => { + const $ = mount(); + expect($.text()).toBe( + '1.01.52.02.53.068101214x: 0y: 125x: 87.5y: 75.00000000000001x: 125y: 250x: 250y: 0x: 187.5y: 200' + ); + expect($.find('.rv-xy-plot__series--custom-svg').length).toBe(5); + expect($.find('.rv-xy-plot__series--custom-svg polygon').length).toBe(0); + expect($.find('.rv-xy-plot__series--custom-svg circle').length).toBe(5); + expect($.find('.rv-xy-plot__series--custom-svg rect').length).toBe(0); + expect($.find('.rv-xy-plot__series--custom-svg text').length).toBe(5); + }); -test('CustomSVGSeries: Showcase Example - CustomSVGAllTheMarks', () => { - const textContent = 'REVERSE0123402468101214'; - const hoverText = 'star'; + test('Showcase Example - CustomSVGAllTheMarks', () => { + const textContent = 'REVERSE0123402468101214'; + const hoverText = 'star'; - const $ = mount(); - expect($.text()).toBe(textContent); - $.find('.rv-xy-plot__series--custom-svg') - .at(0) - .simulate('mouseEnter'); - expect($.text()).toBe(`${textContent}${hoverText}`); - expect($.find('.rv-xy-plot__series--custom-svg').length).toBe(20); - expect($.find('.rv-xy-plot__series--custom-svg polygon').length).toBe(10); - expect($.find('.rv-xy-plot__series--custom-svg circle').length).toBe(5); - expect($.find('.rv-xy-plot__series--custom-svg rect').length).toBe(5); + const $ = mount(); + expect($.text()).toBe(textContent); + $.find('.rv-xy-plot__series--custom-svg') + .at(0) + .simulate('mouseEnter'); + expect($.text()).toBe(`${textContent}${hoverText}`); + expect($.find('.rv-xy-plot__series--custom-svg').length).toBe(20); + expect($.find('.rv-xy-plot__series--custom-svg polygon').length).toBe(10); + expect($.find('.rv-xy-plot__series--custom-svg circle').length).toBe(5); + expect($.find('.rv-xy-plot__series--custom-svg rect').length).toBe(5); + }); }); diff --git a/packages/react-vis/tests/components/data-article-tests.js b/packages/react-vis/tests/components/data-article-tests.js index 9d51cf918..ebce79c10 100644 --- a/packages/react-vis/tests/components/data-article-tests.js +++ b/packages/react-vis/tests/components/data-article-tests.js @@ -3,7 +3,9 @@ import {mount} from 'enzyme'; import {MiniCharts} from '../../../showcase/data/mini-data-examples'; -test('Scales and data examples: MiniCharts', () => { - const $ = mount(); - expect($.find('.rv-xy-plot').length).toBe(3); +describe('Scales and data examples', () => { + test('MiniCharts', () => { + const $ = mount(); + expect($.find('.rv-xy-plot').length).toBe(3); + }); }); diff --git a/packages/react-vis/tests/components/decorative-axis-tests.js b/packages/react-vis/tests/components/decorative-axis-tests.js index 6acaa3b26..6ae3d2f89 100644 --- a/packages/react-vis/tests/components/decorative-axis-tests.js +++ b/packages/react-vis/tests/components/decorative-axis-tests.js @@ -12,22 +12,24 @@ testRenderWithProps(DecorativeAxis, { axisDomain: [0, 1] }); -test('DecorativeAxis: Showcase Example - DecorativeAxisCrissCross', () => { - const $ = mount(); - expect($.text()).toBe( - '-101.01223344556677889100¡1000!¡990!¡980!¡970!¡960!¡950!¡940!¡930!¡920!¡910!¡900!' - ); - expect($.find('.rv-xy-manipulable-axis').length).toBe(2); - expect($.find('.rv-xy-plot__axis__tick__line').length).toBe(22); - expect($.find('.rv-xy-plot__axis__tick__text').length).toBe(22); -}); +describe('DecorativeAxis', () => { + test('Showcase Example - DecorativeAxisCrissCross', () => { + const $ = mount(); + expect($.text()).toBe( + '-101.01223344556677889100¡1000!¡990!¡980!¡970!¡960!¡950!¡940!¡930!¡920!¡910!¡900!' + ); + expect($.find('.rv-xy-manipulable-axis').length).toBe(2); + expect($.find('.rv-xy-plot__axis__tick__line').length).toBe(22); + expect($.find('.rv-xy-plot__axis__tick__text').length).toBe(22); + }); -test('DecorativeAxis: Showcase Example - ParallelCoordinatesExample', () => { - const $ = mount(); - expect($.text()).toBe( - '0.04.79.314192328333742473.03.54.04.55.05.56.06.57.07.58.0681101501802202603003403804204600.023466992120140160180210230160020002300270030003400370041004400480051008.09.71113151618202123257071727475767778808182' - ); - expect($.find('.rv-xy-manipulable-axis').length).toBe(7); - expect($.find('.rv-xy-plot__axis__tick__line').length).toBe(77); - expect($.find('.rv-xy-plot__axis__tick__text').length).toBe(77); + test('Showcase Example - ParallelCoordinatesExample', () => { + const $ = mount(); + expect($.text()).toBe( + '0.04.79.314192328333742473.03.54.04.55.05.56.06.57.07.58.0681101501802202603003403804204600.023466992120140160180210230160020002300270030003400370041004400480051008.09.71113151618202123257071727475767778808182' + ); + expect($.find('.rv-xy-manipulable-axis').length).toBe(7); + expect($.find('.rv-xy-plot__axis__tick__line').length).toBe(77); + expect($.find('.rv-xy-plot__axis__tick__text').length).toBe(77); + }); }); diff --git a/packages/react-vis/tests/components/gradient-tests.js b/packages/react-vis/tests/components/gradient-tests.js index 19a3ac3c8..ed31778ef 100644 --- a/packages/react-vis/tests/components/gradient-tests.js +++ b/packages/react-vis/tests/components/gradient-tests.js @@ -5,18 +5,20 @@ import {testRenderWithProps, GENERIC_XYPLOT_SERIES_PROPS} from '../test-utils'; import TriangleExample from '../../../showcase/misc/triangle-example'; import GradientExample from '../../../showcase/misc/gradient-example'; -testRenderWithProps(GradientDefs, GENERIC_XYPLOT_SERIES_PROPS); +describe('GradientDefs', () => { + testRenderWithProps(GradientDefs, GENERIC_XYPLOT_SERIES_PROPS); -test('GradientDefs: TriangleExample', () => { - const $ = mount(); - expect($.find('.rv-xy-plot__series--polygon').length).toBe(121); - expect($.find('.rv-gradient-defs').length).toBe(1); - expect($.find('#grad1').length).toBe(1); -}); + test('TriangleExample', () => { + const $ = mount(); + expect($.find('.rv-xy-plot__series--polygon').length).toBe(121); + expect($.find('.rv-gradient-defs').length).toBe(1); + expect($.find('#grad1').length).toBe(1); + }); -test('GradientDefs: GradientExample', () => { - const $ = mount(); - expect($.find('.rv-xy-plot__series--line').length).toBe(2); - expect($.find('.rv-gradient-defs').length).toBe(1); - expect($.find('#CoolGradient').length).toBe(1); + test('GradientExample', () => { + const $ = mount(); + expect($.find('.rv-xy-plot__series--line').length).toBe(2); + expect($.find('.rv-gradient-defs').length).toBe(1); + expect($.find('#CoolGradient').length).toBe(1); + }); }); diff --git a/packages/react-vis/tests/components/grid-lines-tests.js b/packages/react-vis/tests/components/grid-lines-tests.js index e39e6c773..bd265c507 100644 --- a/packages/react-vis/tests/components/grid-lines-tests.js +++ b/packages/react-vis/tests/components/grid-lines-tests.js @@ -5,34 +5,36 @@ import LineSeries from 'plot/series/line-series'; import HorizontalGridLines from 'plot/horizontal-grid-lines'; import VerticalGridLines from 'plot/vertical-grid-lines'; -test('GridLines: HorizontalGridLines', () => { - const wrapper = shallow( - - - - - ); +describe('GridLines', () => { + test('HorizontalGridLines', () => { + const wrapper = shallow( + + + + + ); - expect( - wrapper - .find(HorizontalGridLines) - .at(0) - .hasClass('test-class-name') - ).toBe(true); -}); + expect( + wrapper + .find(HorizontalGridLines) + .at(0) + .hasClass('test-class-name') + ).toBe(true); + }); -test('GridLines: VerticalGridLines', () => { - const wrapper = shallow( - - - - - ); + test('VerticalGridLines', () => { + const wrapper = shallow( + + + + + ); - expect( - wrapper - .find(VerticalGridLines) - .at(0) - .hasClass('test-class-name') - ).toBe(true); + expect( + wrapper + .find(VerticalGridLines) + .at(0) + .hasClass('test-class-name') + ).toBe(true); + }); }); diff --git a/packages/react-vis/tests/components/heatmap-tests.js b/packages/react-vis/tests/components/heatmap-tests.js index 4a899f19d..72109a0af 100644 --- a/packages/react-vis/tests/components/heatmap-tests.js +++ b/packages/react-vis/tests/components/heatmap-tests.js @@ -24,39 +24,43 @@ const HEATMAP_PROPS = { ] }; -testRenderWithProps(HeatmapSeries, GENERIC_XYPLOT_SERIES_PROPS); +describe('Heatmap', () => { + testRenderWithProps(HeatmapSeries, GENERIC_XYPLOT_SERIES_PROPS); -test('Heatmap: basic rendering', () => { - const $ = mount( - - - - ); - expect($.find('.rv-xy-plot__series--heatmap').length).toBe(1); - expect($.find('.rv-xy-plot__series--heatmap rect').length).toBe(12); - expect($.find('g.heatmap-series-example').length).toBe(1); + test('basic rendering', () => { + const $ = mount( + + + + ); + expect($.find('.rv-xy-plot__series--heatmap').length).toBe(1); + expect($.find('.rv-xy-plot__series--heatmap rect').length).toBe(12); + expect($.find('g.heatmap-series-example').length).toBe(1); - $.setProps({children: }); - expect($.find('.rv-xy-plot__series--heatmap').length).toBe(0); - expect($.find('.rv-xy-plot__series--heatmap rect').length).toBe(0); - expect($.find('.heatmap-series-example').length).toBe(0); -}); + $.setProps({ + children: + }); + expect($.find('.rv-xy-plot__series--heatmap').length).toBe(0); + expect($.find('.rv-xy-plot__series--heatmap rect').length).toBe(0); + expect($.find('.heatmap-series-example').length).toBe(0); + }); -test('Heatmap: Showcase Example - HeatmapChart', () => { - const $ = mount(); - expect($.find('.rv-xy-plot__series--heatmap').length).toBe(1); - expect($.find('.rv-xy-plot__series--heatmap rect').length).toBe(12); - expect($.find('g.heatmap-series-example').length).toBe(1); - expect($.text()).toBe('0.51.01.52.02.53.03.5051015'); -}); + test('Showcase Example - HeatmapChart', () => { + const $ = mount(); + expect($.find('.rv-xy-plot__series--heatmap').length).toBe(1); + expect($.find('.rv-xy-plot__series--heatmap rect').length).toBe(12); + expect($.find('g.heatmap-series-example').length).toBe(1); + expect($.text()).toBe('0.51.01.52.02.53.03.5051015'); + }); -test('Heatmap: Showcase Example - LabeledHeatmap', () => { - const $ = mount(); - expect($.find('.rv-xy-plot__series--heatmap').length).toBe(1); - expect($.find('.rv-xy-plot__series--label').length).toBe(1); - expect($.find('.rv-xy-plot__series--heatmap rect').length).toBe(100); - expect($.find('g.heatmap-series-example').length).toBe(1); - expect($.text()).toBe( - 'A1B1C1D1E1F1G1H1I1J1J2I2H2G2F2E2D2C2B2A20123456789111111111122222122233333331313444444444155555555556666666666777777777788888888889999999999' - ); + test('Showcase Example - LabeledHeatmap', () => { + const $ = mount(); + expect($.find('.rv-xy-plot__series--heatmap').length).toBe(1); + expect($.find('.rv-xy-plot__series--label').length).toBe(1); + expect($.find('.rv-xy-plot__series--heatmap rect').length).toBe(100); + expect($.find('g.heatmap-series-example').length).toBe(1); + expect($.text()).toBe( + 'A1B1C1D1E1F1G1H1I1J1J2I2H2G2F2E2D2C2B2A20123456789111111111122222122233333331313444444444155555555556666666666777777777788888888889999999999' + ); + }); }); diff --git a/packages/react-vis/tests/components/hexbin-series-tests.js b/packages/react-vis/tests/components/hexbin-series-tests.js index 616877796..61f855a01 100644 --- a/packages/react-vis/tests/components/hexbin-series-tests.js +++ b/packages/react-vis/tests/components/hexbin-series-tests.js @@ -5,69 +5,71 @@ import {testRenderWithProps, GENERIC_XYPLOT_SERIES_PROPS} from '../test-utils'; import HexHeatmap from '../../../showcase/plot/hex-heatmap'; import HexbinSizeExample from '../../../showcase/plot/hexbin-size-example'; -testRenderWithProps(HexbinSeries, GENERIC_XYPLOT_SERIES_PROPS); +describe('HexbinSeries', () => { + testRenderWithProps(HexbinSeries, GENERIC_XYPLOT_SERIES_PROPS); -test('HexbinSeries: Showcase Example - HexHeatmap', () => { - const $ = mount(); - expect($.find('.rv-xy-plot__series--hexbin').length).toBe(1); - expect($.find('.rv-xy-plot__series--hexbin path').length).toBe(53); - expect($.find('g.hexbin-example').length).toBe(1); - expect($.text()).toBe( - '4050607080901002345678UPDATE DATAUPDATE RADIUSUPDATE OFFSET' - ); + test('Showcase Example - HexHeatmap', () => { + const $ = mount(); + expect($.find('.rv-xy-plot__series--hexbin').length).toBe(1); + expect($.find('.rv-xy-plot__series--hexbin path').length).toBe(53); + expect($.find('g.hexbin-example').length).toBe(1); + expect($.text()).toBe( + '4050607080901002345678UPDATE DATAUPDATE RADIUSUPDATE OFFSET' + ); - $.find('.rv-xy-plot__series--hexbin path') - .at(2) - .simulate('mouseOver'); - expect($.text()).toBe( - '4050607080901002345678x: 138.56406460551017y: 180value: 1UPDATE DATAUPDATE RADIUSUPDATE OFFSET' - ); -}); + $.find('.rv-xy-plot__series--hexbin path') + .at(2) + .simulate('mouseOver'); + expect($.text()).toBe( + '4050607080901002345678x: 138.56406460551017y: 180value: 1UPDATE DATAUPDATE RADIUSUPDATE OFFSET' + ); + }); -test('HexbinSeries: Showcase Example - HexbinSizeExample', () => { - const $ = mount(); - expect($.find('g.alt-x-label').length).toBe(1); - expect($.find('g.alt-y-label').length).toBe(1); - [ - { - numHexes: 56, - text: - 'PREV X X AXIS economy (mpg) NEXT XPREV Y Y AXIS power (hp) NEXT Y051015202530354045050100150200economy (mpg)power (hp)', - buttonToPress: null - }, + test('Showcase Example - HexbinSizeExample', () => { + const $ = mount(); + expect($.find('g.alt-x-label').length).toBe(1); + expect($.find('g.alt-y-label').length).toBe(1); + [ + { + numHexes: 56, + text: + 'PREV X X AXIS economy (mpg) NEXT XPREV Y Y AXIS power (hp) NEXT Y051015202530354045050100150200economy (mpg)power (hp)', + buttonToPress: null + }, - // click next x - { - numHexes: 56, - text: - 'PREV X X AXIS cylinders NEXT XPREV Y Y AXIS power (hp) NEXT Y3.03.54.04.55.05.56.06.57.07.58.0050100150200cylinderspower (hp)', - buttonToPress: 1 - }, + // click next x + { + numHexes: 56, + text: + 'PREV X X AXIS cylinders NEXT XPREV Y Y AXIS power (hp) NEXT Y3.03.54.04.55.05.56.06.57.07.58.0050100150200cylinderspower (hp)', + buttonToPress: 1 + }, - // click next y - { - numHexes: 20, - text: - 'PREV X X AXIS cylinders NEXT XPREV Y Y AXIS weight (lb) NEXT Y3.03.54.04.55.05.56.06.57.07.58.02,0002,5003,0003,5004,0004,5005,000cylindersweight (lb)', - buttonToPress: 3 - }, + // click next y + { + numHexes: 20, + text: + 'PREV X X AXIS cylinders NEXT XPREV Y Y AXIS weight (lb) NEXT Y3.03.54.04.55.05.56.06.57.07.58.02,0002,5003,0003,5004,0004,5005,000cylindersweight (lb)', + buttonToPress: 3 + }, - // click prev y - { - numHexes: 20, - text: - 'PREV X X AXIS cylinders NEXT XPREV Y Y AXIS weight (lb) NEXT Y3.03.54.04.55.05.56.06.57.07.58.02,0002,5003,0003,5004,0004,5005,000cylindersweight (lb)', - buttonToPress: 0 - } - ].forEach(({numHexes, text, buttonToPress}) => { - if (buttonToPress) { - $.find('.showcase-button') - .at(buttonToPress) - .simulate('click'); - } - expect($.find('.rv-xy-plot__series--hexbin').length).toBe(1); - expect($.find('.rv-xy-plot__series--hexbin path').length).toBe(numHexes); - expect($.find('g.hexbin-size-example').length).toBe(1); - expect($.text()).toBe(text); + // click prev y + { + numHexes: 20, + text: + 'PREV X X AXIS cylinders NEXT XPREV Y Y AXIS weight (lb) NEXT Y3.03.54.04.55.05.56.06.57.07.58.02,0002,5003,0003,5004,0004,5005,000cylindersweight (lb)', + buttonToPress: 0 + } + ].forEach(({numHexes, text, buttonToPress}) => { + if (buttonToPress) { + $.find('.showcase-button') + .at(buttonToPress) + .simulate('click'); + } + expect($.find('.rv-xy-plot__series--hexbin').length).toBe(1); + expect($.find('.rv-xy-plot__series--hexbin path').length).toBe(numHexes); + expect($.find('g.hexbin-size-example').length).toBe(1); + expect($.text()).toBe(text); + }); }); }); diff --git a/packages/react-vis/tests/components/highlight-tests.js b/packages/react-vis/tests/components/highlight-tests.js index b15cab1c0..a9f589203 100644 --- a/packages/react-vis/tests/components/highlight-tests.js +++ b/packages/react-vis/tests/components/highlight-tests.js @@ -8,138 +8,140 @@ import BidirectionDragChart from '../../../showcase/misc/2d-dragable-plot'; import {testRenderWithProps, GENERIC_XYPLOT_SERIES_PROPS} from '../test-utils'; -testRenderWithProps(Highlight, GENERIC_XYPLOT_SERIES_PROPS); +describe('Highlight', () => { + testRenderWithProps(Highlight, GENERIC_XYPLOT_SERIES_PROPS); -test('Highlight: DragableExample', () => { - const $ = mount(); - const initialText = - '0.00.51.01.52.02.53.03.54.04.55.05.56.06.57.00246810selectionStart: 0,selectionEnd: 0,'; - expect($.text()).toBe(initialText); + test('DragableExample', () => { + const $ = mount(); + const initialText = + '0.00.51.01.52.02.53.03.54.04.55.05.56.06.57.00246810selectionStart: 0,selectionEnd: 0,'; + expect($.text()).toBe(initialText); - $.find('.rv-mouse-target').simulate('mouseDown', { - nativeEvent: {offsetX: 100, offsetY: 100} - }); - for (let i = 0; i < 100; i++) { - $.find('.rv-mouse-target').simulate('mouseMove', { - nativeEvent: {offsetX: 100 + i, offsetY: 100} - }); - } - expect($.text()).toBe(initialText); - $.find('.rv-mouse-target').simulate('mouseUp', { - nativeEvent: {offsetX: 200, offsetY: 100} - }); - expect($.text()).toBe( - '0.00.51.01.52.02.53.03.54.04.55.05.56.06.57.00246810selectionStart: 0.93,selectionEnd: 2.47,' - ); + $.find('.rv-mouse-target').simulate('mouseDown', { + nativeEvent: {offsetX: 100, offsetY: 100} + }); + for (let i = 0; i < 100; i++) { + $.find('.rv-mouse-target').simulate('mouseMove', { + nativeEvent: {offsetX: 100 + i, offsetY: 100} + }); + } + expect($.text()).toBe(initialText); + $.find('.rv-mouse-target').simulate('mouseUp', { + nativeEvent: {offsetX: 200, offsetY: 100} + }); + expect($.text()).toBe( + '0.00.51.01.52.02.53.03.54.04.55.05.56.06.57.00246810selectionStart: 0.93,selectionEnd: 2.47,' + ); - // click to clear - $.find('.rv-mouse-target').simulate('mouseDown', { - nativeEvent: {offsetX: 0, offsetY: 0} - }); - $.find('.rv-mouse-target').simulate('mouseUp', { - nativeEvent: {offsetX: 0, offsetY: 0} + // click to clear + $.find('.rv-mouse-target').simulate('mouseDown', { + nativeEvent: {offsetX: 0, offsetY: 0} + }); + $.find('.rv-mouse-target').simulate('mouseUp', { + nativeEvent: {offsetX: 0, offsetY: 0} + }); + expect($.text()).toBe(initialText); }); - expect($.text()).toBe(initialText); -}); -test('Highlight: ZoomableChartExample', () => { - const $ = mount(); - const initialText = - '-5051015200102030405060708090Reset ZoomLast Draw AreaN/A'; - expect($.text()).toBe(initialText); + test('ZoomableChartExample', () => { + const $ = mount(); + const initialText = + '-5051015200102030405060708090Reset ZoomLast Draw AreaN/A'; + expect($.text()).toBe(initialText); - // brush in a drag area - $.find('.rv-mouse-target').simulate('mouseDown', { - nativeEvent: {offsetX: 100, offsetY: 100} - }); - for (let i = 0; i < 100; i++) { - $.find('.rv-mouse-target').simulate('mouseMove', { - nativeEvent: {offsetX: 100 + i, offsetY: 100 + i} + // brush in a drag area + $.find('.rv-mouse-target').simulate('mouseDown', { + nativeEvent: {offsetX: 100, offsetY: 100} }); - } - expect($.text()).toBe(initialText); - - $.find('.rv-mouse-target').simulate('mouseUp', { - nativeEvent: {offsetX: 200, offsetY: 200} + for (let i = 0; i < 100; i++) { + $.find('.rv-mouse-target').simulate('mouseMove', { + nativeEvent: {offsetX: 100 + i, offsetY: 100 + i} + }); + } + expect($.text()).toBe(initialText); + + $.find('.rv-mouse-target').simulate('mouseUp', { + nativeEvent: {offsetX: 200, offsetY: 200} + }); + expect($.text()).toBe( + '-5051015200102030405060708090Reset ZoomLast Draw AreaTop: 11.083578425950623Right: 34.98Bottom: -0.5863163548405383Left: 13.2' + ); }); - expect($.text()).toBe( - '-5051015200102030405060708090Reset ZoomLast Draw AreaTop: 11.083578425950623Right: 34.98Bottom: -0.5863163548405383Left: 13.2' - ); -}); -test('Highlight: SelectionPlotExample', () => { - const $ = mount(); + test('SelectionPlotExample', () => { + const $ = mount(); - const initialText = '0.51.01.52.02.5681012There are 0 selected points'; - expect($.find('g.selection-example').length).toBe(1); - expect($.text()).toBe(initialText); + const initialText = '0.51.01.52.02.5681012There are 0 selected points'; + expect($.find('g.selection-example').length).toBe(1); + expect($.text()).toBe(initialText); - $.find('.rv-mouse-target').simulate('mouseDown', { - nativeEvent: {offsetX: 100, offsetY: 100} - }); - for (let i = 0; i < 100; i++) { - $.find('.rv-mouse-target').simulate('mouseMove', { - nativeEvent: {offsetX: 100, offsetY: 100 + i} - }); - } - expect($.text()).toBe('0.51.01.52.02.5681012There are 4 selected points'); - $.find('.rv-mouse-target').simulate('mouseUp', { - nativeEvent: {offsetX: 100, offsetY: 200} - }); - expect($.text()).toBe('0.51.01.52.02.5681012There are 4 selected points'); + $.find('.rv-mouse-target').simulate('mouseDown', { + nativeEvent: {offsetX: 100, offsetY: 100} + }); + for (let i = 0; i < 100; i++) { + $.find('.rv-mouse-target').simulate('mouseMove', { + nativeEvent: {offsetX: 100, offsetY: 100 + i} + }); + } + expect($.text()).toBe('0.51.01.52.02.5681012There are 4 selected points'); + $.find('.rv-mouse-target').simulate('mouseUp', { + nativeEvent: {offsetX: 100, offsetY: 200} + }); + expect($.text()).toBe('0.51.01.52.02.5681012There are 4 selected points'); - // click to clear - $.find('.rv-mouse-target').simulate('mouseDown', { - nativeEvent: {offsetX: 0, offsetY: 0} - }); - $.find('.rv-mouse-target').simulate('mouseUp', { - nativeEvent: {offsetX: 0, offsetY: 0} + // click to clear + $.find('.rv-mouse-target').simulate('mouseDown', { + nativeEvent: {offsetX: 0, offsetY: 0} + }); + $.find('.rv-mouse-target').simulate('mouseUp', { + nativeEvent: {offsetX: 0, offsetY: 0} + }); + expect($.text()).toBe(initialText); }); - expect($.text()).toBe(initialText); -}); -test('Highlight: BidirectionDragChart', () => { - const $ = mount(); + test('BidirectionDragChart', () => { + const $ = mount(); - // brush in a drag area - expect($.text()).toBe('12342468There are 0 selected points'); + // brush in a drag area + expect($.text()).toBe('12342468There are 0 selected points'); - $.find('.rv-mouse-target').simulate('mouseDown', { - nativeEvent: {offsetX: 100, offsetY: 100} - }); - for (let i = 0; i < 100; i++) { - $.find('.rv-mouse-target').simulate('mouseMove', { - nativeEvent: {offsetX: 100 + i, offsetY: 100 + i} + $.find('.rv-mouse-target').simulate('mouseDown', { + nativeEvent: {offsetX: 100, offsetY: 100} }); - } - expect($.text()).toBe('12342468There are 5 selected points'); - - $.find('.rv-mouse-target').simulate('mouseUp', { - nativeEvent: {offsetX: 200, offsetY: 200} - }); - expect($.text()).toBe('12342468There are 5 selected points'); + for (let i = 0; i < 100; i++) { + $.find('.rv-mouse-target').simulate('mouseMove', { + nativeEvent: {offsetX: 100 + i, offsetY: 100 + i} + }); + } + expect($.text()).toBe('12342468There are 5 selected points'); + + $.find('.rv-mouse-target').simulate('mouseUp', { + nativeEvent: {offsetX: 200, offsetY: 200} + }); + expect($.text()).toBe('12342468There are 5 selected points'); - // execute dragging - $.find('.rv-mouse-target').simulate('mouseDown', { - nativeEvent: {offsetX: 150, offsetY: 150} - }); - for (let i = 0; i < 50; i++) { - $.find('.rv-mouse-target').simulate('mouseMove', { - nativeEvent: {offsetX: 150 + i, offsetY: 150 + i} - }); - } - expect($.text()).toBe('12342468There are 6 selected points'); - $.find('.rv-mouse-target').simulate('mouseUp', { - nativeEvent: {offsetX: 200, offsetY: 200} - }); - expect($.text()).toBe('12342468There are 6 selected points'); + // execute dragging + $.find('.rv-mouse-target').simulate('mouseDown', { + nativeEvent: {offsetX: 150, offsetY: 150} + }); + for (let i = 0; i < 50; i++) { + $.find('.rv-mouse-target').simulate('mouseMove', { + nativeEvent: {offsetX: 150 + i, offsetY: 150 + i} + }); + } + expect($.text()).toBe('12342468There are 6 selected points'); + $.find('.rv-mouse-target').simulate('mouseUp', { + nativeEvent: {offsetX: 200, offsetY: 200} + }); + expect($.text()).toBe('12342468There are 6 selected points'); - // click to clear - $.find('.rv-mouse-target').simulate('mouseDown', { - nativeEvent: {offsetX: 75, offsetY: 75} - }); - $.find('.rv-mouse-target').simulate('mouseUp', { - nativeEvent: {offsetX: 75, offsetY: 75} + // click to clear + $.find('.rv-mouse-target').simulate('mouseDown', { + nativeEvent: {offsetX: 75, offsetY: 75} + }); + $.find('.rv-mouse-target').simulate('mouseUp', { + nativeEvent: {offsetX: 75, offsetY: 75} + }); + expect($.text()).toBe('12342468There are 0 selected points'); }); - expect($.text()).toBe('12342468There are 0 selected points'); }); diff --git a/packages/react-vis/tests/components/hints-tests.js b/packages/react-vis/tests/components/hints-tests.js index 5e521bf19..395ab20ef 100644 --- a/packages/react-vis/tests/components/hints-tests.js +++ b/packages/react-vis/tests/components/hints-tests.js @@ -2,16 +2,18 @@ import React from 'react'; import {shallow} from 'enzyme'; import Hint from 'plot/hint'; -test('Hint: Appends user-input class name to the class signatures list', () => { - const wrapper = shallow( - - ); +describe('Hint', () => { + test('Appends user-input class name to the class signatures list', () => { + const wrapper = shallow( + + ); - expect(wrapper.hasClass('test-class-name')).toBe(true); -}); + expect(wrapper.hasClass('test-class-name')).toBe(true); + }); -test('Hint: Assigns only default class names when no custom class specified', () => { - const wrapper = shallow(); + test('Assigns only default class names when no custom class specified', () => { + const wrapper = shallow(); - expect(wrapper.hasClass('undefined')).toBe(false); + expect(wrapper.hasClass('undefined')).toBe(false); + }); }); diff --git a/packages/react-vis/tests/components/interaction-article-tests.js b/packages/react-vis/tests/components/interaction-article-tests.js index 86242a8f1..39a594d0d 100644 --- a/packages/react-vis/tests/components/interaction-article-tests.js +++ b/packages/react-vis/tests/components/interaction-article-tests.js @@ -8,22 +8,24 @@ import { ScatterPlotOnNearestXY } from '../../../showcase/interaction/interaction-examples'; -test('Interaction examples: LinkedCharts', () => { - const $ = mount(); - expect($.find('.rv-xy-plot').length).toBe(3); -}); +describe('Interaction examples', () => { + test('LinkedCharts', () => { + const $ = mount(); + expect($.find('.rv-xy-plot').length).toBe(3); + }); -test('Interaction examples: LineChartMouseOverXY', () => { - const $ = mount(); - expect($.find('.rv-xy-plot').length).toBe(1); -}); + test('LineChartMouseOverXY', () => { + const $ = mount(); + expect($.find('.rv-xy-plot').length).toBe(1); + }); -test('Interaction examples: LineChartMouseOverSeries', () => { - const $ = mount(); - expect($.find('.rv-xy-plot').length).toBe(1); -}); + test('LineChartMouseOverSeries', () => { + const $ = mount(); + expect($.find('.rv-xy-plot').length).toBe(1); + }); -test('Interaction examples: ScatterPlotOnNearestXY', () => { - const $ = mount(); - expect($.find('.rv-xy-plot').length).toBe(1); + test('ScatterPlotOnNearestXY', () => { + const $ = mount(); + expect($.find('.rv-xy-plot').length).toBe(1); + }); }); diff --git a/packages/react-vis/tests/components/label-series-tests.js b/packages/react-vis/tests/components/label-series-tests.js index 740c90c7f..055190965 100644 --- a/packages/react-vis/tests/components/label-series-tests.js +++ b/packages/react-vis/tests/components/label-series-tests.js @@ -7,24 +7,26 @@ import LabeledStackedVerticalBarChart from '../../../showcase/plot/labeled-stack testRenderWithProps(LabelSeries, GENERIC_XYPLOT_SERIES_PROPS); -test('LabelSeries: Showcase Example - LabelSeriesExample', () => { - const $ = mount(); - expect($.text()).toBe( - 'UPDATE-101234505101520WigglytuffPsyduckGeodudeDittoSnorlax' - ); - expect($.find('.rv-xy-plot__series--label text').length).toBe(5); +describe('LabelSeries', () => { + test('Showcase Example - LabelSeriesExample', () => { + const $ = mount(); + expect($.text()).toBe( + 'UPDATE-101234505101520WigglytuffPsyduckGeodudeDittoSnorlax' + ); + expect($.find('.rv-xy-plot__series--label text').length).toBe(5); - $.find('.showcase-button').simulate('click'); - expect($.text()).toBe( - 'UPDATE-101234505101520WigglytuffPsyduckGeoduderedblue' - ); - $.find('.showcase-button').simulate('click'); - expect($.text()).toBe( - 'UPDATE-101234505101520WigglytuffPsyduckGeoduderedblue' - ); -}); + $.find('.showcase-button').simulate('click'); + expect($.text()).toBe( + 'UPDATE-101234505101520WigglytuffPsyduckGeoduderedblue' + ); + $.find('.showcase-button').simulate('click'); + expect($.text()).toBe( + 'UPDATE-101234505101520WigglytuffPsyduckGeoduderedblue' + ); + }); -test('BarSeries: Showcase Example - LabeledStackedVerticalBarChart', () => { - const $ = mount(); - expect($.find('.rv-xy-plot__series--label text').length).toBe(9); + test('Showcase Example - LabeledStackedVerticalBarChart', () => { + const $ = mount(); + expect($.find('.rv-xy-plot__series--label text').length).toBe(9); + }); }); diff --git a/packages/react-vis/tests/components/legends-tests.js b/packages/react-vis/tests/components/legends-tests.js index 09404beb0..bdc2b5190 100644 --- a/packages/react-vis/tests/components/legends-tests.js +++ b/packages/react-vis/tests/components/legends-tests.js @@ -10,133 +10,135 @@ import SearchableDiscreteColorLegendHoverExample from '../../../showcase/legends import HorizontalDiscreteCustomPalette from '../../../showcase/legends/horizontal-discrete-custom-palette'; import ClusteredStackedVerticalBarChart from '../../../showcase/plot/clustered-stacked-bar-chart'; -test('Discrete Legend has no clickable className while onItemClick is not passing', () => { - const withOnClick$ = mount(); - const withoutOnClick$ = mount(); +describe('Legends', () => { + test('Discrete Legend has no clickable className while onItemClick is not passing', () => { + const withOnClick$ = mount(); + const withoutOnClick$ = mount(); - expect( - withOnClick$ - .find('.rv-discrete-color-legend-item.vertical') - .first() - .props().onClick - ).toBe(null); - expect( - withoutOnClick$ - .find('.rv-discrete-color-legend-item.vertical.clickable') - .first() - .props().onClick - ).not.toBe(Function); -}); + expect( + withOnClick$ + .find('.rv-discrete-color-legend-item.vertical') + .first() + .props().onClick + ).toBe(null); + expect( + withoutOnClick$ + .find('.rv-discrete-color-legend-item.vertical.clickable') + .first() + .props().onClick + ).not.toBe(Function); + }); -test('Continuous Size Legend', () => { - const $ = mount(); - expect($.text()).toBe(' 100200'); - expect($.find('.rv-bubble').length).toBe(10); -}); + test('Continuous Size Legend', () => { + const $ = mount(); + expect($.text()).toBe(' 100200'); + expect($.find('.rv-bubble').length).toBe(10); + }); -test('Continuous Color Legend', () => { - const $ = mount(); - expect($.text()).toBe('100200150'); - const expectedStyle = { - background: 'linear-gradient(to right, #EF5D28,#FF9833)' - }; - expect($.find('.rv-gradient').props().style).toEqual(expectedStyle); -}); + test('Continuous Color Legend', () => { + const $ = mount(); + expect($.text()).toBe('100200150'); + const expectedStyle = { + background: 'linear-gradient(to right, #EF5D28,#FF9833)' + }; + expect($.find('.rv-gradient').props().style).toEqual(expectedStyle); + }); -test('Discrete Legends', () => { - const verticalLegend = mount(); - expect(verticalLegend.text()).toBe( - 'OptionsButtonsSelect boxesDate inputsPassword inputsFormsOther' - ); - expect( - verticalLegend.find('.rv-discrete-color-legend-item__color').length - ).toBe(7); + test('Discrete Legends', () => { + const verticalLegend = mount(); + expect(verticalLegend.text()).toBe( + 'OptionsButtonsSelect boxesDate inputsPassword inputsFormsOther' + ); + expect( + verticalLegend.find('.rv-discrete-color-legend-item__color').length + ).toBe(7); - expect( - verticalLegend - .find('.rv-discrete-color-legend-item__color__path') - .first() - .props().style - ).toEqual({stroke: '#12939A'}); + expect( + verticalLegend + .find('.rv-discrete-color-legend-item__color__path') + .first() + .props().style + ).toEqual({stroke: '#12939A'}); - expect( - mount() - .find('.rv-discrete-color-legend-item__color__path') - .first() - .props().style - ).toEqual({stroke: '#6588cd'}); + expect( + mount() + .find('.rv-discrete-color-legend-item__color__path') + .first() + .props().style + ).toEqual({stroke: '#6588cd'}); - const $ = mount(); - expect($.text()).toBe( - 'ApplesBananasBlueberriesCarrotsEggplantsLimesPotatoes' - ); - expect($.find('.rv-discrete-color-legend-item__color').length).toBe(7); - expect( - mount() - .find('.rv-discrete-color-legend-item__color__path') - .first() - .props().style - ).toEqual({strokeDasharray: '6, 2', stroke: '#45aeb1'}); - expect( - mount() - .find('.rv-discrete-color-legend-item__color__path') - .at(4) - .props().style - ).toEqual({strokeWidth: 13, stroke: 'url(#stripes)'}); - $.find('.rv-search-wrapper__form__input').simulate('change', { - target: {value: 'egg'} - }); - expect($.text()).toBe('Eggplants'); - const itemsFound = $.find('.rv-discrete-color-legend-item__color').length; - expect(itemsFound).toBe(1); + const $ = mount(); + expect($.text()).toBe( + 'ApplesBananasBlueberriesCarrotsEggplantsLimesPotatoes' + ); + expect($.find('.rv-discrete-color-legend-item__color').length).toBe(7); + expect( + mount() + .find('.rv-discrete-color-legend-item__color__path') + .first() + .props().style + ).toEqual({strokeDasharray: '6, 2', stroke: '#45aeb1'}); + expect( + mount() + .find('.rv-discrete-color-legend-item__color__path') + .at(4) + .props().style + ).toEqual({strokeWidth: 13, stroke: 'url(#stripes)'}); + $.find('.rv-search-wrapper__form__input').simulate('change', { + target: {value: 'egg'} + }); + expect($.text()).toBe('Eggplants'); + const itemsFound = $.find('.rv-discrete-color-legend-item__color').length; + expect(itemsFound).toBe(1); - expect($.find('.disabled').length).toBe(0); - $.find('.clickable').simulate('click'); - expect($.find('.disabled').length).toBe(1); + expect($.find('.disabled').length).toBe(0); + $.find('.clickable').simulate('click'); + expect($.find('.disabled').length).toBe(1); - expect( - mount() - .find('.rv-discrete-color-legend') - .first() - .props().style - ).toEqual({ - width: undefined, - height: undefined, - position: 'absolute', - left: '50px', - top: '10px' + expect( + mount() + .find('.rv-discrete-color-legend') + .first() + .props().style + ).toEqual({ + width: undefined, + height: undefined, + position: 'absolute', + left: '50px', + top: '10px' + }); }); -}); -test('Discrete Legends Showcase: HorizontalDiscreteCustomPalette', () => { - const $ = mount(); - const colors = $.find('.rv-discrete-color-legend-item__color__path') - .map(colorBrick => { - return colorBrick.props().style.stroke; - }) - .join(' '); + test('Discrete Legends Showcase: HorizontalDiscreteCustomPalette', () => { + const $ = mount(); + const colors = $.find('.rv-discrete-color-legend-item__color__path') + .map(colorBrick => { + return colorBrick.props().style.stroke; + }) + .join(' '); - expect(colors).toBe( - '#6588cd #66b046 #a361c7 #ad953f #c75a87 #55a47b #cb6141' - ); - expect($.text()).toBe( - 'OptionsButtonsSelect boxesDate inputsPassword inputsFormsOther' - ); + expect(colors).toBe( + '#6588cd #66b046 #a361c7 #ad953f #c75a87 #55a47b #cb6141' + ); + expect($.text()).toBe( + 'OptionsButtonsSelect boxesDate inputsPassword inputsFormsOther' + ); - $.find('.rv-discrete-color-legend-item') - .first() - .simulate('mouseEnter'); - expect($.text()).toBe( - 'OptionsSELECTEDButtonsSelect boxesDate inputsPassword inputsFormsOther' - ); -}); + $.find('.rv-discrete-color-legend-item') + .first() + .simulate('mouseEnter'); + expect($.text()).toBe( + 'OptionsSELECTEDButtonsSelect boxesDate inputsPassword inputsFormsOther' + ); + }); -test('Discrete Legends Showcase: SearchableDiscreteLegendHover', () => { - const $ = mount(); - $.find('.rv-discrete-color-legend-item') - .first() - .simulate('mouseEnter'); - expect($.text()).toBe( - 'Apples:SELECTEDBananasBlueberriesCarrotsEggplantsLimesPotatoes' - ); + test('Discrete Legends Showcase: SearchableDiscreteLegendHover', () => { + const $ = mount(); + $.find('.rv-discrete-color-legend-item') + .first() + .simulate('mouseEnter'); + expect($.text()).toBe( + 'Apples:SELECTEDBananasBlueberriesCarrotsEggplantsLimesPotatoes' + ); + }); }); diff --git a/packages/react-vis/tests/components/line-series-canvas-test.js b/packages/react-vis/tests/components/line-series-canvas-test.js index c0fc65053..feef794e3 100644 --- a/packages/react-vis/tests/components/line-series-canvas-test.js +++ b/packages/react-vis/tests/components/line-series-canvas-test.js @@ -3,56 +3,58 @@ import {mount} from 'enzyme'; import XYPlot from 'plot/xy-plot'; import LineSeriesCanvas from 'plot/series/line-series-canvas'; -test('LineSeriesCanvas: should be rendered', () => { - const k = 7; +describe('LineSeriesCanvas', () => { + test('should be rendered', () => { + const k = 7; - const $ = mount( - - {Array(k) - .fill(0) - .map(() => ( + const $ = mount( + + {Array(k) + .fill(0) + .map(() => ( + + ))} + + ); + + expect( + $.find('CanvasWrapper') + .children() + .find('LineSeriesCanvas').length + ).toBe(k); + }); + + test('on onNearestXY should be called and retur ncorrect values', () => { + const k = 7; + expect.assertions(k); + + const $ = mount( + + {[...Array(k).keys()].map(v => ( { + expect({x: v, y: v * v}).toEqual(value); + }} /> ))} - - ); - - expect( - $.find('CanvasWrapper') - .children() - .find('LineSeriesCanvas').length - ).toBe(k); -}); - -test('LineSeriesCanvas: on onNearestXY should be called and retur ncorrect values', () => { - const k = 7; - expect.assertions(k); - - const $ = mount( - - {[...Array(k).keys()].map(v => ( - { - expect({x: v, y: v * v}).toEqual(value); - }} - /> - ))} - - ); + + ); - $.find('.rv-xy-plot__inner').simulate('mousemove', { - nativeEvent: {clientX: 150, clientY: 150} + $.find('.rv-xy-plot__inner').simulate('mousemove', { + nativeEvent: {clientX: 150, clientY: 150} + }); }); }); diff --git a/packages/react-vis/tests/components/line-series-tests.js b/packages/react-vis/tests/components/line-series-tests.js index face11968..f4261dafe 100644 --- a/packages/react-vis/tests/components/line-series-tests.js +++ b/packages/react-vis/tests/components/line-series-tests.js @@ -45,183 +45,187 @@ const LINE_WITH_MANY_COLORS_COLORS = [ 'rgb(255, 65, 0)' ]; -test('LineSeries: basic rendering', () => { - const $ = mount( - - - - ); - expect($.find('.rv-xy-plot__series').length).toBe(1); - expect($.find('path.rv-xy-plot__series').length).toBe(1); - expect($.find('path.line-chart-example').length).toBe(1); - - $.setProps({children: }); - expect($.find('.rv-xy-plot__series').length).toBe(0); - expect($.find('.rv-xy-plot__series path').length).toBe(0); - expect($.find('.line-chart-example').length).toBe(0); -}); - -test('LineSeries: Showcase Example - LineChart', () => { - const $ = mount(); - expect($.find('g.alt-x-label').length).toBe(1); - - expect($.find('g.alt-y-label').length).toBe(1); - expect($.text()).toBe( - 'TOGGLE TO CANVAS1.01.52.02.53.03.54.02468101214X AxisY Axis' - ); - expect($.find('.rv-xy-plot__series--line').length).toBe(3); - - ['first-series', 'third-series', 'fourth-series'].forEach(customClassName => { - expect($.find(`.rv-xy-plot__series--line.${customClassName}`).length).toBe( - 1 +describe('LineSeries', () => { + test('basic rendering', () => { + const $ = mount( + + + ); + expect($.find('.rv-xy-plot__series').length).toBe(1); + expect($.find('path.rv-xy-plot__series').length).toBe(1); + expect($.find('path.line-chart-example').length).toBe(1); + + $.setProps({children: }); + expect($.find('.rv-xy-plot__series').length).toBe(0); + expect($.find('.rv-xy-plot__series path').length).toBe(0); + expect($.find('.line-chart-example').length).toBe(0); }); - expect($.find('path.second-series').length).toBe(0); + test('Showcase Example - LineChart', () => { + const $ = mount(); + expect($.find('g.alt-x-label').length).toBe(1); - $.find('button').simulate('click'); - expect($.find('.rv-xy-plot__series--line').length).toBe(0); - - $.find('button').simulate('click'); - expect($.find('.rv-xy-plot__series--line').length).toBe(3); -}); + expect($.find('g.alt-y-label').length).toBe(1); + expect($.text()).toBe( + 'TOGGLE TO CANVAS1.01.52.02.53.03.54.02468101214X AxisY Axis' + ); + expect($.find('.rv-xy-plot__series--line').length).toBe(3); + + ['first-series', 'third-series', 'fourth-series'].forEach( + customClassName => { + expect( + $.find(`.rv-xy-plot__series--line.${customClassName}`).length + ).toBe(1); + } + ); -test('LineSeries: Showcase Example - LineMarkSeries', () => { - const $ = mount(); - expect($.text()).toBe('1.01.52.02.53.0510152025'); - expect($.find('.rv-xy-plot__series--linemark').length).toBe(2); - expect($.find('.rv-xy-plot__series circle').length).toBe(6); + expect($.find('path.second-series').length).toBe(0); - ['linemark-series-example', 'linemark-series-example-2'].forEach( - customClassName => { - expect($.find(`MarkSeries.${customClassName}`).length).toBe(1); + $.find('button').simulate('click'); + expect($.find('.rv-xy-plot__series--line').length).toBe(0); - expect($.find(`LineSeries.${customClassName}`).length).toBe(1); - } - ); -}); + $.find('button').simulate('click'); + expect($.find('.rv-xy-plot__series--line').length).toBe(3); + }); -test('LineSeries: Showcase Example - LineChartManyColors', () => { - const $ = mount(); - const lines = $.find('.rv-xy-plot__series'); - expect(lines.length).toBe(20); - lines.forEach((node, i) => - expect(node.props().style.stroke).toBe(LINE_WITH_MANY_COLORS_COLORS[i]) - ); -}); + test('Showcase Example - LineMarkSeries', () => { + const $ = mount(); + expect($.text()).toBe('1.01.52.02.53.0510152025'); + expect($.find('.rv-xy-plot__series--linemark').length).toBe(2); + expect($.find('.rv-xy-plot__series circle').length).toBe(6); -test('LineSeries: Showcase Example - TimeChart', () => { - const $ = mount(); - expect($.find('.rv-xy-plot__series--line').length).toBe(2); - expect($.text()).toBe( - 'Sep 1012 PMMon 1112 PMTue 1212 PMWed 13X Axis2468101214Y Axis' - ); -}); + ['linemark-series-example', 'linemark-series-example-2'].forEach( + customClassName => { + expect($.find(`MarkSeries.${customClassName}`).length).toBe(1); -test('LineSeries: Showcase Example - SyncedCharts', () => { - const $ = mount(); - const tests = () => { - expect($.find('.rv-xy-plot').length).toBe(2); - expect($.find('.rv-xy-plot__series--line').length).toBe(4); - expect($.text()).toBe('1.01.52.02.53.024681012141.01.52.02.53.0246810'); - }; - tests(); - $.find('.rv-xy-plot__series--line') - .at(0) - .simulate('mouseEnter'); - tests(); - $.find('.rv-xy-plot') - .at(0) - .simulate('mouseLeave'); -}); + expect($.find(`LineSeries.${customClassName}`).length).toBe(1); + } + ); + }); -test('LineSeries: Line Styling', () => { - const $ = mount( - - - - ); - - const lineStyle = $.find('path.rv-xy-plot__series').prop('style'); - - expect(lineStyle.opacity).toBe(0.5); - expect(lineStyle.strokeWidth).toBe('3px'); - expect(lineStyle.stroke).toBe('rgb(255, 255, 255)'); - expect(lineStyle.strokeDasharray).toBe('3, 1'); -}); + test('Showcase Example - LineChartManyColors', () => { + const $ = mount(); + const lines = $.find('.rv-xy-plot__series'); + expect(lines.length).toBe(20); + lines.forEach((node, i) => + expect(node.props().style.stroke).toBe(LINE_WITH_MANY_COLORS_COLORS[i]) + ); + }); -test('getNull prop: Showcase Example - Null Data Example', () => { - const $ = mount(); - expect($.find('path.rv-xy-plot__series').length).toBe(2); - expect($.find('.rv-xy-plot__series--mark circle').length).toBe(3); + test('Showcase Example - TimeChart', () => { + const $ = mount(); + expect($.find('.rv-xy-plot__series--line').length).toBe(2); + expect($.text()).toBe( + 'Sep 1012 PMMon 1112 PMTue 1212 PMWed 13X Axis2468101214Y Axis' + ); + }); - simulateMouseMove(35); - expect($.find('.rv-crosshair__title').text()).toBe('x: 1'); - expect( - $.find('.rv-crosshair__item') - .at(0) - .text() - ).toBe('0: 10'); - expect( - $.find('.rv-crosshair__item') - .at(1) - .text() - ).toBe('1: 30'); - - $.find('.rv-xy-plot__inner').simulate('mouseleave'); - expect($.find('.rv-crosshair').exists()).toBe(false); - - simulateMouseMove(100); - expect($.find('.rv-crosshair__title').text()).toBe('x: 2'); - expect( - $.find('.rv-crosshair__item') + test('Showcase Example - SyncedCharts', () => { + const $ = mount(); + const tests = () => { + expect($.find('.rv-xy-plot').length).toBe(2); + expect($.find('.rv-xy-plot__series--line').length).toBe(4); + expect($.text()).toBe('1.01.52.02.53.024681012141.01.52.02.53.0246810'); + }; + tests(); + $.find('.rv-xy-plot__series--line') .at(0) - .text() - ).toBe('0: 10'); - expect( - $.find('.rv-crosshair__item') - .at(1) - .text() - ).toBe('1: 0'); - - simulateMouseMove(165); - expect($.find('.rv-crosshair__title').text()).toBe('x: 3'); - expect( - $.find('.rv-crosshair__item') + .simulate('mouseEnter'); + tests(); + $.find('.rv-xy-plot') .at(0) - .text() - ).toBe('0: 13'); - expect( - $.find('.rv-crosshair__item') - .at(1) - .exists() - ).toBe(false); - - simulateMouseMove(230); - expect($.find('.rv-crosshair__title').text()).toBe('x: 4'); - expect( - $.find('.rv-crosshair__item') - .at(0) - .text() - ).toBe('0: 7'); - expect( - $.find('.rv-crosshair__item') - .at(1) - .text() - ).toBe('1: 15'); - - simulateMouseMove(295); - expect($.find('.rv-crosshair').exists()).toBe(false); - - function simulateMouseMove(x) { - $.find('.rv-xy-plot__inner').simulate('mousemove', { - nativeEvent: {clientX: x, clientY: 150} - }); - } + .simulate('mouseLeave'); + }); + + test('Line Styling', () => { + const $ = mount( + + + + ); + + const lineStyle = $.find('path.rv-xy-plot__series').prop('style'); + + expect(lineStyle.opacity).toBe(0.5); + expect(lineStyle.strokeWidth).toBe('3px'); + expect(lineStyle.stroke).toBe('rgb(255, 255, 255)'); + expect(lineStyle.strokeDasharray).toBe('3, 1'); + }); + + test('getNull prop: Showcase Example - Null Data Example', () => { + const $ = mount(); + expect($.find('path.rv-xy-plot__series').length).toBe(2); + expect($.find('.rv-xy-plot__series--mark circle').length).toBe(3); + + simulateMouseMove(35); + expect($.find('.rv-crosshair__title').text()).toBe('x: 1'); + expect( + $.find('.rv-crosshair__item') + .at(0) + .text() + ).toBe('0: 10'); + expect( + $.find('.rv-crosshair__item') + .at(1) + .text() + ).toBe('1: 30'); + + $.find('.rv-xy-plot__inner').simulate('mouseleave'); + expect($.find('.rv-crosshair').exists()).toBe(false); + + simulateMouseMove(100); + expect($.find('.rv-crosshair__title').text()).toBe('x: 2'); + expect( + $.find('.rv-crosshair__item') + .at(0) + .text() + ).toBe('0: 10'); + expect( + $.find('.rv-crosshair__item') + .at(1) + .text() + ).toBe('1: 0'); + + simulateMouseMove(165); + expect($.find('.rv-crosshair__title').text()).toBe('x: 3'); + expect( + $.find('.rv-crosshair__item') + .at(0) + .text() + ).toBe('0: 13'); + expect( + $.find('.rv-crosshair__item') + .at(1) + .exists() + ).toBe(false); + + simulateMouseMove(230); + expect($.find('.rv-crosshair__title').text()).toBe('x: 4'); + expect( + $.find('.rv-crosshair__item') + .at(0) + .text() + ).toBe('0: 7'); + expect( + $.find('.rv-crosshair__item') + .at(1) + .text() + ).toBe('1: 15'); + + simulateMouseMove(295); + expect($.find('.rv-crosshair').exists()).toBe(false); + + function simulateMouseMove(x) { + $.find('.rv-xy-plot__inner').simulate('mousemove', { + nativeEvent: {clientX: x, clientY: 150} + }); + } + }); }); diff --git a/packages/react-vis/tests/components/make-vis-flexible-tests.js b/packages/react-vis/tests/components/make-vis-flexible-tests.js index d2e8743c0..6e9a79f35 100644 --- a/packages/react-vis/tests/components/make-vis-flexible-tests.js +++ b/packages/react-vis/tests/components/make-vis-flexible-tests.js @@ -1,16 +1,18 @@ import {makeWidthFlexible} from 'make-vis-flexible'; -test('makeWidthFlexible: displayName given', () => { - function ChildComponent() {} - ChildComponent.displayName = 'ChildComponentWithDisplayName'; - const FlexibleComponent = makeWidthFlexible(ChildComponent); - expect(FlexibleComponent.displayName).toBe( - 'FlexibleChildComponentWithDisplayName' - ); -}); +describe('makeWidthFlexible', () => { + test('displayName given', () => { + function ChildComponent() {} + ChildComponent.displayName = 'ChildComponentWithDisplayName'; + const FlexibleComponent = makeWidthFlexible(ChildComponent); + expect(FlexibleComponent.displayName).toBe( + 'FlexibleChildComponentWithDisplayName' + ); + }); -test('makeWidthFlexible: displayName not given', () => { - function ChildComponent() {} - const FlexibleComponent = makeWidthFlexible(ChildComponent); - expect(FlexibleComponent.displayName).toBe('FlexibleChildComponent'); + test('displayName not given', () => { + function ChildComponent() {} + const FlexibleComponent = makeWidthFlexible(ChildComponent); + expect(FlexibleComponent.displayName).toBe('FlexibleChildComponent'); + }); }); diff --git a/packages/react-vis/tests/components/mark-series-tests.js b/packages/react-vis/tests/components/mark-series-tests.js index af278619d..60cd6e8aa 100644 --- a/packages/react-vis/tests/components/mark-series-tests.js +++ b/packages/react-vis/tests/components/mark-series-tests.js @@ -5,56 +5,55 @@ import {testRenderWithProps, GENERIC_XYPLOT_SERIES_PROPS} from '../test-utils'; import Scatterplot from '../../../showcase/plot/scatterplot'; import DynamicCrosshairScatterplot from '../../../showcase/axes/dynamic-crosshair-scatterplot'; -testRenderWithProps(MarkSeries, GENERIC_XYPLOT_SERIES_PROPS); - -test('MarkSeries: Showcase Example - Scatterplot', () => { - const $ = mount(); - expect($.text()).toBe('1.01.52.02.53.068101214'); - expect($.find('.rv-xy-plot__series--mark circle').length).toBe(5); - expect($.find('g.mark-series-example').length).toBe(1); -}); - -test('MarkSeries: Showcase Example - Dynamic Crosshair Scatterplot', () => { - const $ = mount(); - // NOTE: Point 0 (P0) and Point 1 (P1) are vertically aligned - const yDistanceBetweenP0andP1 = 2.5; - const chatTopPadding = 10; - - const highlightedCircles1 = $.find('.rv-xy-plot__series--mark circle').reduce( - highlightedCircle, - [] - ); - expect(highlightedCircles1.length).toBe(0); - - updateCursor(0, yDistanceBetweenP0andP1 / 2 - 0.01); - const highlightedCircles2 = $.find('.rv-xy-plot__series--mark circle').reduce( - highlightedCircle, - [] - ); - expect(highlightedCircles2.length).toBe(1); - expect(highlightedCircles2[0]).toEqual({cx: 0, cy: 0}); - - updateCursor(0, yDistanceBetweenP0andP1 / 2); - const highlightedCircles3 = $.find('.rv-xy-plot__series--mark circle').reduce( - highlightedCircle, - [] - ); - expect(highlightedCircles3.length).toBe(1); - - expect(Math.abs(highlightedCircles3[0].cx - 0) < 0.005).toBeTruthy(); - expect(Math.abs(highlightedCircles3[0].cy - 2.5) < 0.005).toBeTruthy(); - - function updateCursor(x, y) { - $.find('.rv-xy-plot__series--mark').simulate('mousemove', { - nativeEvent: {clientX: x, clientY: y + chatTopPadding} - }); - } - - function highlightedCircle(_highlightedCircle, circle) { - const isHighlighted = circle.prop('style').fill === '#FF9833'; - const circlePosition = {cx: circle.prop('cx'), cy: circle.prop('cy')}; - return isHighlighted - ? [..._highlightedCircle, circlePosition] - : _highlightedCircle; - } +describe('MarkSeries', () => { + testRenderWithProps(MarkSeries, GENERIC_XYPLOT_SERIES_PROPS); + + test('MShowcase Example - Scatterplot', () => { + const $ = mount(); + expect($.text()).toBe('1.01.52.02.53.068101214'); + expect($.find('.rv-xy-plot__series--mark circle').length).toBe(5); + expect($.find('g.mark-series-example').length).toBe(1); + }); + + test('MShowcase Example - Dynamic Crosshair Scatterplot', () => { + const $ = mount(); + // NOTE: Point 0 (P0) and Point 1 (P1) are vertically aligned + const yDistanceBetweenP0andP1 = 2.5; + const chatTopPadding = 10; + + const highlightedCircles1 = $.find( + '.rv-xy-plot__series--mark circle' + ).reduce(highlightedCircle, []); + expect(highlightedCircles1.length).toBe(0); + + updateCursor(0, yDistanceBetweenP0andP1 / 2 - 0.01); + const highlightedCircles2 = $.find( + '.rv-xy-plot__series--mark circle' + ).reduce(highlightedCircle, []); + expect(highlightedCircles2.length).toBe(1); + expect(highlightedCircles2[0]).toEqual({cx: 0, cy: 0}); + + updateCursor(0, yDistanceBetweenP0andP1 / 2); + const highlightedCircles3 = $.find( + '.rv-xy-plot__series--mark circle' + ).reduce(highlightedCircle, []); + expect(highlightedCircles3.length).toBe(1); + + expect(Math.abs(highlightedCircles3[0].cx - 0) < 0.005).toBeTruthy(); + expect(Math.abs(highlightedCircles3[0].cy - 2.5) < 0.005).toBeTruthy(); + + function updateCursor(x, y) { + $.find('.rv-xy-plot__series--mark').simulate('mousemove', { + nativeEvent: {clientX: x, clientY: y + chatTopPadding} + }); + } + + function highlightedCircle(_highlightedCircle, circle) { + const isHighlighted = circle.prop('style').fill === '#FF9833'; + const circlePosition = {cx: circle.prop('cx'), cy: circle.prop('cy')}; + return isHighlighted + ? [..._highlightedCircle, circlePosition] + : _highlightedCircle; + } + }); }); diff --git a/packages/react-vis/tests/components/parallel-coordinates-tests.js b/packages/react-vis/tests/components/parallel-coordinates-tests.js index 1007df001..27b2e23e5 100644 --- a/packages/react-vis/tests/components/parallel-coordinates-tests.js +++ b/packages/react-vis/tests/components/parallel-coordinates-tests.js @@ -27,80 +27,83 @@ const PARALLEL_COODINATES_PROPS = { height: 300, width: 400 }; -// make sure that the components render at all -testRenderWithProps(ParallelCoordinates, PARALLEL_COODINATES_PROPS); -test('Parallel Coordinates: Basic Parallel Coordinates', () => { - const $ = mount(); - expect($.find('div.rv-parallel-coordinates-chart').length).toBe(1); - expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(6); - expect($.find('LineSeries.rv-parallel-coordinates-chart-line').length).toBe( - 3 - ); - expect($.find('MarkSeries.rv-parallel-coordinates-chart-line').length).toBe( - 3 - ); +describe('Parallel Coordinates', () => { + // make sure that the components render at all + testRenderWithProps(ParallelCoordinates, PARALLEL_COODINATES_PROPS); - expect($.find('circle').length).toBe(18); - expect($.find('div.rv-parallel-coordinates-chart').text()).toBe( - '0.002.004.006.008.0010.0$2.0$4.8$7.6$10$13$165.006.007.008.009.0010.00.002.004.006.008.0010.00.001.402.804.205.607.0010.08.406.805.203.602.00mileagepricesafetyperformanceinteriorwarranty' - ); -}); + test('Basic Parallel Coordinates', () => { + const $ = mount(); + expect($.find('div.rv-parallel-coordinates-chart').length).toBe(1); + expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(6); + expect($.find('LineSeries.rv-parallel-coordinates-chart-line').length).toBe( + 3 + ); + expect($.find('MarkSeries.rv-parallel-coordinates-chart-line').length).toBe( + 3 + ); -test('Parallel Coordinates: Animated Parallel Coordinates ', () => { - const $ = mount(); - expect($.find('div.rv-parallel-coordinates-chart').length).toBe(1); - expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(5); - expect($.find('path.rv-parallel-coordinates-chart-line').length).toBe(1); - // This relies on floating point - // t.equal( - // $.find('div.rv-parallel-coordinates-chart').text(), - // '020406080100niceexplosionswowdogsickMoves', - // 'should find the right text content' - // ); + expect($.find('circle').length).toBe(18); + expect($.find('div.rv-parallel-coordinates-chart').text()).toBe( + '0.002.004.006.008.0010.0$2.0$4.8$7.6$10$13$165.006.007.008.009.0010.00.002.004.006.008.0010.00.001.402.804.205.607.0010.08.406.805.203.602.00mileagepricesafetyperformanceinteriorwarranty' + ); + }); - $.find('.showcase-button').simulate('click'); - expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(5); - expect($.find('path.rv-parallel-coordinates-chart-line').length).toBe(1); -}); + test('Animated Parallel Coordinates ', () => { + const $ = mount(); + expect($.find('div.rv-parallel-coordinates-chart').length).toBe(1); + expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(5); + expect($.find('path.rv-parallel-coordinates-chart-line').length).toBe(1); + // This relies on floating point + // t.equal( + // $.find('div.rv-parallel-coordinates-chart').text(), + // '020406080100niceexplosionswowdogsickMoves', + // 'should find the right text content' + // ); + + $.find('.showcase-button').simulate('click'); + expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(5); + expect($.find('path.rv-parallel-coordinates-chart-line').length).toBe(1); + }); -test('Parallel Coordinates: Brushed Parallel Coordinates', () => { - const $ = mount(); - expect($.find('path.rv-parallel-coordinates-chart-line').length).toBe(150); - expect($.find('div.rv-parallel-coordinates-chart').text()).toBe( - '4.35.05.76.57.27.92.02.53.03.43.94.41.02.23.44.55.76.90.100.581.11.52.02.5sepal lengthsepal widthpetal lengthpetal width' - ); + test('Brushed Parallel Coordinates', () => { + const $ = mount(); + expect($.find('path.rv-parallel-coordinates-chart-line').length).toBe(150); + expect($.find('div.rv-parallel-coordinates-chart').text()).toBe( + '4.35.05.76.57.27.92.02.53.03.43.94.41.02.23.44.55.76.90.100.581.11.52.02.5sepal lengthsepal widthpetal lengthpetal width' + ); - // brush - $.find('.rv-mouse-target') - .at(0) - .simulate('mouseDown', {nativeEvent: {offsetX: 50, offsetY: 100}}); - for (let i = 0; i < 100; i++) { + // brush $.find('.rv-mouse-target') .at(0) - .simulate('mouseMove', {nativeEvent: {offsetX: 50, offsetY: 100 + i}}); - } - expect($.find('.rv-parallel-coordinates-chart-line-unselected').length).toBe( - 0 - ); + .simulate('mouseDown', {nativeEvent: {offsetX: 50, offsetY: 100}}); + for (let i = 0; i < 100; i++) { + $.find('.rv-mouse-target') + .at(0) + .simulate('mouseMove', {nativeEvent: {offsetX: 50, offsetY: 100 + i}}); + } + expect( + $.find('.rv-parallel-coordinates-chart-line-unselected').length + ).toBe(0); - $.find('.rv-mouse-target') - .at(0) - .simulate('mouseUp', {nativeEvent: {offsetX: 50, offsetY: 200}}); + $.find('.rv-mouse-target') + .at(0) + .simulate('mouseUp', {nativeEvent: {offsetX: 50, offsetY: 200}}); - expect( - $.find('path.rv-parallel-coordinates-chart-line-unselected').length - ).toBe(102); + expect( + $.find('path.rv-parallel-coordinates-chart-line-unselected').length + ).toBe(102); - // click to clear - $.find('.rv-mouse-target') - .at(0) - .simulate('mouseDown', {nativeEvent: {offsetX: 50, offsetY: 95}}); - $.find('.rv-mouse-target') - .at(0) - .simulate('mouseUp', {nativeEvent: {offsetX: 50, offsetY: 95}}); + // click to clear + $.find('.rv-mouse-target') + .at(0) + .simulate('mouseDown', {nativeEvent: {offsetX: 50, offsetY: 95}}); + $.find('.rv-mouse-target') + .at(0) + .simulate('mouseUp', {nativeEvent: {offsetX: 50, offsetY: 95}}); - expect($.find('.rv-parallel-coordinates-chart-line-unselected').length).toBe( - 0 - ); + expect( + $.find('.rv-parallel-coordinates-chart-line-unselected').length + ).toBe(0); + }); }); diff --git a/packages/react-vis/tests/components/polygon-series-tests.js b/packages/react-vis/tests/components/polygon-series-tests.js index 352f091a8..c751b9352 100644 --- a/packages/react-vis/tests/components/polygon-series-tests.js +++ b/packages/react-vis/tests/components/polygon-series-tests.js @@ -4,10 +4,12 @@ import PolygonSeries from 'plot/series/mark-series'; import {testRenderWithProps, GENERIC_XYPLOT_SERIES_PROPS} from '../test-utils'; import TriangleExample from '../../../showcase/misc/triangle-example'; -testRenderWithProps(PolygonSeries, GENERIC_XYPLOT_SERIES_PROPS); +describe('PolygonSeries', () => { + testRenderWithProps(PolygonSeries, GENERIC_XYPLOT_SERIES_PROPS); -test('PolygonSeries: Showcase Example - Triangle Example', () => { - const $ = mount(); - expect($.text()).toBe('024681012024681012'); - expect($.find('.rv-xy-plot__series--polygon').length).toBe(121); + test('Showcase Example - Triangle Example', () => { + const $ = mount(); + expect($.text()).toBe('024681012024681012'); + expect($.find('.rv-xy-plot__series--polygon').length).toBe(121); + }); }); diff --git a/packages/react-vis/tests/components/radar-chart-tests.js b/packages/react-vis/tests/components/radar-chart-tests.js index be15b86f6..63acb0fdc 100644 --- a/packages/react-vis/tests/components/radar-chart-tests.js +++ b/packages/react-vis/tests/components/radar-chart-tests.js @@ -29,90 +29,95 @@ const RADAR_PROPS = { height: 300, width: 400 }; -// make sure that the components render at all -testRenderWithProps(RadialChart, RADAR_PROPS); -test('Radar: Showcase Example - Basic Radar Chart', () => { - const $ = mount(); - expect($.find('div.rv-radar-chart').length).toBe(1); - expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(6); - expect($.find('path.rv-radar-chart-polygon').length).toBe(3); - expect($.find('div.rv-radar-chart').text()).toBe( - '2.004.006.008.0010.0$4.8$7.6$10$13$166.007.008.009.0010.02.004.006.008.0010.01.402.804.205.607.008.406.805.203.602.00mileagepricesafetyperformanceinteriorwarranty' - ); - expect($.find('.rv-xy-plot__series--custom-svg').length).toBe(0); -}); +describe('Radar', () => { + // make sure that the components render at all + testRenderWithProps(RadialChart, RADAR_PROPS); -test('Radar: Showcase Example - Animated Radial ', () => { - const $ = mount(); - expect($.find('div.rv-radar-chart').length).toBe(1); - expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(5); - expect($.find('path.rv-radar-chart-polygon').length).toBe(1); - // Floating point - // t.equal( - // $.find('div.rv-radar-chart').text(), - // '20406080100niceexplosionswowdogsickMoves', - // 'should find the right text content' - // ); - expect($.find('.rv-xy-plot__circular-grid-lines__line').length).toBe(10); + test('Radar: Showcase Example - Basic Radar Chart', () => { + const $ = mount(); + expect($.find('div.rv-radar-chart').length).toBe(1); + expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(6); + expect($.find('path.rv-radar-chart-polygon').length).toBe(3); + expect($.find('div.rv-radar-chart').text()).toBe( + '2.004.006.008.0010.0$4.8$7.6$10$13$166.007.008.009.0010.02.004.006.008.0010.01.402.804.205.607.008.406.805.203.602.00mileagepricesafetyperformanceinteriorwarranty' + ); + expect($.find('.rv-xy-plot__series--custom-svg').length).toBe(0); + }); - $.find('.showcase-button').simulate('click'); - expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(5); + test('Radar: Showcase Example - Animated Radial ', () => { + const $ = mount(); + expect($.find('div.rv-radar-chart').length).toBe(1); + expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(5); + expect($.find('path.rv-radar-chart-polygon').length).toBe(1); + // Floating point + // t.equal( + // $.find('div.rv-radar-chart').text(), + // '20406080100niceexplosionswowdogsickMoves', + // 'should find the right text content' + // ); + expect($.find('.rv-xy-plot__circular-grid-lines__line').length).toBe(10); - expect($.find('path.rv-radar-chart-polygon').length).toBe(1); - // Floating Point - // t.equal( - // $.find('div.rv-radar-chart').text(), - // '20406080100niceexplosionswowdogsickMoves', - // 'should find the right text content' - // ); - expect($.find('.rv-xy-plot__series--custom-svg').length).toBe(0); -}); + $.find('.showcase-button').simulate('click'); + expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(5); -test('Radar: Showcase Example - Four Quadrant Radar Chart', () => { - const $ = mount(); - expect($.find('div.rv-radar-chart').length).toBe(1); - expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(4); - expect($.find('.rv-xy-manipulable-axis__ticks').children().length).toBe(24); - expect($.find('path.rv-radar-chart-polygon').length).toBe(1); - expect($.find('div.rv-radar-chart').text()).toBe( - '20406080100204060801002040608010020406080100CVisualBasicsExcelAccess' - ); - expect($.find('.rv-xy-plot__series--custom-svg').length).toBe(0); -}); + expect($.find('path.rv-radar-chart-polygon').length).toBe(1); + // Floating Point + // t.equal( + // $.find('div.rv-radar-chart').text(), + // '20406080100niceexplosionswowdogsickMoves', + // 'should find the right text content' + // ); + expect($.find('.rv-xy-plot__series--custom-svg').length).toBe(0); + }); -test('Radar: Showcase Example - Radar Chart with Tooltips', () => { - const $ = mount(); - const chartText = 'mileagepricesafetyperformanceinteriorwarranty1234'; - expect($.find('div.rv-radar-chart').length).toBe(1); - expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(6); - expect($.find('path.rv-radar-chart-polygon').length).toBe(7); - expect($.find('g.rv-radar-chart-polygonPoint').length).toBe(7); - expect($.find('div.rv-radar-chart').text()).toBe(chartText); + test('Radar: Showcase Example - Four Quadrant Radar Chart', () => { + const $ = mount(); + expect($.find('div.rv-radar-chart').length).toBe(1); + expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(4); + expect($.find('.rv-xy-manipulable-axis__ticks').children().length).toBe(24); + expect($.find('path.rv-radar-chart-polygon').length).toBe(1); + expect($.find('div.rv-radar-chart').text()).toBe( + '20406080100204060801002040608010020406080100CVisualBasicsExcelAccess' + ); + expect($.find('.rv-xy-plot__series--custom-svg').length).toBe(0); + }); - // Tooltips - const tooltipText = 'mileage: 3'; - $.find('g.rv-radar-chart-polygonPoint') - .at(6) - .children() - .at(0) - .simulate('mouseOver'); - expect($.text()).toBe(`${chartText}${tooltipText}`); -}); + test('Radar: Showcase Example - Radar Chart with Tooltips', () => { + const $ = mount(); + const chartText = 'mileagepricesafetyperformanceinteriorwarranty1234'; + expect($.find('div.rv-radar-chart').length).toBe(1); + expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(6); + expect($.find('path.rv-radar-chart-polygon').length).toBe(7); + expect($.find('g.rv-radar-chart-polygonPoint').length).toBe(7); + expect($.find('div.rv-radar-chart').text()).toBe(chartText); + + // Tooltips + const tooltipText = 'mileage: 3'; + $.find('g.rv-radar-chart-polygonPoint') + .at(6) + .children() + .at(0) + .simulate('mouseOver'); + expect($.text()).toBe(`${chartText}${tooltipText}`); + }); -test('Radar: Showcase Example - series tooltips', () => { - const $ = mount(); - const chartText = - '2.004.006.008.0010.0$4.8$7.6$10$13$166.007.008.009.0010.02.004.006.008.0010.01.402.804.205.607.008.406.805.203.602.00mileagepricesafetyperformanceinteriorwarranty'; - const hoverText = 'Mercedes'; + test('Radar: Showcase Example - series tooltips', () => { + const $ = mount(); + const chartText = + '2.004.006.008.0010.0$4.8$7.6$10$13$166.007.008.009.0010.02.004.006.008.0010.01.402.804.205.607.008.406.805.203.602.00mileagepricesafetyperformanceinteriorwarranty'; + const hoverText = 'Mercedes'; - expect($.find('div.rv-radar-chart').length).toBe(1); - expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(6); - expect($.find('path.rv-radar-chart-polygon').length).toBe(3); - expect($.find('div.rv-radar-chart').text()).toBe(chartText); - expect($.find('.rv-xy-plot__series--custom-svg').length).toBe(0); - $.find('.rv-radar-chart-polygon') - .at(0) - .simulate('mouseOver'); - expect($.find('div.rv-radar-chart').text()).toBe(`${chartText}${hoverText}`); + expect($.find('div.rv-radar-chart').length).toBe(1); + expect($.find('.rv-xy-manipulable-axis__ticks').length).toBe(6); + expect($.find('path.rv-radar-chart-polygon').length).toBe(3); + expect($.find('div.rv-radar-chart').text()).toBe(chartText); + expect($.find('.rv-xy-plot__series--custom-svg').length).toBe(0); + $.find('.rv-radar-chart-polygon') + .at(0) + .simulate('mouseOver'); + expect($.find('div.rv-radar-chart').text()).toBe( + `${chartText}${hoverText}` + ); + }); }); diff --git a/packages/react-vis/tests/components/radial-tests.js b/packages/react-vis/tests/components/radial-tests.js index cff195bae..a9caafc17 100644 --- a/packages/react-vis/tests/components/radial-tests.js +++ b/packages/react-vis/tests/components/radial-tests.js @@ -21,72 +21,77 @@ const RADIAL_PROPS = { width: 400, padAngle: 0.3 }; -// make sure that the components render at all -testRenderWithProps(RadialChart, RADIAL_PROPS); -test('RadialChart: Basic rendering', () => { - const $ = mount(); - const pieSlices = $.find('.rv-radial-chart__series--pie__slice').length; - expect(pieSlices).toBe(RADIAL_PROPS.data.length); - expect( - $.find('.rv-radial-chart__series--pie__slice') - .at(0) - .prop('className') - ).toBe( - 'rv-xy-plot__series rv-xy-plot__series--arc-path rv-radial-chart__series--pie__slice custom-class' - ); +describe('RadialChart', () => { + // make sure that the components render at all + testRenderWithProps(RadialChart, RADIAL_PROPS); - const labels = $.find('.rv-xy-plot__series--label-text').length; - expect(labels).toBe(RADIAL_PROPS.data.length); - expect($.text()).toBe('yellow againmagentacyanyellowgreen'); + test('Basic rendering', () => { + const $ = mount(); + const pieSlices = $.find('.rv-radial-chart__series--pie__slice').length; + expect(pieSlices).toBe(RADIAL_PROPS.data.length); + expect( + $.find('.rv-radial-chart__series--pie__slice') + .at(0) + .prop('className') + ).toBe( + 'rv-xy-plot__series rv-xy-plot__series--arc-path rv-radial-chart__series--pie__slice custom-class' + ); - $.setProps({data: []}); - expect($.find('.rv-radial-chart__series--pie__slice').length).toBe(0); - expect($.find('.rv-radial-chart__series--pie__slice-overlay').length).toBe(0); - expect($.find('.rv-xy-plot__series--label-text').length).toBe(0); - expect($.text()).toBe(''); -}); + const labels = $.find('.rv-xy-plot__series--label-text').length; + expect(labels).toBe(RADIAL_PROPS.data.length); + expect($.text()).toBe('yellow againmagentacyanyellowgreen'); -test('RadialChart: Showcase Example - Simple Radial Chart Example', () => { - const $ = mount(); - expect($.find('.rv-radial-chart__series--pie__slice').length).toBe(5); - expect($.find('.rv-xy-plot__series--label-text').length).toBe(5); - expect($.text()).toBe('yellow againmagentacyanyellowgreen'); -}); + $.setProps({data: []}); + expect($.find('.rv-radial-chart__series--pie__slice').length).toBe(0); + expect($.find('.rv-radial-chart__series--pie__slice-overlay').length).toBe( + 0 + ); + expect($.find('.rv-xy-plot__series--label-text').length).toBe(0); + expect($.text()).toBe(''); + }); -test('RadialChart: Showcase Example - DonutChart', () => { - const $ = mount(); - expect($.find('.rv-radial-chart__series--pie__slice').length).toBe(5); - expect($.find('.rv-xy-plot__series--label-text').length).toBe(0); - expect($.text()).toBe(''); - $.find('.rv-radial-chart__series--pie__slice') - .at(1) - .simulate('mouseOver'); - expect($.text()).toBe( - 'theta: 3angle0: -2.9171931783333793angle: -4.263590029871862radius0: 0radius: 1color: 1x: -0.4338837391175583y: 0.900968867902419' - ); -}); + test('Showcase Example - Simple Radial Chart Example', () => { + const $ = mount(); + expect($.find('.rv-radial-chart__series--pie__slice').length).toBe(5); + expect($.find('.rv-xy-plot__series--label-text').length).toBe(5); + expect($.text()).toBe('yellow againmagentacyanyellowgreen'); + }); -test('RadialChart: Showcase Example - Custom radius example', () => { - const $ = mount(); - $.find('.rv-radial-chart__series--pie__slice') - .at(1) - .simulate('mouseEnter'); - $.find('.rv-radial-chart__series--pie__slice') - .at(1) - .simulate('mouseLeave'); - // multiplied by two to account for the shadow listeners - expect($.find('.rv-radial-chart__series--pie__slice').length).toBe(2 * 5); - expect($.find('.rv-xy-plot__series--label-text').length).toBe(4); - expect($.text()).toBe( - 'Sub Label onlyAlt LabelSuper Custom labelWith annotation' - ); -}); + test('Showcase Example - DonutChart', () => { + const $ = mount(); + expect($.find('.rv-radial-chart__series--pie__slice').length).toBe(5); + expect($.find('.rv-xy-plot__series--label-text').length).toBe(0); + expect($.text()).toBe(''); + $.find('.rv-radial-chart__series--pie__slice') + .at(1) + .simulate('mouseOver'); + expect($.text()).toBe( + 'theta: 3angle0: -2.9171931783333793angle: -4.263590029871862radius0: 0radius: 1color: 1x: -0.4338837391175583y: 0.900968867902419' + ); + }); + + test('Showcase Example - Custom radius example', () => { + const $ = mount(); + $.find('.rv-radial-chart__series--pie__slice') + .at(1) + .simulate('mouseEnter'); + $.find('.rv-radial-chart__series--pie__slice') + .at(1) + .simulate('mouseLeave'); + // multiplied by two to account for the shadow listeners + expect($.find('.rv-radial-chart__series--pie__slice').length).toBe(2 * 5); + expect($.find('.rv-xy-plot__series--label-text').length).toBe(4); + expect($.text()).toBe( + 'Sub Label onlyAlt LabelSuper Custom labelWith annotation' + ); + }); -test('RadialChart: Showcase Example - Gradient Pie Example', () => { - const $ = mount(); - // multiplied by two to account for the shadow listeners - expect($.find('.rv-radial-chart__series--pie__slice').length).toBe(3); - expect($.find('.rv-xy-plot__series--label-text').length).toBe(0); - expect($.find('.rv-gradient-defs linearGradient').length).toBe(3); + test('Showcase Example - Gradient Pie Example', () => { + const $ = mount(); + // multiplied by two to account for the shadow listeners + expect($.find('.rv-radial-chart__series--pie__slice').length).toBe(3); + expect($.find('.rv-xy-plot__series--label-text').length).toBe(0); + expect($.find('.rv-gradient-defs linearGradient').length).toBe(3); + }); }); diff --git a/packages/react-vis/tests/components/rect-series-tests.js b/packages/react-vis/tests/components/rect-series-tests.js index 61760925f..e105d9a1f 100644 --- a/packages/react-vis/tests/components/rect-series-tests.js +++ b/packages/react-vis/tests/components/rect-series-tests.js @@ -6,21 +6,24 @@ import {testRenderWithProps, GENERIC_XYPLOT_SERIES_PROPS} from '../test-utils'; import Histogram from '../../../showcase/plot/histogram'; import StackedHistogram from '../../../showcase/plot/stacked-histogram'; -testRenderWithProps(HorizontalRectSeries, GENERIC_XYPLOT_SERIES_PROPS); -testRenderWithProps(VerticalRectSeries, GENERIC_XYPLOT_SERIES_PROPS); +describe('RectSeries', () => { + testRenderWithProps(HorizontalRectSeries, GENERIC_XYPLOT_SERIES_PROPS); -test('RectSeries: Showcase Example - StackedHistogram', () => { - const $ = mount(); - expect($.text()).toBe('TOGGLE TO CANVAS01234567051015202530'); - expect($.find('.rv-xy-plot__series--rect rect').length).toBe(6); + testRenderWithProps(VerticalRectSeries, GENERIC_XYPLOT_SERIES_PROPS); - $.find('.showcase-button').simulate('click'); - expect($.find('.rv-xy-plot__series--rect rect').length).toBe(0); - expect($.find('.rv-xy-canvas canvas').length).toBe(1); -}); + test('Showcase Example - StackedHistogram', () => { + const $ = mount(); + expect($.text()).toBe('TOGGLE TO CANVAS01234567051015202530'); + expect($.find('.rv-xy-plot__series--rect rect').length).toBe(6); + + $.find('.showcase-button').simulate('click'); + expect($.find('.rv-xy-plot__series--rect rect').length).toBe(0); + expect($.find('.rv-xy-canvas canvas').length).toBe(1); + }); -test('RectSeries: Showcase Example - Histogram', () => { - const $ = mount(); - expect($.text()).toBe('May 21May 28Jun 04Jun 11Jun 180.51.01.52.0'); - expect($.find('.rv-xy-plot__series--rect rect').length).toBe(8); + test('Showcase Example - Histogram', () => { + const $ = mount(); + expect($.text()).toBe('May 21May 28Jun 04Jun 11Jun 180.51.01.52.0'); + expect($.find('.rv-xy-plot__series--rect rect').length).toBe(8); + }); }); diff --git a/packages/react-vis/tests/components/sankey-tests.js b/packages/react-vis/tests/components/sankey-tests.js index 6707aa8df..a5ee1055f 100644 --- a/packages/react-vis/tests/components/sankey-tests.js +++ b/packages/react-vis/tests/components/sankey-tests.js @@ -18,111 +18,113 @@ const SANKEY_PROPS = { import {testRenderWithProps} from '../test-utils'; -// make sure that the components render at all -testRenderWithProps(Sankey, SANKEY_PROPS); - -test('Sankey: labels', () => { - const wrap = mount( - - ); - - expect(wrap.find('text').length).toBe(2); - wrap.setProps({hideLabels: true}); - expect(wrap.find('text').length).toBe(0); -}); +describe('Sankey', () => { + // make sure that the components render at all + testRenderWithProps(Sankey, SANKEY_PROPS); + + test('labels', () => { + const wrap = mount( + + ); + + expect(wrap.find('text').length).toBe(2); + wrap.setProps({hideLabels: true}); + expect(wrap.find('text').length).toBe(0); + }); -test('Sankey: children', () => { - const $ = mount( - - - - ); - expect($.find(Hint).length).toBe(1); -}); + test('children', () => { + const $ = mount( + + + + ); + expect($.find(Hint).length).toBe(1); + }); -test('Sankey: Showcase Example - BasicSankey', () => { - const $ = mount(); - expect($.find('.rv-sankey__link').length).toBe(3); - expect($.find('.rv-sankey__node rect').length).toBe(3); -}); + test('Showcase Example - BasicSankey', () => { + const $ = mount(); + expect($.find('.rv-sankey__link').length).toBe(3); + expect($.find('.rv-sankey__node rect').length).toBe(3); + }); -test('Sankey: Showcase Example - VoronoiSankey', () => { - const $ = mount(); - - expect($.find('.rv-sankey__link').length).toBe(3); - expect($.find('.rv-sankey__node rect').length).toBe(3); - expect($.find('.rv-voronoi').length).toBe(1); - expect($.find('.rv-voronoi__cell').length).toBe(3); - - expect($.text()).toBe('None selectedabc'); - $.find('.rv-voronoi__cell') - .at(0) - .simulate('mouseOver'); - expect($.text()).toBe('a selected!a!bc'); - $.find('.rv-voronoi__cell') - .at(0) - .simulate('mouseLeave'); -}); + test('Showcase Example - VoronoiSankey', () => { + const $ = mount(); + + expect($.find('.rv-sankey__link').length).toBe(3); + expect($.find('.rv-sankey__node rect').length).toBe(3); + expect($.find('.rv-voronoi').length).toBe(1); + expect($.find('.rv-voronoi__cell').length).toBe(3); + + expect($.text()).toBe('None selectedabc'); + $.find('.rv-voronoi__cell') + .at(0) + .simulate('mouseOver'); + expect($.text()).toBe('a selected!a!bc'); + $.find('.rv-voronoi__cell') + .at(0) + .simulate('mouseLeave'); + }); -test('Sankey: Showcase Example - LinkEventSankey', () => { - const $ = mount(); - - expect($.find('.rv-sankey__link').length).toBe(3); - expect($.find('.rv-sankey__node rect').length).toBe(3); - - expect($.text()).toBe('None selectedabc'); - $.find('.rv-sankey__link') - .at(0) - .simulate('mouseOver'); - expect($.text()).toBe('a -> b selectedabc'); - $.find('.rv-sankey__link') - .at(0) - .simulate('mouseOut'); - expect($.text()).toBe('None selectedabc'); -}); + test('Showcase Example - LinkEventSankey', () => { + const $ = mount(); + + expect($.find('.rv-sankey__link').length).toBe(3); + expect($.find('.rv-sankey__node rect').length).toBe(3); + + expect($.text()).toBe('None selectedabc'); + $.find('.rv-sankey__link') + .at(0) + .simulate('mouseOver'); + expect($.text()).toBe('a -> b selectedabc'); + $.find('.rv-sankey__link') + .at(0) + .simulate('mouseOut'); + expect($.text()).toBe('None selectedabc'); + }); -test('Sankey: Showcase Example - EnergySankey', () => { - const $ = mount(); - - [ - "PREV MODE justify NEXT MODEAgricultural 'waste'Bio-conversionLiquidLossesSolidGasBiofuel importsBiomass importsCoal importsCoalCoal reservesDistrict heatingIndustryHeating and cooling - commercialHeating and cooling - homesElectricity gridOver generation / exportsH2 conversionRoad transportAgricultureRail transportLighting & appliances - commercialLighting & appliances - homesGas importsNgasGas reservesThermal generationGeothermalH2HydroInternational shippingDomestic aviationInternational aviationNational navigationMarine algaeNuclearOil importsOilOil reservesOther wastePumped heatSolar PVSolar ThermalSolarTidalUK land based bioenergyWaveWind", - "PREV MODE center NEXT MODEAgricultural 'waste'Bio-conversionLiquidLossesSolidGasBiofuel importsBiomass importsCoal importsCoalCoal reservesDistrict heatingIndustryHeating and cooling - commercialHeating and cooling - homesElectricity gridOver generation / exportsH2 conversionRoad transportAgricultureRail transportLighting & appliances - commercialLighting & appliances - homesGas importsNgasGas reservesThermal generationGeothermalH2HydroInternational shippingDomestic aviationInternational aviationNational navigationMarine algaeNuclearOil importsOilOil reservesOther wastePumped heatSolar PVSolar ThermalSolarTidalUK land based bioenergyWaveWind", - "PREV MODE left NEXT MODEAgricultural 'waste'Bio-conversionLiquidLossesSolidGasBiofuel importsBiomass importsCoal importsCoalCoal reservesDistrict heatingIndustryHeating and cooling - commercialHeating and cooling - homesElectricity gridOver generation / exportsH2 conversionRoad transportAgricultureRail transportLighting & appliances - commercialLighting & appliances - homesGas importsNgasGas reservesThermal generationGeothermalH2HydroInternational shippingDomestic aviationInternational aviationNational navigationMarine algaeNuclearOil importsOilOil reservesOther wastePumped heatSolar PVSolar ThermalSolarTidalUK land based bioenergyWaveWind", - "PREV MODE right NEXT MODEAgricultural 'waste'Bio-conversionLiquidLossesSolidGasBiofuel importsBiomass importsCoal importsCoalCoal reservesDistrict heatingIndustryHeating and cooling - commercialHeating and cooling - homesElectricity gridOver generation / exportsH2 conversionRoad transportAgricultureRail transportLighting & appliances - commercialLighting & appliances - homesGas importsNgasGas reservesThermal generationGeothermalH2HydroInternational shippingDomestic aviationInternational aviationNational navigationMarine algaeNuclearOil importsOilOil reservesOther wastePumped heatSolar PVSolar ThermalSolarTidalUK land based bioenergyWaveWind" - ].forEach(testMessage => { - expect($.text()).toBe(testMessage); - $.find('.showcase-button') - .at(1) - .simulate('click'); - - expect($.find('.rv-sankey__link').length).toBe(68); - expect($.find('.rv-sankey__node rect').length).toBe(48); + test('Showcase Example - EnergySankey', () => { + const $ = mount(); + + [ + "PREV MODE justify NEXT MODEAgricultural 'waste'Bio-conversionLiquidLossesSolidGasBiofuel importsBiomass importsCoal importsCoalCoal reservesDistrict heatingIndustryHeating and cooling - commercialHeating and cooling - homesElectricity gridOver generation / exportsH2 conversionRoad transportAgricultureRail transportLighting & appliances - commercialLighting & appliances - homesGas importsNgasGas reservesThermal generationGeothermalH2HydroInternational shippingDomestic aviationInternational aviationNational navigationMarine algaeNuclearOil importsOilOil reservesOther wastePumped heatSolar PVSolar ThermalSolarTidalUK land based bioenergyWaveWind", + "PREV MODE center NEXT MODEAgricultural 'waste'Bio-conversionLiquidLossesSolidGasBiofuel importsBiomass importsCoal importsCoalCoal reservesDistrict heatingIndustryHeating and cooling - commercialHeating and cooling - homesElectricity gridOver generation / exportsH2 conversionRoad transportAgricultureRail transportLighting & appliances - commercialLighting & appliances - homesGas importsNgasGas reservesThermal generationGeothermalH2HydroInternational shippingDomestic aviationInternational aviationNational navigationMarine algaeNuclearOil importsOilOil reservesOther wastePumped heatSolar PVSolar ThermalSolarTidalUK land based bioenergyWaveWind", + "PREV MODE left NEXT MODEAgricultural 'waste'Bio-conversionLiquidLossesSolidGasBiofuel importsBiomass importsCoal importsCoalCoal reservesDistrict heatingIndustryHeating and cooling - commercialHeating and cooling - homesElectricity gridOver generation / exportsH2 conversionRoad transportAgricultureRail transportLighting & appliances - commercialLighting & appliances - homesGas importsNgasGas reservesThermal generationGeothermalH2HydroInternational shippingDomestic aviationInternational aviationNational navigationMarine algaeNuclearOil importsOilOil reservesOther wastePumped heatSolar PVSolar ThermalSolarTidalUK land based bioenergyWaveWind", + "PREV MODE right NEXT MODEAgricultural 'waste'Bio-conversionLiquidLossesSolidGasBiofuel importsBiomass importsCoal importsCoalCoal reservesDistrict heatingIndustryHeating and cooling - commercialHeating and cooling - homesElectricity gridOver generation / exportsH2 conversionRoad transportAgricultureRail transportLighting & appliances - commercialLighting & appliances - homesGas importsNgasGas reservesThermal generationGeothermalH2HydroInternational shippingDomestic aviationInternational aviationNational navigationMarine algaeNuclearOil importsOilOil reservesOther wastePumped heatSolar PVSolar ThermalSolarTidalUK land based bioenergyWaveWind" + ].forEach(testMessage => { + expect($.text()).toBe(testMessage); + $.find('.showcase-button') + .at(1) + .simulate('click'); + + expect($.find('.rv-sankey__link').length).toBe(68); + expect($.find('.rv-sankey__node rect').length).toBe(48); + }); }); -}); -test('Sankey: Showcase Example - LinkHintSankey', () => { - const $ = mount(); - - expect($.find('.rv-sankey__link').length).toBe(3); - expect($.find('.rv-sankey__node rect').length).toBe(3); - - expect($.find(Hint).length).toBe(0); - $.find('.rv-sankey__link') - .at(0) - .simulate('mouseOver'); - expect($.find(Hint).length).toBe(1); - $.find('.rv-sankey__link') - .at(0) - .simulate('mouseOut'); - expect($.find(Hint).length).toBe(0); + test('Showcase Example - LinkHintSankey', () => { + const $ = mount(); + + expect($.find('.rv-sankey__link').length).toBe(3); + expect($.find('.rv-sankey__node rect').length).toBe(3); + + expect($.find(Hint).length).toBe(0); + $.find('.rv-sankey__link') + .at(0) + .simulate('mouseOver'); + expect($.find(Hint).length).toBe(1); + $.find('.rv-sankey__link') + .at(0) + .simulate('mouseOut'); + expect($.find(Hint).length).toBe(0); + }); }); diff --git a/packages/react-vis/tests/components/sunburst-tests.js b/packages/react-vis/tests/components/sunburst-tests.js index d0b54ebae..0f6b27470 100644 --- a/packages/react-vis/tests/components/sunburst-tests.js +++ b/packages/react-vis/tests/components/sunburst-tests.js @@ -46,70 +46,72 @@ const SUNBURST_PROPS = { } }; -// make sure that the components render at all -testRenderWithProps(Sunburst, SUNBURST_PROPS); +describe('Sunburst', () => { + // make sure that the components render at all + testRenderWithProps(Sunburst, SUNBURST_PROPS); -test('Sunburst: Basic rendering + data changes', () => { - const $ = mount(); - expect( - $.find('.little-nested-burst-example.rv-xy-plot__series--arc path').length - ).toBe(21); + test('Basic rendering + data changes', () => { + const $ = mount(); + expect( + $.find('.little-nested-burst-example.rv-xy-plot__series--arc path').length + ).toBe(21); - $.setProps({data: INTERPOLATE_DATA}); - expect($.find('.rv-xy-plot__series--arc-path').length).toBe(9); -}); + $.setProps({data: INTERPOLATE_DATA}); + expect($.find('.rv-xy-plot__series--arc-path').length).toBe(9); + }); -test('Sunburst: Empty', () => { - const $ = mount(); - expect($.find('.rv-xy-plot__series--arc-path').length).toBe(0); -}); + test('Empty', () => { + const $ = mount(); + expect($.find('.rv-xy-plot__series--arc-path').length).toBe(0); + }); -test('Sunburst: BasicSunburst', () => { - const $ = mount(); - // multiplied by two to account for the shadow listeners - expect($.find('.rv-xy-plot__series--arc path').length).toBe(251 * 2); - expect($.text()).toBe('click to lock selectionSUNBURST'); - // check hover state - expect($.state().pathValue).toEqual(false); - $.find('.rv-xy-plot__series--arc-path') - .at(200) - .simulate('mouseover'); - expect($.state().pathValue).toEqual('root > vis > events > DataEvent'); + test('BasicSunburst', () => { + const $ = mount(); + // multiplied by two to account for the shadow listeners + expect($.find('.rv-xy-plot__series--arc path').length).toBe(251 * 2); + expect($.text()).toBe('click to lock selectionSUNBURST'); + // check hover state + expect($.state().pathValue).toEqual(false); + $.find('.rv-xy-plot__series--arc-path') + .at(200) + .simulate('mouseover'); + expect($.state().pathValue).toEqual('root > vis > events > DataEvent'); - $.find('.rv-xy-plot__series--arc-path') - .at(1) - .simulate('click'); - expect($.text()).toBe( - 'click to unlock selectionDataEventroot > vis > events > DataEvent' - ); - $.find('.rv-xy-plot__series--arc-path') - .at(1) - .simulate('mouseLeave'); - $.find('.rv-xy-plot__series--arc-path') - .at(10) - .simulate('mouseEnter'); + $.find('.rv-xy-plot__series--arc-path') + .at(1) + .simulate('click'); + expect($.text()).toBe( + 'click to unlock selectionDataEventroot > vis > events > DataEvent' + ); + $.find('.rv-xy-plot__series--arc-path') + .at(1) + .simulate('mouseLeave'); + $.find('.rv-xy-plot__series--arc-path') + .at(10) + .simulate('mouseEnter'); - expect($.text()).toBe( - 'click to unlock selectionDataEventroot > vis > events > DataEvent' - ); -}); + expect($.text()).toBe( + 'click to unlock selectionDataEventroot > vis > events > DataEvent' + ); + }); -test('Sunburst: SunburstWithTooltips', () => { - const $ = mount(); - expect($.text()).toBe('cooldogssunglassesexcellentchartgreatlabel'); - expect($.find('.rv-xy-plot__series--arc path').length).toBe(10); - $.find('.rv-xy-plot__series--arc-path') - .at(1) - .simulate('mouseOver'); - expect($.text()).toBe('cooldogssunglassesexcellentchartgreatlabel#FF991F'); -}); + test('SunburstWithTooltips', () => { + const $ = mount(); + expect($.text()).toBe('cooldogssunglassesexcellentchartgreatlabel'); + expect($.find('.rv-xy-plot__series--arc path').length).toBe(10); + $.find('.rv-xy-plot__series--arc-path') + .at(1) + .simulate('mouseOver'); + expect($.text()).toBe('cooldogssunglassesexcellentchartgreatlabel#FF991F'); + }); -test('Sunburst: AnimatedSunburst', () => { - const $ = mount(); - expect($.text()).toBe('UPDATENOT HOVERED'); - expect($.find('.rv-xy-plot__series--arc path').length > 2).toBeTruthy(); - $.find('.rv-xy-plot__series--arc-path') - .at(1) - .simulate('mouseOver'); - expect($.text()).toBe('UPDATECURRENTLY HOVERING'); + test('AnimatedSunburst', () => { + const $ = mount(); + expect($.text()).toBe('UPDATENOT HOVERED'); + expect($.find('.rv-xy-plot__series--arc path').length > 2).toBeTruthy(); + $.find('.rv-xy-plot__series--arc-path') + .at(1) + .simulate('mouseOver'); + expect($.text()).toBe('UPDATECURRENTLY HOVERING'); + }); }); diff --git a/packages/react-vis/tests/components/treemap-tests.js b/packages/react-vis/tests/components/treemap-tests.js index 6c15cd42c..71ef792bc 100644 --- a/packages/react-vis/tests/components/treemap-tests.js +++ b/packages/react-vis/tests/components/treemap-tests.js @@ -45,158 +45,160 @@ const TREEMAP_PROPS = { } }; -// make sure that the components render at all -testRenderWithProps(Treemap, TREEMAP_PROPS); - -test('Treemap: Basic rendering', () => { - const $ = mount(); - expect($.find('.rv-treemap__leaf').length).toBe(22); - const expectedText = - 'EasingNeonateinterpolateISchedulableParallelPauseFunctionSequenceSequenceTransitionTransitionerTransitionEventSchedulerArrayInterpolatorColorInterpolatorDateInterpolatorInterpolatorMatrixInterpolatorNumberInterpolatorObjectInterpolatorPointInterpolatorRectangleInterpolator'; - expect($.find('.rv-treemap').text()).toBe(expectedText); - expect($.find('div.little-nested-tree-example').length).toBe(1); - - $.setProps({data: INTERPOLATE_DATA}); - expect($.find('.rv-treemap__leaf').length).toBe(10); - const newText = - 'interpolateArrayInterpolatorColorInterpolatorDateInterpolatorInterpolatorMatrixInterpolatorNumberInterpolatorObjectInterpolatorPointInterpolatorRectangleInterpolator'; - expect($.find('.rv-treemap').text()).toBe(newText); - expect($.find('div.little-nested-tree-example').length).toBe(1); -}); - -test('Treemap: Custom Sorting', () => { - const $ = mount(); - const expectedText = - 'interpolateTransitionerEasingTransitionNeonateFunctionSequenceSchedulerSequenceParallelTransitionEventISchedulablePauseInterpolatorMatrixInterpolatorColorInterpolatorRectangleInterpolatorArrayInterpolatorPointInterpolatorObjectInterpolatorNumberInterpolatorDateInterpolator'; - const expectedReverseText = - 'PauseISchedulableTransitionEventParallelSequenceSchedulerFunctionSequenceNeonateTransitionEasingTransitionerinterpolateDateInterpolatorNumberInterpolatorObjectInterpolatorPointInterpolatorArrayInterpolatorRectangleInterpolatorColorInterpolatorMatrixInterpolatorInterpolator'; - const expectedNewText = - 'interpolateInterpolatorMatrixInterpolatorColorInterpolatorRectangleInterpolatorArrayInterpolatorPointInterpolatorObjectInterpolatorNumberInterpolatorDateInterpolator'; - const expectedReverseNewText = - 'interpolateDateInterpolatorNumberInterpolatorObjectInterpolatorPointInterpolatorArrayInterpolatorRectangleInterpolatorColorInterpolatorMatrixInterpolatorInterpolator'; - - [ - 'circlePack', - 'partition', - 'partition-pivot', - 'squarify', - 'resquarify', - 'slice', - 'dice', - 'slicedice', - 'binary' - ].forEach(mode => { - $.setProps({ - mode, - sortFunction: (a, b) => b.value - a.value, - ...TREEMAP_PROPS - }); +describe('Treemap', () => { + // make sure that the components render at all + testRenderWithProps(Treemap, TREEMAP_PROPS); + + test('Basic rendering', () => { + const $ = mount(); + expect($.find('.rv-treemap__leaf').length).toBe(22); + const expectedText = + 'EasingNeonateinterpolateISchedulableParallelPauseFunctionSequenceSequenceTransitionTransitionerTransitionEventSchedulerArrayInterpolatorColorInterpolatorDateInterpolatorInterpolatorMatrixInterpolatorNumberInterpolatorObjectInterpolatorPointInterpolatorRectangleInterpolator'; expect($.find('.rv-treemap').text()).toBe(expectedText); - $.setProps({sortFunction: (a, b) => a.value - b.value}); - expect($.find('.rv-treemap').text()).toBe(expectedReverseText); + expect($.find('div.little-nested-tree-example').length).toBe(1); + + $.setProps({data: INTERPOLATE_DATA}); + expect($.find('.rv-treemap__leaf').length).toBe(10); + const newText = + 'interpolateArrayInterpolatorColorInterpolatorDateInterpolatorInterpolatorMatrixInterpolatorNumberInterpolatorObjectInterpolatorPointInterpolatorRectangleInterpolator'; + expect($.find('.rv-treemap').text()).toBe(newText); + expect($.find('div.little-nested-tree-example').length).toBe(1); + }); - // circle pack includes the root node, while the other modes do not. The root of INTERPOLATE_DATA has a title, but the root of the default data does not - $.setProps({ - data: INTERPOLATE_DATA, - sortFunction: (a, b) => b.value - a.value + test('Custom Sorting', () => { + const $ = mount(); + const expectedText = + 'interpolateTransitionerEasingTransitionNeonateFunctionSequenceSchedulerSequenceParallelTransitionEventISchedulablePauseInterpolatorMatrixInterpolatorColorInterpolatorRectangleInterpolatorArrayInterpolatorPointInterpolatorObjectInterpolatorNumberInterpolatorDateInterpolator'; + const expectedReverseText = + 'PauseISchedulableTransitionEventParallelSequenceSchedulerFunctionSequenceNeonateTransitionEasingTransitionerinterpolateDateInterpolatorNumberInterpolatorObjectInterpolatorPointInterpolatorArrayInterpolatorRectangleInterpolatorColorInterpolatorMatrixInterpolatorInterpolator'; + const expectedNewText = + 'interpolateInterpolatorMatrixInterpolatorColorInterpolatorRectangleInterpolatorArrayInterpolatorPointInterpolatorObjectInterpolatorNumberInterpolatorDateInterpolator'; + const expectedReverseNewText = + 'interpolateDateInterpolatorNumberInterpolatorObjectInterpolatorPointInterpolatorArrayInterpolatorRectangleInterpolatorColorInterpolatorMatrixInterpolatorInterpolator'; + + [ + 'circlePack', + 'partition', + 'partition-pivot', + 'squarify', + 'resquarify', + 'slice', + 'dice', + 'slicedice', + 'binary' + ].forEach(mode => { + $.setProps({ + mode, + sortFunction: (a, b) => b.value - a.value, + ...TREEMAP_PROPS + }); + expect($.find('.rv-treemap').text()).toBe(expectedText); + $.setProps({sortFunction: (a, b) => a.value - b.value}); + expect($.find('.rv-treemap').text()).toBe(expectedReverseText); + + // circle pack includes the root node, while the other modes do not. The root of INTERPOLATE_DATA has a title, but the root of the default data does not + $.setProps({ + data: INTERPOLATE_DATA, + sortFunction: (a, b) => b.value - a.value + }); + expect($.find('.rv-treemap').text()).toBe(expectedNewText); + $.setProps({sortFunction: (a, b) => a.value - b.value}); + expect($.find('.rv-treemap').text()).toBe(expectedReverseNewText); }); - expect($.find('.rv-treemap').text()).toBe(expectedNewText); - $.setProps({sortFunction: (a, b) => a.value - b.value}); - expect($.find('.rv-treemap').text()).toBe(expectedReverseNewText); }); -}); -test('Treemap: Empty treemap', () => { - const $ = mount(); - // 1 is the empty root node - expect($.find('.rv-treemap__leaf').length).toBe(1); - expect($.find('.rv-treemap').text()).toBe(''); - expect($.find('div.little-nested-tree-example').length).toBe(1); -}); - -test('Treemap: Hide Root Node', () => { - const $ = mount(); - // the tree from TREEMAP_PROPS doesn't have a title so its text is the same with ot without the root - const expectedText = - 'EasingNeonateinterpolateISchedulableParallelPauseFunctionSequenceSequenceTransitionTransitionerTransitionEventSchedulerArrayInterpolatorColorInterpolatorDateInterpolatorInterpolatorMatrixInterpolatorNumberInterpolatorObjectInterpolatorPointInterpolatorRectangleInterpolator'; - const numberOfElements = 21; - const numberOfElementsWithRoot = numberOfElements + 1; - const expectedNewText = - 'ArrayInterpolatorColorInterpolatorDateInterpolatorInterpolatorMatrixInterpolatorNumberInterpolatorObjectInterpolatorPointInterpolatorRectangleInterpolator'; - const expectedNewTextWithRoot = `interpolate${expectedNewText}`; - const numberOfNewElements = 9; - const numberOfNewElementsWithRoot = numberOfNewElements + 1; - [ - 'circlePack', - 'partition', - 'partition-pivot', - 'squarify', - 'resquarify', - 'slice', - 'dice', - 'slicedice', - 'binary' - ].forEach(mode => { - $.setProps({mode, ...TREEMAP_PROPS, hideRootNode: false}); - expect($.find('.rv-treemap').text()).toBe(expectedText); - expect($.find('.rv-treemap__leaf').length).toBe(numberOfElementsWithRoot); - $.setProps({hideRootNode: true}); - expect($.find('.rv-treemap').text()).toBe(expectedText); - expect($.find('.rv-treemap__leaf').length).toBe(numberOfElements); + test('Empty treemap', () => { + const $ = mount(); + // 1 is the empty root node + expect($.find('.rv-treemap__leaf').length).toBe(1); + expect($.find('.rv-treemap').text()).toBe(''); + expect($.find('div.little-nested-tree-example').length).toBe(1); + }); - $.setProps({data: INTERPOLATE_DATA, hideRootNode: false}); - expect($.find('.rv-treemap').text()).toBe(expectedNewTextWithRoot); - expect($.find('.rv-treemap__leaf').length).toBe( - numberOfNewElementsWithRoot - ); - $.setProps({hideRootNode: true}); - expect($.find('.rv-treemap').text()).toBe(expectedNewText); - expect($.find('.rv-treemap__leaf').length).toBe(numberOfNewElements); + test('Hide Root Node', () => { + const $ = mount(); + // the tree from TREEMAP_PROPS doesn't have a title so its text is the same with ot without the root + const expectedText = + 'EasingNeonateinterpolateISchedulableParallelPauseFunctionSequenceSequenceTransitionTransitionerTransitionEventSchedulerArrayInterpolatorColorInterpolatorDateInterpolatorInterpolatorMatrixInterpolatorNumberInterpolatorObjectInterpolatorPointInterpolatorRectangleInterpolator'; + const numberOfElements = 21; + const numberOfElementsWithRoot = numberOfElements + 1; + const expectedNewText = + 'ArrayInterpolatorColorInterpolatorDateInterpolatorInterpolatorMatrixInterpolatorNumberInterpolatorObjectInterpolatorPointInterpolatorRectangleInterpolator'; + const expectedNewTextWithRoot = `interpolate${expectedNewText}`; + const numberOfNewElements = 9; + const numberOfNewElementsWithRoot = numberOfNewElements + 1; + [ + 'circlePack', + 'partition', + 'partition-pivot', + 'squarify', + 'resquarify', + 'slice', + 'dice', + 'slicedice', + 'binary' + ].forEach(mode => { + $.setProps({mode, ...TREEMAP_PROPS, hideRootNode: false}); + expect($.find('.rv-treemap').text()).toBe(expectedText); + expect($.find('.rv-treemap__leaf').length).toBe(numberOfElementsWithRoot); + $.setProps({hideRootNode: true}); + expect($.find('.rv-treemap').text()).toBe(expectedText); + expect($.find('.rv-treemap__leaf').length).toBe(numberOfElements); + + $.setProps({data: INTERPOLATE_DATA, hideRootNode: false}); + expect($.find('.rv-treemap').text()).toBe(expectedNewTextWithRoot); + expect($.find('.rv-treemap__leaf').length).toBe( + numberOfNewElementsWithRoot + ); + $.setProps({hideRootNode: true}); + expect($.find('.rv-treemap').text()).toBe(expectedNewText); + expect($.find('.rv-treemap__leaf').length).toBe(numberOfNewElements); + }); }); -}); -test('Treemap: SimpleTreemap', () => { - const $ = mount(); - [ - 'circlePack', - 'partition', - 'partition-pivot', - 'squarify', - 'resquarify', - 'slice', - 'dice', - 'slicedice', - 'binary' - ].forEach(mode => { - const selector = - mode === 'circlePack' - ? '.rv-treemap__leaf circle' - : 'path.rv-treemap__leaf'; - // circle pack includes the root node, while the other modes do not - const numberOfElements = 252; - expect($.find(selector).length).toBe(numberOfElements); - expect($.text()).toBe(`USE DOMPREV MODE ${mode} NEXT MODE`); - // switch to svg - $.find('.showcase-button') - .at(0) - .simulate('click'); - expect($.find('.rv-treemap__leaf').length).toBe(numberOfElements); - expect($.text()).toBe(`USE SVGPREV MODE ${mode} NEXT MODE`); - - // switch back to dom and go to next mode - $.find('.showcase-button') - .at(0) - .simulate('click'); - $.find('.showcase-button') - .at(2) - .simulate('click'); + test('SimpleTreemap', () => { + const $ = mount(); + [ + 'circlePack', + 'partition', + 'partition-pivot', + 'squarify', + 'resquarify', + 'slice', + 'dice', + 'slicedice', + 'binary' + ].forEach(mode => { + const selector = + mode === 'circlePack' + ? '.rv-treemap__leaf circle' + : 'path.rv-treemap__leaf'; + // circle pack includes the root node, while the other modes do not + const numberOfElements = 252; + expect($.find(selector).length).toBe(numberOfElements); + expect($.text()).toBe(`USE DOMPREV MODE ${mode} NEXT MODE`); + // switch to svg + $.find('.showcase-button') + .at(0) + .simulate('click'); + expect($.find('.rv-treemap__leaf').length).toBe(numberOfElements); + expect($.text()).toBe(`USE SVGPREV MODE ${mode} NEXT MODE`); + + // switch back to dom and go to next mode + $.find('.showcase-button') + .at(0) + .simulate('click'); + $.find('.showcase-button') + .at(2) + .simulate('click'); + }); }); -}); -test('Treemap: DynamicTreemap', () => { - const $ = mount(); - expect($.find('.rv-treemap__leaf').length).toBe(21); - expect($.find('.rv-treemap').text()).toBe( - '2020202020202020202020202020202020202020' - ); + test('DynamicTreemap', () => { + const $ = mount(); + expect($.find('.rv-treemap__leaf').length).toBe(21); + expect($.find('.rv-treemap').text()).toBe( + '2020202020202020202020202020202020202020' + ); + }); }); diff --git a/packages/react-vis/tests/components/voronoi-tests.js b/packages/react-vis/tests/components/voronoi-tests.js index 8a3127770..801118ef3 100644 --- a/packages/react-vis/tests/components/voronoi-tests.js +++ b/packages/react-vis/tests/components/voronoi-tests.js @@ -30,46 +30,48 @@ const StatelessVoronoiWrapper = () => ( ); -test('Voronoi: Basic Chart', () => { - const $ = mount(); +describe('Voronoi', () => { + test('Basic Chart', () => { + const $ = mount(); - expect( - $.find('.rv-voronoi__cell') - .at(30) - .prop('style').color - ).toBe('red'); - expect( - $.find('.rv-voronoi__cell') - .at(30) - .hasClass('my-class-30') - ).toBe(true); - expect( - $.find('.rv-voronoi__cell') - .at(50) - .hasClass('my-class-50') - ).toBe(true); -}); + expect( + $.find('.rv-voronoi__cell') + .at(30) + .prop('style').color + ).toBe('red'); + expect( + $.find('.rv-voronoi__cell') + .at(30) + .hasClass('my-class-30') + ).toBe(true); + expect( + $.find('.rv-voronoi__cell') + .at(50) + .hasClass('my-class-50') + ).toBe(true); + }); -test('Voronoi: Showcase Example - VoronoiLineChart', () => { - const $ = mount(); + test('VoronoiLineChart', () => { + const $ = mount(); - expect($.text()).toBe( - 'Show Voronoi1.01.52.02.53.03.54.0X Axis2468101214Y Axis' - ); - expect($.find('.rv-voronoi__cell').length).toBe(12); - expect($.find('.rv-xy-plot__series--line').length).toBe(3); - expect($.find('circle').length).toBe(0); + expect($.text()).toBe( + 'Show Voronoi1.01.52.02.53.03.54.0X Axis2468101214Y Axis' + ); + expect($.find('.rv-voronoi__cell').length).toBe(12); + expect($.find('.rv-xy-plot__series--line').length).toBe(3); + expect($.find('circle').length).toBe(0); - $.find('input').simulate('click'); - $.find('.rv-voronoi__cell') - .at(0) - .simulate('mouseOver'); + $.find('input').simulate('click'); + $.find('.rv-voronoi__cell') + .at(0) + .simulate('mouseOver'); - expect($.find('circle').length).toBe(1); + expect($.find('circle').length).toBe(1); - $.find('.rv-voronoi__cell') - .at(0) - .simulate('mouseOut'); + $.find('.rv-voronoi__cell') + .at(0) + .simulate('mouseOut'); - expect($.find('circle').length).toBe(0); + expect($.find('circle').length).toBe(0); + }); }); diff --git a/packages/react-vis/tests/components/whisker-series-tests.js b/packages/react-vis/tests/components/whisker-series-tests.js index 8fd481639..0a15564b8 100644 --- a/packages/react-vis/tests/components/whisker-series-tests.js +++ b/packages/react-vis/tests/components/whisker-series-tests.js @@ -6,10 +6,12 @@ import WhiskerChart from '../../../showcase/plot/whisker-chart'; testRenderWithProps(WhiskerSeries, GENERIC_XYPLOT_SERIES_PROPS); -test('WhiskerSeries: Showcase Example - Whisker Scatterplot', () => { - const $ = mount(); - expect($.text()).toBe('1.01.52.02.53.068101214'); - expect($.find('g.whisker-series-example').length).toBe(1); - // 8 lines each per 5 (double) whiskers - expect($.find('.rv-xy-plot__series--whisker line').length).toBe(40); +describe('WhiskerSeries', () => { + test('Showcase Example - Whisker Scatterplot', () => { + const $ = mount(); + expect($.text()).toBe('1.01.52.02.53.068101214'); + expect($.find('g.whisker-series-example').length).toBe(1); + // 8 lines each per 5 (double) whiskers + expect($.find('.rv-xy-plot__series--whisker line').length).toBe(40); + }); }); diff --git a/packages/react-vis/tests/components/xy-plot-tests.js b/packages/react-vis/tests/components/xy-plot-tests.js index 0f2a3c138..5e6ee3c83 100644 --- a/packages/react-vis/tests/components/xy-plot-tests.js +++ b/packages/react-vis/tests/components/xy-plot-tests.js @@ -38,269 +38,271 @@ const XYPLOT_PROPS = {width: 10, height: 10}; testRenderWithProps(XYPlot, XYPLOT_PROPS); -test('Render a stacked bar chart', () => { - const wrapper = shallow( - - - - - ); - - const renderedVerticalBarsWrapper = wrapper.find(VerticalBarSeries); - - expect(renderedVerticalBarsWrapper.at(0).prop('data')).toEqual([ - {x: 1, y: 0}, - {x: 2, y: 1}, - {x: 3, y: 2} - ]); - - expect(renderedVerticalBarsWrapper.at(1).prop('data')).toEqual([ - {x: 1, y: 2, y0: 0}, - {x: 2, y: 2, y0: 1}, - {x: 3, y: 2, y0: 2} - ]); -}); - -test('Render a stacked bar chart with other children', () => { - const wrapper = shallow( - - - - - { - // Empty div here is intentional, to test series children handling - } -
- - ); - - const renderedVerticalBarsWrapper = wrapper.find(VerticalBarSeries); - - expect(renderedVerticalBarsWrapper.at(0).prop('data')).toEqual([ - {x: 1, y: 0} - ]); - - expect(renderedVerticalBarsWrapper.at(1).prop('data')).toEqual([ - {x: 1, y: 2, y0: 0} - ]); -}); +describe('XYPlot', () => { + test('Render a stacked bar chart', () => { + const wrapper = shallow( + + + + + ); + + const renderedVerticalBarsWrapper = wrapper.find(VerticalBarSeries); + + expect(renderedVerticalBarsWrapper.at(0).prop('data')).toEqual([ + {x: 1, y: 0}, + {x: 2, y: 1}, + {x: 3, y: 2} + ]); + + expect(renderedVerticalBarsWrapper.at(1).prop('data')).toEqual([ + {x: 1, y: 2, y0: 0}, + {x: 2, y: 2, y0: 1}, + {x: 3, y: 2, y0: 2} + ]); + }); -test('Render a bar chart with some nonAnimatedProps', () => { - const wrapper = shallow( - - - - - ); - - const renderedXAxisWrapper = wrapper.find(XAxis); - const renderedVerticalBarsWrapper = wrapper.find(VerticalBarSeries); - - expect(renderedXAxisWrapper.at(0).prop('animation')).toEqual({ - nonAnimatedProps: ['xDomain'] + test('Render a stacked bar chart with other children', () => { + const wrapper = shallow( + + + + + { + // Empty div here is intentional, to test series children handling + } +
+ + ); + + const renderedVerticalBarsWrapper = wrapper.find(VerticalBarSeries); + + expect(renderedVerticalBarsWrapper.at(0).prop('data')).toEqual([ + {x: 1, y: 0} + ]); + + expect(renderedVerticalBarsWrapper.at(1).prop('data')).toEqual([ + {x: 1, y: 2, y0: 0} + ]); }); - expect(renderedVerticalBarsWrapper.at(0).prop('animation')).toEqual({ - nonAnimatedProps: ['xDomain'] + test('Render a bar chart with some nonAnimatedProps', () => { + const wrapper = shallow( + + + + + ); + + const renderedXAxisWrapper = wrapper.find(XAxis); + const renderedVerticalBarsWrapper = wrapper.find(VerticalBarSeries); + + expect(renderedXAxisWrapper.at(0).prop('animation')).toEqual({ + nonAnimatedProps: ['xDomain'] + }); + + expect(renderedVerticalBarsWrapper.at(0).prop('animation')).toEqual({ + nonAnimatedProps: ['xDomain'] + }); }); -}); -test('testing flexible charts', () => { - const $ = mount(FlexibleCharts({height: 200, width: 400})); - const w = $.find('.flexible-width .rv-xy-plot').prop('style'); - const h = $.find('.flexible-height .rv-xy-plot').prop('style'); - const v = $.find('.flexible-vis .rv-xy-plot').prop('style'); - - expect(w.width).not.toBe('100px'); - expect(w.height).toEqual('100px'); - expect(h.width).toEqual('100px'); - expect(h.height).not.toBe('100px'); - expect(v.width).not.toBe('100px'); - expect(v.height).not.toBe('100px'); -}); + test('testing flexible charts', () => { + const $ = mount(FlexibleCharts({height: 200, width: 400})); + const w = $.find('.flexible-width .rv-xy-plot').prop('style'); + const h = $.find('.flexible-height .rv-xy-plot').prop('style'); + const v = $.find('.flexible-vis .rv-xy-plot').prop('style'); + + expect(w.width).not.toBe('100px'); + expect(w.height).toEqual('100px'); + expect(h.width).toEqual('100px'); + expect(h.height).not.toBe('100px'); + expect(v.width).not.toBe('100px'); + expect(v.height).not.toBe('100px'); + }); -test('Render two stacked bar series with a non-stacked line series chart', () => { - const $ = mount(); - - const renderedBarsWrapper = $.find(BarSeries); - const renderedLineWrapper = $.find(LineSeries); - expect(renderedBarsWrapper.at(0).prop('data')).toEqual([ - {x: 2, y: 10}, - {x: 4, y: 5}, - {x: 5, y: 15} - ]); - - expect(renderedBarsWrapper.at(1).prop('data')).toEqual([ - {x: 2, y: 22, y0: 10}, - {x: 4, y: 7, y0: 5}, - {x: 5, y: 26, y0: 15} - ]); - - expect(renderedLineWrapper.at(0).prop('data')).toEqual([ - {x: 2, y: 26}, - {x: 4, y: 8}, - {x: 5, y: 30} - ]); -}); + test('Render two stacked bar series with a non-stacked line series chart', () => { + const $ = mount(); + + const renderedBarsWrapper = $.find(BarSeries); + const renderedLineWrapper = $.find(LineSeries); + expect(renderedBarsWrapper.at(0).prop('data')).toEqual([ + {x: 2, y: 10}, + {x: 4, y: 5}, + {x: 5, y: 15} + ]); + + expect(renderedBarsWrapper.at(1).prop('data')).toEqual([ + {x: 2, y: 22, y0: 10}, + {x: 4, y: 7, y0: 5}, + {x: 5, y: 26, y0: 15} + ]); + + expect(renderedLineWrapper.at(0).prop('data')).toEqual([ + {x: 2, y: 26}, + {x: 4, y: 8}, + {x: 5, y: 30} + ]); + }); -test('Render a line series with data accessors', () => { - const $ = mount( - d[0]} getY={d => d[1]}> - - - ); - - const renderedLineWrapper = $.find(LineSeries); - const dataProp = renderedLineWrapper.at(0).prop('data'); - const getXProp = renderedLineWrapper.at(0).prop('getX'); - const getYProp = renderedLineWrapper.at(0).prop('getY'); - expect(dataProp.map(getXProp)).toEqual([1, 2, 3]); - expect(dataProp.map(getYProp)).toEqual([0, 1, 2]); -}); + test('Render a line series with data accessors', () => { + const $ = mount( + d[0]} getY={d => d[1]}> + + + ); + + const renderedLineWrapper = $.find(LineSeries); + const dataProp = renderedLineWrapper.at(0).prop('data'); + const getXProp = renderedLineWrapper.at(0).prop('getX'); + const getYProp = renderedLineWrapper.at(0).prop('getY'); + expect(dataProp.map(getXProp)).toEqual([1, 2, 3]); + expect(dataProp.map(getYProp)).toEqual([0, 1, 2]); + }); -test('Trigger all onParentMouse handlers on Series components', () => { - const onParentMouseHandler = jest.fn(); - - class ExtendedSeries extends AbstractSeries { - onParentMouseUp = onParentMouseHandler; - onParentMouseDown = onParentMouseHandler; - onParentMouseMove = onParentMouseHandler; - onParentMouseLeave = onParentMouseHandler; - onParentMouseEnter = onParentMouseHandler; - onParentTouchStart = onParentMouseHandler; - onParentTouchMove = onParentMouseHandler; - render() { - return null; + test('Trigger all onParentMouse handlers on Series components', () => { + const onParentMouseHandler = jest.fn(); + + class ExtendedSeries extends AbstractSeries { + onParentMouseUp = onParentMouseHandler; + onParentMouseDown = onParentMouseHandler; + onParentMouseMove = onParentMouseHandler; + onParentMouseLeave = onParentMouseHandler; + onParentMouseEnter = onParentMouseHandler; + onParentTouchStart = onParentMouseHandler; + onParentTouchMove = onParentMouseHandler; + render() { + return null; + } } - } - const $ = mount( - d[0]} getY={d => d[1]}> - - - - ); - $.find('svg') - .at(0) - .simulate('mouseenter'); - $.find('svg') - .at(0) - .simulate('mousedown'); - $.find('svg') - .at(0) - .simulate('mousemove'); - $.find('svg') - .at(0) - .simulate('mouseup'); - $.find('svg') - .at(0) - .simulate('mouseleave'); - $.find('svg') - .at(0) - .simulate('touchstart'); - $.find('svg') - .at(0) - .simulate('touchmove'); - - expect(onParentMouseHandler).toHaveBeenCalledTimes(14); -}); + const $ = mount( + d[0]} getY={d => d[1]}> + + + + ); + $.find('svg') + .at(0) + .simulate('mouseenter'); + $.find('svg') + .at(0) + .simulate('mousedown'); + $.find('svg') + .at(0) + .simulate('mousemove'); + $.find('svg') + .at(0) + .simulate('mouseup'); + $.find('svg') + .at(0) + .simulate('mouseleave'); + $.find('svg') + .at(0) + .simulate('touchstart'); + $.find('svg') + .at(0) + .simulate('touchmove'); + + expect(onParentMouseHandler).toHaveBeenCalledTimes(14); + }); -test('XYPlot dontCheckIfEmpty - Showcase example EmptyChart', () => { - const $ = mount(); - expect($.find('.rv-xy-plot__series').length).toBe(0); - expect($.text()).toBe('1!1.5!2!3!Empty Chart Right Here'); -}); + test('dontCheckIfEmpty - Showcase example EmptyChart', () => { + const $ = mount(); + expect($.find('.rv-xy-plot__series').length).toBe(0); + expect($.text()).toBe('1!1.5!2!3!Empty Chart Right Here'); + }); -test('XYPlot attach ref only to series components', () => { - const Stateless = () => { - return
stateless
; - }; - const $ = mount( - - - - - - - ); - - const clonedChilds = $.instance()._getClonedChildComponents(); - const horizontalGridLinesChild = clonedChilds.find( - element => element.type === HorizontalGridLines - ); - const axisChild = clonedChilds.find(element => element.type === XAxis); - const lineSeriesChild = clonedChilds.find( - element => element.type === LineSeries - ); - const statelessChild = clonedChilds.find( - element => element.type === Stateless - ); - expect(horizontalGridLinesChild.ref === null).toBeTruthy(); - expect(axisChild.ref === null).toBeTruthy(); - expect(typeof lineSeriesChild.ref === 'function').toBeTruthy(); - expect(statelessChild.ref === null).toBeTruthy(); -}); + test('attach ref only to series components', () => { + const Stateless = () => { + return
stateless
; + }; + const $ = mount( + + + + + + + ); + + const clonedChilds = $.instance()._getClonedChildComponents(); + const horizontalGridLinesChild = clonedChilds.find( + element => element.type === HorizontalGridLines + ); + const axisChild = clonedChilds.find(element => element.type === XAxis); + const lineSeriesChild = clonedChilds.find( + element => element.type === LineSeries + ); + const statelessChild = clonedChilds.find( + element => element.type === Stateless + ); + expect(horizontalGridLinesChild.ref === null).toBeTruthy(); + expect(axisChild.ref === null).toBeTruthy(); + expect(typeof lineSeriesChild.ref === 'function').toBeTruthy(); + expect(statelessChild.ref === null).toBeTruthy(); + }); -test('XYPlot with wheel event callback', () => { - const onWheel = jest.fn(); - - const $ = mount( - - - - ); - - $.find('svg') - .at(0) - .simulate('wheel'); - - expect(onWheel).toHaveBeenCalledTimes(1); + test('with wheel event callback', () => { + const onWheel = jest.fn(); + + const $ = mount( + + + + ); + + $.find('svg') + .at(0) + .simulate('wheel'); + + expect(onWheel).toHaveBeenCalledTimes(1); + }); }); diff --git a/packages/react-vis/tests/test-utils.js b/packages/react-vis/tests/test-utils.js index 806953abb..79076bf9e 100644 --- a/packages/react-vis/tests/test-utils.js +++ b/packages/react-vis/tests/test-utils.js @@ -34,6 +34,7 @@ export const GENERIC_XYPLOT_SERIES_PROPS = { }; export const testRenderWithProps = (Component, props) => + // eslint-disable-next-line jest/require-top-level-describe test(`Rendering ${Component.displayName}`, () => { const wrapper = mount(); const wrapperProps = wrapper.props(); diff --git a/packages/react-vis/tests/utils/axis-utils-tests.js b/packages/react-vis/tests/utils/axis-utils-tests.js index 54abe3240..5ec53d752 100644 --- a/packages/react-vis/tests/utils/axis-utils-tests.js +++ b/packages/react-vis/tests/utils/axis-utils-tests.js @@ -29,135 +29,137 @@ import { generatePoints } from 'utils/axis-utils'; -test('axis-utils #getTicksTotalFromSize', () => { - expect(getTicksTotalFromSize(0) === 5).toBeTruthy(); - expect(getTicksTotalFromSize(301) === 10).toBeTruthy(); - expect(getTicksTotalFromSize(701) === 20).toBeTruthy(); -}); - -test('axis-utils #getTickValues', () => { - const scale = scaleLinear() - .domain([0, 1]) - .range(['red', 'blue']); - expect( - getTickValues(scale, 10, false).map(d => Math.round(d * 1000) / 1000) - ).toEqual([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]); - - const predefinedVals = ['got dang', 1, undefined, 'lolz']; - expect(getTickValues(scale, 10, predefinedVals)).toEqual(predefinedVals); -}); +describe('axis-utils', () => { + test('getTicksTotalFromSize', () => { + expect(getTicksTotalFromSize(0) === 5).toBeTruthy(); + expect(getTicksTotalFromSize(301) === 10).toBeTruthy(); + expect(getTicksTotalFromSize(701) === 20).toBeTruthy(); + }); -test('axis-utils #getAxisAngle', () => { - expect(getAxisAngle({x: 0, y: 0}, {x: 1, y: 1})).toBe(Math.PI / 4); - expect(getAxisAngle({x: 0, y: 0}, {x: 0, y: 1})).toBe(Math.PI / 2); - expect(getAxisAngle({x: 0, y: 0}, {x: 0, y: -1})).toBe((3 * Math.PI) / 2); -}); + test('getTickValues', () => { + const scale = scaleLinear() + .domain([0, 1]) + .range(['red', 'blue']); + expect( + getTickValues(scale, 10, false).map(d => Math.round(d * 1000) / 1000) + ).toEqual([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]); -test('axis-utils #generateFit', () => { - expect(generateFit({x: 0, y: 0}, {x: 1, y: 1})).toEqual({ - left: 0, - offset: 0, - right: 1, - slope: 1 - }); - expect(generateFit({x: 0, y: 0}, {x: 0, y: 1})).toEqual({ - left: 0, - offset: 0, - right: 1, - slope: 0 + const predefinedVals = ['got dang', 1, undefined, 'lolz']; + expect(getTickValues(scale, 10, predefinedVals)).toEqual(predefinedVals); }); - expect(generateFit({x: 0, y: 0}, {x: 0, y: -1})).toEqual({ - left: 0, - offset: 0, - right: -1, - slope: 0 - }); - const result = generateFit( - {x: 175, y: 125}, - {x: 17.33044811707665, y: 179.23546738969475} - ); - const numberOfTicks = 5; - const left = result.left; - const right = result.right; - const pointSlope = (right - left) / numberOfTicks; - const lengthOfGeneratedPoints = range(left, right + pointSlope, pointSlope) - .length; - expect(lengthOfGeneratedPoints).toBe(7); -}); -test('axis-utils #generatePoints', () => { - const result = generatePoints({ - axisStart: {x: 0, y: 1}, - axisEnd: {x: 1, y: 1}, - numberOfTicks: 5, - axisDomain: [10, 100] - }); - const expectedResult = { - points: [ - {text: 10, y: 1, x: 0}, - {text: 28, y: 1, x: 0.2}, - {text: 46, y: 1, x: 0.4}, - {text: 64, y: 1, x: 0.6000000000000001}, - {text: 82, y: 1, x: 0.8}, - {text: 100, y: 1, x: 1} - ], - slope: -0 - }; - // const result2 = generatePoints({ - // axisStart: {x: 175, y: 125}, - // axisEnd: {x: 17.33044811707665, y: 179.23546738969475}, - // numberOfTicks: 5, - // axisDomain: [0, 100] - // }); - const expectedResult2 = { - points: [ - {text: 0, y: 125.00000000000001, x: 175}, - {text: 20, y: 135.84709347793896, x: 143.46608962341534}, - {text: 40, y: 146.6941869558779, x: 111.93217924683066}, - {text: 59.99999999999999, y: 157.54128043381687, x: 80.398268870246}, - {text: 80, y: 168.38837391175582, x: 48.86435849366133}, - {text: 100, y: 179.23546738969478, x: 17.330448117076656} - ], - slope: -0.34398187057680607 - }; - const result3 = generatePoints({ - axisStart: {x: 175, y: 125}, - axisEnd: {x: 175, y: 250}, - numberOfTicks: 5, - axisDomain: [0, 100] + test('getAxisAngle', () => { + expect(getAxisAngle({x: 0, y: 0}, {x: 1, y: 1})).toBe(Math.PI / 4); + expect(getAxisAngle({x: 0, y: 0}, {x: 0, y: 1})).toBe(Math.PI / 2); + expect(getAxisAngle({x: 0, y: 0}, {x: 0, y: -1})).toBe((3 * Math.PI) / 2); }); - const expectedResult3 = { - points: [ - {text: 0, y: 125, x: 175}, - {text: 20, y: 150, x: 175}, - {text: 40, y: 175, x: 175}, - {text: 60, y: 200, x: 175}, - {text: 80, y: 225, x: 175}, - {text: 100, y: 250, x: 175} - ], - slope: Infinity - }; - const result4 = generatePoints({ - axisStart: {x: 175, y: 125}, - axisEnd: {x: 174.99999999999997, y: 250}, - numberOfTicks: 5, - axisDomain: [0, 100] + + test('generateFit', () => { + expect(generateFit({x: 0, y: 0}, {x: 1, y: 1})).toEqual({ + left: 0, + offset: 0, + right: 1, + slope: 1 + }); + expect(generateFit({x: 0, y: 0}, {x: 0, y: 1})).toEqual({ + left: 0, + offset: 0, + right: 1, + slope: 0 + }); + expect(generateFit({x: 0, y: 0}, {x: 0, y: -1})).toEqual({ + left: 0, + offset: 0, + right: -1, + slope: 0 + }); + const result = generateFit( + {x: 175, y: 125}, + {x: 17.33044811707665, y: 179.23546738969475} + ); + const numberOfTicks = 5; + const left = result.left; + const right = result.right; + const pointSlope = (right - left) / numberOfTicks; + const lengthOfGeneratedPoints = range(left, right + pointSlope, pointSlope) + .length; + expect(lengthOfGeneratedPoints).toBe(7); }); - const expectedResult4 = { - points: [ - {text: 0, y: 128, x: 175}, - {text: 0, y: 128, x: 175}, - {text: 0, y: 128, x: 175}, - {text: 100, y: 256, x: 174.99999999999997}, - {text: 100, y: 256, x: 174.99999999999997} - ], - slope: -4398046511104000 - }; - expect(result).toEqual(expectedResult); - // Relies on testing library to handle differences in floating point numbers. - // t.deepEqual(result2, expectedResult2); - expect(expectedResult2.points.length).toBe(6); - expect(result3).toEqual(expectedResult3); - expect(result4).toEqual(expectedResult4); + test('generatePoints', () => { + const result = generatePoints({ + axisStart: {x: 0, y: 1}, + axisEnd: {x: 1, y: 1}, + numberOfTicks: 5, + axisDomain: [10, 100] + }); + const expectedResult = { + points: [ + {text: 10, y: 1, x: 0}, + {text: 28, y: 1, x: 0.2}, + {text: 46, y: 1, x: 0.4}, + {text: 64, y: 1, x: 0.6000000000000001}, + {text: 82, y: 1, x: 0.8}, + {text: 100, y: 1, x: 1} + ], + slope: -0 + }; + // const result2 = generatePoints({ + // axisStart: {x: 175, y: 125}, + // axisEnd: {x: 17.33044811707665, y: 179.23546738969475}, + // numberOfTicks: 5, + // axisDomain: [0, 100] + // }); + const expectedResult2 = { + points: [ + {text: 0, y: 125.00000000000001, x: 175}, + {text: 20, y: 135.84709347793896, x: 143.46608962341534}, + {text: 40, y: 146.6941869558779, x: 111.93217924683066}, + {text: 59.99999999999999, y: 157.54128043381687, x: 80.398268870246}, + {text: 80, y: 168.38837391175582, x: 48.86435849366133}, + {text: 100, y: 179.23546738969478, x: 17.330448117076656} + ], + slope: -0.34398187057680607 + }; + const result3 = generatePoints({ + axisStart: {x: 175, y: 125}, + axisEnd: {x: 175, y: 250}, + numberOfTicks: 5, + axisDomain: [0, 100] + }); + const expectedResult3 = { + points: [ + {text: 0, y: 125, x: 175}, + {text: 20, y: 150, x: 175}, + {text: 40, y: 175, x: 175}, + {text: 60, y: 200, x: 175}, + {text: 80, y: 225, x: 175}, + {text: 100, y: 250, x: 175} + ], + slope: Infinity + }; + const result4 = generatePoints({ + axisStart: {x: 175, y: 125}, + axisEnd: {x: 174.99999999999997, y: 250}, + numberOfTicks: 5, + axisDomain: [0, 100] + }); + const expectedResult4 = { + points: [ + {text: 0, y: 128, x: 175}, + {text: 0, y: 128, x: 175}, + {text: 0, y: 128, x: 175}, + {text: 100, y: 256, x: 174.99999999999997}, + {text: 100, y: 256, x: 174.99999999999997} + ], + slope: -4398046511104000 + }; + expect(result).toEqual(expectedResult); + + // Relies on testing library to handle differences in floating point numbers. + // t.deepEqual(result2, expectedResult2); + expect(expectedResult2.points.length).toBe(6); + expect(result3).toEqual(expectedResult3); + expect(result4).toEqual(expectedResult4); + }); }); diff --git a/packages/react-vis/tests/utils/chart-utils-tests.js b/packages/react-vis/tests/utils/chart-utils-tests.js index f98770e5e..9f74f6a56 100644 --- a/packages/react-vis/tests/utils/chart-utils-tests.js +++ b/packages/react-vis/tests/utils/chart-utils-tests.js @@ -20,25 +20,27 @@ import {getRadialLayoutMargin} from 'utils/chart-utils'; -test('chart-utils #getRadialLayoutMargin', () => { - expect(getRadialLayoutMargin(500, 300, 120)).toEqual({ - bottom: 30, - left: 130, - right: 130, - top: 30 - }); +describe('chart-utils', () => { + test('getRadialLayoutMargin', () => { + expect(getRadialLayoutMargin(500, 300, 120)).toEqual({ + bottom: 30, + left: 130, + right: 130, + top: 30 + }); - expect(getRadialLayoutMargin(300, 500, 120)).toEqual({ - bottom: 130, - left: 30, - right: 30, - top: 130 - }); + expect(getRadialLayoutMargin(300, 500, 120)).toEqual({ + bottom: 130, + left: 30, + right: 30, + top: 130 + }); - expect(getRadialLayoutMargin(300, 300, 120)).toEqual({ - bottom: 30, - left: 30, - right: 30, - top: 30 + expect(getRadialLayoutMargin(300, 300, 120)).toEqual({ + bottom: 30, + left: 30, + right: 30, + top: 30 + }); }); }); diff --git a/packages/react-vis/tests/utils/data-utils-tests.js b/packages/react-vis/tests/utils/data-utils-tests.js index 01b647abf..6e6747b28 100644 --- a/packages/react-vis/tests/utils/data-utils-tests.js +++ b/packages/react-vis/tests/utils/data-utils-tests.js @@ -26,22 +26,26 @@ import { const arr = [{a: 1}, {b: 3, a: 2}, {a: 2}]; -test('data-utils #getUniquePropertyValues', () => { - const result = getUniquePropertyValues(arr, d => d.a); - expect(result.length === 2).toBeTruthy(); - expect(result.indexOf(1) !== -1 && result.indexOf(2) !== -1).toBeTruthy(); -}); +describe('data-utils', () => { + test('getUniquePropertyValues', () => { + const result = getUniquePropertyValues(arr, d => d.a); + expect(result.length === 2).toBeTruthy(); + expect(result.indexOf(1) !== -1 && result.indexOf(2) !== -1).toBeTruthy(); + }); -test('data-utils #addValueToArray', () => { - expect(addValueToArray([-10, 10], 1)).toEqual([-10, 10]); - expect(addValueToArray([-10, 0], 1)).toEqual([-10, 1]); - expect(addValueToArray([0, 10], -1)).toEqual([-1, 10]); -}); + test('addValueToArray', () => { + expect(addValueToArray([-10, 10], 1)).toEqual([-10, 10]); + expect(addValueToArray([-10, 0], 1)).toEqual([-10, 1]); + expect(addValueToArray([0, 10], -1)).toEqual([-1, 10]); + }); -test('data-utils #transformValueToString', () => { - expect(transformValueToString(0)).toEqual(0); + test('transformValueToString', () => { + expect(transformValueToString(0)).toEqual(0); - // 43200000 - this is the timestamp for 12PM on 1970-01-01 - // This plays much nicer when running tests locally for different timezones. - expect(transformValueToString(new Date(43200000))).toEqual('Thu Jan 01 1970'); + // 43200000 - this is the timestamp for 12PM on 1970-01-01 + // This plays much nicer when running tests locally for different timezones. + expect(transformValueToString(new Date(43200000))).toEqual( + 'Thu Jan 01 1970' + ); + }); }); diff --git a/packages/react-vis/tests/utils/react-utils-tests.js b/packages/react-vis/tests/utils/react-utils-tests.js index 1f9d7a156..845cafb27 100644 --- a/packages/react-vis/tests/utils/react-utils-tests.js +++ b/packages/react-vis/tests/utils/react-utils-tests.js @@ -1,5 +1,7 @@ import {isReactDOMSupported} from 'utils/react-utils'; -test('react-utils #isReactDOMSupported', () => { - expect(isReactDOMSupported()).toBeTruthy(); +describe('react-utils', () => { + test('isReactDOMSupported', () => { + expect(isReactDOMSupported()).toBeTruthy(); + }); }); diff --git a/packages/react-vis/tests/utils/scales-utils-tests.js b/packages/react-vis/tests/utils/scales-utils-tests.js index e1af64b69..670b02a50 100644 --- a/packages/react-vis/tests/utils/scales-utils-tests.js +++ b/packages/react-vis/tests/utils/scales-utils-tests.js @@ -54,513 +54,520 @@ const xDomain = [1, 5]; const xType = 'ordinal'; const xDistance = 10; -test('scales-utils #getScaleObjectFromProps ', () => { - // with empty props - const nullResult = getScaleObjectFromProps({}, 'x'); - expect(nullResult).toBe(null); - // with empty domain - const noRangeResult = getScaleObjectFromProps({xDomain}, 'x'); - expect(noRangeResult).toBe(null); - // with empty range - const noDomainResult = getScaleObjectFromProps({xRange}, 'x'); - expect(noDomainResult).toBe(null); - - // with all props - const completeResult = getScaleObjectFromProps( - {xRange, _allData, xDomain, xType, xDistance}, - 'x' - ); - expect(isScaleConsistent(completeResult, 'x')).toBeTruthy(); - expect(completeResult.type).toBe(xType); - // does not mutate passed domain - const tXDomain = [1, 5]; - const scaleObj = getScaleObjectFromProps( - { - xRange, - _adjustBy: ['x'], - _adjustWhat: [0], - _allData, - xDomain: tXDomain, - xDistance - }, - 'x' - ); +describe('scales-utils', () => { + test('getScaleObjectFromProps ', () => { + // with empty props + const nullResult = getScaleObjectFromProps({}, 'x'); + expect(nullResult).toBe(null); + // with empty domain + const noRangeResult = getScaleObjectFromProps({xDomain}, 'x'); + expect(noRangeResult).toBe(null); + // with empty range + const noDomainResult = getScaleObjectFromProps({xRange}, 'x'); + expect(noDomainResult).toBe(null); + + // with all props + const completeResult = getScaleObjectFromProps( + {xRange, _allData, xDomain, xType, xDistance}, + 'x' + ); + expect(isScaleConsistent(completeResult, 'x')).toBeTruthy(); + expect(completeResult.type).toBe(xType); + // does not mutate passed domain + const tXDomain = [1, 5]; + const scaleObj = getScaleObjectFromProps( + { + xRange, + _adjustBy: ['x'], + _adjustWhat: [0], + _allData, + xDomain: tXDomain, + xDistance + }, + 'x' + ); - expect(scaleObj.domain).toEqual([0.5, 5.5]); - expect(tXDomain).toEqual([1, 5]); + expect(scaleObj.domain).toEqual([0.5, 5.5]); + expect(tXDomain).toEqual([1, 5]); - // with the value that overrides props - const valueResult = getScaleObjectFromProps({x: 10, _allData}, 'x'); - expect(isScaleConsistent(valueResult, 'x')).toBeTruthy(); - expect(valueResult.isValue).toBe(true); -}); + // with the value that overrides props + const valueResult = getScaleObjectFromProps({x: 10, _allData}, 'x'); + expect(isScaleConsistent(valueResult, 'x')).toBeTruthy(); + expect(valueResult.isValue).toBe(true); + }); -test('scales-utils #getScalePropTypesByAttribute', () => { - const result = Object.keys(getScalePropTypesByAttribute('size')); - const expectedResult = [ - '_sizeValue', - 'sizeDomain', - 'getSize', - 'getSize0', - 'sizeRange', - 'sizeType', - 'sizeDistance', - 'sizeBaseValue' - ]; - expect(result).toEqual(expectedResult); -}); + test('getScalePropTypesByAttribute', () => { + const result = Object.keys(getScalePropTypesByAttribute('size')); + const expectedResult = [ + '_sizeValue', + 'sizeDomain', + 'getSize', + 'getSize0', + 'sizeRange', + 'sizeType', + 'sizeDistance', + 'sizeBaseValue' + ]; + expect(result).toEqual(expectedResult); + }); -test('scales-utils #getAttributeFunctor', () => { - // without props - let result = getAttributeFunctor({_xValue}, 'x'); - expect(result({x: Math.random()}) === _xValue).toBeTruthy(); - expect(result({})).toBe(_xValue); - // with props - result = getAttributeFunctor({xRange, xDomain}, 'x'); - const isFunction = typeof result === 'function'; - expect(isFunction).toBeTruthy(); - expect(result(_allData[0][0])).toBe(xRange[0]); + test('getAttributeFunctor', () => { + // without props + let result = getAttributeFunctor({_xValue}, 'x'); + expect(result({x: Math.random()}) === _xValue).toBeTruthy(); + expect(result({})).toBe(_xValue); + // with props + result = getAttributeFunctor({xRange, xDomain}, 'x'); + const isFunction = typeof result === 'function'; + expect(isFunction).toBeTruthy(); + expect(result(_allData[0][0])).toBe(xRange[0]); - expect(result({data: {x: 10}})).toBe(225); + expect(result({data: {x: 10}})).toBe(225); - // with custom accessor - result = getAttributeFunctor({xRange, xDomain, getX: d => d.value}, 'x'); - expect(typeof result === 'function').toBeTruthy(); + // with custom accessor + result = getAttributeFunctor({xRange, xDomain, getX: d => d.value}, 'x'); + expect(typeof result === 'function').toBeTruthy(); - expect(result({data: {x: 10, value: 1}})).toBe(0); -}); + expect(result({data: {x: 10, value: 1}})).toBe(0); + }); -test('scales-utils #getAttr0Functor', () => { - // without props - let result = getAttr0Functor({}, 'x'); - expect(null).toBe(null); - - // using a literal scale to check that the fall back is working correctly - const exNaughtData = [[{x: 1, x0: 1}, {x: 0}, {x: 3, x0: 3}, {x: 2, x0: 4}]]; - result = getAttr0Functor( - { - xRange, - _allData: exNaughtData, - xDomain, - xType: 'literal', - xDistance - }, - 'x' - ); - expect(typeof result === 'function').toBeTruthy(); - expect(result(exNaughtData[0][0])).toBe(1); - expect(result(exNaughtData[0][1])).toBe(1); - - expect(result({data: {x: 10, x0: 5}})).toBe(5); - - // with custom accessor - result = getAttr0Functor( - { - xRange, - _allData: exNaughtData, - getX0: d => d.z, - xDomain, - xType: 'literal', - xDistance - }, - 'x' - ); - expect(typeof result === 'function').toBeTruthy(); - expect(result({data: {x: 10, x0: 5, z: 1}})).toBe(1); - - // now with a linear scale - result = getAttr0Functor( - { - xRange, - _allData: exNaughtData, - xDomain, - xType: 'linear', - xDistance - }, - 'x' - ); + test('getAttr0Functor', () => { + // without props + let result = getAttr0Functor({}, 'x'); + expect(null).toBe(null); - expect(typeof result === 'function').toBeTruthy(); - expect(result(exNaughtData[0][0])).toBe(xRange[0]); - expect(result(exNaughtData[0][1])).toBe(0); + // using a literal scale to check that the fall back is working correctly + const exNaughtData = [ + [{x: 1, x0: 1}, {x: 0}, {x: 3, x0: 3}, {x: 2, x0: 4}] + ]; + result = getAttr0Functor( + { + xRange, + _allData: exNaughtData, + xDomain, + xType: 'literal', + xDistance + }, + 'x' + ); + expect(typeof result === 'function').toBeTruthy(); + expect(result(exNaughtData[0][0])).toBe(1); + expect(result(exNaughtData[0][1])).toBe(1); - expect(result({data: {x: 10, x0: 5}})).toBe(100); -}); + expect(result({data: {x: 10, x0: 5}})).toBe(5); -test('scales-utils #getAttributeScale', () => { - // without props - let result = getAttributeScale({}, 'x'); - expect(result === null).toBeTruthy(); - // with props - result = getAttributeScale({xRange, xDomain}, 'x'); - const isFunction = typeof result === 'function'; - expect(isFunction).toBeTruthy(); - expect(result(_allData[0][0].x)).toBe(xRange[0]); -}); + // with custom accessor + result = getAttr0Functor( + { + xRange, + _allData: exNaughtData, + getX0: d => d.z, + xDomain, + xType: 'literal', + xDistance + }, + 'x' + ); + expect(typeof result === 'function').toBeTruthy(); + expect(result({data: {x: 10, x0: 5, z: 1}})).toBe(1); -test('scales-utils #getAttributeValue ', () => { - // without props - let result = getAttributeValue({_xValue}, 'x'); - expect(result === _xValue).toBeTruthy(); - // with props - result = getAttributeValue({x: 10}, 'x'); - expect(result).toBe(10); - // with props including a scale type - result = getAttributeValue({opacity: 0.5, opacityType: 'literal'}, 'opacity'); - expect(result).toBe(0.5); -}); + // now with a linear scale + result = getAttr0Functor( + { + xRange, + _allData: exNaughtData, + xDomain, + xType: 'linear', + xDistance + }, + 'x' + ); -test('scales-utils #_getSmallestDistanceIndex', () => { - const scaleObj = {type: 'linear', domain: [0, 1], range: [0, 1]}; - const runTest = arg => _getSmallestDistanceIndex(arg, scaleObj); + expect(typeof result === 'function').toBeTruthy(); + expect(result(exNaughtData[0][0])).toBe(xRange[0]); + expect(result(exNaughtData[0][1])).toBe(0); - expect(runTest([0, 0, 2])).toBe(1); - expect(runTest([0, 1, 2])).toBe(1); - expect(runTest([0, 2, 2])).toBe(2); - expect(runTest([0, 2, 2])).toBe(2); - expect(runTest([1, 2, 2])).toBe(2); - expect(runTest([2, 2, 2])).toBe(1); -}); + expect(result({data: {x: 10, x0: 5}})).toBe(100); + }); -test('scales-utils #extractScalePropsFromProps', () => { - expect( - Object.keys(extractScalePropsFromProps({}, [])).length === 0 - ).toBeTruthy(); - - const props = { - aType: 'linear', - aRange: [1, 2], - _aValue: 10, - somethingElse: [], - bDomain: [1, 2, 3], - getA: d => d.a - }; - - const result = extractScalePropsFromProps(props, ['a', 'b']); - expect( - Object.keys(result).length === 5 && - result.aType === props.aType && - result.aRange === props.aRange && - result._aValue === props._aValue && - result.bDomain === props.bDomain && - result.getA === props.getA - ).toBeTruthy(); -}); + test('getAttributeScale', () => { + // without props + let result = getAttributeScale({}, 'x'); + expect(result === null).toBeTruthy(); + // with props + result = getAttributeScale({xRange, xDomain}, 'x'); + const isFunction = typeof result === 'function'; + expect(isFunction).toBeTruthy(); + expect(result(_allData[0][0].x)).toBe(xRange[0]); + }); -test('scales-utils #getMissingScaleProps', () => { - const fakeDataInteger = [ - {x: 10, y: 10}, - {x: 15, y: 15}, - {x: 20, y: 20} - ]; - const fakeDataIntegerDomain = [9, 21]; - const fakeDataString = [{x: 'React'}, {x: 'Vis'}]; - const fakeDataStringDomain = ['React', 'Vis']; - const dayOne = 971136000; - const dayTen = 972000000; - const fakeDomain = [0, 100]; - const fakeDataUnixTime = [{x: dayOne}, {x: dayTen}]; - const paddedDayOne = dayOne - (dayTen - dayOne) * 0.1; - const paddedDayTen = dayTen + (dayTen - dayOne) * 0.1; - const fakePadding = 10; - - expect(Object.keys(getMissingScaleProps({}, [], [])).length).toBe(0); - const result = getMissingScaleProps({}, _allData[0], ['x']); - expect( - Boolean(result.xDomain) && - result.xDomain.length === 2 && - result.xDomain[0] === 1 && - result.xDomain[1] === 3 - ).toBeTruthy(); - - expect( - getMissingScaleProps( - { - xPadding: fakePadding - }, - fakeDataInteger, - ['x'] - ).xDomain - ).toEqual(fakeDataIntegerDomain); - // need to use json stringify to peel off the functions - expect( - JSON.stringify( + test('getAttributeValue ', () => { + // without props + let result = getAttributeValue({_xValue}, 'x'); + expect(result === _xValue).toBeTruthy(); + // with props + result = getAttributeValue({x: 10}, 'x'); + expect(result).toBe(10); + // with props including a scale type + result = getAttributeValue( + {opacity: 0.5, opacityType: 'literal'}, + 'opacity' + ); + expect(result).toBe(0.5); + }); + + test('_getSmallestDistanceIndex', () => { + const scaleObj = {type: 'linear', domain: [0, 1], range: [0, 1]}; + const runTest = arg => _getSmallestDistanceIndex(arg, scaleObj); + + expect(runTest([0, 0, 2])).toBe(1); + expect(runTest([0, 1, 2])).toBe(1); + expect(runTest([0, 2, 2])).toBe(2); + expect(runTest([0, 2, 2])).toBe(2); + expect(runTest([1, 2, 2])).toBe(2); + expect(runTest([2, 2, 2])).toBe(1); + }); + + test('extractScalePropsFromProps', () => { + expect( + Object.keys(extractScalePropsFromProps({}, [])).length === 0 + ).toBeTruthy(); + + const props = { + aType: 'linear', + aRange: [1, 2], + _aValue: 10, + somethingElse: [], + bDomain: [1, 2, 3], + getA: d => d.a + }; + + const result = extractScalePropsFromProps(props, ['a', 'b']); + expect( + Object.keys(result).length === 5 && + result.aType === props.aType && + result.aRange === props.aRange && + result._aValue === props._aValue && + result.bDomain === props.bDomain && + result.getA === props.getA + ).toBeTruthy(); + }); + + test('getMissingScaleProps', () => { + const fakeDataInteger = [ + {x: 10, y: 10}, + {x: 15, y: 15}, + {x: 20, y: 20} + ]; + const fakeDataIntegerDomain = [9, 21]; + const fakeDataString = [{x: 'React'}, {x: 'Vis'}]; + const fakeDataStringDomain = ['React', 'Vis']; + const dayOne = 971136000; + const dayTen = 972000000; + const fakeDomain = [0, 100]; + const fakeDataUnixTime = [{x: dayOne}, {x: dayTen}]; + const paddedDayOne = dayOne - (dayTen - dayOne) * 0.1; + const paddedDayTen = dayTen + (dayTen - dayOne) * 0.1; + const fakePadding = 10; + + expect(Object.keys(getMissingScaleProps({}, [], [])).length).toBe(0); + const result = getMissingScaleProps({}, _allData[0], ['x']); + expect( + Boolean(result.xDomain) && + result.xDomain.length === 2 && + result.xDomain[0] === 1 && + result.xDomain[1] === 3 + ).toBeTruthy(); + + expect( getMissingScaleProps( { - xPadding: fakePadding, - xDomain: fakeDomain + xPadding: fakePadding }, fakeDataInteger, ['x'] + ).xDomain + ).toEqual(fakeDataIntegerDomain); + // need to use json stringify to peel off the functions + expect( + JSON.stringify( + getMissingScaleProps( + { + xPadding: fakePadding, + xDomain: fakeDomain + }, + fakeDataInteger, + ['x'] + ) ) - ) - ).toEqual('{}'); - expect( - Object.keys( + ).toEqual('{}'); + expect( + Object.keys( + getMissingScaleProps( + { + xPadding: fakePadding, + xDomain: fakeDomain + }, + fakeDataInteger, + ['x'] + ) + ) + ).toEqual(['getX', 'getX0']); + expect( getMissingScaleProps( { - xPadding: fakePadding, - xDomain: fakeDomain + yPadding: fakePadding }, fakeDataInteger, + ['y'] + ).yDomain + ).toEqual(fakeDataIntegerDomain); + expect( + getMissingScaleProps( + { + xPadding: fakePadding + }, + fakeDataString, ['x'] - ) - ) - ).toEqual(['getX', 'getX0']); - expect( - getMissingScaleProps( - { - yPadding: fakePadding - }, - fakeDataInteger, - ['y'] - ).yDomain - ).toEqual(fakeDataIntegerDomain); - expect( - getMissingScaleProps( - { - xPadding: fakePadding - }, - fakeDataString, - ['x'] - ).xDomain - ).toEqual(fakeDataStringDomain); - expect( - getMissingScaleProps( - { - xPadding: fakePadding - }, - fakeDataUnixTime, - ['x'] - ).xDomain - ).toEqual([paddedDayOne, paddedDayTen]); -}); - -test('scales-utils #literalScale', () => { - const s = literalScale(5); - - expect(s(0.5)).toBe(0.5); - expect(s(1)).toBe(1); - expect(s(1.5)).toBe(1.5); - expect(s(2)).toBe(2); - expect(s(2.5)).toBe(2.5); - expect(s()).toBe(5); - expect(s('2')).toBe('2'); -}); - -test('scales-utils #getFontColorFromBackground', () => { - expect(getFontColorFromBackground('#fff')).toBe('#222'); - expect(getFontColorFromBackground('#000')).toBe('#fff'); - expect(getFontColorFromBackground(null)).toBe(null); -}); - -test('scales-utils #getScaleFnFromScaleObject', () => { - expect(getScaleFnFromScaleObject()).toBe(null); - const linearScale = getScaleFnFromScaleObject({ - type: 'linear', - domain: [0, 1], - range: [1, 0] - }); - - const literalScaleWithDefaultValue = getScaleFnFromScaleObject({ - type: 'literal', - domain: [], - range: [5] + ).xDomain + ).toEqual(fakeDataStringDomain); + expect( + getMissingScaleProps( + { + xPadding: fakePadding + }, + fakeDataUnixTime, + ['x'] + ).xDomain + ).toEqual([paddedDayOne, paddedDayTen]); }); - expect(linearScale.domain()).toEqual([0, 1]); - expect(linearScale.range()).toEqual([1, 0]); - - expect(literalScaleWithDefaultValue()).toEqual(5); - expect(literalScaleWithDefaultValue(2)).toEqual(2); + test('literalScale', () => { + const s = literalScale(5); - const modScaleWithZero = getScaleFnFromScaleObject({ - type: 'linear', - domain: [0, 0], - range: [1, 0] + expect(s(0.5)).toBe(0.5); + expect(s(1)).toBe(1); + expect(s(1.5)).toBe(1.5); + expect(s(2)).toBe(2); + expect(s(2.5)).toBe(2.5); + expect(s()).toBe(5); + expect(s('2')).toBe('2'); }); - expect(modScaleWithZero.domain()).toEqual([-1, 0]); - const modScale = getScaleFnFromScaleObject({ - type: 'linear', - domain: [1, 1], - range: [1, 0] + test('getFontColorFromBackground', () => { + expect(getFontColorFromBackground('#fff')).toBe('#222'); + expect(getFontColorFromBackground('#000')).toBe('#fff'); + expect(getFontColorFromBackground(null)).toBe(null); }); - expect(modScale.domain()).toEqual([-1, 1]); - const ordinalScale = getScaleFnFromScaleObject({ - type: 'ordinal', - domain: ['a', 'b', 'c', 'd', 'e'], - range: [20, 120] + test('getScaleFnFromScaleObject', () => { + expect(getScaleFnFromScaleObject()).toBe(null); + const linearScale = getScaleFnFromScaleObject({ + type: 'linear', + domain: [0, 1], + range: [1, 0] + }); + + const literalScaleWithDefaultValue = getScaleFnFromScaleObject({ + type: 'literal', + domain: [], + range: [5] + }); + + expect(linearScale.domain()).toEqual([0, 1]); + expect(linearScale.range()).toEqual([1, 0]); + + expect(literalScaleWithDefaultValue()).toEqual(5); + expect(literalScaleWithDefaultValue(2)).toEqual(2); + + const modScaleWithZero = getScaleFnFromScaleObject({ + type: 'linear', + domain: [0, 0], + range: [1, 0] + }); + expect(modScaleWithZero.domain()).toEqual([-1, 0]); + + const modScale = getScaleFnFromScaleObject({ + type: 'linear', + domain: [1, 1], + range: [1, 0] + }); + expect(modScale.domain()).toEqual([-1, 1]); + + const ordinalScale = getScaleFnFromScaleObject({ + type: 'ordinal', + domain: ['a', 'b', 'c', 'd', 'e'], + range: [20, 120] + }); + + expect(ordinalScale.invert(-10)).toBe('a'); + expect(ordinalScale.invert(25)).toBe('a'); + expect(ordinalScale.invert(40)).toBe('a'); + expect(ordinalScale.invert(60)).toBe('b'); + expect(ordinalScale.invert(80)).toBe('c'); + expect(ordinalScale.invert(100)).toBe('d'); + expect(ordinalScale.invert(115)).toBe('e'); + expect(ordinalScale.invert(130)).toBe('e'); }); - expect(ordinalScale.invert(-10)).toBe('a'); - expect(ordinalScale.invert(25)).toBe('a'); - expect(ordinalScale.invert(40)).toBe('a'); - expect(ordinalScale.invert(60)).toBe('b'); - expect(ordinalScale.invert(80)).toBe('c'); - expect(ordinalScale.invert(100)).toBe('d'); - expect(ordinalScale.invert(115)).toBe('e'); - expect(ordinalScale.invert(130)).toBe('e'); -}); - -function generateFakeData() { - return new Array(100).fill(0).map((zero, i) => ({xxxx: i})); -} - -test('scales-utils #_getScaleDistanceAndAdjustedDomain', () => { - const FAKE_DATA = generateFakeData(); - const scaleObject = { - attr: 'x', - domain: [0, 100], - range: [0, 1], - type: 'linear', - // the extra x's are here to test the accessor behaviour - accessor: d => d.xxxx - }; - const resultObject = _getScaleDistanceAndAdjustedDomain( - FAKE_DATA, - scaleObject - ); - const expectedResults = { - distance: 0.009900990099009799, - domain0: -0.5, - domainN: 100.5 - }; - expect(resultObject).toEqual(expectedResults); - - const FAKE_TIME_DATA_WITH_ONE_VALUE_AND_X0 = [ - { - x: 1422774000000, - x0: 1420095600000, - y: 16 - } - ]; - - const FAKE_TIME_DATA_WITH_ONE_VALUE_AND_Y0 = [ - { - x: 16, - y0: 1420095600000, - y: 1422774000000 - } - ]; - - const timeScaleObjectX = { - attr: 'x', - domain: [1417546800000, 1430420400000], - range: [0, 550], - type: 'time', - accessor: d => d.x, - accessor0: d => d.x0 - }; - const timeResultWithOneValueAndX0 = _getScaleDistanceAndAdjustedDomain( - FAKE_TIME_DATA_WITH_ONE_VALUE_AND_X0, - timeScaleObjectX - ); - const expectedTimeResultsWithOneValueAndX0 = { - distance: 94.72222222222223, - domain0: 1416207600000, - domainN: 1431759600000 - }; - expect(timeResultWithOneValueAndX0).toEqual( - expectedTimeResultsWithOneValueAndX0 - ); - - const timeScaleObjectY = { - attr: 'y', - domain: [1417546800000, 1430420400000], - range: [0, 550], - type: 'time', - accessor: d => d.y, - accessor0: d => d.y0 - }; - const timeResultWithOneValueAndY0 = _getScaleDistanceAndAdjustedDomain( - FAKE_TIME_DATA_WITH_ONE_VALUE_AND_Y0, - timeScaleObjectY - ); - const expectedTimeResultsWithOneValueAndY0 = { - distance: 94.72222222222223, - domain0: 1416207600000, - domainN: 1431759600000 - }; - expect(timeResultWithOneValueAndY0).toEqual( - expectedTimeResultsWithOneValueAndY0 - ); + function generateFakeData() { + return new Array(100).fill(0).map((zero, i) => ({xxxx: i})); + } + + test('_getScaleDistanceAndAdjustedDomain', () => { + const FAKE_DATA = generateFakeData(); + const scaleObject = { + attr: 'x', + domain: [0, 100], + range: [0, 1], + type: 'linear', + // the extra x's are here to test the accessor behaviour + accessor: d => d.xxxx + }; + const resultObject = _getScaleDistanceAndAdjustedDomain( + FAKE_DATA, + scaleObject + ); + const expectedResults = { + distance: 0.009900990099009799, + domain0: -0.5, + domainN: 100.5 + }; + expect(resultObject).toEqual(expectedResults); + + const FAKE_TIME_DATA_WITH_ONE_VALUE_AND_X0 = [ + { + x: 1422774000000, + x0: 1420095600000, + y: 16 + } + ]; - const timeResult = _getScaleDistanceAndAdjustedDomain(FAKE_DATA, { - ...timeScaleObjectX, - accessor: d => d.xxxx + const FAKE_TIME_DATA_WITH_ONE_VALUE_AND_Y0 = [ + { + x: 16, + y0: 1420095600000, + y: 1422774000000 + } + ]; + + const timeScaleObjectX = { + attr: 'x', + domain: [1417546800000, 1430420400000], + range: [0, 550], + type: 'time', + accessor: d => d.x, + accessor0: d => d.x0 + }; + const timeResultWithOneValueAndX0 = _getScaleDistanceAndAdjustedDomain( + FAKE_TIME_DATA_WITH_ONE_VALUE_AND_X0, + timeScaleObjectX + ); + const expectedTimeResultsWithOneValueAndX0 = { + distance: 94.72222222222223, + domain0: 1416207600000, + domainN: 1431759600000 + }; + expect(timeResultWithOneValueAndX0).toEqual( + expectedTimeResultsWithOneValueAndX0 + ); + + const timeScaleObjectY = { + attr: 'y', + domain: [1417546800000, 1430420400000], + range: [0, 550], + type: 'time', + accessor: d => d.y, + accessor0: d => d.y0 + }; + const timeResultWithOneValueAndY0 = _getScaleDistanceAndAdjustedDomain( + FAKE_TIME_DATA_WITH_ONE_VALUE_AND_Y0, + timeScaleObjectY + ); + const expectedTimeResultsWithOneValueAndY0 = { + distance: 94.72222222222223, + domain0: 1416207600000, + domainN: 1431759600000 + }; + expect(timeResultWithOneValueAndY0).toEqual( + expectedTimeResultsWithOneValueAndY0 + ); + + const timeResult = _getScaleDistanceAndAdjustedDomain(FAKE_DATA, { + ...timeScaleObjectX, + accessor: d => d.xxxx + }); + const expectedTimeResults = { + distance: 4.272442311048508e-8, + domain0: 1417546799999.5, + domainN: 1430420400000.5 + }; + expect(timeResult).toEqual(expectedTimeResults); + + const logScaleObject = { + attr: 'x', + domain: [-0.5, 1], + range: [1, 10], + type: 'log', + accessor: d => d.xxxx + }; + const logResult = _getScaleDistanceAndAdjustedDomain( + FAKE_DATA, + logScaleObject + ); + const expectedLogResults = {distance: NaN, domain0: 0.1, domainN: 1.5}; + expect(logResult).toEqual(expectedLogResults); }); - const expectedTimeResults = { - distance: 4.272442311048508e-8, - domain0: 1417546799999.5, - domainN: 1430420400000.5 - }; - expect(timeResult).toEqual(expectedTimeResults); - - const logScaleObject = { - attr: 'x', - domain: [-0.5, 1], - range: [1, 10], - type: 'log', - accessor: d => d.xxxx - }; - const logResult = _getScaleDistanceAndAdjustedDomain( - FAKE_DATA, - logScaleObject - ); - const expectedLogResults = {distance: NaN, domain0: 0.1, domainN: 1.5}; - expect(logResult).toEqual(expectedLogResults); -}); - -test('scales-utils getXYPlotValues', () => { - const XYPlotProps = { - colorType: 'linear', - colorRange: ['#000', '#fff'], - colorDomain: [0, 1] - }; - const children = [ - {props: {color: 0}}, - {props: {color: 0.5, opacity: '0.5'}}, - {props: {color: 1}} - ]; - const result = getXYPlotValues(XYPlotProps, children); - expect(result[2]._colorValue).toBe('rgb(255, 255, 255)'); - expect(result[1]._opacityValue).toBe('0.5'); -}); -test('scales-utils #_adjustCategoricalScale', () => { - [ - { - scale: {type: 'category', domain: ['a', 'b', 'c'], range: [0, 10]}, - distance: 10 - }, - { - scale: {type: 'category', domain: ['a'], range: [1, 10]}, - distance: 9 - }, - { - scale: {type: 'ordinal', domain: ['a', 'b', 'c', 'd'], range: [10, 0]}, - distance: 2.5 - }, - { - scale: {type: 'ordinal', domain: ['a'], range: [10, 1]}, - distance: 9 - } - ].forEach(({scale, distance}) => { - expect(_adjustCategoricalScale(scale)).toEqual({...scale, distance}); + test('getXYPlotValues', () => { + const XYPlotProps = { + colorType: 'linear', + colorRange: ['#000', '#fff'], + colorDomain: [0, 1] + }; + const children = [ + {props: {color: 0}}, + {props: {color: 0.5, opacity: '0.5'}}, + {props: {color: 1}} + ]; + const result = getXYPlotValues(XYPlotProps, children); + expect(result[2]._colorValue).toBe('rgb(255, 255, 255)'); + expect(result[1]._opacityValue).toBe('0.5'); }); -}); -test('scale-utils #getOptionalScaleProps', () => { - const foundProps = getOptionalScaleProps({node: 1, x: 2, margins: 4}); - expect(foundProps).toEqual({}); + test('_adjustCategoricalScale', () => { + [ + { + scale: {type: 'category', domain: ['a', 'b', 'c'], range: [0, 10]}, + distance: 10 + }, + { + scale: {type: 'category', domain: ['a'], range: [1, 10]}, + distance: 9 + }, + { + scale: {type: 'ordinal', domain: ['a', 'b', 'c', 'd'], range: [10, 0]}, + distance: 2.5 + }, + { + scale: {type: 'ordinal', domain: ['a'], range: [10, 1]}, + distance: 9 + } + ].forEach(({scale, distance}) => { + expect(_adjustCategoricalScale(scale)).toEqual({...scale, distance}); + }); + }); - const paddingProps = getOptionalScaleProps({ - node: 1, - x: 2, - margins: 4, - coolDogExplosionPadding: 10 + test('getOptionalScaleProps', () => { + const foundProps = getOptionalScaleProps({node: 1, x: 2, margins: 4}); + expect(foundProps).toEqual({}); + + const paddingProps = getOptionalScaleProps({ + node: 1, + x: 2, + margins: 4, + coolDogExplosionPadding: 10 + }); + expect(paddingProps).toEqual({coolDogExplosionPadding: 10}); }); - expect(paddingProps).toEqual({coolDogExplosionPadding: 10}); }); diff --git a/packages/react-vis/tests/utils/series-utils-tests.js b/packages/react-vis/tests/utils/series-utils-tests.js index 343c36eb4..ede450c40 100644 --- a/packages/react-vis/tests/utils/series-utils-tests.js +++ b/packages/react-vis/tests/utils/series-utils-tests.js @@ -33,264 +33,266 @@ import HorizontalBarSeries from 'plot/series/horizontal-rect-series'; import VerticalBarSeries from 'plot/series/vertical-rect-series'; import LabelSeries from 'plot/series/label-series'; -test('series-utils #isSeriesChild', () => { - const series = ; - expect(isSeriesChild(series)).toBeTruthy(); - const axis = ( - - ); - expect(isSeriesChild(axis)).toBeFalsy(); -}); +describe('series-utils', () => { + test('isSeriesChild', () => { + const series = ; + expect(isSeriesChild(series)).toBeTruthy(); + const axis = ( + + ); + expect(isSeriesChild(axis)).toBeFalsy(); + }); -test('series-utils #getSeriesChildren', () => { - const children = [ - This squid is heavy , - , - - ]; - const $ = mount( -
- {children} -
- ); - const expectedChildren = [{...children[2], key: '.$woah'}]; - expect(getSeriesChildren($.props().children)).toEqual(expectedChildren); -}); + test('getSeriesChildren', () => { + const children = [ + This squid is heavy , + , + + ]; + const $ = mount( +
+ {children} +
+ ); + const expectedChildren = [{...children[2], key: '.$woah'}]; + expect(getSeriesChildren($.props().children)).toEqual(expectedChildren); + }); -const arePropsValid = seriesProps => { - return ( - typeof seriesProps._colorValue !== 'undefined' && - typeof seriesProps._opacityValue !== 'undefined' && - typeof seriesProps.sameTypeIndex === 'number' && - typeof seriesProps.sameTypeTotal === 'number' && - typeof seriesProps.seriesIndex === 'number' - ); -}; + const arePropsValid = seriesProps => { + return ( + typeof seriesProps._colorValue !== 'undefined' && + typeof seriesProps._opacityValue !== 'undefined' && + typeof seriesProps.sameTypeIndex === 'number' && + typeof seriesProps.sameTypeTotal === 'number' && + typeof seriesProps.seriesIndex === 'number' + ); + }; -test('series-utils #collectSeriesTypesInfo', () => { - const result = getSeriesPropsFromChildren([ - , - - ]); - expect(result.length === 2).toBeTruthy(); - result.forEach(props => expect(arePropsValid(props)).toBeTruthy()); -}); + test('collectSeriesTypesInfo', () => { + const result = getSeriesPropsFromChildren([ + , + + ]); + expect(result.length === 2).toBeTruthy(); + result.forEach(props => expect(arePropsValid(props)).toBeTruthy()); + }); -test('series-utils #seriesClusterProps', () => { - const result = getSeriesPropsFromChildren([ - , - , - , - - ]); - const expectedClusters = ['alpha', 'beta', 'gamma']; - expect(result.length === 4).toBeTruthy(); - result.forEach(props => { - expect( - props.sameTypeIndex === expectedClusters.indexOf(props.cluster) - ).toBeTruthy(); - expect(props.sameTypeTotal === props.clusters.length).toBeTruthy(); - expect(props.clusters.length === 3).toBeTruthy(); + test('seriesClusterProps', () => { + const result = getSeriesPropsFromChildren([ + , + , + , + + ]); + const expectedClusters = ['alpha', 'beta', 'gamma']; + expect(result.length === 4).toBeTruthy(); + result.forEach(props => { + expect( + props.sameTypeIndex === expectedClusters.indexOf(props.cluster) + ).toBeTruthy(); + expect(props.sameTypeTotal === props.clusters.length).toBeTruthy(); + expect(props.clusters.length === 3).toBeTruthy(); + }); }); -}); -// eslint-disable-next-line max-statements -test('series-utils #getStackedData', () => { - const yData = [ - [ - {y: 2, x: 10}, - {y: 4, x: 5}, - {y: 5, x: 15} - ], - [ - {y: 2, x: 12}, - {y: 4, x: 2}, - {y: 5, x: 11} - ] - ]; + // eslint-disable-next-line max-statements + test('getStackedData', () => { + const yData = [ + [ + {y: 2, x: 10}, + {y: 4, x: 5}, + {y: 5, x: 15} + ], + [ + {y: 2, x: 12}, + {y: 4, x: 2}, + {y: 5, x: 11} + ] + ]; - const stackByYExpected = [ - [ - {x: 2, y: 10}, - {x: 4, y: 5}, - {x: 5, y: 15} - ], - [ - {x: 2, y: 22, y0: 10}, - {x: 4, y: 7, y0: 5}, - {x: 5, y: 26, y0: 15} - ], - undefined - ]; + const stackByYExpected = [ + [ + {x: 2, y: 10}, + {x: 4, y: 5}, + {x: 5, y: 15} + ], + [ + {x: 2, y: 22, y0: 10}, + {x: 4, y: 7, y0: 5}, + {x: 5, y: 26, y0: 15} + ], + undefined + ]; - const stackByXExpected = [ - [ - {y: 2, x: 10}, - {y: 4, x: 5}, - {y: 5, x: 15} - ], - [ - {y: 2, x: 22, x0: 10}, - {y: 4, x: 7, x0: 5}, - {y: 5, x: 26, x0: 15} - ], - null - ]; + const stackByXExpected = [ + [ + {y: 2, x: 10}, + {y: 4, x: 5}, + {y: 5, x: 15} + ], + [ + {y: 2, x: 22, x0: 10}, + {y: 4, x: 7, x0: 5}, + {y: 5, x: 26, x0: 15} + ], + null + ]; - const stackByYExpectedPartial = [ - [ - {x: 2, y: 10}, - {x: 4, y: 5} - ], - [ - {x: 4, y: 7, y0: 5}, - {x: 5, y: 11} - ] - ]; + const stackByYExpectedPartial = [ + [ + {x: 2, y: 10}, + {x: 4, y: 5} + ], + [ + {x: 4, y: 7, y0: 5}, + {x: 5, y: 11} + ] + ]; - const stackByXExpectedPartial = [ - [ - {y: 2, x: 10}, - {y: 4, x: 5} - ], - [ - {y: 4, x: 7, x0: 5}, - {y: 5, x: 11} - ] - ]; + const stackByXExpectedPartial = [ + [ + {y: 2, x: 10}, + {y: 4, x: 5} + ], + [ + {y: 4, x: 7, x0: 5}, + {y: 5, x: 11} + ] + ]; - // Transpose data to flip stacking - const xData = yData.map(arr => arr.map(d => ({x: d.y, y: d.x}))); + // Transpose data to flip stacking + const xData = yData.map(arr => arr.map(d => ({x: d.y, y: d.x}))); - const partialYData = [yData[0].slice(0, 2), yData[1].slice(1)]; - const partialXData = partialYData.map(arr => - arr.map(d => ({x: d.y, y: d.x})) - ); + const partialYData = [yData[0].slice(0, 2), yData[1].slice(1)]; + const partialXData = partialYData.map(arr => + arr.map(d => ({x: d.y, y: d.x})) + ); - let children = [ - , - , -
i think i will by that lamp
- ]; + let children = [ + , + , +
i think i will by that lamp
+ ]; - let results = getStackedData(children, 'y'); - expect(results).toEqual(stackByYExpected); + let results = getStackedData(children, 'y'); + expect(results).toEqual(stackByYExpected); - children = [ - , - , - null - ]; - results = getStackedData(children, 'x'); + children = [ + , + , + null + ]; + results = getStackedData(children, 'x'); - expect(results).toEqual(stackByXExpected); + expect(results).toEqual(stackByXExpected); - children = [ - , - , - , - - ]; - results = getStackedData(children, 'x'); - let expectedResults = [ - ...stackByXExpected.slice(0, 2), - ...stackByXExpected.slice(0, 2) - ]; + children = [ + , + , + , + + ]; + results = getStackedData(children, 'x'); + let expectedResults = [ + ...stackByXExpected.slice(0, 2), + ...stackByXExpected.slice(0, 2) + ]; - expect(results).toEqual(expectedResults); + expect(results).toEqual(expectedResults); - children = [ - , - , - , - - ]; - results = getStackedData(children, 'y'); - expectedResults = [ - ...stackByYExpected.slice(0, 2), - ...stackByYExpected.slice(0, 2) - ]; - expect(results).toEqual(expectedResults); + children = [ + , + , + , + + ]; + results = getStackedData(children, 'y'); + expectedResults = [ + ...stackByYExpected.slice(0, 2), + ...stackByYExpected.slice(0, 2) + ]; + expect(results).toEqual(expectedResults); - children = [ - , - , - , - - ]; - results = getStackedData(children, 'x'); - expectedResults = [...stackByXExpectedPartial, ...stackByXExpectedPartial]; - expect(results).toEqual(expectedResults); + children = [ + , + , + , + + ]; + results = getStackedData(children, 'x'); + expectedResults = [...stackByXExpectedPartial, ...stackByXExpectedPartial]; + expect(results).toEqual(expectedResults); - children = [ - , - , - , - - ]; - results = getStackedData(children, 'y'); - expectedResults = [...stackByYExpectedPartial, ...stackByYExpectedPartial]; + children = [ + , + , + , + + ]; + results = getStackedData(children, 'y'); + expectedResults = [...stackByYExpectedPartial, ...stackByYExpectedPartial]; - expect(results).toEqual(expectedResults); + expect(results).toEqual(expectedResults); - children = [ - , - , - - ]; - results = getStackedData(children, 'y'); - expectedResults = [ - yData[0], - [ - {x: 10, y: 5, y0: 2}, - {x: 5, y: 10, y0: 4}, - {x: 15, y: 12, y0: 5} - ], - yData[1] - ]; - expect(results).toEqual(expectedResults); + children = [ + , + , + + ]; + results = getStackedData(children, 'y'); + expectedResults = [ + yData[0], + [ + {x: 10, y: 5, y0: 2}, + {x: 5, y: 10, y0: 4}, + {x: 15, y: 12, y0: 5} + ], + yData[1] + ]; + expect(results).toEqual(expectedResults); - children = [ - , - , - , - , - - ]; - results = getStackedData(children, 'y'); - expectedResults = [ - ...stackByYExpected.slice(0, 2), - ...stackByYExpected.slice(0, 2), - xData[1] - ]; - expect(results).toEqual(expectedResults); + children = [ + , + , + , + , + + ]; + results = getStackedData(children, 'y'); + expectedResults = [ + ...stackByYExpected.slice(0, 2), + ...stackByYExpected.slice(0, 2), + xData[1] + ]; + expect(results).toEqual(expectedResults); - children = [ - , - , - , - - ]; - results = getStackedData(children, 'y'); - expectedResults = [ - ...stackByYExpected.slice(0, 2), - ...stackByYExpected.slice(0, 2) - ]; + children = [ + , + , + , + + ]; + results = getStackedData(children, 'y'); + expectedResults = [ + ...stackByYExpected.slice(0, 2), + ...stackByYExpected.slice(0, 2) + ]; - expect(results).toEqual(expectedResults); + expect(results).toEqual(expectedResults); + }); }); diff --git a/packages/react-vis/tests/utils/styling-utils-tests.js b/packages/react-vis/tests/utils/styling-utils-tests.js index 6f3e74172..ee089de6e 100644 --- a/packages/react-vis/tests/utils/styling-utils-tests.js +++ b/packages/react-vis/tests/utils/styling-utils-tests.js @@ -20,33 +20,35 @@ import {getCombinedClassName} from 'utils/styling-utils'; -test('styling-utils #getCombinedClassName', () => { - const allValidStringParams = [ - 'test_class--1', - 'test_class--2', - 'test_class--3' - ]; - const expectedAllValidStringParamsCombined = - 'test_class--1 test_class--2 test_class--3'; - const falsyValues = [null, undefined, false, '', 0, NaN]; - const nonStringValues = [ - ['invalid_class--1', 'invalid_class--2'], - {foo: 'bar'}, - 123, - () => { - return 'invalid_class--3'; - } - ]; +describe('styling-utils', () => { + test('getCombinedClassName', () => { + const allValidStringParams = [ + 'test_class--1', + 'test_class--2', + 'test_class--3' + ]; + const expectedAllValidStringParamsCombined = + 'test_class--1 test_class--2 test_class--3'; + const falsyValues = [null, undefined, false, '', 0, NaN]; + const nonStringValues = [ + ['invalid_class--1', 'invalid_class--2'], + {foo: 'bar'}, + 123, + () => { + return 'invalid_class--3'; + } + ]; - expect(getCombinedClassName(...allValidStringParams)).toBe( - expectedAllValidStringParamsCombined - ); + expect(getCombinedClassName(...allValidStringParams)).toBe( + expectedAllValidStringParamsCombined + ); - expect(getCombinedClassName(...allValidStringParams, ...falsyValues)).toBe( - expectedAllValidStringParamsCombined - ); + expect(getCombinedClassName(...allValidStringParams, ...falsyValues)).toBe( + expectedAllValidStringParamsCombined + ); - expect( - getCombinedClassName(...allValidStringParams, ...nonStringValues) - ).toBe(expectedAllValidStringParamsCombined); + expect( + getCombinedClassName(...allValidStringParams, ...nonStringValues) + ).toBe(expectedAllValidStringParamsCombined); + }); }); From 99586179e6a2958e6343428d1f7f16e74fadaa33 Mon Sep 17 00:00:00 2001 From: apeltier <26309854+a-peltier@users.noreply.github.com> Date: Thu, 28 May 2020 23:34:36 +0200 Subject: [PATCH 3/6] Remove eslint-plugin-no-only-tests --- .eslintrc | 1 - package.json | 1 - yarn.lock | 5 ----- 3 files changed, 7 deletions(-) diff --git a/.eslintrc b/.eslintrc index 3adc4006a..8a9f4cd3b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -36,7 +36,6 @@ "max-params": ["error", 6], "object-curly-spacing": 0, "babel/object-curly-spacing": 2, - "no-only-tests/no-only-tests": 2, "jest/require-top-level-describe":"error", "react/prop-types": "off", "prettier/prettier": "warn" diff --git a/package.json b/package.json index 9e8b97300..725d4ba5f 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "eslint": "6.8.0", "eslint-config-prettier": "^6.11.0", "eslint-plugin-babel": "^5.3.0", - "eslint-plugin-no-only-tests": "^2.4.0", "eslint-plugin-prettier": "^3.1.3", "eslint-plugin-react": "^7.20.0", "husky": "^1.1.2" diff --git a/yarn.lock b/yarn.lock index 8ebf76a63..dd358d7d2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6588,11 +6588,6 @@ eslint-plugin-jest@^23.13.2: dependencies: "@typescript-eslint/experimental-utils" "^2.5.0" -eslint-plugin-no-only-tests@^2.4.0: - version "2.4.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-no-only-tests/-/eslint-plugin-no-only-tests-2.4.0.tgz#7d565434aa7d16ccc7eea957c391d98f827332ca" - integrity sha1-fVZUNKp9FszH7qlXw5HZj4JzMso= - eslint-plugin-prettier@^3.1.3: version "3.1.3" resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.3.tgz#ae116a0fc0e598fdae48743a4430903de5b4e6ca" From f4c707979a8daf1d091b8c1bf71fdc2690285d32 Mon Sep 17 00:00:00 2001 From: apeltier <26309854+a-peltier@users.noreply.github.com> Date: Fri, 29 May 2020 10:10:47 +0200 Subject: [PATCH 4/6] fixup! Remove eslint-plugin-no-only-tests --- .eslintrc | 1 - 1 file changed, 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 8a9f4cd3b..be727efd6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,7 +11,6 @@ "react", "prettier", "babel", - "no-only-tests", "jest" ], "ignorePatterns": [ From 2111b19c6039515aa025ca3e5f535891d5c41ae8 Mon Sep 17 00:00:00 2001 From: apeltier <26309854+a-peltier@users.noreply.github.com> Date: Fri, 29 May 2020 00:01:16 +0200 Subject: [PATCH 5/6] Rename all test files as *.test.js --- packages/react-vis/jest.config.js | 1 - .../tests/components/{animation-tests.js => animation.test.js} | 0 .../tests/components/{arc-series-tests.js => arc-series.test.js} | 0 .../components/{area-series-tests.js => area-series.test.js} | 0 .../react-vis/tests/components/{axes-tests.js => axes.test.js} | 0 .../{axis-tick-format-tests.js => axis-tick-format.test.js} | 0 .../tests/components/{axis-title-tests.js => axis-title.test.js} | 0 .../tests/components/{bar-series-tests.js => bar-series.test.js} | 0 .../tests/components/{borders-tests.js => borders.test.js} | 0 .../{canvas-component-tests.js => canvas-component.test.js} | 0 ...{circular-grid-lines-tests.js => circular-grid-lines.test.js} | 0 .../components/{color-article-tests.js => color-article.test.js} | 0 .../{contour-series-tests.js => contour-series.test.js} | 0 .../tests/components/{crosshair-tests.js => crosshair.test.js} | 0 .../{custom-svg-series-tests.js => custom-svg-series.test.js} | 0 .../components/{data-article-tests.js => data-article.test.js} | 0 .../{decorative-axis-tests.js => decorative-axis.test.js} | 0 .../tests/components/{gradient-tests.js => gradient.test.js} | 0 .../tests/components/{grid-lines-tests.js => grid-lines.test.js} | 0 .../tests/components/{heatmap-tests.js => heatmap.test.js} | 0 .../components/{hexbin-series-tests.js => hexbin-series.test.js} | 0 .../tests/components/{highlight-tests.js => highlight.test.js} | 0 .../react-vis/tests/components/{hints-tests.js => hints.test.js} | 0 ...{interaction-article-tests.js => interaction-article.test.js} | 0 .../components/{label-series-tests.js => label-series.test.js} | 0 .../tests/components/{legends-tests.js => legends.test.js} | 0 .../{line-series-canvas-test.js => line-series-canvas.test.js} | 0 .../components/{line-series-tests.js => line-series.test.js} | 0 .../{make-vis-flexible-tests.js => make-vis-flexible.test.js} | 0 .../components/{mark-series-tests.js => mark-series.test.js} | 0 ...arallel-coordinates-tests.js => parallel-coordinates.test.js} | 0 .../{polygon-series-tests.js => polygon-series.test.js} | 0 .../components/{radar-chart-tests.js => radar-chart.test.js} | 0 .../tests/components/{radial-tests.js => radial.test.js} | 0 .../components/{rect-series-tests.js => rect-series.test.js} | 0 .../tests/components/{sankey-tests.js => sankey.test.js} | 0 .../tests/components/{sunburst-tests.js => sunburst.test.js} | 0 .../tests/components/{treemap-tests.js => treemap.test.js} | 0 .../tests/components/{voronoi-tests.js => voronoi.test.js} | 0 .../{whisker-series-tests.js => whisker-series.test.js} | 0 .../tests/components/{xy-plot-tests.js => xy-plot.test.js} | 0 .../tests/utils/{axis-utils-tests.js => axis-utils.test.js} | 0 .../tests/utils/{chart-utils-tests.js => chart-utils.test.js} | 0 .../tests/utils/{data-utils-tests.js => data-utils.test.js} | 0 .../tests/utils/{react-utils-tests.js => react-utils.test.js} | 0 .../tests/utils/{scales-utils-tests.js => scales-utils.test.js} | 0 .../tests/utils/{series-utils-tests.js => series-utils.test.js} | 0 .../utils/{styling-utils-tests.js => styling-utils.test.js} | 0 48 files changed, 1 deletion(-) rename packages/react-vis/tests/components/{animation-tests.js => animation.test.js} (100%) rename packages/react-vis/tests/components/{arc-series-tests.js => arc-series.test.js} (100%) rename packages/react-vis/tests/components/{area-series-tests.js => area-series.test.js} (100%) rename packages/react-vis/tests/components/{axes-tests.js => axes.test.js} (100%) rename packages/react-vis/tests/components/{axis-tick-format-tests.js => axis-tick-format.test.js} (100%) rename packages/react-vis/tests/components/{axis-title-tests.js => axis-title.test.js} (100%) rename packages/react-vis/tests/components/{bar-series-tests.js => bar-series.test.js} (100%) rename packages/react-vis/tests/components/{borders-tests.js => borders.test.js} (100%) rename packages/react-vis/tests/components/{canvas-component-tests.js => canvas-component.test.js} (100%) rename packages/react-vis/tests/components/{circular-grid-lines-tests.js => circular-grid-lines.test.js} (100%) rename packages/react-vis/tests/components/{color-article-tests.js => color-article.test.js} (100%) rename packages/react-vis/tests/components/{contour-series-tests.js => contour-series.test.js} (100%) rename packages/react-vis/tests/components/{crosshair-tests.js => crosshair.test.js} (100%) rename packages/react-vis/tests/components/{custom-svg-series-tests.js => custom-svg-series.test.js} (100%) rename packages/react-vis/tests/components/{data-article-tests.js => data-article.test.js} (100%) rename packages/react-vis/tests/components/{decorative-axis-tests.js => decorative-axis.test.js} (100%) rename packages/react-vis/tests/components/{gradient-tests.js => gradient.test.js} (100%) rename packages/react-vis/tests/components/{grid-lines-tests.js => grid-lines.test.js} (100%) rename packages/react-vis/tests/components/{heatmap-tests.js => heatmap.test.js} (100%) rename packages/react-vis/tests/components/{hexbin-series-tests.js => hexbin-series.test.js} (100%) rename packages/react-vis/tests/components/{highlight-tests.js => highlight.test.js} (100%) rename packages/react-vis/tests/components/{hints-tests.js => hints.test.js} (100%) rename packages/react-vis/tests/components/{interaction-article-tests.js => interaction-article.test.js} (100%) rename packages/react-vis/tests/components/{label-series-tests.js => label-series.test.js} (100%) rename packages/react-vis/tests/components/{legends-tests.js => legends.test.js} (100%) rename packages/react-vis/tests/components/{line-series-canvas-test.js => line-series-canvas.test.js} (100%) rename packages/react-vis/tests/components/{line-series-tests.js => line-series.test.js} (100%) rename packages/react-vis/tests/components/{make-vis-flexible-tests.js => make-vis-flexible.test.js} (100%) rename packages/react-vis/tests/components/{mark-series-tests.js => mark-series.test.js} (100%) rename packages/react-vis/tests/components/{parallel-coordinates-tests.js => parallel-coordinates.test.js} (100%) rename packages/react-vis/tests/components/{polygon-series-tests.js => polygon-series.test.js} (100%) rename packages/react-vis/tests/components/{radar-chart-tests.js => radar-chart.test.js} (100%) rename packages/react-vis/tests/components/{radial-tests.js => radial.test.js} (100%) rename packages/react-vis/tests/components/{rect-series-tests.js => rect-series.test.js} (100%) rename packages/react-vis/tests/components/{sankey-tests.js => sankey.test.js} (100%) rename packages/react-vis/tests/components/{sunburst-tests.js => sunburst.test.js} (100%) rename packages/react-vis/tests/components/{treemap-tests.js => treemap.test.js} (100%) rename packages/react-vis/tests/components/{voronoi-tests.js => voronoi.test.js} (100%) rename packages/react-vis/tests/components/{whisker-series-tests.js => whisker-series.test.js} (100%) rename packages/react-vis/tests/components/{xy-plot-tests.js => xy-plot.test.js} (100%) rename packages/react-vis/tests/utils/{axis-utils-tests.js => axis-utils.test.js} (100%) rename packages/react-vis/tests/utils/{chart-utils-tests.js => chart-utils.test.js} (100%) rename packages/react-vis/tests/utils/{data-utils-tests.js => data-utils.test.js} (100%) rename packages/react-vis/tests/utils/{react-utils-tests.js => react-utils.test.js} (100%) rename packages/react-vis/tests/utils/{scales-utils-tests.js => scales-utils.test.js} (100%) rename packages/react-vis/tests/utils/{series-utils-tests.js => series-utils.test.js} (100%) rename packages/react-vis/tests/utils/{styling-utils-tests.js => styling-utils.test.js} (100%) diff --git a/packages/react-vis/jest.config.js b/packages/react-vis/jest.config.js index f7529c1e2..46a594b3f 100644 --- a/packages/react-vis/jest.config.js +++ b/packages/react-vis/jest.config.js @@ -2,7 +2,6 @@ const path = require('path'); module.exports = { - testMatch: ['**/?(*-)+(test|tests).[tj]s?(x)'], transform: { '^.+\\.js$': path.resolve(__dirname, './jestBabelTransform.js') }, diff --git a/packages/react-vis/tests/components/animation-tests.js b/packages/react-vis/tests/components/animation.test.js similarity index 100% rename from packages/react-vis/tests/components/animation-tests.js rename to packages/react-vis/tests/components/animation.test.js diff --git a/packages/react-vis/tests/components/arc-series-tests.js b/packages/react-vis/tests/components/arc-series.test.js similarity index 100% rename from packages/react-vis/tests/components/arc-series-tests.js rename to packages/react-vis/tests/components/arc-series.test.js diff --git a/packages/react-vis/tests/components/area-series-tests.js b/packages/react-vis/tests/components/area-series.test.js similarity index 100% rename from packages/react-vis/tests/components/area-series-tests.js rename to packages/react-vis/tests/components/area-series.test.js diff --git a/packages/react-vis/tests/components/axes-tests.js b/packages/react-vis/tests/components/axes.test.js similarity index 100% rename from packages/react-vis/tests/components/axes-tests.js rename to packages/react-vis/tests/components/axes.test.js diff --git a/packages/react-vis/tests/components/axis-tick-format-tests.js b/packages/react-vis/tests/components/axis-tick-format.test.js similarity index 100% rename from packages/react-vis/tests/components/axis-tick-format-tests.js rename to packages/react-vis/tests/components/axis-tick-format.test.js diff --git a/packages/react-vis/tests/components/axis-title-tests.js b/packages/react-vis/tests/components/axis-title.test.js similarity index 100% rename from packages/react-vis/tests/components/axis-title-tests.js rename to packages/react-vis/tests/components/axis-title.test.js diff --git a/packages/react-vis/tests/components/bar-series-tests.js b/packages/react-vis/tests/components/bar-series.test.js similarity index 100% rename from packages/react-vis/tests/components/bar-series-tests.js rename to packages/react-vis/tests/components/bar-series.test.js diff --git a/packages/react-vis/tests/components/borders-tests.js b/packages/react-vis/tests/components/borders.test.js similarity index 100% rename from packages/react-vis/tests/components/borders-tests.js rename to packages/react-vis/tests/components/borders.test.js diff --git a/packages/react-vis/tests/components/canvas-component-tests.js b/packages/react-vis/tests/components/canvas-component.test.js similarity index 100% rename from packages/react-vis/tests/components/canvas-component-tests.js rename to packages/react-vis/tests/components/canvas-component.test.js diff --git a/packages/react-vis/tests/components/circular-grid-lines-tests.js b/packages/react-vis/tests/components/circular-grid-lines.test.js similarity index 100% rename from packages/react-vis/tests/components/circular-grid-lines-tests.js rename to packages/react-vis/tests/components/circular-grid-lines.test.js diff --git a/packages/react-vis/tests/components/color-article-tests.js b/packages/react-vis/tests/components/color-article.test.js similarity index 100% rename from packages/react-vis/tests/components/color-article-tests.js rename to packages/react-vis/tests/components/color-article.test.js diff --git a/packages/react-vis/tests/components/contour-series-tests.js b/packages/react-vis/tests/components/contour-series.test.js similarity index 100% rename from packages/react-vis/tests/components/contour-series-tests.js rename to packages/react-vis/tests/components/contour-series.test.js diff --git a/packages/react-vis/tests/components/crosshair-tests.js b/packages/react-vis/tests/components/crosshair.test.js similarity index 100% rename from packages/react-vis/tests/components/crosshair-tests.js rename to packages/react-vis/tests/components/crosshair.test.js diff --git a/packages/react-vis/tests/components/custom-svg-series-tests.js b/packages/react-vis/tests/components/custom-svg-series.test.js similarity index 100% rename from packages/react-vis/tests/components/custom-svg-series-tests.js rename to packages/react-vis/tests/components/custom-svg-series.test.js diff --git a/packages/react-vis/tests/components/data-article-tests.js b/packages/react-vis/tests/components/data-article.test.js similarity index 100% rename from packages/react-vis/tests/components/data-article-tests.js rename to packages/react-vis/tests/components/data-article.test.js diff --git a/packages/react-vis/tests/components/decorative-axis-tests.js b/packages/react-vis/tests/components/decorative-axis.test.js similarity index 100% rename from packages/react-vis/tests/components/decorative-axis-tests.js rename to packages/react-vis/tests/components/decorative-axis.test.js diff --git a/packages/react-vis/tests/components/gradient-tests.js b/packages/react-vis/tests/components/gradient.test.js similarity index 100% rename from packages/react-vis/tests/components/gradient-tests.js rename to packages/react-vis/tests/components/gradient.test.js diff --git a/packages/react-vis/tests/components/grid-lines-tests.js b/packages/react-vis/tests/components/grid-lines.test.js similarity index 100% rename from packages/react-vis/tests/components/grid-lines-tests.js rename to packages/react-vis/tests/components/grid-lines.test.js diff --git a/packages/react-vis/tests/components/heatmap-tests.js b/packages/react-vis/tests/components/heatmap.test.js similarity index 100% rename from packages/react-vis/tests/components/heatmap-tests.js rename to packages/react-vis/tests/components/heatmap.test.js diff --git a/packages/react-vis/tests/components/hexbin-series-tests.js b/packages/react-vis/tests/components/hexbin-series.test.js similarity index 100% rename from packages/react-vis/tests/components/hexbin-series-tests.js rename to packages/react-vis/tests/components/hexbin-series.test.js diff --git a/packages/react-vis/tests/components/highlight-tests.js b/packages/react-vis/tests/components/highlight.test.js similarity index 100% rename from packages/react-vis/tests/components/highlight-tests.js rename to packages/react-vis/tests/components/highlight.test.js diff --git a/packages/react-vis/tests/components/hints-tests.js b/packages/react-vis/tests/components/hints.test.js similarity index 100% rename from packages/react-vis/tests/components/hints-tests.js rename to packages/react-vis/tests/components/hints.test.js diff --git a/packages/react-vis/tests/components/interaction-article-tests.js b/packages/react-vis/tests/components/interaction-article.test.js similarity index 100% rename from packages/react-vis/tests/components/interaction-article-tests.js rename to packages/react-vis/tests/components/interaction-article.test.js diff --git a/packages/react-vis/tests/components/label-series-tests.js b/packages/react-vis/tests/components/label-series.test.js similarity index 100% rename from packages/react-vis/tests/components/label-series-tests.js rename to packages/react-vis/tests/components/label-series.test.js diff --git a/packages/react-vis/tests/components/legends-tests.js b/packages/react-vis/tests/components/legends.test.js similarity index 100% rename from packages/react-vis/tests/components/legends-tests.js rename to packages/react-vis/tests/components/legends.test.js diff --git a/packages/react-vis/tests/components/line-series-canvas-test.js b/packages/react-vis/tests/components/line-series-canvas.test.js similarity index 100% rename from packages/react-vis/tests/components/line-series-canvas-test.js rename to packages/react-vis/tests/components/line-series-canvas.test.js diff --git a/packages/react-vis/tests/components/line-series-tests.js b/packages/react-vis/tests/components/line-series.test.js similarity index 100% rename from packages/react-vis/tests/components/line-series-tests.js rename to packages/react-vis/tests/components/line-series.test.js diff --git a/packages/react-vis/tests/components/make-vis-flexible-tests.js b/packages/react-vis/tests/components/make-vis-flexible.test.js similarity index 100% rename from packages/react-vis/tests/components/make-vis-flexible-tests.js rename to packages/react-vis/tests/components/make-vis-flexible.test.js diff --git a/packages/react-vis/tests/components/mark-series-tests.js b/packages/react-vis/tests/components/mark-series.test.js similarity index 100% rename from packages/react-vis/tests/components/mark-series-tests.js rename to packages/react-vis/tests/components/mark-series.test.js diff --git a/packages/react-vis/tests/components/parallel-coordinates-tests.js b/packages/react-vis/tests/components/parallel-coordinates.test.js similarity index 100% rename from packages/react-vis/tests/components/parallel-coordinates-tests.js rename to packages/react-vis/tests/components/parallel-coordinates.test.js diff --git a/packages/react-vis/tests/components/polygon-series-tests.js b/packages/react-vis/tests/components/polygon-series.test.js similarity index 100% rename from packages/react-vis/tests/components/polygon-series-tests.js rename to packages/react-vis/tests/components/polygon-series.test.js diff --git a/packages/react-vis/tests/components/radar-chart-tests.js b/packages/react-vis/tests/components/radar-chart.test.js similarity index 100% rename from packages/react-vis/tests/components/radar-chart-tests.js rename to packages/react-vis/tests/components/radar-chart.test.js diff --git a/packages/react-vis/tests/components/radial-tests.js b/packages/react-vis/tests/components/radial.test.js similarity index 100% rename from packages/react-vis/tests/components/radial-tests.js rename to packages/react-vis/tests/components/radial.test.js diff --git a/packages/react-vis/tests/components/rect-series-tests.js b/packages/react-vis/tests/components/rect-series.test.js similarity index 100% rename from packages/react-vis/tests/components/rect-series-tests.js rename to packages/react-vis/tests/components/rect-series.test.js diff --git a/packages/react-vis/tests/components/sankey-tests.js b/packages/react-vis/tests/components/sankey.test.js similarity index 100% rename from packages/react-vis/tests/components/sankey-tests.js rename to packages/react-vis/tests/components/sankey.test.js diff --git a/packages/react-vis/tests/components/sunburst-tests.js b/packages/react-vis/tests/components/sunburst.test.js similarity index 100% rename from packages/react-vis/tests/components/sunburst-tests.js rename to packages/react-vis/tests/components/sunburst.test.js diff --git a/packages/react-vis/tests/components/treemap-tests.js b/packages/react-vis/tests/components/treemap.test.js similarity index 100% rename from packages/react-vis/tests/components/treemap-tests.js rename to packages/react-vis/tests/components/treemap.test.js diff --git a/packages/react-vis/tests/components/voronoi-tests.js b/packages/react-vis/tests/components/voronoi.test.js similarity index 100% rename from packages/react-vis/tests/components/voronoi-tests.js rename to packages/react-vis/tests/components/voronoi.test.js diff --git a/packages/react-vis/tests/components/whisker-series-tests.js b/packages/react-vis/tests/components/whisker-series.test.js similarity index 100% rename from packages/react-vis/tests/components/whisker-series-tests.js rename to packages/react-vis/tests/components/whisker-series.test.js diff --git a/packages/react-vis/tests/components/xy-plot-tests.js b/packages/react-vis/tests/components/xy-plot.test.js similarity index 100% rename from packages/react-vis/tests/components/xy-plot-tests.js rename to packages/react-vis/tests/components/xy-plot.test.js diff --git a/packages/react-vis/tests/utils/axis-utils-tests.js b/packages/react-vis/tests/utils/axis-utils.test.js similarity index 100% rename from packages/react-vis/tests/utils/axis-utils-tests.js rename to packages/react-vis/tests/utils/axis-utils.test.js diff --git a/packages/react-vis/tests/utils/chart-utils-tests.js b/packages/react-vis/tests/utils/chart-utils.test.js similarity index 100% rename from packages/react-vis/tests/utils/chart-utils-tests.js rename to packages/react-vis/tests/utils/chart-utils.test.js diff --git a/packages/react-vis/tests/utils/data-utils-tests.js b/packages/react-vis/tests/utils/data-utils.test.js similarity index 100% rename from packages/react-vis/tests/utils/data-utils-tests.js rename to packages/react-vis/tests/utils/data-utils.test.js diff --git a/packages/react-vis/tests/utils/react-utils-tests.js b/packages/react-vis/tests/utils/react-utils.test.js similarity index 100% rename from packages/react-vis/tests/utils/react-utils-tests.js rename to packages/react-vis/tests/utils/react-utils.test.js diff --git a/packages/react-vis/tests/utils/scales-utils-tests.js b/packages/react-vis/tests/utils/scales-utils.test.js similarity index 100% rename from packages/react-vis/tests/utils/scales-utils-tests.js rename to packages/react-vis/tests/utils/scales-utils.test.js diff --git a/packages/react-vis/tests/utils/series-utils-tests.js b/packages/react-vis/tests/utils/series-utils.test.js similarity index 100% rename from packages/react-vis/tests/utils/series-utils-tests.js rename to packages/react-vis/tests/utils/series-utils.test.js diff --git a/packages/react-vis/tests/utils/styling-utils-tests.js b/packages/react-vis/tests/utils/styling-utils.test.js similarity index 100% rename from packages/react-vis/tests/utils/styling-utils-tests.js rename to packages/react-vis/tests/utils/styling-utils.test.js From 747aa86752cbe32a3f881c0b86e2a647451adf38 Mon Sep 17 00:00:00 2001 From: apeltier <26309854+a-peltier@users.noreply.github.com> Date: Fri, 29 May 2020 09:10:18 +0200 Subject: [PATCH 6/6] Drop node 8 test in CI --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bc260dcab..a255579e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: node_js node_js: - - '8' - '10' script: - npm run lint