@automattic/vip-design-system 0.9.0 → 0.9.3
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/build/system/Avatar/Avatar.test.js +41 -22
- package/build/system/Badge/Badge.test.js +73 -0
- package/build/system/BlankState/BlankState.js +12 -9
- package/build/system/BlankState/BlankState.test.js +124 -0
- package/build/system/Button/Button.test.js +44 -0
- package/build/system/Card/Card.js +5 -7
- package/build/system/Card/Card.test.js +78 -0
- package/build/system/Code/Code.js +11 -8
- package/build/system/Code/Code.test.js +167 -0
- package/build/system/Dialog/DialogContent.js +3 -1
- package/build/system/Form/Input.js +7 -9
- package/build/system/Form/Select.js +29 -12
- package/build/system/Form/Textarea.js +5 -7
- package/build/system/Timeline/index.js +11 -9
- package/build/system/index.js +4 -0
- package/build/system/theme/index.js +1 -1
- package/package.json +15 -4
- package/src/system/Avatar/Avatar.test.js +9 -10
- package/src/system/Badge/Badge.test.js +30 -0
- package/src/system/BlankState/BlankState.js +13 -5
- package/src/system/BlankState/BlankState.test.js +58 -0
- package/src/system/Button/Button.test.js +21 -0
- package/src/system/Card/Card.js +16 -14
- package/src/system/Card/Card.test.js +33 -0
- package/src/system/Code/Code.js +12 -9
- package/src/system/Code/Code.stories.js +2 -0
- package/src/system/Code/Code.test.js +69 -0
- package/src/system/Dialog/DialogContent.js +2 -0
- package/src/system/Form/Input.js +6 -6
- package/src/system/Form/Select.js +16 -6
- package/src/system/Form/Select.stories.js +52 -24
- package/src/system/Form/Textarea.js +4 -4
- package/src/system/Timeline/index.js +46 -0
- package/src/system/index.js +2 -0
- package/src/system/theme/index.js +1 -1
|
@@ -13,42 +13,61 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
13
13
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
14
14
|
|
|
15
15
|
describe('<Avatar />', function () {
|
|
16
|
-
it('renders the Avatar without an image', function () {
|
|
17
|
-
|
|
18
|
-
name: "John Doe"
|
|
19
|
-
}));
|
|
20
|
-
expect(_react.screen.getByText('J')).toBeInTheDocument();
|
|
21
|
-
});
|
|
22
|
-
it('renders the Avatar with image', function () {
|
|
23
|
-
(0, _react.render)((0, _jsxRuntime.jsx)(_Avatar.Avatar, {
|
|
24
|
-
name: "John Doe",
|
|
25
|
-
src: "path/to/image"
|
|
26
|
-
}));
|
|
27
|
-
expect(_react.screen.getByAltText('Avatar image from John Doe')).toBeInTheDocument();
|
|
28
|
-
});
|
|
29
|
-
it('should not have basic accessibility issues', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
30
|
-
var _render, container, results;
|
|
16
|
+
it('renders the Avatar without an image', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
17
|
+
var _render, container;
|
|
31
18
|
|
|
32
19
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
33
20
|
while (1) {
|
|
34
21
|
switch (_context.prev = _context.next) {
|
|
35
22
|
case 0:
|
|
36
23
|
_render = (0, _react.render)((0, _jsxRuntime.jsx)(_Avatar.Avatar, {
|
|
37
|
-
name: "John Doe"
|
|
38
|
-
src: "path/to/image"
|
|
24
|
+
name: "John Doe"
|
|
39
25
|
})), container = _render.container;
|
|
40
|
-
|
|
41
|
-
return (0, _jestAxe.axe)(container);
|
|
26
|
+
expect(_react.screen.getByText('J')).toBeInTheDocument(); // Check for accessibility issues
|
|
42
27
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
28
|
+
_context.t0 = expect;
|
|
29
|
+
_context.next = 5;
|
|
30
|
+
return (0, _jestAxe.axe)(container);
|
|
46
31
|
|
|
47
32
|
case 5:
|
|
33
|
+
_context.t1 = _context.sent;
|
|
34
|
+
_context.next = 8;
|
|
35
|
+
return (0, _context.t0)(_context.t1).toHaveNoViolations();
|
|
36
|
+
|
|
37
|
+
case 8:
|
|
48
38
|
case "end":
|
|
49
39
|
return _context.stop();
|
|
50
40
|
}
|
|
51
41
|
}
|
|
52
42
|
}, _callee);
|
|
53
43
|
})));
|
|
44
|
+
it('renders the Avatar with image', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
45
|
+
var _render2, container;
|
|
46
|
+
|
|
47
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
48
|
+
while (1) {
|
|
49
|
+
switch (_context2.prev = _context2.next) {
|
|
50
|
+
case 0:
|
|
51
|
+
_render2 = (0, _react.render)((0, _jsxRuntime.jsx)(_Avatar.Avatar, {
|
|
52
|
+
name: "John Doe",
|
|
53
|
+
src: "path/to/image"
|
|
54
|
+
})), container = _render2.container;
|
|
55
|
+
expect(_react.screen.getByAltText('Avatar image from John Doe')).toBeInTheDocument(); // Check for accessibility issues
|
|
56
|
+
|
|
57
|
+
_context2.t0 = expect;
|
|
58
|
+
_context2.next = 5;
|
|
59
|
+
return (0, _jestAxe.axe)(container);
|
|
60
|
+
|
|
61
|
+
case 5:
|
|
62
|
+
_context2.t1 = _context2.sent;
|
|
63
|
+
_context2.next = 8;
|
|
64
|
+
return (0, _context2.t0)(_context2.t1).toHaveNoViolations();
|
|
65
|
+
|
|
66
|
+
case 8:
|
|
67
|
+
case "end":
|
|
68
|
+
return _context2.stop();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}, _callee2);
|
|
72
|
+
})));
|
|
54
73
|
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
5
|
+
var _jestAxe = require("jest-axe");
|
|
6
|
+
|
|
7
|
+
var _Badge = require("./Badge");
|
|
8
|
+
|
|
9
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
10
|
+
|
|
11
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
12
|
+
|
|
13
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
14
|
+
|
|
15
|
+
describe('<Badge />', function () {
|
|
16
|
+
it('renders the Badge component', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
17
|
+
var _render, container;
|
|
18
|
+
|
|
19
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
20
|
+
while (1) {
|
|
21
|
+
switch (_context.prev = _context.next) {
|
|
22
|
+
case 0:
|
|
23
|
+
_render = (0, _react.render)((0, _jsxRuntime.jsx)(_Badge.Badge, {
|
|
24
|
+
children: "Badge text"
|
|
25
|
+
})), container = _render.container;
|
|
26
|
+
expect(_react.screen.getByText('Badge text')).toBeInTheDocument(); // Check for accessibility issues
|
|
27
|
+
|
|
28
|
+
_context.t0 = expect;
|
|
29
|
+
_context.next = 5;
|
|
30
|
+
return (0, _jestAxe.axe)(container);
|
|
31
|
+
|
|
32
|
+
case 5:
|
|
33
|
+
_context.t1 = _context.sent;
|
|
34
|
+
_context.next = 8;
|
|
35
|
+
return (0, _context.t0)(_context.t1).toHaveNoViolations();
|
|
36
|
+
|
|
37
|
+
case 8:
|
|
38
|
+
case "end":
|
|
39
|
+
return _context.stop();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}, _callee);
|
|
43
|
+
})));
|
|
44
|
+
it('renders the Badge component with a different variant', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
45
|
+
var _render2, container;
|
|
46
|
+
|
|
47
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
48
|
+
while (1) {
|
|
49
|
+
switch (_context2.prev = _context2.next) {
|
|
50
|
+
case 0:
|
|
51
|
+
_render2 = (0, _react.render)((0, _jsxRuntime.jsx)(_Badge.Badge, {
|
|
52
|
+
variant: "primary",
|
|
53
|
+
children: "Badge text"
|
|
54
|
+
})), container = _render2.container;
|
|
55
|
+
expect(_react.screen.getByText('Badge text')).toBeInTheDocument(); // Check for accessibility issues
|
|
56
|
+
|
|
57
|
+
_context2.t0 = expect;
|
|
58
|
+
_context2.next = 5;
|
|
59
|
+
return (0, _jestAxe.axe)(container);
|
|
60
|
+
|
|
61
|
+
case 5:
|
|
62
|
+
_context2.t1 = _context2.sent;
|
|
63
|
+
_context2.next = 8;
|
|
64
|
+
return (0, _context2.t0)(_context2.t1).toHaveNoViolations();
|
|
65
|
+
|
|
66
|
+
case 8:
|
|
67
|
+
case "end":
|
|
68
|
+
return _context2.stop();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}, _callee2);
|
|
72
|
+
})));
|
|
73
|
+
});
|
|
@@ -21,11 +21,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
21
21
|
* Internal dependencies
|
|
22
22
|
*/
|
|
23
23
|
var BlankState = function BlankState(_ref) {
|
|
24
|
-
var
|
|
24
|
+
var body = _ref.body,
|
|
25
|
+
cta = _ref.cta,
|
|
25
26
|
icon = _ref.icon,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
image = _ref.image,
|
|
28
|
+
_ref$imageAlt = _ref.imageAlt,
|
|
29
|
+
imageAlt = _ref$imageAlt === void 0 ? 'Image representing the blank state' : _ref$imageAlt,
|
|
30
|
+
title = _ref.title;
|
|
29
31
|
return (0, _jsxRuntime.jsxs)(_.Box, {
|
|
30
32
|
sx: {
|
|
31
33
|
textAlign: 'center',
|
|
@@ -36,7 +38,7 @@ var BlankState = function BlankState(_ref) {
|
|
|
36
38
|
sx: {
|
|
37
39
|
mb: 3
|
|
38
40
|
},
|
|
39
|
-
alt:
|
|
41
|
+
alt: imageAlt
|
|
40
42
|
}), (0, _jsxRuntime.jsx)(_.Heading, {
|
|
41
43
|
variant: "h4",
|
|
42
44
|
children: title
|
|
@@ -53,9 +55,10 @@ var BlankState = function BlankState(_ref) {
|
|
|
53
55
|
|
|
54
56
|
exports.BlankState = BlankState;
|
|
55
57
|
BlankState.propTypes = {
|
|
56
|
-
image: _propTypes["default"].oneOfType([_propTypes["default"].object, _propTypes["default"].string]),
|
|
57
|
-
icon: _propTypes["default"].node,
|
|
58
|
-
title: _propTypes["default"].node,
|
|
59
58
|
body: _propTypes["default"].node,
|
|
60
|
-
cta: _propTypes["default"].node
|
|
59
|
+
cta: _propTypes["default"].node,
|
|
60
|
+
icon: _propTypes["default"].node,
|
|
61
|
+
image: _propTypes["default"].oneOfType([_propTypes["default"].object, _propTypes["default"].string]),
|
|
62
|
+
imageAlt: _propTypes["default"].string,
|
|
63
|
+
title: _propTypes["default"].node
|
|
61
64
|
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
5
|
+
var _jestAxe = require("jest-axe");
|
|
6
|
+
|
|
7
|
+
var _md = require("react-icons/md");
|
|
8
|
+
|
|
9
|
+
var _BlankState = require("./BlankState");
|
|
10
|
+
|
|
11
|
+
var _Link = require("../Link");
|
|
12
|
+
|
|
13
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
14
|
+
|
|
15
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
16
|
+
|
|
17
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
18
|
+
|
|
19
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
20
|
+
|
|
21
|
+
// eslint-disable-next-line max-len
|
|
22
|
+
var image = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='79' height='79' viewBox='0 0 79 79' fill='none'%3E%3Cpath d='M66.3001 15.9C66.3001 15.9 66.3 15.8 66.2 15.8C66.1 15.7 66 15.5 65.9001 15.4C65.9001 15.4 65.9001 15.4 65.9001 15.3L44.4001 0.2C44.3001 0.0999998 44.2 0.0999994 44.1 0.0999994C44 0.0999994 44.0001 0 43.9001 0H43.3C43.2 0 43.1 0.0999994 43.1 0.0999994C43 0.0999994 42.9 0.2 42.8 0.2L28.2001 10.3C28.1 10.4 28.0001 10.5 27.9001 10.6C27.9001 10.6 27.9001 10.6 27.9001 10.7C27.8001 10.8 27.7001 11 27.7001 11.2C27.7001 11.2 27.7001 11.2 27.7001 11.3V31.1L13.9 40.8L13.7001 41C13.6001 41.1 13.6 41.1 13.6 41.2L13.5 41.3C13.5 41.4 13.4 41.5 13.4 41.5V41.6C13.4 41.7 13.3 41.8 13.3 42V62.2C13.3 62.4 13.3 62.6 13.4 62.7V62.8C13.5 62.9 13.6001 63.1 13.7001 63.2C13.7001 63.2 13.7 63.2 13.8 63.3L13.9 63.4L35.3 78.6H35.4001C35.4001 78.6 35.5 78.6 35.5 78.7H35.6C35.8 78.8 36 78.8 36.2001 78.8C36.3001 78.8 36.5 78.8 36.6 78.7H36.7001C36.8001 78.7 36.8001 78.7 36.9001 78.6C36.9001 78.6 37 78.6 37 78.5H37.1L66 58.3C66.1 58.2 66.2001 58.1 66.3001 58V15.9ZM34.6 74.5L16.1 61.3V44.7L34.6 57.8V74.5ZM36 55.3L17.2001 41.9L29 33.5L47.9001 46.9L36 55.3ZM49 44.1L30.5 31V14.4L49 27.5V44.1ZM50.5 24.9L31.6 11.5L43.5 3.2L62.4001 16.6L50.5 24.9Z' fill='%23BD9D70'/%3E%3C/svg%3E";
|
|
23
|
+
var defaultProps = {
|
|
24
|
+
body: 'Sorry, there\'s nothing here yet.',
|
|
25
|
+
cta: (0, _jsxRuntime.jsx)(_Link.Link, {
|
|
26
|
+
as: "a",
|
|
27
|
+
children: "Explore add-ons \u2192"
|
|
28
|
+
}),
|
|
29
|
+
image: image,
|
|
30
|
+
imageAlt: 'This is the image alt',
|
|
31
|
+
title: 'Power up your application'
|
|
32
|
+
};
|
|
33
|
+
describe('<BlankState />', function () {
|
|
34
|
+
it('renders the BlankState component', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
35
|
+
var _render, container;
|
|
36
|
+
|
|
37
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
38
|
+
while (1) {
|
|
39
|
+
switch (_context.prev = _context.next) {
|
|
40
|
+
case 0:
|
|
41
|
+
_render = (0, _react.render)((0, _jsxRuntime.jsx)(_BlankState.BlankState, _extends({}, defaultProps))), container = _render.container;
|
|
42
|
+
expect(_react.screen.getByText(defaultProps.body)).toBeInTheDocument();
|
|
43
|
+
expect(_react.screen.getByText(defaultProps.title)).toBeInTheDocument();
|
|
44
|
+
expect(_react.screen.getByText('Explore add-ons →')).toBeInTheDocument();
|
|
45
|
+
expect(_react.screen.getByAltText(defaultProps.imageAlt)).toBeInTheDocument(); // Check for accessibility issues
|
|
46
|
+
|
|
47
|
+
_context.t0 = expect;
|
|
48
|
+
_context.next = 8;
|
|
49
|
+
return (0, _jestAxe.axe)(container);
|
|
50
|
+
|
|
51
|
+
case 8:
|
|
52
|
+
_context.t1 = _context.sent;
|
|
53
|
+
_context.next = 11;
|
|
54
|
+
return (0, _context.t0)(_context.t1).toHaveNoViolations();
|
|
55
|
+
|
|
56
|
+
case 11:
|
|
57
|
+
case "end":
|
|
58
|
+
return _context.stop();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}, _callee);
|
|
62
|
+
})));
|
|
63
|
+
it('renders the BlankState component with default alt text for the given image', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
64
|
+
var props, _render2, container;
|
|
65
|
+
|
|
66
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
67
|
+
while (1) {
|
|
68
|
+
switch (_context2.prev = _context2.next) {
|
|
69
|
+
case 0:
|
|
70
|
+
props = _extends({}, defaultProps, {
|
|
71
|
+
imageAlt: undefined
|
|
72
|
+
});
|
|
73
|
+
_render2 = (0, _react.render)((0, _jsxRuntime.jsx)(_BlankState.BlankState, _extends({}, props))), container = _render2.container;
|
|
74
|
+
expect(_react.screen.getByAltText('Image representing the blank state')).toBeInTheDocument(); // Check for accessibility issues
|
|
75
|
+
|
|
76
|
+
_context2.t0 = expect;
|
|
77
|
+
_context2.next = 6;
|
|
78
|
+
return (0, _jestAxe.axe)(container);
|
|
79
|
+
|
|
80
|
+
case 6:
|
|
81
|
+
_context2.t1 = _context2.sent;
|
|
82
|
+
_context2.next = 9;
|
|
83
|
+
return (0, _context2.t0)(_context2.t1).toHaveNoViolations();
|
|
84
|
+
|
|
85
|
+
case 9:
|
|
86
|
+
case "end":
|
|
87
|
+
return _context2.stop();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}, _callee2);
|
|
91
|
+
})));
|
|
92
|
+
it('renders the BlankState component with an icon', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
93
|
+
var icon, props, _render3, container;
|
|
94
|
+
|
|
95
|
+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
96
|
+
while (1) {
|
|
97
|
+
switch (_context3.prev = _context3.next) {
|
|
98
|
+
case 0:
|
|
99
|
+
icon = (0, _jsxRuntime.jsx)(_md.MdContentCopy, {
|
|
100
|
+
title: "this is an icon"
|
|
101
|
+
});
|
|
102
|
+
props = _extends({}, defaultProps, {
|
|
103
|
+
icon: icon
|
|
104
|
+
});
|
|
105
|
+
_render3 = (0, _react.render)((0, _jsxRuntime.jsx)(_BlankState.BlankState, _extends({}, props))), container = _render3.container;
|
|
106
|
+
expect(_react.screen.getByTitle('this is an icon')).toBeInTheDocument(); // Check for accessibility issues
|
|
107
|
+
|
|
108
|
+
_context3.t0 = expect;
|
|
109
|
+
_context3.next = 7;
|
|
110
|
+
return (0, _jestAxe.axe)(container);
|
|
111
|
+
|
|
112
|
+
case 7:
|
|
113
|
+
_context3.t1 = _context3.sent;
|
|
114
|
+
_context3.next = 10;
|
|
115
|
+
return (0, _context3.t0)(_context3.t1).toHaveNoViolations();
|
|
116
|
+
|
|
117
|
+
case 10:
|
|
118
|
+
case "end":
|
|
119
|
+
return _context3.stop();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}, _callee3);
|
|
123
|
+
})));
|
|
124
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
5
|
+
var _jestAxe = require("jest-axe");
|
|
6
|
+
|
|
7
|
+
var _Button = require("./Button");
|
|
8
|
+
|
|
9
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
10
|
+
|
|
11
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
12
|
+
|
|
13
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
14
|
+
|
|
15
|
+
describe('<Button />', function () {
|
|
16
|
+
it('renders the Button component', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
17
|
+
var _render, container;
|
|
18
|
+
|
|
19
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
20
|
+
while (1) {
|
|
21
|
+
switch (_context.prev = _context.next) {
|
|
22
|
+
case 0:
|
|
23
|
+
_render = (0, _react.render)((0, _jsxRuntime.jsx)(_Button.Button, {
|
|
24
|
+
children: "Button text"
|
|
25
|
+
})), container = _render.container;
|
|
26
|
+
expect(_react.screen.getByText('Button text')).toBeInTheDocument(); // Check for accessibility issues
|
|
27
|
+
|
|
28
|
+
_context.t0 = expect;
|
|
29
|
+
_context.next = 5;
|
|
30
|
+
return (0, _jestAxe.axe)(container);
|
|
31
|
+
|
|
32
|
+
case 5:
|
|
33
|
+
_context.t1 = _context.sent;
|
|
34
|
+
_context.next = 8;
|
|
35
|
+
return (0, _context.t0)(_context.t1).toHaveNoViolations();
|
|
36
|
+
|
|
37
|
+
case 8:
|
|
38
|
+
case "end":
|
|
39
|
+
return _context.stop();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}, _callee);
|
|
43
|
+
})));
|
|
44
|
+
});
|
|
@@ -19,7 +19,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
|
19
19
|
|
|
20
20
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
21
21
|
|
|
22
|
-
var
|
|
22
|
+
var Card = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
|
|
23
23
|
var _ref$variant = _ref.variant,
|
|
24
24
|
variant = _ref$variant === void 0 ? 'primary' : _ref$variant,
|
|
25
25
|
_ref$sx = _ref.sx,
|
|
@@ -34,13 +34,11 @@ var CardComponent = function CardComponent(_ref, ref) {
|
|
|
34
34
|
overflow: 'hidden'
|
|
35
35
|
}, sx)
|
|
36
36
|
}, props));
|
|
37
|
-
};
|
|
37
|
+
});
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
exports.Card = Card;
|
|
40
|
+
Card.propTypes = {
|
|
40
41
|
variant: _propTypes["default"].string,
|
|
41
42
|
sx: _propTypes["default"].object
|
|
42
43
|
};
|
|
43
|
-
|
|
44
|
-
var Card = /*#__PURE__*/_react["default"].forwardRef(CardComponent);
|
|
45
|
-
|
|
46
|
-
exports.Card = Card;
|
|
44
|
+
Card.displayName = 'Card';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
5
|
+
var _jestAxe = require("jest-axe");
|
|
6
|
+
|
|
7
|
+
var _md = require("react-icons/md");
|
|
8
|
+
|
|
9
|
+
var _Card = require("./Card");
|
|
10
|
+
|
|
11
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
12
|
+
|
|
13
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
14
|
+
|
|
15
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
16
|
+
|
|
17
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
18
|
+
|
|
19
|
+
var defaultProps = {};
|
|
20
|
+
describe('<Card />', function () {
|
|
21
|
+
it('renders the Card component', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
22
|
+
var _render, container;
|
|
23
|
+
|
|
24
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
25
|
+
while (1) {
|
|
26
|
+
switch (_context.prev = _context.next) {
|
|
27
|
+
case 0:
|
|
28
|
+
_render = (0, _react.render)((0, _jsxRuntime.jsx)(_Card.Card, _extends({}, defaultProps, {
|
|
29
|
+
children: "This is a Card"
|
|
30
|
+
}))), container = _render.container;
|
|
31
|
+
expect(_react.screen.getByText('This is a Card')).toBeInTheDocument(); // Check for accessibility issues
|
|
32
|
+
|
|
33
|
+
_context.t0 = expect;
|
|
34
|
+
_context.next = 5;
|
|
35
|
+
return (0, _jestAxe.axe)(container);
|
|
36
|
+
|
|
37
|
+
case 5:
|
|
38
|
+
_context.t1 = _context.sent;
|
|
39
|
+
_context.next = 8;
|
|
40
|
+
return (0, _context.t0)(_context.t1).toHaveNoViolations();
|
|
41
|
+
|
|
42
|
+
case 8:
|
|
43
|
+
case "end":
|
|
44
|
+
return _context.stop();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}, _callee);
|
|
48
|
+
})));
|
|
49
|
+
it('renders the Card component with a different variant', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
50
|
+
var _render2, container;
|
|
51
|
+
|
|
52
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
53
|
+
while (1) {
|
|
54
|
+
switch (_context2.prev = _context2.next) {
|
|
55
|
+
case 0:
|
|
56
|
+
_render2 = (0, _react.render)((0, _jsxRuntime.jsx)(_Card.Card, {
|
|
57
|
+
variant: "primary",
|
|
58
|
+
children: "Card text"
|
|
59
|
+
})), container = _render2.container;
|
|
60
|
+
expect(_react.screen.getByText('Card text')).toBeInTheDocument(); // Check for accessibility issues
|
|
61
|
+
|
|
62
|
+
_context2.t0 = expect;
|
|
63
|
+
_context2.next = 5;
|
|
64
|
+
return (0, _jestAxe.axe)(container);
|
|
65
|
+
|
|
66
|
+
case 5:
|
|
67
|
+
_context2.t1 = _context2.sent;
|
|
68
|
+
_context2.next = 8;
|
|
69
|
+
return (0, _context2.t0)(_context2.t1).toHaveNoViolations();
|
|
70
|
+
|
|
71
|
+
case 8:
|
|
72
|
+
case "end":
|
|
73
|
+
return _context2.stop();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, _callee2);
|
|
77
|
+
})));
|
|
78
|
+
});
|
|
@@ -61,18 +61,21 @@ var Code = function Code(_ref) {
|
|
|
61
61
|
sx: {
|
|
62
62
|
position: 'relative'
|
|
63
63
|
},
|
|
64
|
-
children: [codeDom, (0, _jsxRuntime.jsx)("
|
|
64
|
+
children: [codeDom, (0, _jsxRuntime.jsx)("button", {
|
|
65
|
+
"aria-label": "Copy",
|
|
65
66
|
sx: {
|
|
66
|
-
position: 'absolute',
|
|
67
|
-
top: 0,
|
|
68
67
|
bg: 'grey.10',
|
|
69
|
-
right: 0,
|
|
70
|
-
paddingRight: 2,
|
|
71
|
-
paddingLeft: 2,
|
|
72
|
-
paddingTop: 1,
|
|
73
|
-
paddingBottom: 1,
|
|
74
68
|
borderTopRightRadius: 1,
|
|
69
|
+
borderWidth: 0,
|
|
70
|
+
color: 'muted',
|
|
75
71
|
opacity: 0.8,
|
|
72
|
+
paddingBottom: 1,
|
|
73
|
+
paddingLeft: 2,
|
|
74
|
+
paddingRight: 2,
|
|
75
|
+
paddingTop: 1,
|
|
76
|
+
position: 'absolute',
|
|
77
|
+
right: 0,
|
|
78
|
+
top: '-1px',
|
|
76
79
|
'&:hover': {
|
|
77
80
|
opacity: 1,
|
|
78
81
|
cursor: 'pointer'
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
|
+
|
|
5
|
+
var _jestAxe = require("jest-axe");
|
|
6
|
+
|
|
7
|
+
var _md = require("react-icons/md");
|
|
8
|
+
|
|
9
|
+
var _Code = require("./Code");
|
|
10
|
+
|
|
11
|
+
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
12
|
+
|
|
13
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
14
|
+
|
|
15
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
16
|
+
|
|
17
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
18
|
+
|
|
19
|
+
var defaultProps = {
|
|
20
|
+
showCopy: false
|
|
21
|
+
}; // Mock navigator.clipboard because jsdom doesn't support it
|
|
22
|
+
|
|
23
|
+
Object.defineProperty(window.navigator, 'clipboard', {
|
|
24
|
+
value: {
|
|
25
|
+
writeText: function writeText() {}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
describe('<Code />', function () {
|
|
29
|
+
it('renders the Code component', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
30
|
+
var _render, container;
|
|
31
|
+
|
|
32
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
33
|
+
while (1) {
|
|
34
|
+
switch (_context.prev = _context.next) {
|
|
35
|
+
case 0:
|
|
36
|
+
_render = (0, _react.render)((0, _jsxRuntime.jsx)(_Code.Code, _extends({}, defaultProps, {
|
|
37
|
+
children: "This is a code"
|
|
38
|
+
}))), container = _render.container;
|
|
39
|
+
expect(_react.screen.getByText('This is a code')).toBeInTheDocument(); // Check for accessibility issues
|
|
40
|
+
|
|
41
|
+
_context.t0 = expect;
|
|
42
|
+
_context.next = 5;
|
|
43
|
+
return (0, _jestAxe.axe)(container);
|
|
44
|
+
|
|
45
|
+
case 5:
|
|
46
|
+
_context.t1 = _context.sent;
|
|
47
|
+
_context.next = 8;
|
|
48
|
+
return (0, _context.t0)(_context.t1).toHaveNoViolations();
|
|
49
|
+
|
|
50
|
+
case 8:
|
|
51
|
+
case "end":
|
|
52
|
+
return _context.stop();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}, _callee);
|
|
56
|
+
}))); // jsdom currently doesn't support pseudo-elements with getComputedStyle
|
|
57
|
+
|
|
58
|
+
it.skip('renders "$" in front of the code when in prompt mode', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
59
|
+
var props, _render2, container, codeElement;
|
|
60
|
+
|
|
61
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
62
|
+
while (1) {
|
|
63
|
+
switch (_context2.prev = _context2.next) {
|
|
64
|
+
case 0:
|
|
65
|
+
props = _extends({}, defaultProps, {
|
|
66
|
+
prompt: true
|
|
67
|
+
});
|
|
68
|
+
_render2 = (0, _react.render)((0, _jsxRuntime.jsx)(_Code.Code, _extends({}, props, {
|
|
69
|
+
children: "This is a code"
|
|
70
|
+
}))), container = _render2.container;
|
|
71
|
+
codeElement = _react.screen.getByText('This is a code');
|
|
72
|
+
expect(window.getComputedStyle(codeElement, ':before').content).toEqual('$'); // Check for accessibility issues
|
|
73
|
+
|
|
74
|
+
_context2.t0 = expect;
|
|
75
|
+
_context2.next = 7;
|
|
76
|
+
return (0, _jestAxe.axe)(container);
|
|
77
|
+
|
|
78
|
+
case 7:
|
|
79
|
+
_context2.t1 = _context2.sent;
|
|
80
|
+
_context2.next = 10;
|
|
81
|
+
return (0, _context2.t0)(_context2.t1).toHaveNoViolations();
|
|
82
|
+
|
|
83
|
+
case 10:
|
|
84
|
+
case "end":
|
|
85
|
+
return _context2.stop();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, _callee2);
|
|
89
|
+
})));
|
|
90
|
+
it('renders the Code component with a copy button', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
91
|
+
var props, _render3, container;
|
|
92
|
+
|
|
93
|
+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
94
|
+
while (1) {
|
|
95
|
+
switch (_context3.prev = _context3.next) {
|
|
96
|
+
case 0:
|
|
97
|
+
props = _extends({}, defaultProps, {
|
|
98
|
+
showCopy: true
|
|
99
|
+
});
|
|
100
|
+
_render3 = (0, _react.render)((0, _jsxRuntime.jsx)(_Code.Code, _extends({}, props, {
|
|
101
|
+
children: "This is a code"
|
|
102
|
+
}))), container = _render3.container;
|
|
103
|
+
expect(_react.screen.getByRole('button', {
|
|
104
|
+
name: 'Copy'
|
|
105
|
+
})).toBeInTheDocument(); // Check for accessibility issues
|
|
106
|
+
|
|
107
|
+
_context3.t0 = expect;
|
|
108
|
+
_context3.next = 6;
|
|
109
|
+
return (0, _jestAxe.axe)(container);
|
|
110
|
+
|
|
111
|
+
case 6:
|
|
112
|
+
_context3.t1 = _context3.sent;
|
|
113
|
+
_context3.next = 9;
|
|
114
|
+
return (0, _context3.t0)(_context3.t1).toHaveNoViolations();
|
|
115
|
+
|
|
116
|
+
case 9:
|
|
117
|
+
case "end":
|
|
118
|
+
return _context3.stop();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}, _callee3);
|
|
122
|
+
})));
|
|
123
|
+
it('updates the the UI after clicking on "Copy"', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
124
|
+
var props, _render4, container;
|
|
125
|
+
|
|
126
|
+
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
127
|
+
while (1) {
|
|
128
|
+
switch (_context4.prev = _context4.next) {
|
|
129
|
+
case 0:
|
|
130
|
+
props = _extends({}, defaultProps, {
|
|
131
|
+
showCopy: true
|
|
132
|
+
});
|
|
133
|
+
_render4 = (0, _react.render)((0, _jsxRuntime.jsx)(_Code.Code, _extends({}, props, {
|
|
134
|
+
children: "This is a code"
|
|
135
|
+
}))), container = _render4.container;
|
|
136
|
+
|
|
137
|
+
_react.fireEvent.click(_react.screen.getByRole('button', {
|
|
138
|
+
name: 'Copy'
|
|
139
|
+
}));
|
|
140
|
+
|
|
141
|
+
_context4.next = 5;
|
|
142
|
+
return (0, _react.waitFor)(function () {
|
|
143
|
+
return new Promise(function (res) {
|
|
144
|
+
return setTimeout(res, 0);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
case 5:
|
|
149
|
+
expect(_react.screen.getByText('Copied!')).toBeInTheDocument(); // Check for accessibility issues
|
|
150
|
+
|
|
151
|
+
_context4.t0 = expect;
|
|
152
|
+
_context4.next = 9;
|
|
153
|
+
return (0, _jestAxe.axe)(container);
|
|
154
|
+
|
|
155
|
+
case 9:
|
|
156
|
+
_context4.t1 = _context4.sent;
|
|
157
|
+
_context4.next = 12;
|
|
158
|
+
return (0, _context4.t0)(_context4.t1).toHaveNoViolations();
|
|
159
|
+
|
|
160
|
+
case 12:
|
|
161
|
+
case "end":
|
|
162
|
+
return _context4.stop();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}, _callee4);
|
|
166
|
+
})));
|
|
167
|
+
});
|