@instructure/ui-metric 10.2.0 → 10.2.1-snapshot-1
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 +8 -0
- package/es/Metric/__new-tests__/Metric.test.js +95 -0
- package/es/MetricGroup/__new-tests__/MetricGroup.test.js +133 -0
- package/lib/Metric/__new-tests__/Metric.test.js +97 -0
- package/lib/MetricGroup/__new-tests__/MetricGroup.test.js +135 -0
- package/package.json +15 -12
- package/src/Metric/__new-tests__/Metric.test.tsx +96 -0
- package/src/MetricGroup/__new-tests__/MetricGroup.test.tsx +125 -0
- package/tsconfig.build.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Metric/__new-tests__/Metric.test.d.ts +2 -0
- package/types/Metric/__new-tests__/Metric.test.d.ts.map +1 -0
- package/types/MetricGroup/__new-tests__/MetricGroup.test.d.ts +2 -0
- package/types/MetricGroup/__new-tests__/MetricGroup.test.d.ts.map +1 -0
- package/es/Metric/MetricLocator.js +0 -28
- package/es/Metric/locator.js +0 -26
- package/es/MetricGroup/MetricGroupLocator.js +0 -39
- package/es/MetricGroup/locator.js +0 -26
- package/lib/Metric/MetricLocator.js +0 -34
- package/lib/Metric/locator.js +0 -37
- package/lib/MetricGroup/MetricGroupLocator.js +0 -45
- package/lib/MetricGroup/locator.js +0 -37
- package/src/Metric/MetricLocator.ts +0 -29
- package/src/Metric/locator.ts +0 -27
- package/src/MetricGroup/MetricGroupLocator.ts +0 -40
- package/src/MetricGroup/locator.ts +0 -27
- package/types/Metric/MetricLocator.d.ts +0 -428
- package/types/Metric/MetricLocator.d.ts.map +0 -1
- package/types/Metric/locator.d.ts +0 -4
- package/types/Metric/locator.d.ts.map +0 -1
- package/types/MetricGroup/MetricGroupLocator.d.ts +0 -1823
- package/types/MetricGroup/MetricGroupLocator.d.ts.map +0 -1
- package/types/MetricGroup/locator.d.ts +0 -4
- package/types/MetricGroup/locator.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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
|
+
## [10.2.1-snapshot-1](https://github.com/instructure/instructure-ui/compare/v10.2.0...v10.2.1-snapshot-1) (2024-08-27)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-metric
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [10.2.0](https://github.com/instructure/instructure-ui/compare/v10.0.0...v10.2.0) (2024-08-23)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @instructure/ui-metric
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
var _Metric, _Metric2, _Metric3, _Metric4, _Metric5, _Metric6;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { render, screen } from '@testing-library/react';
|
|
28
|
+
import '@testing-library/jest-dom';
|
|
29
|
+
import { vi } from 'vitest';
|
|
30
|
+
import { Metric } from '../index';
|
|
31
|
+
describe('<Metric />', () => {
|
|
32
|
+
it('should render the label', async () => {
|
|
33
|
+
const _render = render(_Metric || (_Metric = /*#__PURE__*/React.createElement(Metric, {
|
|
34
|
+
renderLabel: "Grade",
|
|
35
|
+
renderValue: "80%"
|
|
36
|
+
}))),
|
|
37
|
+
container = _render.container;
|
|
38
|
+
expect(container).toHaveTextContent('Grade');
|
|
39
|
+
});
|
|
40
|
+
it('should render the value', async () => {
|
|
41
|
+
const _render2 = render(_Metric2 || (_Metric2 = /*#__PURE__*/React.createElement(Metric, {
|
|
42
|
+
renderLabel: "Grade",
|
|
43
|
+
renderValue: "80%"
|
|
44
|
+
}))),
|
|
45
|
+
container = _render2.container;
|
|
46
|
+
expect(container).toHaveTextContent('80%');
|
|
47
|
+
});
|
|
48
|
+
it('passes props through to Metric element', async () => {
|
|
49
|
+
render(_Metric3 || (_Metric3 = /*#__PURE__*/React.createElement(Metric, {
|
|
50
|
+
"data-testid": "metric",
|
|
51
|
+
"data-automation": "foo",
|
|
52
|
+
renderLabel: "Grade",
|
|
53
|
+
renderValue: "80%"
|
|
54
|
+
})));
|
|
55
|
+
const metric = screen.getByTestId('metric');
|
|
56
|
+
expect(metric).toHaveAttribute('data-automation', 'foo');
|
|
57
|
+
});
|
|
58
|
+
it('should not have role="gridcell" for the value', async () => {
|
|
59
|
+
render(_Metric4 || (_Metric4 = /*#__PURE__*/React.createElement(Metric, {
|
|
60
|
+
renderLabel: "Grade",
|
|
61
|
+
renderValue: "80%"
|
|
62
|
+
})));
|
|
63
|
+
const value = screen.getByText('80%');
|
|
64
|
+
expect(value).not.toHaveAttribute('role', 'gridcell');
|
|
65
|
+
});
|
|
66
|
+
it('should not have role=rowheader for the label', async () => {
|
|
67
|
+
render(_Metric5 || (_Metric5 = /*#__PURE__*/React.createElement(Metric, {
|
|
68
|
+
renderLabel: "Grade",
|
|
69
|
+
renderValue: "80%"
|
|
70
|
+
})));
|
|
71
|
+
const label = screen.getByText('Grade');
|
|
72
|
+
expect(label).not.toHaveAttribute('role', 'rowheader');
|
|
73
|
+
});
|
|
74
|
+
it('should allow ReactNodes as labels and values', async () => {
|
|
75
|
+
const _render3 = render(_Metric6 || (_Metric6 = /*#__PURE__*/React.createElement(Metric, {
|
|
76
|
+
renderLabel: /*#__PURE__*/React.createElement("div", null, "hello")
|
|
77
|
+
}))),
|
|
78
|
+
container = _render3.container;
|
|
79
|
+
expect(container).toHaveTextContent('hello');
|
|
80
|
+
});
|
|
81
|
+
it('should allow methods as labels', async () => {
|
|
82
|
+
const renderLabel = vi.fn();
|
|
83
|
+
render( /*#__PURE__*/React.createElement(Metric, {
|
|
84
|
+
renderLabel: renderLabel
|
|
85
|
+
}));
|
|
86
|
+
expect(renderLabel).toHaveBeenCalled();
|
|
87
|
+
});
|
|
88
|
+
it('should allow methods as values', async () => {
|
|
89
|
+
const renderValue = vi.fn();
|
|
90
|
+
render( /*#__PURE__*/React.createElement(Metric, {
|
|
91
|
+
renderValue: renderValue
|
|
92
|
+
}));
|
|
93
|
+
expect(renderValue).toHaveBeenCalled();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
var _MetricGroup, _MetricGroup2, _MetricGroup3, _MetricGroup4, _MetricGroup5, _MetricGroup6;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { render, screen } from '@testing-library/react';
|
|
28
|
+
import '@testing-library/jest-dom';
|
|
29
|
+
import { vi } from 'vitest';
|
|
30
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
31
|
+
import { MetricGroup } from '../index';
|
|
32
|
+
import { Metric } from '../../Metric';
|
|
33
|
+
describe('<MetricGroup />', () => {
|
|
34
|
+
let consoleErrorMock;
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
// Mocking console to prevent test output pollution and expect for messages
|
|
37
|
+
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
38
|
+
});
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
consoleErrorMock.mockRestore();
|
|
41
|
+
});
|
|
42
|
+
it('should render children', async () => {
|
|
43
|
+
const _render = render(_MetricGroup || (_MetricGroup = /*#__PURE__*/React.createElement(MetricGroup, null, /*#__PURE__*/React.createElement(Metric, {
|
|
44
|
+
renderLabel: "Grade",
|
|
45
|
+
renderValue: "80%"
|
|
46
|
+
}), /*#__PURE__*/React.createElement(Metric, {
|
|
47
|
+
renderLabel: "Late",
|
|
48
|
+
renderValue: "4"
|
|
49
|
+
}), /*#__PURE__*/React.createElement(Metric, {
|
|
50
|
+
renderLabel: "Missing",
|
|
51
|
+
renderValue: "2"
|
|
52
|
+
})))),
|
|
53
|
+
container = _render.container;
|
|
54
|
+
expect(container).toHaveTextContent('Grade80%Late4Missing2');
|
|
55
|
+
});
|
|
56
|
+
it('passes props through to MetricGroup element', async () => {
|
|
57
|
+
render(_MetricGroup2 || (_MetricGroup2 = /*#__PURE__*/React.createElement(MetricGroup, {
|
|
58
|
+
"data-testid": "metric-group",
|
|
59
|
+
"data-automation": "foo"
|
|
60
|
+
}, /*#__PURE__*/React.createElement(Metric, {
|
|
61
|
+
renderLabel: "Grade",
|
|
62
|
+
renderValue: "80%"
|
|
63
|
+
}), /*#__PURE__*/React.createElement(Metric, {
|
|
64
|
+
renderLabel: "Late",
|
|
65
|
+
renderValue: "4"
|
|
66
|
+
}), /*#__PURE__*/React.createElement(Metric, {
|
|
67
|
+
renderLabel: "Missing",
|
|
68
|
+
renderValue: "2"
|
|
69
|
+
}))));
|
|
70
|
+
const metric = screen.getByTestId('metric-group');
|
|
71
|
+
expect(metric).toHaveAttribute('data-automation', 'foo');
|
|
72
|
+
});
|
|
73
|
+
describe('for a11y', () => {
|
|
74
|
+
it('should meet standards', async () => {
|
|
75
|
+
const _render2 = render(_MetricGroup3 || (_MetricGroup3 = /*#__PURE__*/React.createElement(MetricGroup, null, /*#__PURE__*/React.createElement(Metric, {
|
|
76
|
+
renderLabel: "Grade",
|
|
77
|
+
renderValue: "80%"
|
|
78
|
+
}), /*#__PURE__*/React.createElement(Metric, {
|
|
79
|
+
renderLabel: "Late",
|
|
80
|
+
renderValue: "4"
|
|
81
|
+
}), /*#__PURE__*/React.createElement(Metric, {
|
|
82
|
+
renderLabel: "Missing",
|
|
83
|
+
renderValue: "2"
|
|
84
|
+
})))),
|
|
85
|
+
container = _render2.container;
|
|
86
|
+
const axeCheck = await runAxeCheck(container);
|
|
87
|
+
expect(axeCheck).toBe(true);
|
|
88
|
+
});
|
|
89
|
+
it('should have role=grid with aria-readonly=true', async () => {
|
|
90
|
+
render(_MetricGroup4 || (_MetricGroup4 = /*#__PURE__*/React.createElement(MetricGroup, null, /*#__PURE__*/React.createElement(Metric, {
|
|
91
|
+
renderLabel: "Grade",
|
|
92
|
+
renderValue: "80%"
|
|
93
|
+
}), /*#__PURE__*/React.createElement(Metric, {
|
|
94
|
+
renderLabel: "Late",
|
|
95
|
+
renderValue: "4"
|
|
96
|
+
}), /*#__PURE__*/React.createElement(Metric, {
|
|
97
|
+
renderLabel: "Missing",
|
|
98
|
+
renderValue: "2"
|
|
99
|
+
}))));
|
|
100
|
+
const grids = screen.getAllByRole('grid');
|
|
101
|
+
expect(grids.length).toBe(1);
|
|
102
|
+
expect(grids[0]).toHaveAttribute('aria-readonly', 'true');
|
|
103
|
+
});
|
|
104
|
+
it('should have role=row', async () => {
|
|
105
|
+
render(_MetricGroup5 || (_MetricGroup5 = /*#__PURE__*/React.createElement(MetricGroup, null, /*#__PURE__*/React.createElement(Metric, {
|
|
106
|
+
renderLabel: "Grade",
|
|
107
|
+
renderValue: "80%"
|
|
108
|
+
}), /*#__PURE__*/React.createElement(Metric, {
|
|
109
|
+
renderLabel: "Late",
|
|
110
|
+
renderValue: "4"
|
|
111
|
+
}), /*#__PURE__*/React.createElement(Metric, {
|
|
112
|
+
renderLabel: "Missing",
|
|
113
|
+
renderValue: "2"
|
|
114
|
+
}))));
|
|
115
|
+
const rows = screen.getAllByRole('row');
|
|
116
|
+
expect(rows.length).toBe(3);
|
|
117
|
+
});
|
|
118
|
+
it('should have role=gridcell', async () => {
|
|
119
|
+
render(_MetricGroup6 || (_MetricGroup6 = /*#__PURE__*/React.createElement(MetricGroup, null, /*#__PURE__*/React.createElement(Metric, {
|
|
120
|
+
renderLabel: "Grade",
|
|
121
|
+
renderValue: "80%"
|
|
122
|
+
}), /*#__PURE__*/React.createElement(Metric, {
|
|
123
|
+
renderLabel: "Late",
|
|
124
|
+
renderValue: "4"
|
|
125
|
+
}), /*#__PURE__*/React.createElement(Metric, {
|
|
126
|
+
renderLabel: "Missing",
|
|
127
|
+
renderValue: "2"
|
|
128
|
+
}))));
|
|
129
|
+
const cells = screen.getAllByRole('gridcell');
|
|
130
|
+
expect(cells.length).toBe(3);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
require("@testing-library/jest-dom");
|
|
7
|
+
var _vitest = require("vitest");
|
|
8
|
+
var _index = require("../index");
|
|
9
|
+
var _Metric, _Metric2, _Metric3, _Metric4, _Metric5, _Metric6;
|
|
10
|
+
/*
|
|
11
|
+
* The MIT License (MIT)
|
|
12
|
+
*
|
|
13
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
14
|
+
*
|
|
15
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
* in the Software without restriction, including without limitation the rights
|
|
18
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
* furnished to do so, subject to the following conditions:
|
|
21
|
+
*
|
|
22
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
* copies or substantial portions of the Software.
|
|
24
|
+
*
|
|
25
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
* SOFTWARE.
|
|
32
|
+
*/
|
|
33
|
+
describe('<Metric />', () => {
|
|
34
|
+
it('should render the label', async () => {
|
|
35
|
+
const _render = (0, _react2.render)(_Metric || (_Metric = /*#__PURE__*/_react.default.createElement(_index.Metric, {
|
|
36
|
+
renderLabel: "Grade",
|
|
37
|
+
renderValue: "80%"
|
|
38
|
+
}))),
|
|
39
|
+
container = _render.container;
|
|
40
|
+
expect(container).toHaveTextContent('Grade');
|
|
41
|
+
});
|
|
42
|
+
it('should render the value', async () => {
|
|
43
|
+
const _render2 = (0, _react2.render)(_Metric2 || (_Metric2 = /*#__PURE__*/_react.default.createElement(_index.Metric, {
|
|
44
|
+
renderLabel: "Grade",
|
|
45
|
+
renderValue: "80%"
|
|
46
|
+
}))),
|
|
47
|
+
container = _render2.container;
|
|
48
|
+
expect(container).toHaveTextContent('80%');
|
|
49
|
+
});
|
|
50
|
+
it('passes props through to Metric element', async () => {
|
|
51
|
+
(0, _react2.render)(_Metric3 || (_Metric3 = /*#__PURE__*/_react.default.createElement(_index.Metric, {
|
|
52
|
+
"data-testid": "metric",
|
|
53
|
+
"data-automation": "foo",
|
|
54
|
+
renderLabel: "Grade",
|
|
55
|
+
renderValue: "80%"
|
|
56
|
+
})));
|
|
57
|
+
const metric = _react2.screen.getByTestId('metric');
|
|
58
|
+
expect(metric).toHaveAttribute('data-automation', 'foo');
|
|
59
|
+
});
|
|
60
|
+
it('should not have role="gridcell" for the value', async () => {
|
|
61
|
+
(0, _react2.render)(_Metric4 || (_Metric4 = /*#__PURE__*/_react.default.createElement(_index.Metric, {
|
|
62
|
+
renderLabel: "Grade",
|
|
63
|
+
renderValue: "80%"
|
|
64
|
+
})));
|
|
65
|
+
const value = _react2.screen.getByText('80%');
|
|
66
|
+
expect(value).not.toHaveAttribute('role', 'gridcell');
|
|
67
|
+
});
|
|
68
|
+
it('should not have role=rowheader for the label', async () => {
|
|
69
|
+
(0, _react2.render)(_Metric5 || (_Metric5 = /*#__PURE__*/_react.default.createElement(_index.Metric, {
|
|
70
|
+
renderLabel: "Grade",
|
|
71
|
+
renderValue: "80%"
|
|
72
|
+
})));
|
|
73
|
+
const label = _react2.screen.getByText('Grade');
|
|
74
|
+
expect(label).not.toHaveAttribute('role', 'rowheader');
|
|
75
|
+
});
|
|
76
|
+
it('should allow ReactNodes as labels and values', async () => {
|
|
77
|
+
const _render3 = (0, _react2.render)(_Metric6 || (_Metric6 = /*#__PURE__*/_react.default.createElement(_index.Metric, {
|
|
78
|
+
renderLabel: /*#__PURE__*/_react.default.createElement("div", null, "hello")
|
|
79
|
+
}))),
|
|
80
|
+
container = _render3.container;
|
|
81
|
+
expect(container).toHaveTextContent('hello');
|
|
82
|
+
});
|
|
83
|
+
it('should allow methods as labels', async () => {
|
|
84
|
+
const renderLabel = _vitest.vi.fn();
|
|
85
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Metric, {
|
|
86
|
+
renderLabel: renderLabel
|
|
87
|
+
}));
|
|
88
|
+
expect(renderLabel).toHaveBeenCalled();
|
|
89
|
+
});
|
|
90
|
+
it('should allow methods as values', async () => {
|
|
91
|
+
const renderValue = _vitest.vi.fn();
|
|
92
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Metric, {
|
|
93
|
+
renderValue: renderValue
|
|
94
|
+
}));
|
|
95
|
+
expect(renderValue).toHaveBeenCalled();
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
require("@testing-library/jest-dom");
|
|
7
|
+
var _vitest = require("vitest");
|
|
8
|
+
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
9
|
+
var _index = require("../index");
|
|
10
|
+
var _Metric = require("../../Metric");
|
|
11
|
+
var _MetricGroup, _MetricGroup2, _MetricGroup3, _MetricGroup4, _MetricGroup5, _MetricGroup6;
|
|
12
|
+
/*
|
|
13
|
+
* The MIT License (MIT)
|
|
14
|
+
*
|
|
15
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
16
|
+
*
|
|
17
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
18
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
19
|
+
* in the Software without restriction, including without limitation the rights
|
|
20
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
21
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
22
|
+
* furnished to do so, subject to the following conditions:
|
|
23
|
+
*
|
|
24
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
25
|
+
* copies or substantial portions of the Software.
|
|
26
|
+
*
|
|
27
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
28
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
29
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
30
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
31
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
32
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
|
+
* SOFTWARE.
|
|
34
|
+
*/
|
|
35
|
+
describe('<MetricGroup />', () => {
|
|
36
|
+
let consoleErrorMock;
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
// Mocking console to prevent test output pollution and expect for messages
|
|
39
|
+
consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
40
|
+
});
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
consoleErrorMock.mockRestore();
|
|
43
|
+
});
|
|
44
|
+
it('should render children', async () => {
|
|
45
|
+
const _render = (0, _react2.render)(_MetricGroup || (_MetricGroup = /*#__PURE__*/_react.default.createElement(_index.MetricGroup, null, /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
46
|
+
renderLabel: "Grade",
|
|
47
|
+
renderValue: "80%"
|
|
48
|
+
}), /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
49
|
+
renderLabel: "Late",
|
|
50
|
+
renderValue: "4"
|
|
51
|
+
}), /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
52
|
+
renderLabel: "Missing",
|
|
53
|
+
renderValue: "2"
|
|
54
|
+
})))),
|
|
55
|
+
container = _render.container;
|
|
56
|
+
expect(container).toHaveTextContent('Grade80%Late4Missing2');
|
|
57
|
+
});
|
|
58
|
+
it('passes props through to MetricGroup element', async () => {
|
|
59
|
+
(0, _react2.render)(_MetricGroup2 || (_MetricGroup2 = /*#__PURE__*/_react.default.createElement(_index.MetricGroup, {
|
|
60
|
+
"data-testid": "metric-group",
|
|
61
|
+
"data-automation": "foo"
|
|
62
|
+
}, /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
63
|
+
renderLabel: "Grade",
|
|
64
|
+
renderValue: "80%"
|
|
65
|
+
}), /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
66
|
+
renderLabel: "Late",
|
|
67
|
+
renderValue: "4"
|
|
68
|
+
}), /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
69
|
+
renderLabel: "Missing",
|
|
70
|
+
renderValue: "2"
|
|
71
|
+
}))));
|
|
72
|
+
const metric = _react2.screen.getByTestId('metric-group');
|
|
73
|
+
expect(metric).toHaveAttribute('data-automation', 'foo');
|
|
74
|
+
});
|
|
75
|
+
describe('for a11y', () => {
|
|
76
|
+
it('should meet standards', async () => {
|
|
77
|
+
const _render2 = (0, _react2.render)(_MetricGroup3 || (_MetricGroup3 = /*#__PURE__*/_react.default.createElement(_index.MetricGroup, null, /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
78
|
+
renderLabel: "Grade",
|
|
79
|
+
renderValue: "80%"
|
|
80
|
+
}), /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
81
|
+
renderLabel: "Late",
|
|
82
|
+
renderValue: "4"
|
|
83
|
+
}), /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
84
|
+
renderLabel: "Missing",
|
|
85
|
+
renderValue: "2"
|
|
86
|
+
})))),
|
|
87
|
+
container = _render2.container;
|
|
88
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
89
|
+
expect(axeCheck).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
it('should have role=grid with aria-readonly=true', async () => {
|
|
92
|
+
(0, _react2.render)(_MetricGroup4 || (_MetricGroup4 = /*#__PURE__*/_react.default.createElement(_index.MetricGroup, null, /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
93
|
+
renderLabel: "Grade",
|
|
94
|
+
renderValue: "80%"
|
|
95
|
+
}), /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
96
|
+
renderLabel: "Late",
|
|
97
|
+
renderValue: "4"
|
|
98
|
+
}), /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
99
|
+
renderLabel: "Missing",
|
|
100
|
+
renderValue: "2"
|
|
101
|
+
}))));
|
|
102
|
+
const grids = _react2.screen.getAllByRole('grid');
|
|
103
|
+
expect(grids.length).toBe(1);
|
|
104
|
+
expect(grids[0]).toHaveAttribute('aria-readonly', 'true');
|
|
105
|
+
});
|
|
106
|
+
it('should have role=row', async () => {
|
|
107
|
+
(0, _react2.render)(_MetricGroup5 || (_MetricGroup5 = /*#__PURE__*/_react.default.createElement(_index.MetricGroup, null, /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
108
|
+
renderLabel: "Grade",
|
|
109
|
+
renderValue: "80%"
|
|
110
|
+
}), /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
111
|
+
renderLabel: "Late",
|
|
112
|
+
renderValue: "4"
|
|
113
|
+
}), /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
114
|
+
renderLabel: "Missing",
|
|
115
|
+
renderValue: "2"
|
|
116
|
+
}))));
|
|
117
|
+
const rows = _react2.screen.getAllByRole('row');
|
|
118
|
+
expect(rows.length).toBe(3);
|
|
119
|
+
});
|
|
120
|
+
it('should have role=gridcell', async () => {
|
|
121
|
+
(0, _react2.render)(_MetricGroup6 || (_MetricGroup6 = /*#__PURE__*/_react.default.createElement(_index.MetricGroup, null, /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
122
|
+
renderLabel: "Grade",
|
|
123
|
+
renderValue: "80%"
|
|
124
|
+
}), /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
125
|
+
renderLabel: "Late",
|
|
126
|
+
renderValue: "4"
|
|
127
|
+
}), /*#__PURE__*/_react.default.createElement(_Metric.Metric, {
|
|
128
|
+
renderLabel: "Missing",
|
|
129
|
+
renderValue: "2"
|
|
130
|
+
}))));
|
|
131
|
+
const cells = _react2.screen.getAllByRole('gridcell');
|
|
132
|
+
expect(cells.length).toBe(3);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-metric",
|
|
3
|
-
"version": "10.2.
|
|
3
|
+
"version": "10.2.1-snapshot-1",
|
|
4
4
|
"description": "A UI component for displaying Metrics",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -24,20 +24,23 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "^7.24.5",
|
|
27
|
-
"@instructure/console": "10.2.
|
|
28
|
-
"@instructure/emotion": "10.2.
|
|
29
|
-
"@instructure/shared-types": "10.2.
|
|
30
|
-
"@instructure/ui-prop-types": "10.2.
|
|
31
|
-
"@instructure/ui-react-utils": "10.2.
|
|
32
|
-
"@instructure/ui-testable": "10.2.
|
|
27
|
+
"@instructure/console": "10.2.1-snapshot-1",
|
|
28
|
+
"@instructure/emotion": "10.2.1-snapshot-1",
|
|
29
|
+
"@instructure/shared-types": "10.2.1-snapshot-1",
|
|
30
|
+
"@instructure/ui-prop-types": "10.2.1-snapshot-1",
|
|
31
|
+
"@instructure/ui-react-utils": "10.2.1-snapshot-1",
|
|
32
|
+
"@instructure/ui-testable": "10.2.1-snapshot-1",
|
|
33
33
|
"prop-types": "^15.8.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@instructure/ui-
|
|
37
|
-
"@instructure/ui-
|
|
38
|
-
"@instructure/ui-
|
|
39
|
-
"@instructure/ui-test-utils": "10.2.
|
|
40
|
-
"@instructure/ui-themes": "10.2.
|
|
36
|
+
"@instructure/ui-axe-check": "10.2.1-snapshot-1",
|
|
37
|
+
"@instructure/ui-babel-preset": "10.2.1-snapshot-1",
|
|
38
|
+
"@instructure/ui-color-utils": "10.2.1-snapshot-1",
|
|
39
|
+
"@instructure/ui-test-utils": "10.2.1-snapshot-1",
|
|
40
|
+
"@instructure/ui-themes": "10.2.1-snapshot-1",
|
|
41
|
+
"@testing-library/jest-dom": "^6.4.6",
|
|
42
|
+
"@testing-library/react": "^15.0.7",
|
|
43
|
+
"vitest": "^2.0.2"
|
|
41
44
|
},
|
|
42
45
|
"peerDependencies": {
|
|
43
46
|
"react": ">=16.8 <=18"
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React from 'react'
|
|
26
|
+
import { render, screen } from '@testing-library/react'
|
|
27
|
+
import '@testing-library/jest-dom'
|
|
28
|
+
import { vi } from 'vitest'
|
|
29
|
+
|
|
30
|
+
import { Metric } from '../index'
|
|
31
|
+
|
|
32
|
+
describe('<Metric />', () => {
|
|
33
|
+
it('should render the label', async () => {
|
|
34
|
+
const { container } = render(
|
|
35
|
+
<Metric renderLabel="Grade" renderValue="80%" />
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
expect(container).toHaveTextContent('Grade')
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('should render the value', async () => {
|
|
42
|
+
const { container } = render(
|
|
43
|
+
<Metric renderLabel="Grade" renderValue="80%" />
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
expect(container).toHaveTextContent('80%')
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('passes props through to Metric element', async () => {
|
|
50
|
+
render(
|
|
51
|
+
<Metric
|
|
52
|
+
data-testid="metric"
|
|
53
|
+
data-automation="foo"
|
|
54
|
+
renderLabel="Grade"
|
|
55
|
+
renderValue="80%"
|
|
56
|
+
/>
|
|
57
|
+
)
|
|
58
|
+
const metric = screen.getByTestId('metric')
|
|
59
|
+
|
|
60
|
+
expect(metric).toHaveAttribute('data-automation', 'foo')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('should not have role="gridcell" for the value', async () => {
|
|
64
|
+
render(<Metric renderLabel="Grade" renderValue="80%" />)
|
|
65
|
+
const value = screen.getByText('80%')
|
|
66
|
+
|
|
67
|
+
expect(value).not.toHaveAttribute('role', 'gridcell')
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('should not have role=rowheader for the label', async () => {
|
|
71
|
+
render(<Metric renderLabel="Grade" renderValue="80%" />)
|
|
72
|
+
const label = screen.getByText('Grade')
|
|
73
|
+
|
|
74
|
+
expect(label).not.toHaveAttribute('role', 'rowheader')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('should allow ReactNodes as labels and values', async () => {
|
|
78
|
+
const { container } = render(<Metric renderLabel={<div>hello</div>} />)
|
|
79
|
+
|
|
80
|
+
expect(container).toHaveTextContent('hello')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('should allow methods as labels', async () => {
|
|
84
|
+
const renderLabel = vi.fn()
|
|
85
|
+
render(<Metric renderLabel={renderLabel} />)
|
|
86
|
+
|
|
87
|
+
expect(renderLabel).toHaveBeenCalled()
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('should allow methods as values', async () => {
|
|
91
|
+
const renderValue = vi.fn()
|
|
92
|
+
render(<Metric renderValue={renderValue} />)
|
|
93
|
+
|
|
94
|
+
expect(renderValue).toHaveBeenCalled()
|
|
95
|
+
})
|
|
96
|
+
})
|