@pie-lib/tools 0.43.0-mui-update.0 → 1.0.0-next.0
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.md +11 -106
- package/package.json +11 -3
- package/src/__tests__/rotatable.test.jsx +84 -41
- package/src/protractor/__tests__/graphic.test.jsx +57 -6
- package/src/protractor/__tests__/index.test.jsx +58 -6
- package/src/ruler/__tests__/graphic.test.jsx +57 -16
- package/src/ruler/__tests__/index.test.jsx +70 -12
- package/src/ruler/__tests__/unit-type.test.jsx +59 -6
- package/src/ruler/__tests__/unit.test.jsx +61 -8
- package/src/__tests__/__snapshots__/rotatable.test.jsx.snap +0 -37
- package/src/protractor/__tests__/__snapshots__/graphic.test.jsx.snap +0 -1234
- package/src/protractor/__tests__/__snapshots__/index.test.jsx.snap +0 -40
- package/src/ruler/__tests__/__snapshots__/graphic.test.jsx.snap +0 -160
- package/src/ruler/__tests__/__snapshots__/index.test.jsx.snap +0 -45
- package/src/ruler/__tests__/__snapshots__/unit-type.test.jsx.snap +0 -12
- package/src/ruler/__tests__/__snapshots__/unit.test.jsx.snap +0 -30
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
# [0.
|
|
6
|
+
# [1.0.0-next.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.29.2-next.0...@pie-lib/tools@1.0.0-next.0) (2026-01-19)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @pie-lib/tools
|
|
9
9
|
|
|
@@ -11,44 +11,12 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @pie-lib/tools
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# [0.41.0-mui-update.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.40.0-mui-update.0...@pie-lib/tools@0.41.0-mui-update.0) (2025-12-17)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @pie-lib/tools
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
# [0.40.0-mui-update.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.39.0-mui-update.0...@pie-lib/tools@0.40.0-mui-update.0) (2025-12-17)
|
|
31
|
-
|
|
32
|
-
**Note:** Version bump only for package @pie-lib/tools
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# [0.39.0-mui-update.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.38.0-mui-update.0...@pie-lib/tools@0.39.0-mui-update.0) (2025-12-11)
|
|
39
|
-
|
|
40
|
-
**Note:** Version bump only for package @pie-lib/tools
|
|
41
|
-
|
|
42
|
-
|
|
14
|
+
## [0.29.2-next.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.43.0-mui-update.0...@pie-lib/tools@0.29.2-next.0) (2026-01-19)
|
|
43
15
|
|
|
44
16
|
|
|
17
|
+
### Bug Fixes
|
|
45
18
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
### Features
|
|
50
|
-
|
|
51
|
-
* sync latest changes from dev ([c936e9c](https://github.com/pie-framework/pie-lib/commit/c936e9c7f9e095e7d9b9805ac2bf72bd271e05f1))
|
|
19
|
+
* bump config-ui PD-5265 ([77d0c78](https://github.com/pie-framework/pie-lib/commit/77d0c78cacfa57e93ed17e7a7f1257f4a9cf6ab3))
|
|
52
20
|
|
|
53
21
|
|
|
54
22
|
|
|
@@ -56,142 +24,79 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
56
24
|
|
|
57
25
|
## [0.29.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.25.1...@pie-lib/tools@0.29.1) (2025-10-22)
|
|
58
26
|
|
|
59
|
-
|
|
60
27
|
### Bug Fixes
|
|
61
28
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
29
|
+
- bump config-ui PD-5265 ([77d0c78](https://github.com/pie-framework/pie-lib/commit/77d0c78cacfa57e93ed17e7a7f1257f4a9cf6ab3))
|
|
67
30
|
|
|
68
31
|
# [0.29.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.25.0...@pie-lib/tools@0.29.0) (2025-10-16)
|
|
69
32
|
|
|
70
33
|
**Note:** Version bump only for package @pie-lib/tools
|
|
71
34
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
35
|
# [0.28.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.25.0...@pie-lib/tools@0.28.0) (2025-10-16)
|
|
77
36
|
|
|
78
37
|
**Note:** Version bump only for package @pie-lib/tools
|
|
79
38
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
39
|
# [0.27.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.25.0...@pie-lib/tools@0.27.0) (2025-10-16)
|
|
85
40
|
|
|
86
41
|
**Note:** Version bump only for package @pie-lib/tools
|
|
87
42
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
43
|
# [0.26.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.25.0...@pie-lib/tools@0.26.0) (2025-10-16)
|
|
93
44
|
|
|
94
45
|
**Note:** Version bump only for package @pie-lib/tools
|
|
95
46
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
47
|
## [0.25.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.25.0...@pie-lib/tools@0.25.1) (2025-10-14)
|
|
101
48
|
|
|
102
49
|
**Note:** Version bump only for package @pie-lib/tools
|
|
103
50
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
51
|
# [0.25.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.9.36...@pie-lib/tools@0.25.0) (2025-09-25)
|
|
109
52
|
|
|
110
|
-
|
|
111
53
|
### Bug Fixes
|
|
112
54
|
|
|
113
|
-
|
|
114
|
-
|
|
55
|
+
- fixed pie-lib/icons import [PD-5126](<[dcb506c](https://github.com/pie-framework/pie-lib/commit/dcb506c914a177f6d88bf73247a023bfe71dac1f)>)
|
|
115
56
|
|
|
116
57
|
### Features
|
|
117
58
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
59
|
+
- split pie-toolbox into multiple packages [PD-5126](<[7d55a25](https://github.com/pie-framework/pie-lib/commit/7d55a2552d084cd3d0d5c00dc77411b2ced2f5e2)>)
|
|
123
60
|
|
|
124
61
|
# [0.24.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.23.0...@pie-lib/tools@0.24.0) (2025-09-18)
|
|
125
62
|
|
|
126
63
|
**Note:** Version bump only for package @pie-lib/tools
|
|
127
64
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
65
|
# [0.23.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.22.0...@pie-lib/tools@0.23.0) (2025-09-18)
|
|
133
66
|
|
|
134
67
|
**Note:** Version bump only for package @pie-lib/tools
|
|
135
68
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
69
|
# [0.22.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.9.36...@pie-lib/tools@0.22.0) (2025-09-18)
|
|
141
70
|
|
|
142
|
-
|
|
143
71
|
### Bug Fixes
|
|
144
72
|
|
|
145
|
-
|
|
146
|
-
|
|
73
|
+
- fixed pie-lib/icons import [PD-5126](<[dcb506c](https://github.com/pie-framework/pie-lib/commit/dcb506c914a177f6d88bf73247a023bfe71dac1f)>)
|
|
147
74
|
|
|
148
75
|
### Features
|
|
149
76
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
77
|
+
- split pie-toolbox into multiple packages [PD-5126](<[7d55a25](https://github.com/pie-framework/pie-lib/commit/7d55a2552d084cd3d0d5c00dc77411b2ced2f5e2)>)
|
|
155
78
|
|
|
156
79
|
# [0.21.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.20.0...@pie-lib/tools@0.21.0) (2025-09-17)
|
|
157
80
|
|
|
158
81
|
**Note:** Version bump only for package @pie-lib/tools
|
|
159
82
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
83
|
# [0.20.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.19.0...@pie-lib/tools@0.20.0) (2025-09-17)
|
|
165
84
|
|
|
166
85
|
**Note:** Version bump only for package @pie-lib/tools
|
|
167
86
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
87
|
# [0.19.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.18.1...@pie-lib/tools@0.19.0) (2025-09-17)
|
|
173
88
|
|
|
174
89
|
**Note:** Version bump only for package @pie-lib/tools
|
|
175
90
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
91
|
## [0.18.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.9.36...@pie-lib/tools@0.18.1) (2025-08-11)
|
|
181
92
|
|
|
182
|
-
|
|
183
93
|
### Bug Fixes
|
|
184
94
|
|
|
185
|
-
|
|
186
|
-
|
|
95
|
+
- fixed pie-lib/icons import [PD-5126](<[dcb506c](https://github.com/pie-framework/pie-lib/commit/dcb506c914a177f6d88bf73247a023bfe71dac1f)>)
|
|
187
96
|
|
|
188
97
|
### Features
|
|
189
98
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
99
|
+
- split pie-toolbox into multiple packages [PD-5126](<[7d55a25](https://github.com/pie-framework/pie-lib/commit/7d55a2552d084cd3d0d5c00dc77411b2ced2f5e2)>)
|
|
195
100
|
|
|
196
101
|
# [0.18.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/tools@0.9.36...@pie-lib/tools@0.18.0) (2025-08-07)
|
|
197
102
|
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "1.0.0-next.0",
|
|
7
7
|
"description": "Some interactive tools",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"react",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@mapbox/point-geometry": "^0.1.0",
|
|
23
23
|
"@mui/icons-material": "^7.3.4",
|
|
24
24
|
"@mui/material": "^7.3.4",
|
|
25
|
-
"@pie-lib/style-utils": "0.
|
|
25
|
+
"@pie-lib/style-utils": "0.21.2-next.16",
|
|
26
26
|
"assert": "^1.4.1",
|
|
27
27
|
"debug": "^4.1.1",
|
|
28
28
|
"lodash": "^4.17.11",
|
|
@@ -39,5 +39,13 @@
|
|
|
39
39
|
"@mui/material": "^7.3.4",
|
|
40
40
|
"react": "^18.2.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "e0f8f2250addd014938f4a631ab86cafe16b2730",
|
|
43
|
+
"exports": {
|
|
44
|
+
".": {
|
|
45
|
+
"require": "./lib/index.js",
|
|
46
|
+
"import": "./src/index.js",
|
|
47
|
+
"default": "./lib/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./esm": "./esm/index.js"
|
|
50
|
+
}
|
|
43
51
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { shallow } from 'enzyme';
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
3
2
|
import { Rotatable } from '../rotatable';
|
|
4
3
|
import React from 'react';
|
|
5
|
-
/** Note: we use the test renderer because we need to make use of ref mocking. */
|
|
6
|
-
import TestRenderer from 'react-test-renderer'; // ES6
|
|
7
4
|
import { distanceBetween } from '../anchor-utils';
|
|
8
5
|
|
|
9
6
|
import Point from '@mapbox/point-geometry';
|
|
@@ -25,59 +22,105 @@ const event = (x = 0, y = 0) => ({
|
|
|
25
22
|
});
|
|
26
23
|
|
|
27
24
|
describe('rotatable', () => {
|
|
28
|
-
describe('
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
describe('rendering', () => {
|
|
26
|
+
// Note: The Rotatable component has a bug where this.handles is undefined
|
|
27
|
+
// when no handle prop is provided, causing componentWillUnmount to crash.
|
|
28
|
+
// We patch the prototype to fix this for testing.
|
|
29
|
+
beforeAll(() => {
|
|
30
|
+
const originalInit = Rotatable.prototype.initHandles;
|
|
31
|
+
Rotatable.prototype.initHandles = function() {
|
|
32
|
+
this.handles = this.handles || [];
|
|
33
|
+
return originalInit.call(this);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const originalUnmount = Rotatable.prototype.componentWillUnmount;
|
|
37
|
+
Rotatable.prototype.componentWillUnmount = function() {
|
|
38
|
+
this.handles = this.handles || [];
|
|
39
|
+
return originalUnmount.call(this);
|
|
40
|
+
};
|
|
32
41
|
});
|
|
33
42
|
|
|
34
|
-
it('renders
|
|
35
|
-
const
|
|
43
|
+
it('renders children', () => {
|
|
44
|
+
const { container } = render(<Rotatable classes={{}}>foo</Rotatable>);
|
|
45
|
+
expect(container).toHaveTextContent('foo');
|
|
46
|
+
});
|
|
36
47
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
it('renders with handle prop', () => {
|
|
49
|
+
const { container } = render(
|
|
50
|
+
<Rotatable handle={[{ class: 'handle', origin: 'bottom left' }]} classes={{}}>
|
|
51
|
+
<div className="handle">foo</div>
|
|
52
|
+
</Rotatable>
|
|
53
|
+
);
|
|
54
|
+
expect(container).toHaveTextContent('foo');
|
|
55
|
+
expect(container.querySelector('.handle')).toBeInTheDocument();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('renders with startPosition prop', () => {
|
|
59
|
+
const { container } = render(
|
|
60
|
+
<Rotatable classes={{}} startPosition={{ left: 50, top: 100 }}>
|
|
61
|
+
foo
|
|
62
|
+
</Rotatable>
|
|
63
|
+
);
|
|
64
|
+
expect(container).toHaveTextContent('foo');
|
|
46
65
|
});
|
|
47
66
|
});
|
|
48
67
|
|
|
49
68
|
describe('logic', () => {
|
|
50
|
-
let
|
|
69
|
+
let el, instance, mockRef;
|
|
51
70
|
|
|
52
71
|
beforeEach(() => {
|
|
72
|
+
// Mock DOM elements
|
|
53
73
|
el = {
|
|
54
74
|
addEventListener: jest.fn(),
|
|
55
75
|
removeEventListener: jest.fn(),
|
|
56
76
|
};
|
|
57
|
-
wrapper = TestRenderer.create(
|
|
58
|
-
<Rotatable handle={[{ class: 'foo', origin: 'bottom left' }]} classes={{ rotatable: 'rotatable' }}>
|
|
59
|
-
<div className={'foo'}>foo</div>
|
|
60
|
-
</Rotatable>,
|
|
61
|
-
{
|
|
62
|
-
createNodeMock: (e) => {
|
|
63
|
-
if (e.props.className === 'rotatable') {
|
|
64
|
-
return {
|
|
65
|
-
querySelector: jest.fn(() => el),
|
|
66
|
-
getBoundingClientRect: jest.fn(() => ({
|
|
67
|
-
left: 0,
|
|
68
|
-
top: 0,
|
|
69
|
-
width: 100,
|
|
70
|
-
height: 100,
|
|
71
|
-
})),
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
);
|
|
77
77
|
|
|
78
|
+
mockRef = {
|
|
79
|
+
querySelector: jest.fn(() => el),
|
|
80
|
+
getBoundingClientRect: jest.fn(() => ({
|
|
81
|
+
left: 0,
|
|
82
|
+
top: 0,
|
|
83
|
+
width: 100,
|
|
84
|
+
height: 100,
|
|
85
|
+
})),
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Mock document methods
|
|
78
89
|
document.addEventListener = jest.fn();
|
|
79
90
|
document.removeEventListener = jest.fn();
|
|
80
|
-
|
|
91
|
+
|
|
92
|
+
// Create component instance directly
|
|
93
|
+
const props = {
|
|
94
|
+
handle: [{ class: 'foo', origin: 'bottom left' }],
|
|
95
|
+
classes: { rotatable: 'rotatable' },
|
|
96
|
+
children: <div className={'foo'}>foo</div>,
|
|
97
|
+
startPosition: { left: 0, top: 0 },
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
instance = new Rotatable(props);
|
|
101
|
+
instance.rotatable = mockRef;
|
|
102
|
+
|
|
103
|
+
// Mock clientWidth and clientHeight for originToXY
|
|
104
|
+
Object.defineProperty(instance.rotatable, 'clientWidth', { value: 100, writable: true });
|
|
105
|
+
Object.defineProperty(instance.rotatable, 'clientHeight', { value: 100, writable: true });
|
|
106
|
+
|
|
107
|
+
// Mock setState to be synchronous for testing
|
|
108
|
+
instance.setState = jest.fn((updater, callback) => {
|
|
109
|
+
if (typeof updater === 'function') {
|
|
110
|
+
instance.state = { ...instance.state, ...updater(instance.state) };
|
|
111
|
+
} else {
|
|
112
|
+
instance.state = { ...instance.state, ...updater };
|
|
113
|
+
}
|
|
114
|
+
if (callback) callback();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Initialize the component
|
|
118
|
+
instance.componentDidMount();
|
|
119
|
+
|
|
120
|
+
// Manually set up handles array if it's still undefined after mount
|
|
121
|
+
if (!instance.handles) {
|
|
122
|
+
instance.handles = [{ el, mousedownHandler: jest.fn() }];
|
|
123
|
+
}
|
|
81
124
|
});
|
|
82
125
|
|
|
83
126
|
describe('rotate', () => {
|
|
@@ -1,13 +1,64 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
|
3
3
|
import { Graphic } from '../graphic';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
|
|
6
6
|
describe('graphic', () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const theme = createTheme();
|
|
8
|
+
|
|
9
|
+
const renderComponent = (props = {}) => {
|
|
10
|
+
return render(
|
|
11
|
+
<ThemeProvider theme={theme}>
|
|
12
|
+
<Graphic {...props} />
|
|
13
|
+
</ThemeProvider>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
describe('rendering', () => {
|
|
18
|
+
it('renders svg with correct viewBox', () => {
|
|
19
|
+
const { container } = renderComponent();
|
|
20
|
+
const svg = container.querySelector('svg');
|
|
21
|
+
expect(svg).toBeInTheDocument();
|
|
22
|
+
expect(svg).toHaveAttribute('viewBox', '0 0 102 61');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('renders path element', () => {
|
|
26
|
+
const { container } = renderComponent();
|
|
27
|
+
const path = container.querySelector('path');
|
|
28
|
+
expect(path).toBeInTheDocument();
|
|
29
|
+
expect(path).toHaveAttribute('d', 'M 1,50 A 1,1 0 0 1 100,50 L 100,60 L 1,60 Z');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('renders circle element', () => {
|
|
33
|
+
const { container } = renderComponent();
|
|
34
|
+
const circle = container.querySelector('circle');
|
|
35
|
+
expect(circle).toBeInTheDocument();
|
|
36
|
+
expect(circle).toHaveAttribute('r', '4');
|
|
37
|
+
expect(circle).toHaveAttribute('cx', '50.5');
|
|
38
|
+
expect(circle).toHaveAttribute('cy', '50');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('renders multiple line elements', () => {
|
|
42
|
+
const { container } = renderComponent();
|
|
43
|
+
const lines = container.querySelectorAll('line');
|
|
44
|
+
// Should render 181 angle lines + 2 crosshair lines = 183+ lines
|
|
45
|
+
expect(lines.length).toBeGreaterThan(180);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('renders text elements for angles', () => {
|
|
49
|
+
const { container } = renderComponent();
|
|
50
|
+
const texts = container.querySelectorAll('text');
|
|
51
|
+
// Should render text for angles 0, 10, 20, ..., 180 (19 texts)
|
|
52
|
+
expect(texts.length).toBeGreaterThan(15);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('renders correct angle labels', () => {
|
|
56
|
+
const { container } = renderComponent();
|
|
57
|
+
const texts = container.querySelectorAll('text');
|
|
58
|
+
const textContents = Array.from(texts).map(t => t.textContent);
|
|
59
|
+
expect(textContents).toContain('0');
|
|
60
|
+
expect(textContents).toContain('90');
|
|
61
|
+
expect(textContents).toContain('180');
|
|
11
62
|
});
|
|
12
63
|
});
|
|
13
64
|
});
|
|
@@ -1,13 +1,65 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
|
3
3
|
import { Protractor } from '../index';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
|
|
6
|
+
// Mock the Rotatable component to avoid complex DOM interactions
|
|
7
|
+
jest.mock('../../rotatable', () => {
|
|
8
|
+
return function MockRotatable({ children }) {
|
|
9
|
+
return <div data-testid="rotatable">{children}</div>;
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// Mock the Graphic component
|
|
14
|
+
jest.mock('../graphic', () => {
|
|
15
|
+
return function MockGraphic() {
|
|
16
|
+
return <div data-testid="protractor-graphic" />;
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
|
|
6
20
|
describe('protractor', () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
21
|
+
const theme = createTheme();
|
|
22
|
+
|
|
23
|
+
const renderComponent = (props = {}) => {
|
|
24
|
+
const defaultProps = {
|
|
25
|
+
width: 450,
|
|
26
|
+
...props,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return render(
|
|
30
|
+
<ThemeProvider theme={theme}>
|
|
31
|
+
<Protractor {...defaultProps} />
|
|
32
|
+
</ThemeProvider>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
describe('rendering', () => {
|
|
37
|
+
it('renders protractor component', () => {
|
|
38
|
+
renderComponent();
|
|
39
|
+
expect(screen.getByTestId('rotatable')).toBeInTheDocument();
|
|
40
|
+
expect(screen.getByTestId('protractor-graphic')).toBeInTheDocument();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('renders with default width', () => {
|
|
44
|
+
const { container } = renderComponent();
|
|
45
|
+
const protractorDiv = container.querySelector('div[style*="width"]');
|
|
46
|
+
expect(protractorDiv).toHaveStyle({ width: '450px' });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('renders with custom width', () => {
|
|
50
|
+
const { container } = renderComponent({ width: 600 });
|
|
51
|
+
const protractorDiv = container.querySelector('div[style*="width"]');
|
|
52
|
+
expect(protractorDiv).toHaveStyle({ width: '600px' });
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('renders with custom startPosition', () => {
|
|
56
|
+
renderComponent({ startPosition: { left: 100, top: 200 } });
|
|
57
|
+
expect(screen.getByTestId('protractor-graphic')).toBeInTheDocument();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('renders with className', () => {
|
|
61
|
+
const { container } = renderComponent({ className: 'custom-class' });
|
|
62
|
+
expect(screen.getByTestId('rotatable')).toBeInTheDocument();
|
|
11
63
|
});
|
|
12
64
|
});
|
|
13
65
|
});
|
|
@@ -1,23 +1,64 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
|
3
3
|
import { Graphic } from '../graphic';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
|
|
6
6
|
describe('graphic', () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
const theme = createTheme();
|
|
8
|
+
|
|
9
|
+
const renderComponent = (props = {}) => {
|
|
10
|
+
const defaultProps = {
|
|
11
|
+
width: 300,
|
|
12
|
+
height: 100,
|
|
13
|
+
units: 12,
|
|
14
|
+
unit: {
|
|
15
|
+
type: 'in',
|
|
16
|
+
ticks: 16,
|
|
17
|
+
},
|
|
18
|
+
...props,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return render(
|
|
22
|
+
<ThemeProvider theme={theme}>
|
|
23
|
+
<Graphic {...defaultProps} />
|
|
24
|
+
</ThemeProvider>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
describe('rendering', () => {
|
|
29
|
+
it('renders svg with correct viewBox', () => {
|
|
30
|
+
const { container } = renderComponent({ width: 300, height: 100 });
|
|
31
|
+
const svg = container.querySelector('svg');
|
|
32
|
+
expect(svg).toBeInTheDocument();
|
|
33
|
+
expect(svg).toHaveAttribute('viewBox', '0 0 300 100');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('renders background rect with correct dimensions', () => {
|
|
37
|
+
const { container } = renderComponent({ width: 300, height: 100 });
|
|
38
|
+
const rect = container.querySelector('rect');
|
|
39
|
+
expect(rect).toBeInTheDocument();
|
|
40
|
+
expect(rect).toHaveAttribute('width', '300');
|
|
41
|
+
expect(rect).toHaveAttribute('height', '100');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('renders correct number of unit markers', () => {
|
|
45
|
+
const { container } = renderComponent({ units: 12 });
|
|
46
|
+
const svg = container.querySelector('svg');
|
|
47
|
+
// Each unit renders as a group element with a specific structure
|
|
48
|
+
const groups = svg.querySelectorAll('g');
|
|
49
|
+
expect(groups.length).toBeGreaterThan(0);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('renders with different unit types', () => {
|
|
53
|
+
const { container } = renderComponent({ unit: { type: 'cm', ticks: 10 } });
|
|
54
|
+
const svg = container.querySelector('svg');
|
|
55
|
+
expect(svg).toBeInTheDocument();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('renders with custom dimensions', () => {
|
|
59
|
+
const { container } = renderComponent({ width: 480, height: 60, units: 10 });
|
|
60
|
+
const svg = container.querySelector('svg');
|
|
61
|
+
expect(svg).toHaveAttribute('viewBox', '0 0 480 60');
|
|
21
62
|
});
|
|
22
63
|
});
|
|
23
64
|
});
|