@instructure/ui-billboard 8.44.1-snapshot-4 → 8.44.1-snapshot-5
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/Billboard/__new-tests__/Billboard.test.js +161 -0
- package/lib/Billboard/__new-tests__/Billboard.test.js +163 -0
- package/package.json +16 -12
- package/src/Billboard/__new-tests__/Billboard.test.tsx +167 -0
- package/tsconfig.build.json +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Billboard/__new-tests__/Billboard.test.d.ts +2 -0
- package/types/Billboard/__new-tests__/Billboard.test.d.ts.map +1 -0
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.44.1-snapshot-
|
|
6
|
+
## [8.44.1-snapshot-5](https://github.com/instructure/instructure-ui/compare/v8.44.0...v8.44.1-snapshot-5) (2023-10-03)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-billboard
|
|
9
9
|
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
var _IconUserLine, _Billboard, _Billboard2, _Billboard3, _Billboard4, _span, _span2, _Billboard5, _Billboard6, _Billboard7;
|
|
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 { fireEvent, render, screen } from '@testing-library/react';
|
|
28
|
+
import userEvent from '@testing-library/user-event';
|
|
29
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
30
|
+
import { Billboard } from '../index';
|
|
31
|
+
import { IconUserLine } from '@instructure/ui-icons';
|
|
32
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
33
|
+
const TEST_HEADING = 'test-heading';
|
|
34
|
+
const TEST_MESSAGE = 'test-message';
|
|
35
|
+
const TEST_LINK = 'http://instructure-test.com';
|
|
36
|
+
const TEST_HERO = () => _IconUserLine || (_IconUserLine = /*#__PURE__*/React.createElement(IconUserLine, {
|
|
37
|
+
size: 'medium'
|
|
38
|
+
}));
|
|
39
|
+
describe('<Billboard />', () => {
|
|
40
|
+
it('should render', () => {
|
|
41
|
+
const _render = render(_Billboard || (_Billboard = /*#__PURE__*/React.createElement(Billboard, null))),
|
|
42
|
+
container = _render.container;
|
|
43
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
44
|
+
});
|
|
45
|
+
it('should be accessible', async () => {
|
|
46
|
+
const _render2 = render(_Billboard2 || (_Billboard2 = /*#__PURE__*/React.createElement(Billboard, {
|
|
47
|
+
heading: TEST_HEADING,
|
|
48
|
+
message: TEST_MESSAGE,
|
|
49
|
+
hero: TEST_HERO
|
|
50
|
+
}))),
|
|
51
|
+
container = _render2.container;
|
|
52
|
+
const axeCheck = await runAxeCheck(container);
|
|
53
|
+
expect(axeCheck).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
it('should render a heading with the correct tag', () => {
|
|
56
|
+
render(_Billboard3 || (_Billboard3 = /*#__PURE__*/React.createElement(Billboard, {
|
|
57
|
+
heading: TEST_HEADING,
|
|
58
|
+
headingAs: "h2"
|
|
59
|
+
})));
|
|
60
|
+
const heading = screen.getByText(TEST_HEADING);
|
|
61
|
+
expect(heading).toBeInTheDocument();
|
|
62
|
+
expect(heading.tagName).toBe('H2');
|
|
63
|
+
});
|
|
64
|
+
it('renders as a link if it has an href prop', () => {
|
|
65
|
+
render(_Billboard4 || (_Billboard4 = /*#__PURE__*/React.createElement(Billboard, {
|
|
66
|
+
href: TEST_LINK
|
|
67
|
+
})));
|
|
68
|
+
const link = screen.getByRole('link');
|
|
69
|
+
expect(link).toBeInTheDocument();
|
|
70
|
+
expect(link).toHaveAttribute('href', TEST_LINK);
|
|
71
|
+
});
|
|
72
|
+
it('renders as a button and responds to onClick event', () => {
|
|
73
|
+
const onClick = jest.fn();
|
|
74
|
+
render( /*#__PURE__*/React.createElement(Billboard, {
|
|
75
|
+
onClick: onClick
|
|
76
|
+
}));
|
|
77
|
+
const button = screen.getByRole('button');
|
|
78
|
+
fireEvent.click(button);
|
|
79
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
80
|
+
});
|
|
81
|
+
describe('when rendering message', () => {
|
|
82
|
+
it('should render message when passed a node', async () => {
|
|
83
|
+
const messageNode = _span || (_span = /*#__PURE__*/React.createElement("span", null, TEST_MESSAGE));
|
|
84
|
+
render( /*#__PURE__*/React.createElement(Billboard, {
|
|
85
|
+
message: messageNode
|
|
86
|
+
}));
|
|
87
|
+
const messageElement = screen.getByText(TEST_MESSAGE);
|
|
88
|
+
expect(messageElement).toBeInTheDocument();
|
|
89
|
+
expect(messageElement.tagName).toBe('SPAN');
|
|
90
|
+
});
|
|
91
|
+
it('should render message passed a function', () => {
|
|
92
|
+
const messageNode = _span2 || (_span2 = /*#__PURE__*/React.createElement("span", null, TEST_MESSAGE));
|
|
93
|
+
render( /*#__PURE__*/React.createElement(Billboard, {
|
|
94
|
+
message: () => messageNode
|
|
95
|
+
}));
|
|
96
|
+
const messageElement = screen.getByText(TEST_MESSAGE);
|
|
97
|
+
expect(messageElement).toBeInTheDocument();
|
|
98
|
+
expect(messageElement.tagName).toBe('SPAN');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
describe('when disabled', () => {
|
|
102
|
+
it('should apply aria-disabled to link', () => {
|
|
103
|
+
render(_Billboard5 || (_Billboard5 = /*#__PURE__*/React.createElement(Billboard, {
|
|
104
|
+
href: TEST_LINK,
|
|
105
|
+
disabled: true
|
|
106
|
+
})));
|
|
107
|
+
const link = screen.getByRole('link');
|
|
108
|
+
expect(link).toHaveAttribute('aria-disabled', 'true');
|
|
109
|
+
});
|
|
110
|
+
it('should not be clickable', () => {
|
|
111
|
+
const onClick = jest.fn();
|
|
112
|
+
render( /*#__PURE__*/React.createElement(Billboard, {
|
|
113
|
+
onClick: onClick,
|
|
114
|
+
disabled: true
|
|
115
|
+
}));
|
|
116
|
+
const button = screen.getByRole('button');
|
|
117
|
+
userEvent.click(button);
|
|
118
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
describe('when readOnly', () => {
|
|
122
|
+
it('should apply aria-disabled', () => {
|
|
123
|
+
render(_Billboard6 || (_Billboard6 = /*#__PURE__*/React.createElement(Billboard, {
|
|
124
|
+
href: TEST_LINK,
|
|
125
|
+
readOnly: true
|
|
126
|
+
})));
|
|
127
|
+
const link = screen.getByRole('link');
|
|
128
|
+
expect(link).toHaveAttribute('aria-disabled', 'true');
|
|
129
|
+
});
|
|
130
|
+
it('should not be clickable', () => {
|
|
131
|
+
const onClick = jest.fn();
|
|
132
|
+
render( /*#__PURE__*/React.createElement(Billboard, {
|
|
133
|
+
onClick: onClick,
|
|
134
|
+
readOnly: true
|
|
135
|
+
}));
|
|
136
|
+
const button = screen.getByRole('button');
|
|
137
|
+
userEvent.click(button);
|
|
138
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
describe('when passing down props to View', () => {
|
|
142
|
+
it('should support an elementRef prop', () => {
|
|
143
|
+
const elementRef = jest.fn();
|
|
144
|
+
render( /*#__PURE__*/React.createElement(Billboard, {
|
|
145
|
+
elementRef: elementRef,
|
|
146
|
+
href: TEST_LINK
|
|
147
|
+
}));
|
|
148
|
+
const link = screen.getByRole('link');
|
|
149
|
+
expect(elementRef).toHaveBeenCalledWith(link);
|
|
150
|
+
});
|
|
151
|
+
it('should support an `as` prop', () => {
|
|
152
|
+
const _render3 = render(_Billboard7 || (_Billboard7 = /*#__PURE__*/React.createElement(Billboard, {
|
|
153
|
+
as: "em"
|
|
154
|
+
}))),
|
|
155
|
+
container = _render3.container;
|
|
156
|
+
const billboardAsEm = container.querySelector('em');
|
|
157
|
+
expect(billboardAsEm).toBeInTheDocument();
|
|
158
|
+
expect(billboardAsEm === null || billboardAsEm === void 0 ? void 0 : billboardAsEm.className).toMatch(/view-billboard/);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
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 = _interopRequireDefault(require("@testing-library/user-event"));
|
|
7
|
+
require("@testing-library/jest-dom/extend-expect");
|
|
8
|
+
var _index = require("../index");
|
|
9
|
+
var _IconUserLine2 = require("@instructure/ui-icons/lib/IconUserLine.js");
|
|
10
|
+
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
11
|
+
var _IconUserLine, _Billboard, _Billboard2, _Billboard3, _Billboard4, _span, _span2, _Billboard5, _Billboard6, _Billboard7;
|
|
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
|
+
const TEST_HEADING = 'test-heading';
|
|
36
|
+
const TEST_MESSAGE = 'test-message';
|
|
37
|
+
const TEST_LINK = 'http://instructure-test.com';
|
|
38
|
+
const TEST_HERO = () => _IconUserLine || (_IconUserLine = /*#__PURE__*/_react.default.createElement(_IconUserLine2.IconUserLine, {
|
|
39
|
+
size: 'medium'
|
|
40
|
+
}));
|
|
41
|
+
describe('<Billboard />', () => {
|
|
42
|
+
it('should render', () => {
|
|
43
|
+
const _render = (0, _react2.render)(_Billboard || (_Billboard = /*#__PURE__*/_react.default.createElement(_index.Billboard, null))),
|
|
44
|
+
container = _render.container;
|
|
45
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
46
|
+
});
|
|
47
|
+
it('should be accessible', async () => {
|
|
48
|
+
const _render2 = (0, _react2.render)(_Billboard2 || (_Billboard2 = /*#__PURE__*/_react.default.createElement(_index.Billboard, {
|
|
49
|
+
heading: TEST_HEADING,
|
|
50
|
+
message: TEST_MESSAGE,
|
|
51
|
+
hero: TEST_HERO
|
|
52
|
+
}))),
|
|
53
|
+
container = _render2.container;
|
|
54
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
55
|
+
expect(axeCheck).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
it('should render a heading with the correct tag', () => {
|
|
58
|
+
(0, _react2.render)(_Billboard3 || (_Billboard3 = /*#__PURE__*/_react.default.createElement(_index.Billboard, {
|
|
59
|
+
heading: TEST_HEADING,
|
|
60
|
+
headingAs: "h2"
|
|
61
|
+
})));
|
|
62
|
+
const heading = _react2.screen.getByText(TEST_HEADING);
|
|
63
|
+
expect(heading).toBeInTheDocument();
|
|
64
|
+
expect(heading.tagName).toBe('H2');
|
|
65
|
+
});
|
|
66
|
+
it('renders as a link if it has an href prop', () => {
|
|
67
|
+
(0, _react2.render)(_Billboard4 || (_Billboard4 = /*#__PURE__*/_react.default.createElement(_index.Billboard, {
|
|
68
|
+
href: TEST_LINK
|
|
69
|
+
})));
|
|
70
|
+
const link = _react2.screen.getByRole('link');
|
|
71
|
+
expect(link).toBeInTheDocument();
|
|
72
|
+
expect(link).toHaveAttribute('href', TEST_LINK);
|
|
73
|
+
});
|
|
74
|
+
it('renders as a button and responds to onClick event', () => {
|
|
75
|
+
const onClick = jest.fn();
|
|
76
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Billboard, {
|
|
77
|
+
onClick: onClick
|
|
78
|
+
}));
|
|
79
|
+
const button = _react2.screen.getByRole('button');
|
|
80
|
+
_react2.fireEvent.click(button);
|
|
81
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
82
|
+
});
|
|
83
|
+
describe('when rendering message', () => {
|
|
84
|
+
it('should render message when passed a node', async () => {
|
|
85
|
+
const messageNode = _span || (_span = /*#__PURE__*/_react.default.createElement("span", null, TEST_MESSAGE));
|
|
86
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Billboard, {
|
|
87
|
+
message: messageNode
|
|
88
|
+
}));
|
|
89
|
+
const messageElement = _react2.screen.getByText(TEST_MESSAGE);
|
|
90
|
+
expect(messageElement).toBeInTheDocument();
|
|
91
|
+
expect(messageElement.tagName).toBe('SPAN');
|
|
92
|
+
});
|
|
93
|
+
it('should render message passed a function', () => {
|
|
94
|
+
const messageNode = _span2 || (_span2 = /*#__PURE__*/_react.default.createElement("span", null, TEST_MESSAGE));
|
|
95
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Billboard, {
|
|
96
|
+
message: () => messageNode
|
|
97
|
+
}));
|
|
98
|
+
const messageElement = _react2.screen.getByText(TEST_MESSAGE);
|
|
99
|
+
expect(messageElement).toBeInTheDocument();
|
|
100
|
+
expect(messageElement.tagName).toBe('SPAN');
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
describe('when disabled', () => {
|
|
104
|
+
it('should apply aria-disabled to link', () => {
|
|
105
|
+
(0, _react2.render)(_Billboard5 || (_Billboard5 = /*#__PURE__*/_react.default.createElement(_index.Billboard, {
|
|
106
|
+
href: TEST_LINK,
|
|
107
|
+
disabled: true
|
|
108
|
+
})));
|
|
109
|
+
const link = _react2.screen.getByRole('link');
|
|
110
|
+
expect(link).toHaveAttribute('aria-disabled', 'true');
|
|
111
|
+
});
|
|
112
|
+
it('should not be clickable', () => {
|
|
113
|
+
const onClick = jest.fn();
|
|
114
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Billboard, {
|
|
115
|
+
onClick: onClick,
|
|
116
|
+
disabled: true
|
|
117
|
+
}));
|
|
118
|
+
const button = _react2.screen.getByRole('button');
|
|
119
|
+
_userEvent.default.click(button);
|
|
120
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
describe('when readOnly', () => {
|
|
124
|
+
it('should apply aria-disabled', () => {
|
|
125
|
+
(0, _react2.render)(_Billboard6 || (_Billboard6 = /*#__PURE__*/_react.default.createElement(_index.Billboard, {
|
|
126
|
+
href: TEST_LINK,
|
|
127
|
+
readOnly: true
|
|
128
|
+
})));
|
|
129
|
+
const link = _react2.screen.getByRole('link');
|
|
130
|
+
expect(link).toHaveAttribute('aria-disabled', 'true');
|
|
131
|
+
});
|
|
132
|
+
it('should not be clickable', () => {
|
|
133
|
+
const onClick = jest.fn();
|
|
134
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Billboard, {
|
|
135
|
+
onClick: onClick,
|
|
136
|
+
readOnly: true
|
|
137
|
+
}));
|
|
138
|
+
const button = _react2.screen.getByRole('button');
|
|
139
|
+
_userEvent.default.click(button);
|
|
140
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
describe('when passing down props to View', () => {
|
|
144
|
+
it('should support an elementRef prop', () => {
|
|
145
|
+
const elementRef = jest.fn();
|
|
146
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Billboard, {
|
|
147
|
+
elementRef: elementRef,
|
|
148
|
+
href: TEST_LINK
|
|
149
|
+
}));
|
|
150
|
+
const link = _react2.screen.getByRole('link');
|
|
151
|
+
expect(elementRef).toHaveBeenCalledWith(link);
|
|
152
|
+
});
|
|
153
|
+
it('should support an `as` prop', () => {
|
|
154
|
+
const _render3 = (0, _react2.render)(_Billboard7 || (_Billboard7 = /*#__PURE__*/_react.default.createElement(_index.Billboard, {
|
|
155
|
+
as: "em"
|
|
156
|
+
}))),
|
|
157
|
+
container = _render3.container;
|
|
158
|
+
const billboardAsEm = container.querySelector('em');
|
|
159
|
+
expect(billboardAsEm).toBeInTheDocument();
|
|
160
|
+
expect(billboardAsEm === null || billboardAsEm === void 0 ? void 0 : billboardAsEm.className).toMatch(/view-billboard/);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-billboard",
|
|
3
|
-
"version": "8.44.1-snapshot-
|
|
3
|
+
"version": "8.44.1-snapshot-5",
|
|
4
4
|
"description": "A UI component to display empty states, 404 pages, redirects, etc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,20 +23,24 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-
|
|
27
|
-
"@instructure/ui-
|
|
28
|
-
"@instructure/ui-
|
|
29
|
-
"@instructure/ui-
|
|
30
|
-
"@instructure/ui-
|
|
26
|
+
"@instructure/ui-axe-check": "8.44.1-snapshot-5",
|
|
27
|
+
"@instructure/ui-babel-preset": "8.44.1-snapshot-5",
|
|
28
|
+
"@instructure/ui-color-utils": "8.44.1-snapshot-5",
|
|
29
|
+
"@instructure/ui-icons": "8.44.1-snapshot-5",
|
|
30
|
+
"@instructure/ui-test-utils": "8.44.1-snapshot-5",
|
|
31
|
+
"@instructure/ui-themes": "8.44.1-snapshot-5",
|
|
32
|
+
"@testing-library/jest-dom": "^5.17.0",
|
|
33
|
+
"@testing-library/react": "^14.0.0",
|
|
34
|
+
"@testing-library/user-event": "^14.4.3"
|
|
31
35
|
},
|
|
32
36
|
"dependencies": {
|
|
33
37
|
"@babel/runtime": "^7.22.15",
|
|
34
|
-
"@instructure/emotion": "8.44.1-snapshot-
|
|
35
|
-
"@instructure/shared-types": "8.44.1-snapshot-
|
|
36
|
-
"@instructure/ui-heading": "8.44.1-snapshot-
|
|
37
|
-
"@instructure/ui-img": "8.44.1-snapshot-
|
|
38
|
-
"@instructure/ui-react-utils": "8.44.1-snapshot-
|
|
39
|
-
"@instructure/ui-view": "8.44.1-snapshot-
|
|
38
|
+
"@instructure/emotion": "8.44.1-snapshot-5",
|
|
39
|
+
"@instructure/shared-types": "8.44.1-snapshot-5",
|
|
40
|
+
"@instructure/ui-heading": "8.44.1-snapshot-5",
|
|
41
|
+
"@instructure/ui-img": "8.44.1-snapshot-5",
|
|
42
|
+
"@instructure/ui-react-utils": "8.44.1-snapshot-5",
|
|
43
|
+
"@instructure/ui-view": "8.44.1-snapshot-5",
|
|
40
44
|
"prop-types": "^15.8.1"
|
|
41
45
|
},
|
|
42
46
|
"peerDependencies": {
|
|
@@ -0,0 +1,167 @@
|
|
|
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 { fireEvent, render, screen } from '@testing-library/react'
|
|
27
|
+
import userEvent from '@testing-library/user-event'
|
|
28
|
+
import '@testing-library/jest-dom/extend-expect'
|
|
29
|
+
|
|
30
|
+
import { Billboard } from '../index'
|
|
31
|
+
import { IconUserLine } from '@instructure/ui-icons'
|
|
32
|
+
import { runAxeCheck } from '@instructure/ui-axe-check'
|
|
33
|
+
|
|
34
|
+
const TEST_HEADING = 'test-heading'
|
|
35
|
+
const TEST_MESSAGE = 'test-message'
|
|
36
|
+
const TEST_LINK = 'http://instructure-test.com'
|
|
37
|
+
const TEST_HERO = () => <IconUserLine size={'medium'} />
|
|
38
|
+
|
|
39
|
+
describe('<Billboard />', () => {
|
|
40
|
+
it('should render', () => {
|
|
41
|
+
const { container } = render(<Billboard />)
|
|
42
|
+
|
|
43
|
+
expect(container.firstChild).toBeInTheDocument()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('should be accessible', async () => {
|
|
47
|
+
const { container } = render(
|
|
48
|
+
<Billboard
|
|
49
|
+
heading={TEST_HEADING}
|
|
50
|
+
message={TEST_MESSAGE}
|
|
51
|
+
hero={TEST_HERO}
|
|
52
|
+
/>
|
|
53
|
+
)
|
|
54
|
+
const axeCheck = await runAxeCheck(container)
|
|
55
|
+
|
|
56
|
+
expect(axeCheck).toBe(true)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('should render a heading with the correct tag', () => {
|
|
60
|
+
render(<Billboard heading={TEST_HEADING} headingAs="h2" />)
|
|
61
|
+
const heading = screen.getByText(TEST_HEADING)
|
|
62
|
+
|
|
63
|
+
expect(heading).toBeInTheDocument()
|
|
64
|
+
expect(heading.tagName).toBe('H2')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('renders as a link if it has an href prop', () => {
|
|
68
|
+
render(<Billboard href={TEST_LINK} />)
|
|
69
|
+
|
|
70
|
+
const link = screen.getByRole('link')
|
|
71
|
+
|
|
72
|
+
expect(link).toBeInTheDocument()
|
|
73
|
+
expect(link).toHaveAttribute('href', TEST_LINK)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('renders as a button and responds to onClick event', () => {
|
|
77
|
+
const onClick = jest.fn()
|
|
78
|
+
|
|
79
|
+
render(<Billboard onClick={onClick} />)
|
|
80
|
+
const button = screen.getByRole('button')
|
|
81
|
+
|
|
82
|
+
fireEvent.click(button)
|
|
83
|
+
|
|
84
|
+
expect(onClick).toHaveBeenCalledTimes(1)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
describe('when rendering message', () => {
|
|
88
|
+
it('should render message when passed a node', async () => {
|
|
89
|
+
const messageNode = <span>{TEST_MESSAGE}</span>
|
|
90
|
+
|
|
91
|
+
render(<Billboard message={messageNode} />)
|
|
92
|
+
const messageElement = screen.getByText(TEST_MESSAGE)
|
|
93
|
+
|
|
94
|
+
expect(messageElement).toBeInTheDocument()
|
|
95
|
+
expect(messageElement.tagName).toBe('SPAN')
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('should render message passed a function', () => {
|
|
99
|
+
const messageNode = <span>{TEST_MESSAGE}</span>
|
|
100
|
+
|
|
101
|
+
render(<Billboard message={() => messageNode} />)
|
|
102
|
+
const messageElement = screen.getByText(TEST_MESSAGE)
|
|
103
|
+
|
|
104
|
+
expect(messageElement).toBeInTheDocument()
|
|
105
|
+
expect(messageElement.tagName).toBe('SPAN')
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
describe('when disabled', () => {
|
|
110
|
+
it('should apply aria-disabled to link', () => {
|
|
111
|
+
render(<Billboard href={TEST_LINK} disabled={true} />)
|
|
112
|
+
const link = screen.getByRole('link')
|
|
113
|
+
|
|
114
|
+
expect(link).toHaveAttribute('aria-disabled', 'true')
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('should not be clickable', () => {
|
|
118
|
+
const onClick = jest.fn()
|
|
119
|
+
|
|
120
|
+
render(<Billboard onClick={onClick} disabled />)
|
|
121
|
+
const button = screen.getByRole('button')
|
|
122
|
+
|
|
123
|
+
userEvent.click(button)
|
|
124
|
+
|
|
125
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
describe('when readOnly', () => {
|
|
130
|
+
it('should apply aria-disabled', () => {
|
|
131
|
+
render(<Billboard href={TEST_LINK} readOnly />)
|
|
132
|
+
const link = screen.getByRole('link')
|
|
133
|
+
|
|
134
|
+
expect(link).toHaveAttribute('aria-disabled', 'true')
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('should not be clickable', () => {
|
|
138
|
+
const onClick = jest.fn()
|
|
139
|
+
|
|
140
|
+
render(<Billboard onClick={onClick} readOnly />)
|
|
141
|
+
const button = screen.getByRole('button')
|
|
142
|
+
|
|
143
|
+
userEvent.click(button)
|
|
144
|
+
|
|
145
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
describe('when passing down props to View', () => {
|
|
150
|
+
it('should support an elementRef prop', () => {
|
|
151
|
+
const elementRef = jest.fn()
|
|
152
|
+
|
|
153
|
+
render(<Billboard elementRef={elementRef} href={TEST_LINK} />)
|
|
154
|
+
const link = screen.getByRole('link')
|
|
155
|
+
|
|
156
|
+
expect(elementRef).toHaveBeenCalledWith(link)
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it('should support an `as` prop', () => {
|
|
160
|
+
const { container } = render(<Billboard as="em" />)
|
|
161
|
+
const billboardAsEm = container.querySelector('em')
|
|
162
|
+
|
|
163
|
+
expect(billboardAsEm).toBeInTheDocument()
|
|
164
|
+
expect(billboardAsEm?.className).toMatch(/view-billboard/)
|
|
165
|
+
})
|
|
166
|
+
})
|
|
167
|
+
})
|
package/tsconfig.build.json
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
{ "path": "../ui-heading/tsconfig.build.json" },
|
|
18
18
|
{ "path": "../ui-img/tsconfig.build.json" },
|
|
19
19
|
{ "path": "../ui-react-utils/tsconfig.build.json" },
|
|
20
|
-
{ "path": "../ui-view/tsconfig.build.json" }
|
|
20
|
+
{ "path": "../ui-view/tsconfig.build.json" },
|
|
21
|
+
{ "path": "../ui-axe-check/tsconfig.build.json" }
|
|
21
22
|
]
|
|
22
23
|
}
|