@instructure/ui-rating 8.53.3-snapshot-9 → 8.53.3-snapshot-11
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 +1 -1
- package/es/Rating/__new-tests__/Rating.test.js +128 -0
- package/es/RatingIcon/__new-tests__/RatingIcon.test.js +109 -0
- package/lib/Rating/__new-tests__/Rating.test.js +130 -0
- package/lib/RatingIcon/__new-tests__/RatingIcon.test.js +111 -0
- package/package.json +16 -15
- package/src/Rating/__new-tests__/Rating.test.tsx +140 -0
- package/src/RatingIcon/__new-tests__/RatingIcon.test.tsx +119 -0
- package/tsconfig.build.json +1 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Rating/__new-tests__/Rating.test.d.ts +2 -0
- package/types/Rating/__new-tests__/Rating.test.d.ts.map +1 -0
- package/types/RatingIcon/__new-tests__/RatingIcon.test.d.ts +2 -0
- package/types/RatingIcon/__new-tests__/RatingIcon.test.d.ts.map +1 -0
- package/es/Rating/RatingLocator.js +0 -29
- package/es/Rating/locator.js +0 -26
- package/lib/Rating/RatingLocator.js +0 -34
- package/lib/Rating/locator.js +0 -37
- package/src/Rating/RatingLocator.ts +0 -29
- package/src/Rating/locator.ts +0 -27
- package/types/Rating/RatingLocator.d.ts +0 -566
- package/types/Rating/RatingLocator.d.ts.map +0 -1
- package/types/Rating/locator.d.ts +0 -4
- package/types/Rating/locator.d.ts.map +0 -1
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
|
-
## [8.53.3-snapshot-
|
|
6
|
+
## [8.53.3-snapshot-11](https://github.com/instructure/instructure-ui/compare/v8.53.2...v8.53.3-snapshot-11) (2024-02-29)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-rating
|
|
9
9
|
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
var _Rating, _Rating2, _Rating3, _Rating4, _Rating5;
|
|
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 } from '@testing-library/react';
|
|
28
|
+
import '@testing-library/jest-dom';
|
|
29
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
30
|
+
import { View } from '@instructure/ui-view';
|
|
31
|
+
import { Rating } from '../index';
|
|
32
|
+
describe('<Rating />', () => {
|
|
33
|
+
it('should render the correct number of icons', () => {
|
|
34
|
+
const _render = render(_Rating || (_Rating = /*#__PURE__*/React.createElement(Rating, {
|
|
35
|
+
label: "Course rating",
|
|
36
|
+
iconCount: 5
|
|
37
|
+
}))),
|
|
38
|
+
container = _render.container;
|
|
39
|
+
const icons = container.querySelectorAll('svg');
|
|
40
|
+
expect(icons).toHaveLength(5);
|
|
41
|
+
});
|
|
42
|
+
it('should handle a valueMax of zero', () => {
|
|
43
|
+
const _render2 = render(_Rating2 || (_Rating2 = /*#__PURE__*/React.createElement(Rating, {
|
|
44
|
+
label: "Course rating",
|
|
45
|
+
valueMax: 0
|
|
46
|
+
}))),
|
|
47
|
+
container = _render2.container;
|
|
48
|
+
const icons = container.querySelectorAll('svg');
|
|
49
|
+
expect(icons).toHaveLength(3);
|
|
50
|
+
});
|
|
51
|
+
it('should fill the correct number of icons', () => {
|
|
52
|
+
const _render3 = render(_Rating3 || (_Rating3 = /*#__PURE__*/React.createElement(Rating, {
|
|
53
|
+
label: "Course rating",
|
|
54
|
+
iconCount: 5,
|
|
55
|
+
valueNow: 89,
|
|
56
|
+
valueMax: 100
|
|
57
|
+
}))),
|
|
58
|
+
container = _render3.container;
|
|
59
|
+
const filledIcons = container.querySelectorAll('svg[name="IconStar"]');
|
|
60
|
+
expect(filledIcons).toHaveLength(4);
|
|
61
|
+
});
|
|
62
|
+
it('never renders more than `iconCount` icons', () => {
|
|
63
|
+
const _render4 = render(_Rating4 || (_Rating4 = /*#__PURE__*/React.createElement(Rating, {
|
|
64
|
+
label: "Course rating",
|
|
65
|
+
iconCount: 5,
|
|
66
|
+
valueNow: 110,
|
|
67
|
+
valueMax: 100
|
|
68
|
+
}))),
|
|
69
|
+
container = _render4.container;
|
|
70
|
+
const icons = container.querySelectorAll('svg');
|
|
71
|
+
expect(icons).toHaveLength(5);
|
|
72
|
+
});
|
|
73
|
+
it('should render screen reader text to give context', () => {
|
|
74
|
+
const _render5 = render( /*#__PURE__*/React.createElement(Rating, {
|
|
75
|
+
label: "Course rating",
|
|
76
|
+
iconCount: 5,
|
|
77
|
+
valueNow: 89,
|
|
78
|
+
valueMax: 100,
|
|
79
|
+
formatValueText: (current, max) => `${current} out of ${max}`
|
|
80
|
+
})),
|
|
81
|
+
container = _render5.container;
|
|
82
|
+
expect(container).toHaveTextContent('Course rating 4 out of 5');
|
|
83
|
+
});
|
|
84
|
+
it('should meet a11y standards', async () => {
|
|
85
|
+
const _render6 = render(_Rating5 || (_Rating5 = /*#__PURE__*/React.createElement(Rating, {
|
|
86
|
+
label: "Course rating",
|
|
87
|
+
iconCount: 5
|
|
88
|
+
}))),
|
|
89
|
+
container = _render6.container;
|
|
90
|
+
const axeCheck = await runAxeCheck(container);
|
|
91
|
+
expect(axeCheck).toBe(true);
|
|
92
|
+
});
|
|
93
|
+
describe('when passing down props to View', () => {
|
|
94
|
+
const allowedProps = {
|
|
95
|
+
margin: 'small'
|
|
96
|
+
};
|
|
97
|
+
View.allowedProps.filter(prop => prop !== 'children').forEach(prop => {
|
|
98
|
+
if (Object.keys(allowedProps).indexOf(prop) < 0) {
|
|
99
|
+
it(`should NOT allow the '${prop}' prop`, () => {
|
|
100
|
+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
101
|
+
const expectedErrorMessage = `Warning: [undefined] prop '${prop}' is not allowed.`;
|
|
102
|
+
const props = {
|
|
103
|
+
[prop]: 'foo'
|
|
104
|
+
};
|
|
105
|
+
render( /*#__PURE__*/React.createElement(Rating, Object.assign({
|
|
106
|
+
label: "Course rating",
|
|
107
|
+
iconCount: 5
|
|
108
|
+
}, props)));
|
|
109
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
|
|
110
|
+
consoleErrorSpy.mockRestore();
|
|
111
|
+
});
|
|
112
|
+
} else {
|
|
113
|
+
it(`should allow the '${prop}' prop`, () => {
|
|
114
|
+
const props = {
|
|
115
|
+
[prop]: allowedProps[prop]
|
|
116
|
+
};
|
|
117
|
+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
118
|
+
render( /*#__PURE__*/React.createElement(Rating, Object.assign({
|
|
119
|
+
label: "Course rating",
|
|
120
|
+
iconCount: 5
|
|
121
|
+
}, props)));
|
|
122
|
+
expect(consoleErrorSpy).not.toHaveBeenCalled();
|
|
123
|
+
consoleErrorSpy.mockRestore();
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
var _RatingIcon, _RatingIcon2, _RatingIcon3, _RatingIcon4;
|
|
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, waitFor } from '@testing-library/react';
|
|
28
|
+
import '@testing-library/jest-dom';
|
|
29
|
+
import { InstUISettingsProvider } from '@instructure/emotion';
|
|
30
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
31
|
+
import { RatingIcon } from '../index';
|
|
32
|
+
describe('<RatingIcon />', () => {
|
|
33
|
+
it('transitions when filled on render and animateFill is true', async () => {
|
|
34
|
+
const _render = render( /*#__PURE__*/React.createElement(InstUISettingsProvider, {
|
|
35
|
+
theme: {
|
|
36
|
+
componentOverrides: {
|
|
37
|
+
Transition: {
|
|
38
|
+
duration: '100ms'
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}, _RatingIcon || (_RatingIcon = /*#__PURE__*/React.createElement(RatingIcon, {
|
|
43
|
+
filled: true,
|
|
44
|
+
animateFill: true
|
|
45
|
+
})))),
|
|
46
|
+
container = _render.container;
|
|
47
|
+
await waitFor(() => {
|
|
48
|
+
const icon = container.querySelector('svg');
|
|
49
|
+
expect(icon).toBeInTheDocument();
|
|
50
|
+
expect(icon.getAttribute('name')).toBe('IconStar');
|
|
51
|
+
expect(icon).toHaveClass('transition--scale-entered');
|
|
52
|
+
}, {
|
|
53
|
+
timeout: 500
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
it('transitions when filled after render and animateFill is true', async () => {
|
|
57
|
+
const _render2 = render( /*#__PURE__*/React.createElement(InstUISettingsProvider, {
|
|
58
|
+
theme: {
|
|
59
|
+
componentOverrides: {
|
|
60
|
+
Transition: {
|
|
61
|
+
duration: '100ms'
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}, _RatingIcon2 || (_RatingIcon2 = /*#__PURE__*/React.createElement(RatingIcon, {
|
|
66
|
+
filled: false,
|
|
67
|
+
animateFill: true
|
|
68
|
+
})))),
|
|
69
|
+
container = _render2.container,
|
|
70
|
+
rerender = _render2.rerender;
|
|
71
|
+
await waitFor(() => {
|
|
72
|
+
const icon = container.querySelector('svg');
|
|
73
|
+
expect(icon).toBeInTheDocument();
|
|
74
|
+
expect(icon.getAttribute('name')).toBe('IconStarLight');
|
|
75
|
+
expect(icon).not.toHaveClass('transition--scale-entered');
|
|
76
|
+
}, {
|
|
77
|
+
timeout: 500
|
|
78
|
+
});
|
|
79
|
+
rerender( /*#__PURE__*/React.createElement(InstUISettingsProvider, {
|
|
80
|
+
theme: {
|
|
81
|
+
componentOverrides: {
|
|
82
|
+
Transition: {
|
|
83
|
+
duration: '100ms'
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}, _RatingIcon3 || (_RatingIcon3 = /*#__PURE__*/React.createElement(RatingIcon, {
|
|
88
|
+
filled: true,
|
|
89
|
+
animateFill: true
|
|
90
|
+
}))));
|
|
91
|
+
await waitFor(() => {
|
|
92
|
+
const icon = container.querySelector('svg');
|
|
93
|
+
expect(icon).toBeInTheDocument();
|
|
94
|
+
expect(icon.getAttribute('name')).toBe('IconStar');
|
|
95
|
+
expect(icon).toHaveClass('transition--scale-entered');
|
|
96
|
+
}, {
|
|
97
|
+
timeout: 500
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
it('should meet a11y standards', async () => {
|
|
101
|
+
const _render3 = render(_RatingIcon4 || (_RatingIcon4 = /*#__PURE__*/React.createElement(RatingIcon, {
|
|
102
|
+
filled: true,
|
|
103
|
+
animateFill: true
|
|
104
|
+
}))),
|
|
105
|
+
container = _render3.container;
|
|
106
|
+
const axeCheck = await runAxeCheck(container);
|
|
107
|
+
expect(axeCheck).toBe(true);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
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 _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
8
|
+
var _View = require("@instructure/ui-view/lib/View");
|
|
9
|
+
var _index = require("../index");
|
|
10
|
+
var _Rating, _Rating2, _Rating3, _Rating4, _Rating5;
|
|
11
|
+
/*
|
|
12
|
+
* The MIT License (MIT)
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
15
|
+
*
|
|
16
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
17
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
18
|
+
* in the Software without restriction, including without limitation the rights
|
|
19
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
20
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
21
|
+
* furnished to do so, subject to the following conditions:
|
|
22
|
+
*
|
|
23
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
24
|
+
* copies or substantial portions of the Software.
|
|
25
|
+
*
|
|
26
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
27
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
28
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
29
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
30
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
31
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
32
|
+
* SOFTWARE.
|
|
33
|
+
*/
|
|
34
|
+
describe('<Rating />', () => {
|
|
35
|
+
it('should render the correct number of icons', () => {
|
|
36
|
+
const _render = (0, _react2.render)(_Rating || (_Rating = /*#__PURE__*/_react.default.createElement(_index.Rating, {
|
|
37
|
+
label: "Course rating",
|
|
38
|
+
iconCount: 5
|
|
39
|
+
}))),
|
|
40
|
+
container = _render.container;
|
|
41
|
+
const icons = container.querySelectorAll('svg');
|
|
42
|
+
expect(icons).toHaveLength(5);
|
|
43
|
+
});
|
|
44
|
+
it('should handle a valueMax of zero', () => {
|
|
45
|
+
const _render2 = (0, _react2.render)(_Rating2 || (_Rating2 = /*#__PURE__*/_react.default.createElement(_index.Rating, {
|
|
46
|
+
label: "Course rating",
|
|
47
|
+
valueMax: 0
|
|
48
|
+
}))),
|
|
49
|
+
container = _render2.container;
|
|
50
|
+
const icons = container.querySelectorAll('svg');
|
|
51
|
+
expect(icons).toHaveLength(3);
|
|
52
|
+
});
|
|
53
|
+
it('should fill the correct number of icons', () => {
|
|
54
|
+
const _render3 = (0, _react2.render)(_Rating3 || (_Rating3 = /*#__PURE__*/_react.default.createElement(_index.Rating, {
|
|
55
|
+
label: "Course rating",
|
|
56
|
+
iconCount: 5,
|
|
57
|
+
valueNow: 89,
|
|
58
|
+
valueMax: 100
|
|
59
|
+
}))),
|
|
60
|
+
container = _render3.container;
|
|
61
|
+
const filledIcons = container.querySelectorAll('svg[name="IconStar"]');
|
|
62
|
+
expect(filledIcons).toHaveLength(4);
|
|
63
|
+
});
|
|
64
|
+
it('never renders more than `iconCount` icons', () => {
|
|
65
|
+
const _render4 = (0, _react2.render)(_Rating4 || (_Rating4 = /*#__PURE__*/_react.default.createElement(_index.Rating, {
|
|
66
|
+
label: "Course rating",
|
|
67
|
+
iconCount: 5,
|
|
68
|
+
valueNow: 110,
|
|
69
|
+
valueMax: 100
|
|
70
|
+
}))),
|
|
71
|
+
container = _render4.container;
|
|
72
|
+
const icons = container.querySelectorAll('svg');
|
|
73
|
+
expect(icons).toHaveLength(5);
|
|
74
|
+
});
|
|
75
|
+
it('should render screen reader text to give context', () => {
|
|
76
|
+
const _render5 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Rating, {
|
|
77
|
+
label: "Course rating",
|
|
78
|
+
iconCount: 5,
|
|
79
|
+
valueNow: 89,
|
|
80
|
+
valueMax: 100,
|
|
81
|
+
formatValueText: (current, max) => `${current} out of ${max}`
|
|
82
|
+
})),
|
|
83
|
+
container = _render5.container;
|
|
84
|
+
expect(container).toHaveTextContent('Course rating 4 out of 5');
|
|
85
|
+
});
|
|
86
|
+
it('should meet a11y standards', async () => {
|
|
87
|
+
const _render6 = (0, _react2.render)(_Rating5 || (_Rating5 = /*#__PURE__*/_react.default.createElement(_index.Rating, {
|
|
88
|
+
label: "Course rating",
|
|
89
|
+
iconCount: 5
|
|
90
|
+
}))),
|
|
91
|
+
container = _render6.container;
|
|
92
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
93
|
+
expect(axeCheck).toBe(true);
|
|
94
|
+
});
|
|
95
|
+
describe('when passing down props to View', () => {
|
|
96
|
+
const allowedProps = {
|
|
97
|
+
margin: 'small'
|
|
98
|
+
};
|
|
99
|
+
_View.View.allowedProps.filter(prop => prop !== 'children').forEach(prop => {
|
|
100
|
+
if (Object.keys(allowedProps).indexOf(prop) < 0) {
|
|
101
|
+
it(`should NOT allow the '${prop}' prop`, () => {
|
|
102
|
+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
103
|
+
const expectedErrorMessage = `Warning: [undefined] prop '${prop}' is not allowed.`;
|
|
104
|
+
const props = {
|
|
105
|
+
[prop]: 'foo'
|
|
106
|
+
};
|
|
107
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Rating, Object.assign({
|
|
108
|
+
label: "Course rating",
|
|
109
|
+
iconCount: 5
|
|
110
|
+
}, props)));
|
|
111
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining(expectedErrorMessage), expect.any(String));
|
|
112
|
+
consoleErrorSpy.mockRestore();
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
it(`should allow the '${prop}' prop`, () => {
|
|
116
|
+
const props = {
|
|
117
|
+
[prop]: allowedProps[prop]
|
|
118
|
+
};
|
|
119
|
+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
120
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Rating, Object.assign({
|
|
121
|
+
label: "Course rating",
|
|
122
|
+
iconCount: 5
|
|
123
|
+
}, props)));
|
|
124
|
+
expect(consoleErrorSpy).not.toHaveBeenCalled();
|
|
125
|
+
consoleErrorSpy.mockRestore();
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
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 _emotion = require("@instructure/emotion");
|
|
8
|
+
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
9
|
+
var _index = require("../index");
|
|
10
|
+
var _RatingIcon, _RatingIcon2, _RatingIcon3, _RatingIcon4;
|
|
11
|
+
/*
|
|
12
|
+
* The MIT License (MIT)
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
15
|
+
*
|
|
16
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
17
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
18
|
+
* in the Software without restriction, including without limitation the rights
|
|
19
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
20
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
21
|
+
* furnished to do so, subject to the following conditions:
|
|
22
|
+
*
|
|
23
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
24
|
+
* copies or substantial portions of the Software.
|
|
25
|
+
*
|
|
26
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
27
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
28
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
29
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
30
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
31
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
32
|
+
* SOFTWARE.
|
|
33
|
+
*/
|
|
34
|
+
describe('<RatingIcon />', () => {
|
|
35
|
+
it('transitions when filled on render and animateFill is true', async () => {
|
|
36
|
+
const _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_emotion.InstUISettingsProvider, {
|
|
37
|
+
theme: {
|
|
38
|
+
componentOverrides: {
|
|
39
|
+
Transition: {
|
|
40
|
+
duration: '100ms'
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}, _RatingIcon || (_RatingIcon = /*#__PURE__*/_react.default.createElement(_index.RatingIcon, {
|
|
45
|
+
filled: true,
|
|
46
|
+
animateFill: true
|
|
47
|
+
})))),
|
|
48
|
+
container = _render.container;
|
|
49
|
+
await (0, _react2.waitFor)(() => {
|
|
50
|
+
const icon = container.querySelector('svg');
|
|
51
|
+
expect(icon).toBeInTheDocument();
|
|
52
|
+
expect(icon.getAttribute('name')).toBe('IconStar');
|
|
53
|
+
expect(icon).toHaveClass('transition--scale-entered');
|
|
54
|
+
}, {
|
|
55
|
+
timeout: 500
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
it('transitions when filled after render and animateFill is true', async () => {
|
|
59
|
+
const _render2 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_emotion.InstUISettingsProvider, {
|
|
60
|
+
theme: {
|
|
61
|
+
componentOverrides: {
|
|
62
|
+
Transition: {
|
|
63
|
+
duration: '100ms'
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, _RatingIcon2 || (_RatingIcon2 = /*#__PURE__*/_react.default.createElement(_index.RatingIcon, {
|
|
68
|
+
filled: false,
|
|
69
|
+
animateFill: true
|
|
70
|
+
})))),
|
|
71
|
+
container = _render2.container,
|
|
72
|
+
rerender = _render2.rerender;
|
|
73
|
+
await (0, _react2.waitFor)(() => {
|
|
74
|
+
const icon = container.querySelector('svg');
|
|
75
|
+
expect(icon).toBeInTheDocument();
|
|
76
|
+
expect(icon.getAttribute('name')).toBe('IconStarLight');
|
|
77
|
+
expect(icon).not.toHaveClass('transition--scale-entered');
|
|
78
|
+
}, {
|
|
79
|
+
timeout: 500
|
|
80
|
+
});
|
|
81
|
+
rerender( /*#__PURE__*/_react.default.createElement(_emotion.InstUISettingsProvider, {
|
|
82
|
+
theme: {
|
|
83
|
+
componentOverrides: {
|
|
84
|
+
Transition: {
|
|
85
|
+
duration: '100ms'
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, _RatingIcon3 || (_RatingIcon3 = /*#__PURE__*/_react.default.createElement(_index.RatingIcon, {
|
|
90
|
+
filled: true,
|
|
91
|
+
animateFill: true
|
|
92
|
+
}))));
|
|
93
|
+
await (0, _react2.waitFor)(() => {
|
|
94
|
+
const icon = container.querySelector('svg');
|
|
95
|
+
expect(icon).toBeInTheDocument();
|
|
96
|
+
expect(icon.getAttribute('name')).toBe('IconStar');
|
|
97
|
+
expect(icon).toHaveClass('transition--scale-entered');
|
|
98
|
+
}, {
|
|
99
|
+
timeout: 500
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
it('should meet a11y standards', async () => {
|
|
103
|
+
const _render3 = (0, _react2.render)(_RatingIcon4 || (_RatingIcon4 = /*#__PURE__*/_react.default.createElement(_index.RatingIcon, {
|
|
104
|
+
filled: true,
|
|
105
|
+
animateFill: true
|
|
106
|
+
}))),
|
|
107
|
+
container = _render3.container;
|
|
108
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
109
|
+
expect(axeCheck).toBe(true);
|
|
110
|
+
});
|
|
111
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-rating",
|
|
3
|
-
"version": "8.53.3-snapshot-
|
|
3
|
+
"version": "8.53.3-snapshot-11",
|
|
4
4
|
"description": "A static rating component",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -24,23 +24,24 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "^7.23.2",
|
|
27
|
-
"@instructure/console": "8.53.3-snapshot-
|
|
28
|
-
"@instructure/emotion": "8.53.3-snapshot-
|
|
29
|
-
"@instructure/shared-types": "8.53.3-snapshot-
|
|
30
|
-
"@instructure/ui-a11y-content": "8.53.3-snapshot-
|
|
31
|
-
"@instructure/ui-dom-utils": "8.53.3-snapshot-
|
|
32
|
-
"@instructure/ui-icons": "8.53.3-snapshot-
|
|
33
|
-
"@instructure/ui-motion": "8.53.3-snapshot-
|
|
34
|
-
"@instructure/ui-react-utils": "8.53.3-snapshot-
|
|
35
|
-
"@instructure/ui-testable": "8.53.3-snapshot-
|
|
36
|
-
"@instructure/ui-view": "8.53.3-snapshot-
|
|
27
|
+
"@instructure/console": "8.53.3-snapshot-11",
|
|
28
|
+
"@instructure/emotion": "8.53.3-snapshot-11",
|
|
29
|
+
"@instructure/shared-types": "8.53.3-snapshot-11",
|
|
30
|
+
"@instructure/ui-a11y-content": "8.53.3-snapshot-11",
|
|
31
|
+
"@instructure/ui-dom-utils": "8.53.3-snapshot-11",
|
|
32
|
+
"@instructure/ui-icons": "8.53.3-snapshot-11",
|
|
33
|
+
"@instructure/ui-motion": "8.53.3-snapshot-11",
|
|
34
|
+
"@instructure/ui-react-utils": "8.53.3-snapshot-11",
|
|
35
|
+
"@instructure/ui-testable": "8.53.3-snapshot-11",
|
|
36
|
+
"@instructure/ui-view": "8.53.3-snapshot-11",
|
|
37
37
|
"prop-types": "^15.8.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@instructure/ui-
|
|
41
|
-
"@instructure/ui-
|
|
42
|
-
"@instructure/ui-
|
|
43
|
-
"@
|
|
40
|
+
"@instructure/ui-axe-check": "8.53.3-snapshot-11",
|
|
41
|
+
"@instructure/ui-babel-preset": "8.53.3-snapshot-11",
|
|
42
|
+
"@instructure/ui-themes": "8.53.3-snapshot-11",
|
|
43
|
+
"@testing-library/jest-dom": "^6.1.4",
|
|
44
|
+
"@testing-library/react": "^14.0.0"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
47
|
"react": ">=16.8 <=18"
|
|
@@ -0,0 +1,140 @@
|
|
|
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 } from '@testing-library/react'
|
|
27
|
+
|
|
28
|
+
import '@testing-library/jest-dom'
|
|
29
|
+
import { runAxeCheck } from '@instructure/ui-axe-check'
|
|
30
|
+
import { View } from '@instructure/ui-view'
|
|
31
|
+
|
|
32
|
+
import { Rating } from '../index'
|
|
33
|
+
|
|
34
|
+
describe('<Rating />', () => {
|
|
35
|
+
it('should render the correct number of icons', () => {
|
|
36
|
+
const { container } = render(<Rating label="Course rating" iconCount={5} />)
|
|
37
|
+
const icons = container.querySelectorAll('svg')
|
|
38
|
+
|
|
39
|
+
expect(icons).toHaveLength(5)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should handle a valueMax of zero', () => {
|
|
43
|
+
const { container } = render(<Rating label="Course rating" valueMax={0} />)
|
|
44
|
+
const icons = container.querySelectorAll('svg')
|
|
45
|
+
|
|
46
|
+
expect(icons).toHaveLength(3)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('should fill the correct number of icons', () => {
|
|
50
|
+
const { container } = render(
|
|
51
|
+
<Rating
|
|
52
|
+
label="Course rating"
|
|
53
|
+
iconCount={5}
|
|
54
|
+
valueNow={89}
|
|
55
|
+
valueMax={100}
|
|
56
|
+
/>
|
|
57
|
+
)
|
|
58
|
+
const filledIcons = container.querySelectorAll('svg[name="IconStar"]')
|
|
59
|
+
|
|
60
|
+
expect(filledIcons).toHaveLength(4)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('never renders more than `iconCount` icons', () => {
|
|
64
|
+
const { container } = render(
|
|
65
|
+
<Rating
|
|
66
|
+
label="Course rating"
|
|
67
|
+
iconCount={5}
|
|
68
|
+
valueNow={110}
|
|
69
|
+
valueMax={100}
|
|
70
|
+
/>
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
const icons = container.querySelectorAll('svg')
|
|
74
|
+
|
|
75
|
+
expect(icons).toHaveLength(5)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('should render screen reader text to give context', () => {
|
|
79
|
+
const { container } = render(
|
|
80
|
+
<Rating
|
|
81
|
+
label="Course rating"
|
|
82
|
+
iconCount={5}
|
|
83
|
+
valueNow={89}
|
|
84
|
+
valueMax={100}
|
|
85
|
+
formatValueText={(current, max) => `${current} out of ${max}`}
|
|
86
|
+
/>
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
expect(container).toHaveTextContent('Course rating 4 out of 5')
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('should meet a11y standards', async () => {
|
|
93
|
+
const { container } = render(<Rating label="Course rating" iconCount={5} />)
|
|
94
|
+
|
|
95
|
+
const axeCheck = await runAxeCheck(container)
|
|
96
|
+
expect(axeCheck).toBe(true)
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
describe('when passing down props to View', () => {
|
|
100
|
+
const allowedProps: { [key: string]: any } = {
|
|
101
|
+
margin: 'small'
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
View.allowedProps
|
|
105
|
+
.filter((prop) => prop !== 'children')
|
|
106
|
+
.forEach((prop) => {
|
|
107
|
+
if (Object.keys(allowedProps).indexOf(prop) < 0) {
|
|
108
|
+
it(`should NOT allow the '${prop}' prop`, () => {
|
|
109
|
+
const consoleErrorSpy = jest
|
|
110
|
+
.spyOn(console, 'error')
|
|
111
|
+
.mockImplementation(() => {})
|
|
112
|
+
const expectedErrorMessage = `Warning: [undefined] prop '${prop}' is not allowed.`
|
|
113
|
+
const props = {
|
|
114
|
+
[prop]: 'foo'
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
render(<Rating label="Course rating" iconCount={5} {...props} />)
|
|
118
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
119
|
+
expect.stringContaining(expectedErrorMessage),
|
|
120
|
+
expect.any(String)
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
consoleErrorSpy.mockRestore()
|
|
124
|
+
})
|
|
125
|
+
} else {
|
|
126
|
+
it(`should allow the '${prop}' prop`, () => {
|
|
127
|
+
const props = { [prop]: allowedProps[prop] }
|
|
128
|
+
const consoleErrorSpy = jest
|
|
129
|
+
.spyOn(console, 'error')
|
|
130
|
+
.mockImplementation(() => {})
|
|
131
|
+
|
|
132
|
+
render(<Rating label="Course rating" iconCount={5} {...props} />)
|
|
133
|
+
expect(consoleErrorSpy).not.toHaveBeenCalled()
|
|
134
|
+
|
|
135
|
+
consoleErrorSpy.mockRestore()
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
})
|