@instructure/ui-tag 9.3.0 → 9.3.1-snapshot-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 +8 -0
- package/es/Tag/__new-tests__/Tag.test.js +125 -0
- package/lib/Tag/__new-tests__/Tag.test.js +127 -0
- package/package.json +19 -14
- package/src/Tag/__new-tests__/Tag.test.tsx +132 -0
- package/tsconfig.build.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Tag/__new-tests__/Tag.test.d.ts +2 -0
- package/types/Tag/__new-tests__/Tag.test.d.ts.map +1 -0
- package/es/Tag/TagLocator.js +0 -28
- package/es/Tag/locator.js +0 -26
- package/lib/Tag/TagLocator.js +0 -34
- package/lib/Tag/locator.js +0 -37
- package/src/Tag/TagLocator.ts +0 -29
- package/src/Tag/locator.ts +0 -27
- package/types/Tag/TagLocator.d.ts +0 -428
- package/types/Tag/TagLocator.d.ts.map +0 -1
- package/types/Tag/locator.d.ts +0 -4
- package/types/Tag/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
|
+
## [9.3.1-snapshot-0](https://github.com/instructure/instructure-ui/compare/v9.3.0...v9.3.1-snapshot-0) (2024-07-17)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-tag
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [9.3.0](https://github.com/instructure/instructure-ui/compare/v9.2.0...v9.3.0) (2024-07-17)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @instructure/ui-tag
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
var _Tag, _Tag2;
|
|
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, waitFor } from '@testing-library/react';
|
|
28
|
+
import { userEvent } from '@testing-library/user-event';
|
|
29
|
+
import '@testing-library/jest-dom';
|
|
30
|
+
import { vi } from 'vitest';
|
|
31
|
+
import { Tag } from '../index';
|
|
32
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
33
|
+
import { View } from '@instructure/ui-view';
|
|
34
|
+
const originalOmitViewProps = View.omitViewProps;
|
|
35
|
+
describe('<Tag />', async () => {
|
|
36
|
+
beforeAll(() => {
|
|
37
|
+
// View component read Component.name instead of Component.displayName
|
|
38
|
+
// causing [undefined] in error messages
|
|
39
|
+
|
|
40
|
+
View.omitViewProps = (props, Component) => {
|
|
41
|
+
const ModifiedComponent = {
|
|
42
|
+
...Component,
|
|
43
|
+
name: 'Tag'
|
|
44
|
+
};
|
|
45
|
+
return originalOmitViewProps(props, ModifiedComponent);
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
afterAll(() => {
|
|
49
|
+
View.omitViewProps = originalOmitViewProps;
|
|
50
|
+
});
|
|
51
|
+
it('should display text', async () => {
|
|
52
|
+
render(_Tag || (_Tag = /*#__PURE__*/React.createElement(Tag, {
|
|
53
|
+
text: "Summer"
|
|
54
|
+
})));
|
|
55
|
+
const tag = screen.getByText('Summer');
|
|
56
|
+
expect(tag).toBeInTheDocument();
|
|
57
|
+
});
|
|
58
|
+
it('should render as a button and respond to onClick event', async () => {
|
|
59
|
+
const onClick = vi.fn();
|
|
60
|
+
render( /*#__PURE__*/React.createElement(Tag, {
|
|
61
|
+
"data-testid": "summer-button",
|
|
62
|
+
text: "Summer",
|
|
63
|
+
onClick: onClick
|
|
64
|
+
}));
|
|
65
|
+
const button = screen.getByTestId('summer-button');
|
|
66
|
+
userEvent.click(button);
|
|
67
|
+
await waitFor(() => {
|
|
68
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
69
|
+
expect(button.tagName).toBe('BUTTON');
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
it('should render a close icon when it is dismissible and clickable', async () => {
|
|
73
|
+
const onClick = vi.fn();
|
|
74
|
+
const _render = render( /*#__PURE__*/React.createElement(Tag, {
|
|
75
|
+
text: "Summer",
|
|
76
|
+
onClick: onClick,
|
|
77
|
+
dismissible: true
|
|
78
|
+
})),
|
|
79
|
+
container = _render.container;
|
|
80
|
+
const icon = container.querySelector('svg');
|
|
81
|
+
expect(icon).toHaveAttribute('name', 'IconX');
|
|
82
|
+
});
|
|
83
|
+
it('should meet a11y standards', async () => {
|
|
84
|
+
const _render2 = render(_Tag2 || (_Tag2 = /*#__PURE__*/React.createElement(Tag, {
|
|
85
|
+
text: "Summer"
|
|
86
|
+
}))),
|
|
87
|
+
container = _render2.container;
|
|
88
|
+
const axeCheck = await runAxeCheck(container);
|
|
89
|
+
expect(axeCheck).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
describe('when passing down props to View', async () => {
|
|
92
|
+
const allowedProps = {
|
|
93
|
+
margin: 'small',
|
|
94
|
+
elementRef: () => {}
|
|
95
|
+
};
|
|
96
|
+
View.allowedProps.filter(prop => prop !== 'children').forEach(prop => {
|
|
97
|
+
if (Object.keys(allowedProps).indexOf(prop) < 0) {
|
|
98
|
+
it(`should NOT allow the '${prop}' prop`, async () => {
|
|
99
|
+
const props = {
|
|
100
|
+
[prop]: 'foo'
|
|
101
|
+
};
|
|
102
|
+
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
103
|
+
render( /*#__PURE__*/React.createElement(Tag, Object.assign({
|
|
104
|
+
text: "Summer"
|
|
105
|
+
}, props)));
|
|
106
|
+
const warning = `Warning: [Tag] prop '${prop}' is not allowed.`;
|
|
107
|
+
expect(consoleError.mock.calls[0][0]).toBe(warning);
|
|
108
|
+
consoleError.mockRestore();
|
|
109
|
+
});
|
|
110
|
+
} else {
|
|
111
|
+
it(`should allow the '${prop}' prop`, async () => {
|
|
112
|
+
const props = {
|
|
113
|
+
[prop]: allowedProps[prop]
|
|
114
|
+
};
|
|
115
|
+
const consoleError = vi.spyOn(console, 'error');
|
|
116
|
+
render( /*#__PURE__*/React.createElement(Tag, Object.assign({
|
|
117
|
+
text: "Summer"
|
|
118
|
+
}, props)));
|
|
119
|
+
expect(consoleError).not.toHaveBeenCalled();
|
|
120
|
+
consoleError.mockRestore();
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
var _userEvent = require("@testing-library/user-event");
|
|
7
|
+
require("@testing-library/jest-dom");
|
|
8
|
+
var _vitest = require("vitest");
|
|
9
|
+
var _index = require("../index");
|
|
10
|
+
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
11
|
+
var _View = require("@instructure/ui-view/lib/View");
|
|
12
|
+
var _Tag, _Tag2;
|
|
13
|
+
/*
|
|
14
|
+
* The MIT License (MIT)
|
|
15
|
+
*
|
|
16
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
17
|
+
*
|
|
18
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
19
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
20
|
+
* in the Software without restriction, including without limitation the rights
|
|
21
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
22
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
23
|
+
* furnished to do so, subject to the following conditions:
|
|
24
|
+
*
|
|
25
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
26
|
+
* copies or substantial portions of the Software.
|
|
27
|
+
*
|
|
28
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
29
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
30
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
31
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
32
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
33
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
34
|
+
* SOFTWARE.
|
|
35
|
+
*/
|
|
36
|
+
const originalOmitViewProps = _View.View.omitViewProps;
|
|
37
|
+
describe('<Tag />', async () => {
|
|
38
|
+
beforeAll(() => {
|
|
39
|
+
// View component read Component.name instead of Component.displayName
|
|
40
|
+
// causing [undefined] in error messages
|
|
41
|
+
|
|
42
|
+
_View.View.omitViewProps = (props, Component) => {
|
|
43
|
+
const ModifiedComponent = {
|
|
44
|
+
...Component,
|
|
45
|
+
name: 'Tag'
|
|
46
|
+
};
|
|
47
|
+
return originalOmitViewProps(props, ModifiedComponent);
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
afterAll(() => {
|
|
51
|
+
_View.View.omitViewProps = originalOmitViewProps;
|
|
52
|
+
});
|
|
53
|
+
it('should display text', async () => {
|
|
54
|
+
(0, _react2.render)(_Tag || (_Tag = /*#__PURE__*/_react.default.createElement(_index.Tag, {
|
|
55
|
+
text: "Summer"
|
|
56
|
+
})));
|
|
57
|
+
const tag = _react2.screen.getByText('Summer');
|
|
58
|
+
expect(tag).toBeInTheDocument();
|
|
59
|
+
});
|
|
60
|
+
it('should render as a button and respond to onClick event', async () => {
|
|
61
|
+
const onClick = _vitest.vi.fn();
|
|
62
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Tag, {
|
|
63
|
+
"data-testid": "summer-button",
|
|
64
|
+
text: "Summer",
|
|
65
|
+
onClick: onClick
|
|
66
|
+
}));
|
|
67
|
+
const button = _react2.screen.getByTestId('summer-button');
|
|
68
|
+
_userEvent.userEvent.click(button);
|
|
69
|
+
await (0, _react2.waitFor)(() => {
|
|
70
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
71
|
+
expect(button.tagName).toBe('BUTTON');
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
it('should render a close icon when it is dismissible and clickable', async () => {
|
|
75
|
+
const onClick = _vitest.vi.fn();
|
|
76
|
+
const _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Tag, {
|
|
77
|
+
text: "Summer",
|
|
78
|
+
onClick: onClick,
|
|
79
|
+
dismissible: true
|
|
80
|
+
})),
|
|
81
|
+
container = _render.container;
|
|
82
|
+
const icon = container.querySelector('svg');
|
|
83
|
+
expect(icon).toHaveAttribute('name', 'IconX');
|
|
84
|
+
});
|
|
85
|
+
it('should meet a11y standards', async () => {
|
|
86
|
+
const _render2 = (0, _react2.render)(_Tag2 || (_Tag2 = /*#__PURE__*/_react.default.createElement(_index.Tag, {
|
|
87
|
+
text: "Summer"
|
|
88
|
+
}))),
|
|
89
|
+
container = _render2.container;
|
|
90
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
91
|
+
expect(axeCheck).toBe(true);
|
|
92
|
+
});
|
|
93
|
+
describe('when passing down props to View', async () => {
|
|
94
|
+
const allowedProps = {
|
|
95
|
+
margin: 'small',
|
|
96
|
+
elementRef: () => {}
|
|
97
|
+
};
|
|
98
|
+
_View.View.allowedProps.filter(prop => prop !== 'children').forEach(prop => {
|
|
99
|
+
if (Object.keys(allowedProps).indexOf(prop) < 0) {
|
|
100
|
+
it(`should NOT allow the '${prop}' prop`, async () => {
|
|
101
|
+
const props = {
|
|
102
|
+
[prop]: 'foo'
|
|
103
|
+
};
|
|
104
|
+
const consoleError = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
105
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Tag, Object.assign({
|
|
106
|
+
text: "Summer"
|
|
107
|
+
}, props)));
|
|
108
|
+
const warning = `Warning: [Tag] prop '${prop}' is not allowed.`;
|
|
109
|
+
expect(consoleError.mock.calls[0][0]).toBe(warning);
|
|
110
|
+
consoleError.mockRestore();
|
|
111
|
+
});
|
|
112
|
+
} else {
|
|
113
|
+
it(`should allow the '${prop}' prop`, async () => {
|
|
114
|
+
const props = {
|
|
115
|
+
[prop]: allowedProps[prop]
|
|
116
|
+
};
|
|
117
|
+
const consoleError = _vitest.vi.spyOn(console, 'error');
|
|
118
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Tag, Object.assign({
|
|
119
|
+
text: "Summer"
|
|
120
|
+
}, props)));
|
|
121
|
+
expect(consoleError).not.toHaveBeenCalled();
|
|
122
|
+
consoleError.mockRestore();
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-tag",
|
|
3
|
-
"version": "9.3.0",
|
|
3
|
+
"version": "9.3.1-snapshot-0",
|
|
4
4
|
"description": "A tag component",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -24,22 +24,27 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "^7.24.5",
|
|
27
|
-
"@instructure/console": "9.3.0",
|
|
28
|
-
"@instructure/emotion": "9.3.0",
|
|
29
|
-
"@instructure/shared-types": "9.3.0",
|
|
30
|
-
"@instructure/ui-color-utils": "9.3.0",
|
|
31
|
-
"@instructure/ui-dom-utils": "9.3.0",
|
|
32
|
-
"@instructure/ui-icons": "9.3.0",
|
|
33
|
-
"@instructure/ui-react-utils": "9.3.0",
|
|
34
|
-
"@instructure/ui-testable": "9.3.0",
|
|
35
|
-
"@instructure/ui-view": "9.3.0",
|
|
27
|
+
"@instructure/console": "9.3.1-snapshot-0",
|
|
28
|
+
"@instructure/emotion": "9.3.1-snapshot-0",
|
|
29
|
+
"@instructure/shared-types": "9.3.1-snapshot-0",
|
|
30
|
+
"@instructure/ui-color-utils": "9.3.1-snapshot-0",
|
|
31
|
+
"@instructure/ui-dom-utils": "9.3.1-snapshot-0",
|
|
32
|
+
"@instructure/ui-icons": "9.3.1-snapshot-0",
|
|
33
|
+
"@instructure/ui-react-utils": "9.3.1-snapshot-0",
|
|
34
|
+
"@instructure/ui-testable": "9.3.1-snapshot-0",
|
|
35
|
+
"@instructure/ui-view": "9.3.1-snapshot-0",
|
|
36
36
|
"prop-types": "^15.8.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@instructure/ui-
|
|
40
|
-
"@instructure/ui-
|
|
41
|
-
"@instructure/ui-test-
|
|
42
|
-
"@instructure/ui-
|
|
39
|
+
"@instructure/ui-axe-check": "9.3.1-snapshot-0",
|
|
40
|
+
"@instructure/ui-babel-preset": "9.3.1-snapshot-0",
|
|
41
|
+
"@instructure/ui-test-locator": "9.3.1-snapshot-0",
|
|
42
|
+
"@instructure/ui-test-utils": "9.3.1-snapshot-0",
|
|
43
|
+
"@instructure/ui-themes": "9.3.1-snapshot-0",
|
|
44
|
+
"@testing-library/jest-dom": "^6.4.5",
|
|
45
|
+
"@testing-library/react": "^15.0.7",
|
|
46
|
+
"@testing-library/user-event": "^14.5.2",
|
|
47
|
+
"vitest": "^1.6.0"
|
|
43
48
|
},
|
|
44
49
|
"peerDependencies": {
|
|
45
50
|
"react": ">=16.8 <=18"
|
|
@@ -0,0 +1,132 @@
|
|
|
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, { ComponentType } from 'react'
|
|
26
|
+
import { render, screen, waitFor } from '@testing-library/react'
|
|
27
|
+
import { userEvent } from '@testing-library/user-event'
|
|
28
|
+
import '@testing-library/jest-dom'
|
|
29
|
+
import { vi } from 'vitest'
|
|
30
|
+
|
|
31
|
+
import { Tag } from '../index'
|
|
32
|
+
import { runAxeCheck } from '@instructure/ui-axe-check'
|
|
33
|
+
import type { ViewProps } from '@instructure/ui-view'
|
|
34
|
+
import { View } from '@instructure/ui-view'
|
|
35
|
+
|
|
36
|
+
const originalOmitViewProps = View.omitViewProps
|
|
37
|
+
|
|
38
|
+
describe('<Tag />', async () => {
|
|
39
|
+
beforeAll(() => {
|
|
40
|
+
// View component read Component.name instead of Component.displayName
|
|
41
|
+
// causing [undefined] in error messages
|
|
42
|
+
type TagComponentType = ComponentType & {
|
|
43
|
+
name: 'Tag'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
View.omitViewProps = (props, Component) => {
|
|
47
|
+
const ModifiedComponent = {
|
|
48
|
+
...Component,
|
|
49
|
+
name: 'Tag'
|
|
50
|
+
} as TagComponentType
|
|
51
|
+
return originalOmitViewProps(props, ModifiedComponent)
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
afterAll(() => {
|
|
55
|
+
View.omitViewProps = originalOmitViewProps
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('should display text', async () => {
|
|
59
|
+
render(<Tag text="Summer" />)
|
|
60
|
+
const tag = screen.getByText('Summer')
|
|
61
|
+
|
|
62
|
+
expect(tag).toBeInTheDocument()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('should render as a button and respond to onClick event', async () => {
|
|
66
|
+
const onClick = vi.fn()
|
|
67
|
+
render(<Tag data-testid="summer-button" text="Summer" onClick={onClick} />)
|
|
68
|
+
|
|
69
|
+
const button = screen.getByTestId('summer-button')
|
|
70
|
+
|
|
71
|
+
userEvent.click(button)
|
|
72
|
+
|
|
73
|
+
await waitFor(() => {
|
|
74
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
75
|
+
expect(button.tagName).toBe('BUTTON')
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('should render a close icon when it is dismissible and clickable', async () => {
|
|
80
|
+
const onClick = vi.fn()
|
|
81
|
+
const { container } = render(
|
|
82
|
+
<Tag text="Summer" onClick={onClick} dismissible={true} />
|
|
83
|
+
)
|
|
84
|
+
const icon = container.querySelector('svg')
|
|
85
|
+
|
|
86
|
+
expect(icon).toHaveAttribute('name', 'IconX')
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('should meet a11y standards', async () => {
|
|
90
|
+
const { container } = render(<Tag text="Summer" />)
|
|
91
|
+
const axeCheck = await runAxeCheck(container)
|
|
92
|
+
|
|
93
|
+
expect(axeCheck).toBe(true)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
describe('when passing down props to View', async () => {
|
|
97
|
+
const allowedProps: Partial<ViewProps> = {
|
|
98
|
+
margin: 'small',
|
|
99
|
+
elementRef: () => {}
|
|
100
|
+
}
|
|
101
|
+
View.allowedProps
|
|
102
|
+
.filter((prop) => prop !== 'children')
|
|
103
|
+
.forEach((prop) => {
|
|
104
|
+
if (Object.keys(allowedProps).indexOf(prop) < 0) {
|
|
105
|
+
it(`should NOT allow the '${prop}' prop`, async () => {
|
|
106
|
+
const props = {
|
|
107
|
+
[prop]: 'foo'
|
|
108
|
+
}
|
|
109
|
+
const consoleError = vi
|
|
110
|
+
.spyOn(console, 'error')
|
|
111
|
+
.mockImplementation(() => {})
|
|
112
|
+
|
|
113
|
+
render(<Tag text="Summer" {...props} />)
|
|
114
|
+
const warning = `Warning: [Tag] prop '${prop}' is not allowed.`
|
|
115
|
+
|
|
116
|
+
expect(consoleError.mock.calls[0][0]).toBe(warning)
|
|
117
|
+
consoleError.mockRestore()
|
|
118
|
+
})
|
|
119
|
+
} else {
|
|
120
|
+
it(`should allow the '${prop}' prop`, async () => {
|
|
121
|
+
const props = { [prop]: allowedProps[prop] }
|
|
122
|
+
const consoleError = vi.spyOn(console, 'error')
|
|
123
|
+
|
|
124
|
+
render(<Tag text="Summer" {...props} />)
|
|
125
|
+
|
|
126
|
+
expect(consoleError).not.toHaveBeenCalled()
|
|
127
|
+
consoleError.mockRestore()
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
})
|
package/tsconfig.build.json
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
{ "path": "../console/tsconfig.build.json" },
|
|
11
11
|
{ "path": "../emotion/tsconfig.build.json" },
|
|
12
12
|
{ "path": "../shared-types/tsconfig.build.json" },
|
|
13
|
+
{ "path": "../ui-axe-check/tsconfig.build.json" },
|
|
13
14
|
{ "path": "../ui-color-utils/tsconfig.build.json" },
|
|
14
15
|
{ "path": "../ui-dom-utils/tsconfig.build.json" },
|
|
15
16
|
{ "path": "../ui-icons/tsconfig.build.json" },
|
|
@@ -17,7 +18,6 @@
|
|
|
17
18
|
{ "path": "../ui-testable/tsconfig.build.json" },
|
|
18
19
|
{ "path": "../ui-view/tsconfig.build.json" },
|
|
19
20
|
{ "path": "../ui-babel-preset/tsconfig.build.json" },
|
|
20
|
-
{ "path": "../ui-test-locator/tsconfig.build.json" },
|
|
21
21
|
{ "path": "../ui-test-utils/tsconfig.build.json" },
|
|
22
22
|
{ "path": "../ui-themes/tsconfig.build.json" }
|
|
23
23
|
]
|