krl-alfred 2.25.3 → 2.25.4
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.
|
@@ -39,7 +39,7 @@ var Children = function (props) {
|
|
|
39
39
|
return iconPosition === 'left' ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [iconElement, content] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [content, iconElement] }));
|
|
40
40
|
};
|
|
41
41
|
var Button = (0, react_1.forwardRef)(function (props, ref) {
|
|
42
|
-
var
|
|
42
|
+
var _a = props.type, type = _a === void 0 ? props_1.ButtonDefault.type : _a, isLoading = props.isLoading, onClick = props.onClick, disabled = props.disabled, size = props.size, variant = props.variant, width = props.width, _b = props.icon, icon = _b === void 0 ? props_1.ButtonDefault.icon : _b, _c = props.iconPosition, iconPosition = _c === void 0 ? props_1.ButtonDefault.iconPosition : _c, children = props.children, _d = props.iconSize, iconSize = _d === void 0 ? props_1.ButtonDefault.iconSize : _d, _e = props.tooltip, tooltip = _e === void 0 ? props_1.ButtonDefault.tooltip : _e, other = __rest(props, ["type", "isLoading", "onClick", "disabled", "size", "variant", "width", "icon", "iconPosition", "children", "iconSize", "tooltip"]);
|
|
43
43
|
var handleClick = function (e) {
|
|
44
44
|
onClick === null || onClick === void 0 ? void 0 : onClick(e);
|
|
45
45
|
e.currentTarget.blur();
|
|
@@ -113,9 +113,47 @@ describe('Button', function () {
|
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
115
|
}); });
|
|
116
|
-
it('
|
|
116
|
+
it('defaults an omitted type to button and does not submit the form', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
117
|
+
var onSubmit, onClick;
|
|
118
|
+
return __generator(this, function (_a) {
|
|
119
|
+
switch (_a.label) {
|
|
120
|
+
case 0:
|
|
121
|
+
onSubmit = jest.fn(function (event) { return event.preventDefault(); });
|
|
122
|
+
onClick = jest.fn();
|
|
123
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)("form", __assign({ onSubmit: onSubmit }, { children: (0, jsx_runtime_1.jsx)(Button_1.default, __assign({ size: "medium", variant: "primary", onClick: onClick }, { children: "Apply" })) })));
|
|
124
|
+
return [4 /*yield*/, user_event_1.default.click(react_1.screen.getByRole('button', { name: 'Apply' }))];
|
|
125
|
+
case 1:
|
|
126
|
+
_a.sent();
|
|
127
|
+
expect(react_1.screen.getByRole('button', { name: 'Apply' })).toHaveAttribute('type', 'button');
|
|
128
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
129
|
+
expect(onSubmit).not.toHaveBeenCalled();
|
|
130
|
+
return [2 /*return*/];
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}); });
|
|
134
|
+
it('submits the form when type is submit', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
135
|
+
var onSubmit;
|
|
136
|
+
return __generator(this, function (_a) {
|
|
137
|
+
switch (_a.label) {
|
|
138
|
+
case 0:
|
|
139
|
+
onSubmit = jest.fn(function (event) { return event.preventDefault(); });
|
|
140
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)("form", __assign({ onSubmit: onSubmit }, { children: (0, jsx_runtime_1.jsx)(Button_1.default, __assign({ size: "medium", variant: "primary", type: "submit" }, { children: "Save" })) })));
|
|
141
|
+
return [4 /*yield*/, user_event_1.default.click(react_1.screen.getByRole('button', { name: 'Save' }))];
|
|
142
|
+
case 1:
|
|
143
|
+
_a.sent();
|
|
144
|
+
expect(react_1.screen.getByRole('button', { name: 'Save' })).toHaveAttribute('type', 'submit');
|
|
145
|
+
expect(onSubmit).toHaveBeenCalledTimes(1);
|
|
146
|
+
return [2 /*return*/];
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}); });
|
|
150
|
+
it('writes type reset onto the DOM', function () {
|
|
151
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(Button_1.default, __assign({ size: "medium", variant: "primary", type: "reset" }, { children: "Reset" })));
|
|
152
|
+
expect(react_1.screen.getByRole('button', { name: 'Reset' })).toHaveAttribute('type', 'reset');
|
|
153
|
+
});
|
|
154
|
+
it('paints primary label white', function () {
|
|
117
155
|
renderButton({ variant: 'primary' });
|
|
118
|
-
expect(declaredColors(react_1.screen.getByRole('button', { name: 'Click' }))).toContain('
|
|
156
|
+
expect(declaredColors(react_1.screen.getByRole('button', { name: 'Click' }))).toContain('white');
|
|
119
157
|
});
|
|
120
158
|
it('keeps success label on hardcoded white', function () {
|
|
121
159
|
renderButton({ variant: 'success' });
|