@enact/moonstone
Version:
Large-screen/TV support library for Enact, containing a variety of UI components.
100 lines (99 loc) • 3.99 kB
JavaScript
;
var _FloatingLayer = require("@enact/ui/FloatingLayer");
require("@testing-library/jest-dom");
var _react = require("@testing-library/react");
var _Popup = _interopRequireDefault(require("../Popup"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var FloatingLayerController = (0, _FloatingLayer.FloatingLayerDecorator)('div');
describe('Popup specs', function () {
test('should be rendered opened if open is set to true', function () {
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(FloatingLayerController, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Popup["default"], {
open: true,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
children: "popup"
})
})
}));
var popup = _react.screen.getByText('popup');
expect(popup).toBeInTheDocument();
});
test('should not be rendered if open is set to false', function () {
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(FloatingLayerController, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Popup["default"], {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
children: "popup"
})
})
}));
var popup = _react.screen.queryByText('popup');
expect(popup).toBeNull();
});
test('should set popup close button "aria-label" to closeButtonAriaLabel', function () {
var label = 'custom close button label';
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(FloatingLayerController, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Popup["default"], {
closeButtonAriaLabel: label,
open: true,
showCloseButton: true,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
children: "popup"
})
})
}));
var expected = label;
var actual = _react.screen.getByRole('button');
expect(actual).toHaveAttribute('aria-label', expected);
});
test('should set role to alert by default', function () {
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(FloatingLayerController, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Popup["default"], {
open: true,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
children: "popup"
})
})
}));
var popup = _react.screen.getByRole('alert');
expect(popup).toBeInTheDocument();
});
test('should allow role to be overridden', function () {
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(FloatingLayerController, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Popup["default"], {
open: true,
role: "dialog",
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
children: "popup"
})
})
}));
var popup = _react.screen.getByRole('dialog');
expect(popup).toBeInTheDocument();
});
test('should set "data-webos-voice-exclusive" when popup is open', function () {
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(FloatingLayerController, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Popup["default"], {
open: true,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
children: "popup"
})
})
}));
var popup = _react.screen.getByRole('alert');
expect(popup).toHaveAttribute('data-webos-voice-exclusive');
});
test('should set "data-webos-voice-disabled" when voice control is disabled', function () {
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(FloatingLayerController, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Popup["default"], {
"data-webos-voice-disabled": true,
open: true,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
children: "popup"
})
})
}));
var popup = _react.screen.getByRole('alert');
expect(popup).toHaveAttribute('data-webos-voice-disabled');
});
});