@enact/moonstone
Version:
Large-screen/TV support library for Enact, containing a variety of UI components.
46 lines (45 loc) • 2.61 kB
JavaScript
;
require("@testing-library/jest-dom");
var _react = require("@testing-library/react");
var _Checkbox = _interopRequireWildcard(require("../Checkbox"));
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
describe('Checkbox Specs', function () {
test('should not include the selected class when not selected', function () {
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Checkbox.CheckboxBase, {
"data-testid": "checkbox"
}));
var checkboxElement = _react.screen.getByTestId('checkbox');
var expected = 'selected';
expect(checkboxElement).not.toHaveClass(expected);
});
test('should add the selected class when given the selected prop', function () {
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Checkbox.CheckboxBase, {
"data-testid": "checkbox",
selected: true
}));
var checkboxElement = _react.screen.getByTestId('checkbox');
var expected = 'selected';
expect(checkboxElement).toHaveClass(expected);
});
test('should check the checkbox with one click', function () {
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Checkbox["default"], {
"data-testid": "checkbox"
}));
var checkboxItem = _react.screen.getByTestId('checkbox');
var expected = 'selected';
_react.fireEvent.click(checkboxItem);
expect(checkboxItem).toHaveClass(expected);
});
test('should uncheck the checkbox with two clicks', function () {
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Checkbox["default"], {
"data-testid": "checkbox"
}));
var actual = _react.screen.getByTestId('checkbox');
var expected = 'selected';
_react.fireEvent.click(actual);
_react.fireEvent.click(actual);
expect(actual).not.toHaveClass(expected);
});
});