@pie-lib/graphing-solution-set 4.0.4-next.30 → 4.0.4-next.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +1 -0
- package/CHANGELOG.md +449 -0
- package/LICENSE.md +5 -0
- package/lib/axis/arrow.js +79 -0
- package/lib/axis/arrow.js.map +1 -0
- package/lib/axis/axes.js +327 -0
- package/lib/axis/axes.js.map +1 -0
- package/lib/axis/index.js +21 -0
- package/lib/axis/index.js.map +1 -0
- package/lib/bg.js +114 -0
- package/lib/bg.js.map +1 -0
- package/lib/container/actions.js +18 -0
- package/lib/container/actions.js.map +1 -0
- package/lib/container/index.js +129 -0
- package/lib/container/index.js.map +1 -0
- package/lib/container/marks.js +22 -0
- package/lib/container/marks.js.map +1 -0
- package/lib/container/middleware.js +19 -0
- package/lib/container/middleware.js.map +1 -0
- package/lib/container/reducer.js +18 -0
- package/lib/container/reducer.js.map +1 -0
- package/lib/coordinates-label.js +77 -0
- package/lib/coordinates-label.js.map +1 -0
- package/lib/graph-with-controls.js +297 -0
- package/lib/graph-with-controls.js.map +1 -0
- package/lib/graph.js +353 -0
- package/lib/graph.js.map +1 -0
- package/lib/grid-setup.js +414 -0
- package/lib/grid-setup.js.map +1 -0
- package/lib/grid.js +131 -0
- package/lib/grid.js.map +1 -0
- package/lib/index.js +40 -0
- package/lib/index.js.map +1 -0
- package/lib/labels.js +199 -0
- package/lib/labels.js.map +1 -0
- package/lib/mark-label.js +159 -0
- package/lib/mark-label.js.map +1 -0
- package/lib/toggle-bar.js +248 -0
- package/lib/toggle-bar.js.map +1 -0
- package/lib/tool-menu.js +218 -0
- package/lib/tool-menu.js.map +1 -0
- package/lib/tools/index.js +24 -0
- package/lib/tools/index.js.map +1 -0
- package/lib/tools/line/component.js +92 -0
- package/lib/tools/line/component.js.map +1 -0
- package/lib/tools/line/index.js +11 -0
- package/lib/tools/line/index.js.map +1 -0
- package/lib/tools/polygon/component.js +358 -0
- package/lib/tools/polygon/component.js.map +1 -0
- package/lib/tools/polygon/index.js +89 -0
- package/lib/tools/polygon/index.js.map +1 -0
- package/lib/tools/polygon/line.js +114 -0
- package/lib/tools/polygon/line.js.map +1 -0
- package/lib/tools/polygon/polygon.js +128 -0
- package/lib/tools/polygon/polygon.js.map +1 -0
- package/lib/tools/shared/arrow-head.js +62 -0
- package/lib/tools/shared/arrow-head.js.map +1 -0
- package/lib/tools/shared/line/index.js +539 -0
- package/lib/tools/shared/line/index.js.map +1 -0
- package/lib/tools/shared/line/line-path.js +121 -0
- package/lib/tools/shared/line/line-path.js.map +1 -0
- package/lib/tools/shared/line/with-root-edge.js +121 -0
- package/lib/tools/shared/line/with-root-edge.js.map +1 -0
- package/lib/tools/shared/point/arrow-point.js +86 -0
- package/lib/tools/shared/point/arrow-point.js.map +1 -0
- package/lib/tools/shared/point/arrow.js +70 -0
- package/lib/tools/shared/point/arrow.js.map +1 -0
- package/lib/tools/shared/point/base-point.js +137 -0
- package/lib/tools/shared/point/base-point.js.map +1 -0
- package/lib/tools/shared/point/index.js +80 -0
- package/lib/tools/shared/point/index.js.map +1 -0
- package/lib/tools/shared/styles.js +26 -0
- package/lib/tools/shared/styles.js.map +1 -0
- package/lib/tools/shared/types.js +15 -0
- package/lib/tools/shared/types.js.map +1 -0
- package/lib/undo-redo.js +67 -0
- package/lib/undo-redo.js.map +1 -0
- package/lib/use-debounce.js +25 -0
- package/lib/use-debounce.js.map +1 -0
- package/lib/utils.js +235 -0
- package/lib/utils.js.map +1 -0
- package/package.json +34 -46
- package/src/__tests__/bg.test.jsx +250 -0
- package/src/__tests__/coordinates-label.test.jsx +243 -0
- package/src/__tests__/graph-with-controls.test.jsx +184 -0
- package/src/__tests__/graph.test.jsx +93 -0
- package/src/__tests__/grid-setup.test.jsx +645 -0
- package/src/__tests__/grid.test.jsx +23 -0
- package/src/__tests__/labels.test.jsx +41 -0
- package/src/__tests__/mark-label.test.jsx +66 -0
- package/src/__tests__/toggle-bar.test.jsx +106 -0
- package/src/__tests__/tool-menu.test.jsx +453 -0
- package/src/__tests__/undo-redo.test.jsx +26 -0
- package/src/__tests__/use-debounce.test.js +21 -0
- package/src/__tests__/utils.js +41 -0
- package/src/__tests__/utils.test.js +105 -0
- package/src/axis/__tests__/arrow.test.jsx +43 -0
- package/src/axis/__tests__/axes.test.jsx +182 -0
- package/src/axis/arrow.jsx +57 -0
- package/src/axis/axes.jsx +284 -0
- package/src/axis/index.js +3 -0
- package/src/bg.jsx +96 -0
- package/src/container/__tests__/actions.test.js +105 -0
- package/src/container/__tests__/index.test.jsx +227 -0
- package/src/container/__tests__/marks.test.js +172 -0
- package/src/container/__tests__/middleware.test.js +235 -0
- package/src/container/__tests__/reducer.test.js +324 -0
- package/src/container/actions.js +8 -0
- package/src/container/index.jsx +93 -0
- package/src/container/marks.js +14 -0
- package/src/container/middleware.js +7 -0
- package/src/container/reducer.js +5 -0
- package/src/coordinates-label.jsx +62 -0
- package/src/graph-with-controls.jsx +242 -0
- package/src/graph.jsx +333 -0
- package/src/grid-setup.jsx +432 -0
- package/src/grid.jsx +133 -0
- package/src/index.js +7 -0
- package/src/labels.jsx +173 -0
- package/src/mark-label.jsx +125 -0
- package/src/toggle-bar.jsx +221 -0
- package/src/tool-menu.jsx +235 -0
- package/src/tools/index.js +8 -0
- package/src/tools/line/__tests__/component.test.jsx +37 -0
- package/src/tools/line/component.jsx +77 -0
- package/src/tools/line/index.js +4 -0
- package/src/tools/polygon/__tests__/component.test.jsx +487 -0
- package/src/tools/polygon/__tests__/index.test.js +65 -0
- package/src/tools/polygon/__tests__/line.test.jsx +23 -0
- package/src/tools/polygon/__tests__/polygon.test.jsx +44 -0
- package/src/tools/polygon/component.jsx +324 -0
- package/src/tools/polygon/index.js +52 -0
- package/src/tools/polygon/line.jsx +80 -0
- package/src/tools/polygon/polygon.jsx +93 -0
- package/src/tools/shared/__tests__/arrow-head.test.jsx +33 -0
- package/src/tools/shared/arrow-head.jsx +46 -0
- package/src/tools/shared/line/__tests__/index.test.jsx +553 -0
- package/src/tools/shared/line/__tests__/line-path.test.jsx +56 -0
- package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +488 -0
- package/src/tools/shared/line/index.jsx +471 -0
- package/src/tools/shared/line/line-path.jsx +85 -0
- package/src/tools/shared/line/with-root-edge.jsx +97 -0
- package/src/tools/shared/point/__tests__/arrow-point.test.jsx +91 -0
- package/src/tools/shared/point/__tests__/arrow.test.jsx +469 -0
- package/src/tools/shared/point/__tests__/base-point.test.jsx +87 -0
- package/src/tools/shared/point/arrow-point.jsx +60 -0
- package/src/tools/shared/point/arrow.jsx +40 -0
- package/src/tools/shared/point/base-point.jsx +113 -0
- package/src/tools/shared/point/index.jsx +58 -0
- package/src/tools/shared/styles.js +20 -0
- package/src/tools/shared/types.js +8 -0
- package/src/undo-redo.jsx +37 -0
- package/src/use-debounce.js +13 -0
- package/src/utils.js +230 -0
- package/dist/_virtual/_rolldown/runtime.js +0 -23
- package/dist/autosize-input.d.ts +0 -10
- package/dist/autosize-input.js +0 -66
- package/dist/axis/arrow.d.ts +0 -13
- package/dist/axis/arrow.js +0 -34
- package/dist/axis/axes.d.ts +0 -132
- package/dist/axis/axes.js +0 -214
- package/dist/axis/index.d.ts +0 -10
- package/dist/bg.d.ts +0 -51
- package/dist/bg.js +0 -44
- package/dist/container/actions.d.ts +0 -15
- package/dist/container/actions.js +0 -7
- package/dist/container/index.d.ts +0 -58
- package/dist/container/index.js +0 -48
- package/dist/container/marks.d.ts +0 -10
- package/dist/container/marks.js +0 -11
- package/dist/container/middleware.d.ts +0 -10
- package/dist/container/middleware.js +0 -4
- package/dist/container/reducer.d.ts +0 -14
- package/dist/container/reducer.js +0 -7
- package/dist/coordinates-label.d.ts +0 -50
- package/dist/coordinates-label.js +0 -46
- package/dist/graph-with-controls.d.ts +0 -85
- package/dist/graph-with-controls.js +0 -155
- package/dist/graph.d.ts +0 -119
- package/dist/graph.js +0 -221
- package/dist/grid-setup.d.ts +0 -27
- package/dist/grid-setup.js +0 -307
- package/dist/grid.d.ts +0 -43
- package/dist/grid.js +0 -59
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -6
- package/dist/labels.d.ts +0 -73
- package/dist/labels.js +0 -134
- package/dist/mark-label.d.ts +0 -50
- package/dist/mark-label.js +0 -84
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/axis/Axis.js +0 -101
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/axis/AxisRenderer.js +0 -63
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/axis/Ticks.js +0 -44
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/constants/orientation.js +0 -9
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/createPoint.js +0 -14
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getAxisRangePaddingConfig.js +0 -21
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getLabelTransform.js +0 -16
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getTickFormatter.js +0 -8
- package/dist/node_modules/.bun/@visx_axis@3.12.0_f4eacebf2041cd4f/node_modules/@visx/axis/esm/utils/getTickPosition.js +0 -15
- package/dist/node_modules/.bun/@visx_grid@3.12.0_f4eacebf2041cd4f/node_modules/@visx/grid/esm/grids/Grid.js +0 -79
- package/dist/node_modules/.bun/@visx_grid@3.12.0_f4eacebf2041cd4f/node_modules/@visx/grid/esm/grids/GridColumns.js +0 -79
- package/dist/node_modules/.bun/@visx_grid@3.12.0_f4eacebf2041cd4f/node_modules/@visx/grid/esm/grids/GridRows.js +0 -79
- package/dist/node_modules/.bun/@visx_grid@3.12.0_f4eacebf2041cd4f/node_modules/@visx/grid/esm/utils/getScaleBandwidth.js +0 -6
- package/dist/node_modules/.bun/@visx_group@3.12.0_f4eacebf2041cd4f/node_modules/@visx/group/esm/Group.js +0 -50
- package/dist/node_modules/.bun/@visx_point@3.12.0/node_modules/@visx/point/esm/Point.js +0 -18
- package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/utils/coerceNumber.js +0 -10
- package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/utils/getTicks.js +0 -9
- package/dist/node_modules/.bun/@visx_scale@3.12.0/node_modules/@visx/scale/esm/utils/toString.js +0 -6
- package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/esm/shapes/Line.js +0 -47
- package/dist/node_modules/.bun/@visx_shape@3.12.0_f4eacebf2041cd4f/node_modules/@visx/shape/lib/shapes/Line.js +0 -53
- package/dist/node_modules/.bun/@visx_text@3.12.0_f4eacebf2041cd4f/node_modules/@visx/text/esm/Text.js +0 -57
- package/dist/node_modules/.bun/@visx_text@3.12.0_f4eacebf2041cd4f/node_modules/@visx/text/esm/hooks/useText.js +0 -91
- package/dist/node_modules/.bun/@visx_text@3.12.0_f4eacebf2041cd4f/node_modules/@visx/text/esm/util/getStringWidth.js +0 -21
- package/dist/node_modules/.bun/balanced-match@0.4.2/node_modules/balanced-match/index.js +0 -32
- package/dist/node_modules/.bun/balanced-match@1.0.2/node_modules/balanced-match/index.js +0 -33
- package/dist/node_modules/.bun/classnames@2.5.1/node_modules/classnames/index.js +0 -32
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +0 -16
- package/dist/node_modules/.bun/invariant@2.2.4/node_modules/invariant/browser.js +0 -28
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_Hash.js +0 -21
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_ListCache.js +0 -21
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_Map.js +0 -10
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_MapCache.js +0 -21
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_Symbol.js +0 -9
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_assocIndexOf.js +0 -14
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_baseGetTag.js +0 -15
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_baseIsNative.js +0 -16
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_coreJsData.js +0 -9
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_freeGlobal.js +0 -8
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_getMapData.js +0 -14
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_getNative.js +0 -15
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_getRawTag.js +0 -19
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_getValue.js +0 -11
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_hashClear.js +0 -13
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_hashDelete.js +0 -12
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_hashGet.js +0 -18
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_hashHas.js +0 -14
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_hashSet.js +0 -14
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_isKeyable.js +0 -12
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_isMasked.js +0 -16
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_listCacheClear.js +0 -11
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_listCacheDelete.js +0 -14
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_listCacheGet.js +0 -14
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_listCacheHas.js +0 -13
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_listCacheSet.js +0 -14
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_mapCacheClear.js +0 -19
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_mapCacheDelete.js +0 -14
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_mapCacheGet.js +0 -13
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_mapCacheHas.js +0 -13
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_mapCacheSet.js +0 -14
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_nativeCreate.js +0 -9
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_objectToString.js +0 -12
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_root.js +0 -10
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/_toSource.js +0 -20
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/eq.js +0 -11
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/isFunction.js +0 -16
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/isObject.js +0 -12
- package/dist/node_modules/.bun/lodash@4.18.1/node_modules/lodash/memoize.js +0 -20
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/formula_evaluator.js +0 -37
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/lexer.js +0 -509
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/math_function.js +0 -108
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/postfix.js +0 -31
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/postfix_evaluator.js +0 -45
- package/dist/node_modules/.bun/react-redux@9.3.0_9e2203c65d1d5fa1/node_modules/react-redux/dist/react-redux.js +0 -471
- package/dist/node_modules/.bun/reduce-css-calc@1.3.0/node_modules/reduce-css-calc/index.js +0 -49
- package/dist/node_modules/.bun/reduce-function-call@1.0.3/node_modules/reduce-function-call/index.js +0 -34
- package/dist/node_modules/.bun/redux-undo@1.1.0/node_modules/redux-undo/dist/redux-undo.js +0 -185
- package/dist/node_modules/.bun/redux@5.0.1/node_modules/redux/dist/redux.js +0 -198
- package/dist/node_modules/.bun/use-sync-external-store@1.6.0_f4eacebf2041cd4f/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.development.js +0 -53
- package/dist/node_modules/.bun/use-sync-external-store@1.6.0_f4eacebf2041cd4f/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.js +0 -51
- package/dist/node_modules/.bun/use-sync-external-store@1.6.0_f4eacebf2041cd4f/node_modules/use-sync-external-store/with-selector.js +0 -10
- package/dist/toggle-bar.d.ts +0 -40
- package/dist/tool-menu.d.ts +0 -21
- package/dist/tool-menu.js +0 -188
- package/dist/tools/index.d.ts +0 -17
- package/dist/tools/index.js +0 -12
- package/dist/tools/line/component.d.ts +0 -113
- package/dist/tools/line/component.js +0 -58
- package/dist/tools/line/index.d.ts +0 -13
- package/dist/tools/line/index.js +0 -6
- package/dist/tools/polygon/component.d.ts +0 -117
- package/dist/tools/polygon/component.js +0 -194
- package/dist/tools/polygon/index.d.ts +0 -19
- package/dist/tools/polygon/index.js +0 -55
- package/dist/tools/polygon/line.d.ts +0 -125
- package/dist/tools/polygon/polygon.d.ts +0 -122
- package/dist/tools/polygon/polygon.js +0 -62
- package/dist/tools/shared/arrow-head.d.ts +0 -43
- package/dist/tools/shared/arrow-head.js +0 -37
- package/dist/tools/shared/line/index.d.ts +0 -240
- package/dist/tools/shared/line/index.js +0 -320
- package/dist/tools/shared/line/line-path.d.ts +0 -57
- package/dist/tools/shared/line/with-root-edge.d.ts +0 -143
- package/dist/tools/shared/point/arrow-point.d.ts +0 -57
- package/dist/tools/shared/point/arrow-point.js +0 -47
- package/dist/tools/shared/point/arrow.d.ts +0 -46
- package/dist/tools/shared/point/arrow.js +0 -36
- package/dist/tools/shared/point/base-point.d.ts +0 -50
- package/dist/tools/shared/point/base-point.js +0 -88
- package/dist/tools/shared/point/index.d.ts +0 -217
- package/dist/tools/shared/point/index.js +0 -51
- package/dist/tools/shared/styles.d.ts +0 -24
- package/dist/tools/shared/styles.js +0 -17
- package/dist/tools/shared/types.d.ts +0 -15
- package/dist/tools/shared/types.js +0 -10
- package/dist/undo-redo.d.ts +0 -20
- package/dist/undo-redo.js +0 -33
- package/dist/use-debounce.d.ts +0 -9
- package/dist/use-debounce.js +0 -13
- package/dist/utils.d.ts +0 -58
- package/dist/utils.js +0 -72
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { coordinates, MarkLabel, position } from '../mark-label';
|
|
4
|
+
import { graphProps as getGraphProps } from './utils';
|
|
5
|
+
|
|
6
|
+
describe('MarkLabel', () => {
|
|
7
|
+
let onChange = jest.fn();
|
|
8
|
+
let inputRef = jest.fn();
|
|
9
|
+
|
|
10
|
+
const renderComponent = (extras) => {
|
|
11
|
+
const defaults = {
|
|
12
|
+
classes: {},
|
|
13
|
+
className: 'className',
|
|
14
|
+
onChange,
|
|
15
|
+
inputRef,
|
|
16
|
+
mark: { x: 1, y: 1 },
|
|
17
|
+
graphProps: getGraphProps(0, 10, 0, 10),
|
|
18
|
+
};
|
|
19
|
+
const props = { ...defaults, ...extras };
|
|
20
|
+
return render(<MarkLabel {...props} />);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe('rendering', () => {
|
|
24
|
+
it('renders without crashing', () => {
|
|
25
|
+
const { container } = renderComponent();
|
|
26
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('renders with different mark position', () => {
|
|
30
|
+
const { container } = renderComponent({ mark: { x: 10, y: 10 } });
|
|
31
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('position', () => {
|
|
37
|
+
const assertPosition = (mark, rect, expected) => {
|
|
38
|
+
it(`${mark.x},${mark.y} + ${rect.width},${rect.height} => ${expected}`, () => {
|
|
39
|
+
// we set range.min to a value because in pixels - the greater the Y the lower down on the screen.
|
|
40
|
+
const graphProps = getGraphProps(0, 12, 12, 0);
|
|
41
|
+
const result = position(graphProps, mark, rect);
|
|
42
|
+
expect(result).toEqual(expected);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
assertPosition({ x: 0, y: 0 }, { width: 10, height: 10 }, 'top-left');
|
|
47
|
+
assertPosition({ x: 0, y: 0 }, { width: 1, height: 1 }, 'bottom-right');
|
|
48
|
+
assertPosition({ x: 0, y: 0 }, { width: 10, height: 0 }, 'bottom-left');
|
|
49
|
+
assertPosition({ x: 0, y: 0 }, { width: 0, height: 10 }, 'top-right');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('coordinates', () => {
|
|
53
|
+
const assertCoordinates = (mark, rect, pos, expected) => {
|
|
54
|
+
it(`${mark.x}, ${mark.y} -> ${pos} = ${expected.left}, ${expected.top}`, () => {
|
|
55
|
+
const result = coordinates(getGraphProps(), mark, rect, pos);
|
|
56
|
+
expect(result).toEqual(expected);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
assertCoordinates({ x: 0, y: 0 }, { width: 0, height: 0 }, 'top-left', { left: -10, top: -10 });
|
|
60
|
+
assertCoordinates({ x: 0, y: 0 }, { width: 0, height: 0 }, 'bottom-left', { left: -10, top: 10 });
|
|
61
|
+
assertCoordinates({ x: 0, y: 0 }, { width: 0, height: 0 }, 'top-right', { left: 10, top: -10 });
|
|
62
|
+
assertCoordinates({ x: 0, y: 0 }, { width: 0, height: 0 }, 'bottom-right', {
|
|
63
|
+
left: 10,
|
|
64
|
+
top: 10,
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { render, screen } from '@pie-lib/test-utils';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
import { ToggleBar } from '../toggle-bar';
|
|
6
|
+
|
|
7
|
+
// Mock DragProvider to avoid @dnd-kit React version conflicts
|
|
8
|
+
jest.mock('@pie-lib/drag', () => ({
|
|
9
|
+
DragProvider: ({ children }) => <div data-testid="drag-provider">{children}</div>,
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
// Mock @dnd-kit/core hooks to avoid DndContext requirement
|
|
13
|
+
jest.mock('@dnd-kit/core', () => ({
|
|
14
|
+
useDraggable: jest.fn(() => ({
|
|
15
|
+
attributes: {
|
|
16
|
+
role: 'button',
|
|
17
|
+
tabIndex: 0,
|
|
18
|
+
},
|
|
19
|
+
listeners: {
|
|
20
|
+
onPointerDown: jest.fn(),
|
|
21
|
+
},
|
|
22
|
+
setNodeRef: jest.fn(),
|
|
23
|
+
transform: null,
|
|
24
|
+
transition: null,
|
|
25
|
+
isDragging: false,
|
|
26
|
+
})),
|
|
27
|
+
useDroppable: jest.fn(() => ({
|
|
28
|
+
setNodeRef: jest.fn(),
|
|
29
|
+
isOver: false,
|
|
30
|
+
active: null,
|
|
31
|
+
})),
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
// Mock @dnd-kit/utilities for CSS transform
|
|
35
|
+
jest.mock('@dnd-kit/utilities', () => ({
|
|
36
|
+
CSS: {
|
|
37
|
+
Transform: {
|
|
38
|
+
toString: jest.fn((transform) => (transform ? 'translate3d(0, 0, 0)' : '')),
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
// Mock @dnd-kit/sortable for arrayMove
|
|
44
|
+
jest.mock('@dnd-kit/sortable', () => ({
|
|
45
|
+
arrayMove: jest.fn((array, from, to) => {
|
|
46
|
+
const newArray = [...array];
|
|
47
|
+
const [removed] = newArray.splice(from, 1);
|
|
48
|
+
newArray.splice(to, 0, removed);
|
|
49
|
+
return newArray;
|
|
50
|
+
}),
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
// Mock Translator to return the key as-is for testing
|
|
54
|
+
jest.mock('@pie-lib/translator', () => ({
|
|
55
|
+
translator: {
|
|
56
|
+
t: (key) => {
|
|
57
|
+
// Extract tool name from key like "graphing.point" -> "point"
|
|
58
|
+
const parts = key.split('.');
|
|
59
|
+
return parts[parts.length - 1];
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
describe('ToggleBar', () => {
|
|
65
|
+
let onChange = jest.fn();
|
|
66
|
+
|
|
67
|
+
beforeEach(() => {
|
|
68
|
+
onChange.mockClear();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const renderComponent = (extras) => {
|
|
72
|
+
const defaults = {
|
|
73
|
+
className: 'className',
|
|
74
|
+
onChange,
|
|
75
|
+
options: ['line', 'polygon'],
|
|
76
|
+
language: 'en',
|
|
77
|
+
};
|
|
78
|
+
const props = { ...defaults, ...extras };
|
|
79
|
+
return render(<ToggleBar {...props} />);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
describe('rendering', () => {
|
|
83
|
+
it('renders without crashing', () => {
|
|
84
|
+
const { container } = renderComponent();
|
|
85
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('renders tool buttons for valid tools', () => {
|
|
89
|
+
renderComponent({ options: ['line', 'polygon'] });
|
|
90
|
+
expect(screen.getByText(/line/i)).toBeInTheDocument();
|
|
91
|
+
expect(screen.getByText(/polygon/i)).toBeInTheDocument();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('interactions', () => {
|
|
96
|
+
it('calls onChange when tool button is clicked', async () => {
|
|
97
|
+
const user = userEvent.setup();
|
|
98
|
+
renderComponent({ options: ['line', 'polygon'] });
|
|
99
|
+
|
|
100
|
+
const lineButton = screen.getByText(/line/i).closest('button');
|
|
101
|
+
await user.click(lineButton);
|
|
102
|
+
|
|
103
|
+
expect(onChange).toHaveBeenCalledWith('line');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import { fireEvent, render } from '@pie-lib/test-utils';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import ToolMenu from '../tool-menu';
|
|
5
|
+
|
|
6
|
+
describe('ToolMenu', () => {
|
|
7
|
+
let onChange;
|
|
8
|
+
const tools = ['one', 'two'];
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
onChange = jest.fn();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const renderComponent = (extras) => {
|
|
15
|
+
const defaults = {
|
|
16
|
+
classes: {},
|
|
17
|
+
className: 'className',
|
|
18
|
+
onChange,
|
|
19
|
+
currentTool: tools[0],
|
|
20
|
+
tools,
|
|
21
|
+
gssLineData: {
|
|
22
|
+
selectedTool: 'lineA',
|
|
23
|
+
numberOfLines: 2,
|
|
24
|
+
lineA: { lineType: 'Solid' },
|
|
25
|
+
lineB: { lineType: 'Solid' },
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
const props = { ...defaults, ...extras };
|
|
29
|
+
return render(<ToolMenu {...props} />);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe('rendering', () => {
|
|
33
|
+
it('renders without crashing', () => {
|
|
34
|
+
const { container } = renderComponent();
|
|
35
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('renders Line A radio button', () => {
|
|
39
|
+
const { getByText } = renderComponent();
|
|
40
|
+
expect(getByText('Line A')).toBeInTheDocument();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('renders Line B radio button when numberOfLines is 2', () => {
|
|
44
|
+
const { getByText } = renderComponent();
|
|
45
|
+
expect(getByText('Line B')).toBeInTheDocument();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('does not render Line B radio button when numberOfLines is 1', () => {
|
|
49
|
+
const { queryByText } = renderComponent({
|
|
50
|
+
gssLineData: {
|
|
51
|
+
selectedTool: 'lineA',
|
|
52
|
+
numberOfLines: 1,
|
|
53
|
+
lineA: { lineType: 'Solid' },
|
|
54
|
+
lineB: { lineType: 'Solid' },
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
expect(queryByText('Line B')).not.toBeInTheDocument();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('renders Solution Set radio button', () => {
|
|
61
|
+
const { getByText } = renderComponent();
|
|
62
|
+
expect(getByText('Solution Set')).toBeInTheDocument();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('renders Solid and Dashed buttons for Line A', () => {
|
|
66
|
+
const { getAllByText } = renderComponent();
|
|
67
|
+
const solidButtons = getAllByText(/Solid/);
|
|
68
|
+
const dashedButtons = getAllByText(/Dashed/);
|
|
69
|
+
expect(solidButtons.length).toBeGreaterThan(0);
|
|
70
|
+
expect(dashedButtons.length).toBeGreaterThan(0);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('shows checkmark on selected line type for Line A', () => {
|
|
74
|
+
const { getAllByText } = renderComponent({
|
|
75
|
+
gssLineData: {
|
|
76
|
+
selectedTool: 'lineA',
|
|
77
|
+
numberOfLines: 2,
|
|
78
|
+
lineA: { lineType: 'Solid' },
|
|
79
|
+
lineB: { lineType: 'Dashed' },
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
const solidButtons = getAllByText(/✔ Solid/);
|
|
83
|
+
expect(solidButtons.length).toBeGreaterThan(0);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('disables all controls when disabled prop is true', () => {
|
|
87
|
+
const { getAllByRole } = renderComponent({ disabled: true });
|
|
88
|
+
const radios = getAllByRole('radio');
|
|
89
|
+
const buttons = getAllByRole('button');
|
|
90
|
+
|
|
91
|
+
radios.forEach((radio) => {
|
|
92
|
+
expect(radio).toBeDisabled();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
buttons.forEach((button) => {
|
|
96
|
+
expect(button).toBeDisabled();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('onChangeRadioValue', () => {
|
|
102
|
+
it('calls onChange with updated selectedTool when lineA radio is clicked', () => {
|
|
103
|
+
const { getAllByRole } = renderComponent({
|
|
104
|
+
gssLineData: {
|
|
105
|
+
selectedTool: 'solutionSet',
|
|
106
|
+
numberOfLines: 2,
|
|
107
|
+
lineA: { lineType: 'Solid' },
|
|
108
|
+
lineB: { lineType: 'Solid' },
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const radios = getAllByRole('radio');
|
|
113
|
+
const lineARadio = radios.find((r) => r.value === 'lineA');
|
|
114
|
+
|
|
115
|
+
fireEvent.click(lineARadio);
|
|
116
|
+
|
|
117
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
118
|
+
const [updatedData, oldSelectedTool] = onChange.mock.calls[0];
|
|
119
|
+
expect(updatedData.selectedTool).toBe('lineA');
|
|
120
|
+
expect(oldSelectedTool).toBe('solutionSet');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('calls onChange with updated selectedTool when lineB radio is clicked', () => {
|
|
124
|
+
const { getAllByRole } = renderComponent({
|
|
125
|
+
gssLineData: {
|
|
126
|
+
selectedTool: 'lineA',
|
|
127
|
+
numberOfLines: 2,
|
|
128
|
+
lineA: { lineType: 'Solid' },
|
|
129
|
+
lineB: { lineType: 'Solid' },
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const radios = getAllByRole('radio');
|
|
134
|
+
const lineBRadio = radios.find((r) => r.value === 'lineB');
|
|
135
|
+
|
|
136
|
+
fireEvent.click(lineBRadio);
|
|
137
|
+
|
|
138
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
139
|
+
const [updatedData, oldSelectedTool] = onChange.mock.calls[0];
|
|
140
|
+
expect(updatedData.selectedTool).toBe('lineB');
|
|
141
|
+
expect(oldSelectedTool).toBe('lineA');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('calls onChange with updated selectedTool when solutionSet radio is clicked', () => {
|
|
145
|
+
const { getAllByRole } = renderComponent({
|
|
146
|
+
gssLineData: {
|
|
147
|
+
selectedTool: 'lineA',
|
|
148
|
+
numberOfLines: 2,
|
|
149
|
+
lineA: { lineType: 'Solid' },
|
|
150
|
+
lineB: { lineType: 'Solid' },
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const radios = getAllByRole('radio');
|
|
155
|
+
const solutionSetRadio = radios.find((r) => r.value === 'solutionSet');
|
|
156
|
+
|
|
157
|
+
fireEvent.click(solutionSetRadio);
|
|
158
|
+
|
|
159
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
160
|
+
const [updatedData, oldSelectedTool] = onChange.mock.calls[0];
|
|
161
|
+
expect(updatedData.selectedTool).toBe('solutionSet');
|
|
162
|
+
expect(oldSelectedTool).toBe('lineA');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('preserves other gssLineData properties when changing selectedTool', () => {
|
|
166
|
+
const { getAllByRole } = renderComponent({
|
|
167
|
+
gssLineData: {
|
|
168
|
+
selectedTool: 'lineA',
|
|
169
|
+
numberOfLines: 2,
|
|
170
|
+
lineA: { lineType: 'Dashed' },
|
|
171
|
+
lineB: { lineType: 'Solid' },
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const radios = getAllByRole('radio');
|
|
176
|
+
const lineBRadio = radios.find((r) => r.value === 'lineB');
|
|
177
|
+
|
|
178
|
+
fireEvent.click(lineBRadio);
|
|
179
|
+
|
|
180
|
+
const [updatedData] = onChange.mock.calls[0];
|
|
181
|
+
expect(updatedData.lineA.lineType).toBe('Dashed');
|
|
182
|
+
expect(updatedData.lineB.lineType).toBe('Solid');
|
|
183
|
+
expect(updatedData.numberOfLines).toBe(2);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('does not call onChange when disabled', () => {
|
|
187
|
+
const { getAllByRole } = renderComponent({
|
|
188
|
+
disabled: true,
|
|
189
|
+
gssLineData: {
|
|
190
|
+
selectedTool: 'lineA',
|
|
191
|
+
numberOfLines: 2,
|
|
192
|
+
lineA: { lineType: 'Solid' },
|
|
193
|
+
lineB: { lineType: 'Solid' },
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const radios = getAllByRole('radio');
|
|
198
|
+
const lineBRadio = radios.find((r) => r.value === 'lineB');
|
|
199
|
+
|
|
200
|
+
// Disabled radios should not fire change events
|
|
201
|
+
expect(lineBRadio).toBeDisabled();
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe('lineTypeChange', () => {
|
|
206
|
+
it('calls onChange with updated lineType for Line A when Solid button is clicked', () => {
|
|
207
|
+
const { getAllByText } = renderComponent({
|
|
208
|
+
gssLineData: {
|
|
209
|
+
selectedTool: 'lineA',
|
|
210
|
+
numberOfLines: 2,
|
|
211
|
+
lineA: { lineType: 'Dashed' },
|
|
212
|
+
lineB: { lineType: 'Solid' },
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
const solidButtons = getAllByText(/Solid/);
|
|
217
|
+
// First solid button should be for Line A
|
|
218
|
+
fireEvent.click(solidButtons[0]);
|
|
219
|
+
|
|
220
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
221
|
+
const [updatedData, oldSelectedTool] = onChange.mock.calls[0];
|
|
222
|
+
expect(updatedData.lineA.lineType).toBe('Solid');
|
|
223
|
+
expect(oldSelectedTool).toBe('lineA');
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('calls onChange with updated lineType for Line A when Dashed button is clicked', () => {
|
|
227
|
+
const { getAllByText } = renderComponent({
|
|
228
|
+
gssLineData: {
|
|
229
|
+
selectedTool: 'lineA',
|
|
230
|
+
numberOfLines: 2,
|
|
231
|
+
lineA: { lineType: 'Solid' },
|
|
232
|
+
lineB: { lineType: 'Solid' },
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const dashedButtons = getAllByText(/Dashed/);
|
|
237
|
+
// First dashed button should be for Line A
|
|
238
|
+
fireEvent.click(dashedButtons[0]);
|
|
239
|
+
|
|
240
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
241
|
+
const [updatedData, oldSelectedTool] = onChange.mock.calls[0];
|
|
242
|
+
expect(updatedData.lineA.lineType).toBe('Dashed');
|
|
243
|
+
expect(oldSelectedTool).toBe('lineA');
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('calls onChange with updated lineType for Line B when Solid button is clicked', () => {
|
|
247
|
+
const { getAllByText } = renderComponent({
|
|
248
|
+
gssLineData: {
|
|
249
|
+
selectedTool: 'lineB',
|
|
250
|
+
numberOfLines: 2,
|
|
251
|
+
lineA: { lineType: 'Solid' },
|
|
252
|
+
lineB: { lineType: 'Dashed' },
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
const solidButtons = getAllByText(/Solid/);
|
|
257
|
+
// Second solid button should be for Line B
|
|
258
|
+
fireEvent.click(solidButtons[1]);
|
|
259
|
+
|
|
260
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
261
|
+
const [updatedData, oldSelectedTool] = onChange.mock.calls[0];
|
|
262
|
+
expect(updatedData.lineB.lineType).toBe('Solid');
|
|
263
|
+
expect(oldSelectedTool).toBe('lineB');
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('calls onChange with updated lineType for Line B when Dashed button is clicked', () => {
|
|
267
|
+
const { getAllByText } = renderComponent({
|
|
268
|
+
gssLineData: {
|
|
269
|
+
selectedTool: 'lineB',
|
|
270
|
+
numberOfLines: 2,
|
|
271
|
+
lineA: { lineType: 'Solid' },
|
|
272
|
+
lineB: { lineType: 'Solid' },
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
const dashedButtons = getAllByText(/Dashed/);
|
|
277
|
+
// Second dashed button should be for Line B
|
|
278
|
+
fireEvent.click(dashedButtons[1]);
|
|
279
|
+
|
|
280
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
281
|
+
const [updatedData, oldSelectedTool] = onChange.mock.calls[0];
|
|
282
|
+
expect(updatedData.lineB.lineType).toBe('Dashed');
|
|
283
|
+
expect(oldSelectedTool).toBe('lineB');
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('preserves other line properties when changing Line A lineType', () => {
|
|
287
|
+
const { getAllByText } = renderComponent({
|
|
288
|
+
gssLineData: {
|
|
289
|
+
selectedTool: 'lineA',
|
|
290
|
+
numberOfLines: 2,
|
|
291
|
+
lineA: { lineType: 'Solid' },
|
|
292
|
+
lineB: { lineType: 'Dashed' },
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const dashedButtons = getAllByText(/Dashed/);
|
|
297
|
+
fireEvent.click(dashedButtons[0]);
|
|
298
|
+
|
|
299
|
+
const [updatedData] = onChange.mock.calls[0];
|
|
300
|
+
expect(updatedData.lineA.lineType).toBe('Dashed');
|
|
301
|
+
expect(updatedData.lineB.lineType).toBe('Dashed');
|
|
302
|
+
expect(updatedData.selectedTool).toBe('lineA');
|
|
303
|
+
expect(updatedData.numberOfLines).toBe(2);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('preserves other line properties when changing Line B lineType', () => {
|
|
307
|
+
const { getAllByText } = renderComponent({
|
|
308
|
+
gssLineData: {
|
|
309
|
+
selectedTool: 'lineB',
|
|
310
|
+
numberOfLines: 2,
|
|
311
|
+
lineA: { lineType: 'Dashed' },
|
|
312
|
+
lineB: { lineType: 'Solid' },
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
const dashedButtons = getAllByText(/Dashed/);
|
|
317
|
+
fireEvent.click(dashedButtons[1]);
|
|
318
|
+
|
|
319
|
+
const [updatedData] = onChange.mock.calls[0];
|
|
320
|
+
expect(updatedData.lineA.lineType).toBe('Dashed');
|
|
321
|
+
expect(updatedData.lineB.lineType).toBe('Dashed');
|
|
322
|
+
expect(updatedData.selectedTool).toBe('lineB');
|
|
323
|
+
expect(updatedData.numberOfLines).toBe(2);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it('handles multiple line type changes correctly', () => {
|
|
327
|
+
const { getAllByText } = renderComponent({
|
|
328
|
+
gssLineData: {
|
|
329
|
+
selectedTool: 'lineA',
|
|
330
|
+
numberOfLines: 2,
|
|
331
|
+
lineA: { lineType: 'Solid' },
|
|
332
|
+
lineB: { lineType: 'Solid' },
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// Change Line A to Dashed
|
|
337
|
+
let dashedButtons = getAllByText(/Dashed/);
|
|
338
|
+
fireEvent.click(dashedButtons[0]);
|
|
339
|
+
|
|
340
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
341
|
+
let [updatedData] = onChange.mock.calls[0];
|
|
342
|
+
expect(updatedData.lineA.lineType).toBe('Dashed');
|
|
343
|
+
|
|
344
|
+
// Change Line B to Dashed
|
|
345
|
+
dashedButtons = getAllByText(/Dashed/);
|
|
346
|
+
fireEvent.click(dashedButtons[1]);
|
|
347
|
+
|
|
348
|
+
expect(onChange).toHaveBeenCalledTimes(2);
|
|
349
|
+
[updatedData] = onChange.mock.calls[1];
|
|
350
|
+
expect(updatedData.lineB.lineType).toBe('Dashed');
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('does not call onChange when line type button is disabled', () => {
|
|
354
|
+
const { getAllByRole } = renderComponent({
|
|
355
|
+
disabled: true,
|
|
356
|
+
gssLineData: {
|
|
357
|
+
selectedTool: 'lineA',
|
|
358
|
+
numberOfLines: 2,
|
|
359
|
+
lineA: { lineType: 'Solid' },
|
|
360
|
+
lineB: { lineType: 'Solid' },
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
const buttons = getAllByRole('button');
|
|
365
|
+
|
|
366
|
+
buttons.forEach((button) => {
|
|
367
|
+
expect(button).toBeDisabled();
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it('maintains correct state when clicking same line type that is already selected', () => {
|
|
372
|
+
const { getAllByText } = renderComponent({
|
|
373
|
+
gssLineData: {
|
|
374
|
+
selectedTool: 'lineA',
|
|
375
|
+
numberOfLines: 2,
|
|
376
|
+
lineA: { lineType: 'Solid' },
|
|
377
|
+
lineB: { lineType: 'Solid' },
|
|
378
|
+
},
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
const solidButtons = getAllByText(/Solid/);
|
|
382
|
+
fireEvent.click(solidButtons[0]); // Click Solid when already Solid
|
|
383
|
+
|
|
384
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
385
|
+
const [updatedData] = onChange.mock.calls[0];
|
|
386
|
+
expect(updatedData.lineA.lineType).toBe('Solid');
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
describe('integration tests', () => {
|
|
391
|
+
it('allows switching selected tool and changing line type in sequence', () => {
|
|
392
|
+
const { getAllByRole, getAllByText } = renderComponent({
|
|
393
|
+
gssLineData: {
|
|
394
|
+
selectedTool: 'lineA',
|
|
395
|
+
numberOfLines: 2,
|
|
396
|
+
lineA: { lineType: 'Solid' },
|
|
397
|
+
lineB: { lineType: 'Solid' },
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
// Switch to Line B
|
|
402
|
+
const radios = getAllByRole('radio');
|
|
403
|
+
const lineBRadio = radios.find((r) => r.value === 'lineB');
|
|
404
|
+
fireEvent.click(lineBRadio);
|
|
405
|
+
|
|
406
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
407
|
+
let [updatedData] = onChange.mock.calls[0];
|
|
408
|
+
expect(updatedData.selectedTool).toBe('lineB');
|
|
409
|
+
|
|
410
|
+
// Change Line B to Dashed
|
|
411
|
+
const dashedButtons = getAllByText(/Dashed/);
|
|
412
|
+
fireEvent.click(dashedButtons[1]);
|
|
413
|
+
|
|
414
|
+
expect(onChange).toHaveBeenCalledTimes(2);
|
|
415
|
+
[updatedData] = onChange.mock.calls[1];
|
|
416
|
+
expect(updatedData.lineB.lineType).toBe('Dashed');
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
it('handles complete workflow of switching between all tools and changing line types', () => {
|
|
420
|
+
const { getAllByRole, getAllByText } = renderComponent({
|
|
421
|
+
gssLineData: {
|
|
422
|
+
selectedTool: 'lineA',
|
|
423
|
+
numberOfLines: 2,
|
|
424
|
+
lineA: { lineType: 'Solid' },
|
|
425
|
+
lineB: { lineType: 'Solid' },
|
|
426
|
+
},
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
// Change Line A to Dashed
|
|
430
|
+
let dashedButtons = getAllByText(/Dashed/);
|
|
431
|
+
fireEvent.click(dashedButtons[0]);
|
|
432
|
+
expect(onChange.mock.calls[0][0].lineA.lineType).toBe('Dashed');
|
|
433
|
+
|
|
434
|
+
// Switch to Line B
|
|
435
|
+
const radios = getAllByRole('radio');
|
|
436
|
+
const lineBRadio = radios.find((r) => r.value === 'lineB');
|
|
437
|
+
fireEvent.click(lineBRadio);
|
|
438
|
+
expect(onChange.mock.calls[1][0].selectedTool).toBe('lineB');
|
|
439
|
+
|
|
440
|
+
// Change Line B to Dashed
|
|
441
|
+
dashedButtons = getAllByText(/Dashed/);
|
|
442
|
+
fireEvent.click(dashedButtons[1]);
|
|
443
|
+
expect(onChange.mock.calls[2][0].lineB.lineType).toBe('Dashed');
|
|
444
|
+
|
|
445
|
+
// Switch to Solution Set
|
|
446
|
+
const solutionSetRadio = radios.find((r) => r.value === 'solutionSet');
|
|
447
|
+
fireEvent.click(solutionSetRadio);
|
|
448
|
+
expect(onChange.mock.calls[3][0].selectedTool).toBe('solutionSet');
|
|
449
|
+
|
|
450
|
+
expect(onChange).toHaveBeenCalledTimes(4);
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { render } from '@pie-lib/test-utils';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import UndoRedo from '../undo-redo';
|
|
4
|
+
|
|
5
|
+
describe('UndoRedo', () => {
|
|
6
|
+
let onUndo = jest.fn();
|
|
7
|
+
let onRedo = jest.fn();
|
|
8
|
+
let onReset = jest.fn();
|
|
9
|
+
|
|
10
|
+
const renderComponent = (extras) => {
|
|
11
|
+
const defaults = {
|
|
12
|
+
onUndo,
|
|
13
|
+
onRedo,
|
|
14
|
+
onReset,
|
|
15
|
+
};
|
|
16
|
+
const props = { ...defaults, ...extras };
|
|
17
|
+
return render(<UndoRedo {...props} />);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('rendering', () => {
|
|
21
|
+
it('renders without crashing', () => {
|
|
22
|
+
const { container } = renderComponent();
|
|
23
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { useDebounce } from '../use-debounce';
|
|
3
|
+
|
|
4
|
+
jest.useFakeTimers();
|
|
5
|
+
|
|
6
|
+
jest.mock('react', () => ({
|
|
7
|
+
useState: jest.fn(),
|
|
8
|
+
useEffect: jest.fn((fn, deps) => fn()),
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
describe('useDebounce', () => {
|
|
12
|
+
it('..', () => {
|
|
13
|
+
const debouncedValue = null;
|
|
14
|
+
const setDebouncedValue = jest.fn();
|
|
15
|
+
|
|
16
|
+
useState.mockReturnValue([debouncedValue, setDebouncedValue]);
|
|
17
|
+
useDebounce('foo', 1000);
|
|
18
|
+
jest.runAllTimers();
|
|
19
|
+
expect(setDebouncedValue).toHaveBeenCalledWith('foo');
|
|
20
|
+
});
|
|
21
|
+
});
|