@zohodesk/dot 1.9.5 → 1.9.6
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/README.md +1 -1
- package/es/list/Subject/Subject.js +1 -2
- package/es/list/Subject/__tests__/Subject.spec.js +108 -0
- package/es/list/Subject/__tests__/__snapshots__/Subject.spec.js.snap +41 -0
- package/es/list/Subject/props/defaultProps.js +3 -2
- package/lib/list/Subject/Subject.js +1 -2
- package/lib/list/Subject/__tests__/Subject.spec.js +115 -0
- package/lib/list/Subject/__tests__/__snapshots__/Subject.spec.js.snap +41 -0
- package/lib/list/Subject/props/defaultProps.js +5 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
In this Library, we Provide Some Basic Components to Build Your Application
|
|
4
4
|
|
|
5
|
-
# 1.9.5
|
|
5
|
+
# 1.9.5, # 1.9.6
|
|
6
6
|
|
|
7
7
|
- **listCommon.module.css** A css active ignore comment has been added to fix the hover and click pseudo-class collision issue on iOS tablets.
|
|
8
8
|
- **list/Subject** dataId and testId have been moved back to the parent element as they were earlier.
|
|
@@ -48,8 +48,7 @@ export default class Subject extends Component {
|
|
|
48
48
|
urlData: urlData,
|
|
49
49
|
onClick: onClick,
|
|
50
50
|
target: target,
|
|
51
|
-
|
|
52
|
-
testId: dataId
|
|
51
|
+
dataId: dataId
|
|
53
52
|
}, LinkProps), children ? children : /*#__PURE__*/React.createElement(Typography, {
|
|
54
53
|
$tagAttributes_text: linkTagAttributes,
|
|
55
54
|
$i18n_dataTitle: text,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
3
4
|
import Subject from "../Subject";
|
|
4
5
|
describe('Subject', () => {
|
|
5
6
|
test('rendering the defult props', () => {
|
|
@@ -26,4 +27,111 @@ describe('Subject', () => {
|
|
|
26
27
|
}));
|
|
27
28
|
expect(asFragment()).toMatchSnapshot();
|
|
28
29
|
});
|
|
30
|
+
test('renders data attributes on link wrapper', () => {
|
|
31
|
+
const dataId = 'subject-id';
|
|
32
|
+
const {
|
|
33
|
+
container
|
|
34
|
+
} = render( /*#__PURE__*/React.createElement(Subject, {
|
|
35
|
+
isLink: true,
|
|
36
|
+
dataId: dataId
|
|
37
|
+
}));
|
|
38
|
+
expect(container).toMatchSnapshot();
|
|
39
|
+
const anchor = container.querySelector('a');
|
|
40
|
+
expect(anchor.getAttribute('data-id')).toBe(dataId);
|
|
41
|
+
expect(anchor.getAttribute('data-test-id')).toBe(dataId);
|
|
42
|
+
});
|
|
43
|
+
test('renders text content', () => {
|
|
44
|
+
const text = 'Test Subject';
|
|
45
|
+
const {
|
|
46
|
+
container
|
|
47
|
+
} = render( /*#__PURE__*/React.createElement(Subject, {
|
|
48
|
+
text: text
|
|
49
|
+
}));
|
|
50
|
+
expect(container.textContent).toContain(text);
|
|
51
|
+
});
|
|
52
|
+
test('renders with custom className', () => {
|
|
53
|
+
const customClass = 'custom-subject';
|
|
54
|
+
const {
|
|
55
|
+
container
|
|
56
|
+
} = render( /*#__PURE__*/React.createElement(Subject, {
|
|
57
|
+
className: customClass
|
|
58
|
+
}));
|
|
59
|
+
expect(container.querySelector(`.${customClass}`)).not.toBeNull();
|
|
60
|
+
});
|
|
61
|
+
test('renders dotted text when isDotted is true', () => {
|
|
62
|
+
const {
|
|
63
|
+
asFragment
|
|
64
|
+
} = render( /*#__PURE__*/React.createElement(Subject, {
|
|
65
|
+
text: "Test",
|
|
66
|
+
isDotted: true
|
|
67
|
+
}));
|
|
68
|
+
expect(asFragment()).toMatchSnapshot();
|
|
69
|
+
});
|
|
70
|
+
test('renders children when provided', () => {
|
|
71
|
+
const {
|
|
72
|
+
container
|
|
73
|
+
} = render( /*#__PURE__*/React.createElement(Subject, {
|
|
74
|
+
isLink: true
|
|
75
|
+
}, /*#__PURE__*/React.createElement("span", null, "Custom Child")));
|
|
76
|
+
expect(container.querySelector('span').textContent).toBe('Custom Child');
|
|
77
|
+
});
|
|
78
|
+
test('applies fontWeight prop', () => {
|
|
79
|
+
const {
|
|
80
|
+
asFragment
|
|
81
|
+
} = render( /*#__PURE__*/React.createElement(Subject, {
|
|
82
|
+
text: "Test",
|
|
83
|
+
fontWeight: "bold"
|
|
84
|
+
}));
|
|
85
|
+
expect(asFragment()).toMatchSnapshot();
|
|
86
|
+
});
|
|
87
|
+
test('renders with href when isLink is true', () => {
|
|
88
|
+
const href = 'https://example.com';
|
|
89
|
+
const {
|
|
90
|
+
container
|
|
91
|
+
} = render( /*#__PURE__*/React.createElement(Subject, {
|
|
92
|
+
isLink: true,
|
|
93
|
+
href: href
|
|
94
|
+
}));
|
|
95
|
+
expect(container.querySelector('a').getAttribute('href')).toBe(href);
|
|
96
|
+
});
|
|
97
|
+
test('calls onClick when link is clicked', () => {
|
|
98
|
+
const handleClick = jest.fn();
|
|
99
|
+
const {
|
|
100
|
+
container
|
|
101
|
+
} = render( /*#__PURE__*/React.createElement(Subject, {
|
|
102
|
+
isLink: true,
|
|
103
|
+
onClick: handleClick
|
|
104
|
+
}));
|
|
105
|
+
container.querySelector('a').click();
|
|
106
|
+
expect(handleClick).toHaveBeenCalled();
|
|
107
|
+
});
|
|
108
|
+
test('renders as non-link when isLink is false', () => {
|
|
109
|
+
const {
|
|
110
|
+
container
|
|
111
|
+
} = render( /*#__PURE__*/React.createElement(Subject, {
|
|
112
|
+
text: "Test",
|
|
113
|
+
isLink: false
|
|
114
|
+
}));
|
|
115
|
+
expect(container.querySelector('a')).toBeNull();
|
|
116
|
+
});
|
|
117
|
+
test('applies custom className to non-link element', () => {
|
|
118
|
+
const customClass = 'test-class';
|
|
119
|
+
const {
|
|
120
|
+
container
|
|
121
|
+
} = render( /*#__PURE__*/React.createElement(Subject, {
|
|
122
|
+
text: "Test",
|
|
123
|
+
className: customClass,
|
|
124
|
+
isLink: false
|
|
125
|
+
}));
|
|
126
|
+
expect(container.querySelector(`.${customClass}`)).not.toBeNull();
|
|
127
|
+
});
|
|
128
|
+
test('renders with target prop on link', () => {
|
|
129
|
+
const {
|
|
130
|
+
container
|
|
131
|
+
} = render( /*#__PURE__*/React.createElement(Subject, {
|
|
132
|
+
isLink: true,
|
|
133
|
+
target: "_blank"
|
|
134
|
+
}));
|
|
135
|
+
expect(container.querySelector('a').getAttribute('target')).toBe('_blank');
|
|
136
|
+
});
|
|
29
137
|
});
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
+
exports[`Subject applies fontWeight prop 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<div
|
|
6
|
+
class="dotted font_bold subject whiteSpace_pre"
|
|
7
|
+
data-title="Test"
|
|
8
|
+
data-title-wrap="pre"
|
|
9
|
+
>
|
|
10
|
+
Test
|
|
11
|
+
</div>
|
|
12
|
+
</DocumentFragment>
|
|
13
|
+
`;
|
|
14
|
+
|
|
3
15
|
exports[`Subject rendering the defult props 1`] = `
|
|
4
16
|
<DocumentFragment>
|
|
5
17
|
<div
|
|
@@ -152,3 +164,32 @@ exports[`Subject rendering the whiteSpace of -pre-wrap 2`] = `
|
|
|
152
164
|
</a>
|
|
153
165
|
</DocumentFragment>
|
|
154
166
|
`;
|
|
167
|
+
|
|
168
|
+
exports[`Subject renders data attributes on link wrapper 1`] = `
|
|
169
|
+
<div>
|
|
170
|
+
<a
|
|
171
|
+
class="container "
|
|
172
|
+
data-id="subject-id"
|
|
173
|
+
data-test-id="subject-id"
|
|
174
|
+
href="javascript:void(0);"
|
|
175
|
+
rel="noopener noreferrer"
|
|
176
|
+
>
|
|
177
|
+
<div
|
|
178
|
+
class="dotted font_regular subject whiteSpace_pre cursorPointer"
|
|
179
|
+
data-title-wrap="pre"
|
|
180
|
+
/>
|
|
181
|
+
</a>
|
|
182
|
+
</div>
|
|
183
|
+
`;
|
|
184
|
+
|
|
185
|
+
exports[`Subject renders dotted text when isDotted is true 1`] = `
|
|
186
|
+
<DocumentFragment>
|
|
187
|
+
<div
|
|
188
|
+
class="dotted font_regular subject whiteSpace_pre"
|
|
189
|
+
data-title="Test"
|
|
190
|
+
data-title-wrap="pre"
|
|
191
|
+
>
|
|
192
|
+
Test
|
|
193
|
+
</div>
|
|
194
|
+
</DocumentFragment>
|
|
195
|
+
`;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { DUMMY_OBJECT } from '@zohodesk/dotkit/es/utils/constants';
|
|
1
2
|
export const defaultProps = {
|
|
2
3
|
isLink: false,
|
|
3
4
|
fontWeight: 'regular',
|
|
4
5
|
className: '',
|
|
5
6
|
isDotted: true,
|
|
6
|
-
customProps:
|
|
7
|
+
customProps: DUMMY_OBJECT,
|
|
7
8
|
whiteSpace: 'pre',
|
|
8
9
|
isHighlighted: false,
|
|
9
|
-
highlightData:
|
|
10
|
+
highlightData: DUMMY_OBJECT
|
|
10
11
|
};
|
|
@@ -106,8 +106,7 @@ var Subject = /*#__PURE__*/function (_Component) {
|
|
|
106
106
|
urlData: urlData,
|
|
107
107
|
onClick: onClick,
|
|
108
108
|
target: target,
|
|
109
|
-
|
|
110
|
-
testId: dataId
|
|
109
|
+
dataId: dataId
|
|
111
110
|
}, LinkProps), children ? children : /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
|
|
112
111
|
$tagAttributes_text: linkTagAttributes,
|
|
113
112
|
$i18n_dataTitle: text,
|
|
@@ -4,6 +4,8 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
4
4
|
|
|
5
5
|
var _react2 = require("@testing-library/react");
|
|
6
6
|
|
|
7
|
+
require("@testing-library/jest-dom");
|
|
8
|
+
|
|
7
9
|
var _Subject = _interopRequireDefault(require("../Subject"));
|
|
8
10
|
|
|
9
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -33,4 +35,117 @@ describe('Subject', function () {
|
|
|
33
35
|
|
|
34
36
|
expect(asFragment()).toMatchSnapshot();
|
|
35
37
|
});
|
|
38
|
+
test('renders data attributes on link wrapper', function () {
|
|
39
|
+
var dataId = 'subject-id';
|
|
40
|
+
|
|
41
|
+
var _render4 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Subject["default"], {
|
|
42
|
+
isLink: true,
|
|
43
|
+
dataId: dataId
|
|
44
|
+
})),
|
|
45
|
+
container = _render4.container;
|
|
46
|
+
|
|
47
|
+
expect(container).toMatchSnapshot();
|
|
48
|
+
var anchor = container.querySelector('a');
|
|
49
|
+
expect(anchor.getAttribute('data-id')).toBe(dataId);
|
|
50
|
+
expect(anchor.getAttribute('data-test-id')).toBe(dataId);
|
|
51
|
+
});
|
|
52
|
+
test('renders text content', function () {
|
|
53
|
+
var text = 'Test Subject';
|
|
54
|
+
|
|
55
|
+
var _render5 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Subject["default"], {
|
|
56
|
+
text: text
|
|
57
|
+
})),
|
|
58
|
+
container = _render5.container;
|
|
59
|
+
|
|
60
|
+
expect(container.textContent).toContain(text);
|
|
61
|
+
});
|
|
62
|
+
test('renders with custom className', function () {
|
|
63
|
+
var customClass = 'custom-subject';
|
|
64
|
+
|
|
65
|
+
var _render6 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Subject["default"], {
|
|
66
|
+
className: customClass
|
|
67
|
+
})),
|
|
68
|
+
container = _render6.container;
|
|
69
|
+
|
|
70
|
+
expect(container.querySelector(".".concat(customClass))).not.toBeNull();
|
|
71
|
+
});
|
|
72
|
+
test('renders dotted text when isDotted is true', function () {
|
|
73
|
+
var _render7 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Subject["default"], {
|
|
74
|
+
text: "Test",
|
|
75
|
+
isDotted: true
|
|
76
|
+
})),
|
|
77
|
+
asFragment = _render7.asFragment;
|
|
78
|
+
|
|
79
|
+
expect(asFragment()).toMatchSnapshot();
|
|
80
|
+
});
|
|
81
|
+
test('renders children when provided', function () {
|
|
82
|
+
var _render8 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Subject["default"], {
|
|
83
|
+
isLink: true
|
|
84
|
+
}, /*#__PURE__*/_react["default"].createElement("span", null, "Custom Child"))),
|
|
85
|
+
container = _render8.container;
|
|
86
|
+
|
|
87
|
+
expect(container.querySelector('span').textContent).toBe('Custom Child');
|
|
88
|
+
});
|
|
89
|
+
test('applies fontWeight prop', function () {
|
|
90
|
+
var _render9 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Subject["default"], {
|
|
91
|
+
text: "Test",
|
|
92
|
+
fontWeight: "bold"
|
|
93
|
+
})),
|
|
94
|
+
asFragment = _render9.asFragment;
|
|
95
|
+
|
|
96
|
+
expect(asFragment()).toMatchSnapshot();
|
|
97
|
+
});
|
|
98
|
+
test('renders with href when isLink is true', function () {
|
|
99
|
+
var href = 'https://example.com';
|
|
100
|
+
|
|
101
|
+
var _render10 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Subject["default"], {
|
|
102
|
+
isLink: true,
|
|
103
|
+
href: href
|
|
104
|
+
})),
|
|
105
|
+
container = _render10.container;
|
|
106
|
+
|
|
107
|
+
expect(container.querySelector('a').getAttribute('href')).toBe(href);
|
|
108
|
+
});
|
|
109
|
+
test('calls onClick when link is clicked', function () {
|
|
110
|
+
var handleClick = jest.fn();
|
|
111
|
+
|
|
112
|
+
var _render11 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Subject["default"], {
|
|
113
|
+
isLink: true,
|
|
114
|
+
onClick: handleClick
|
|
115
|
+
})),
|
|
116
|
+
container = _render11.container;
|
|
117
|
+
|
|
118
|
+
container.querySelector('a').click();
|
|
119
|
+
expect(handleClick).toHaveBeenCalled();
|
|
120
|
+
});
|
|
121
|
+
test('renders as non-link when isLink is false', function () {
|
|
122
|
+
var _render12 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Subject["default"], {
|
|
123
|
+
text: "Test",
|
|
124
|
+
isLink: false
|
|
125
|
+
})),
|
|
126
|
+
container = _render12.container;
|
|
127
|
+
|
|
128
|
+
expect(container.querySelector('a')).toBeNull();
|
|
129
|
+
});
|
|
130
|
+
test('applies custom className to non-link element', function () {
|
|
131
|
+
var customClass = 'test-class';
|
|
132
|
+
|
|
133
|
+
var _render13 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Subject["default"], {
|
|
134
|
+
text: "Test",
|
|
135
|
+
className: customClass,
|
|
136
|
+
isLink: false
|
|
137
|
+
})),
|
|
138
|
+
container = _render13.container;
|
|
139
|
+
|
|
140
|
+
expect(container.querySelector(".".concat(customClass))).not.toBeNull();
|
|
141
|
+
});
|
|
142
|
+
test('renders with target prop on link', function () {
|
|
143
|
+
var _render14 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Subject["default"], {
|
|
144
|
+
isLink: true,
|
|
145
|
+
target: "_blank"
|
|
146
|
+
})),
|
|
147
|
+
container = _render14.container;
|
|
148
|
+
|
|
149
|
+
expect(container.querySelector('a').getAttribute('target')).toBe('_blank');
|
|
150
|
+
});
|
|
36
151
|
});
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
+
exports[`Subject applies fontWeight prop 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<div
|
|
6
|
+
class="dotted font_bold subject whiteSpace_pre"
|
|
7
|
+
data-title="Test"
|
|
8
|
+
data-title-wrap="pre"
|
|
9
|
+
>
|
|
10
|
+
Test
|
|
11
|
+
</div>
|
|
12
|
+
</DocumentFragment>
|
|
13
|
+
`;
|
|
14
|
+
|
|
3
15
|
exports[`Subject rendering the defult props 1`] = `
|
|
4
16
|
<DocumentFragment>
|
|
5
17
|
<div
|
|
@@ -152,3 +164,32 @@ exports[`Subject rendering the whiteSpace of -pre-wrap 2`] = `
|
|
|
152
164
|
</a>
|
|
153
165
|
</DocumentFragment>
|
|
154
166
|
`;
|
|
167
|
+
|
|
168
|
+
exports[`Subject renders data attributes on link wrapper 1`] = `
|
|
169
|
+
<div>
|
|
170
|
+
<a
|
|
171
|
+
class="container "
|
|
172
|
+
data-id="subject-id"
|
|
173
|
+
data-test-id="subject-id"
|
|
174
|
+
href="javascript:void(0);"
|
|
175
|
+
rel="noopener noreferrer"
|
|
176
|
+
>
|
|
177
|
+
<div
|
|
178
|
+
class="dotted font_regular subject whiteSpace_pre cursorPointer"
|
|
179
|
+
data-title-wrap="pre"
|
|
180
|
+
/>
|
|
181
|
+
</a>
|
|
182
|
+
</div>
|
|
183
|
+
`;
|
|
184
|
+
|
|
185
|
+
exports[`Subject renders dotted text when isDotted is true 1`] = `
|
|
186
|
+
<DocumentFragment>
|
|
187
|
+
<div
|
|
188
|
+
class="dotted font_regular subject whiteSpace_pre"
|
|
189
|
+
data-title="Test"
|
|
190
|
+
data-title-wrap="pre"
|
|
191
|
+
>
|
|
192
|
+
Test
|
|
193
|
+
</div>
|
|
194
|
+
</DocumentFragment>
|
|
195
|
+
`;
|
|
@@ -4,14 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.defaultProps = void 0;
|
|
7
|
+
|
|
8
|
+
var _constants = require("@zohodesk/dotkit/es/utils/constants");
|
|
9
|
+
|
|
7
10
|
var defaultProps = {
|
|
8
11
|
isLink: false,
|
|
9
12
|
fontWeight: 'regular',
|
|
10
13
|
className: '',
|
|
11
14
|
isDotted: true,
|
|
12
|
-
customProps:
|
|
15
|
+
customProps: _constants.DUMMY_OBJECT,
|
|
13
16
|
whiteSpace: 'pre',
|
|
14
17
|
isHighlighted: false,
|
|
15
|
-
highlightData:
|
|
18
|
+
highlightData: _constants.DUMMY_OBJECT
|
|
16
19
|
};
|
|
17
20
|
exports.defaultProps = defaultProps;
|