UNPKG

@enact/sandstone

Version:

Large-screen/TV support library for Enact, containing a variety of UI components.

91 lines (90 loc) 3.98 kB
"use strict"; require("@testing-library/jest-dom"); var _react = require("@testing-library/react"); var _Picker = require("../Picker"); var _jsxRuntime = require("react/jsx-runtime"); describe('Picker Specs', function () { test('should render selected child wrapped with <PickerItem/>', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker.Picker, { value: 1, children: [1, 2, 3, 4] })); var pickerText = _react.screen.getByText('2').parentElement.parentElement; var expected = 'item'; expect(pickerText).toHaveClass(expected); }); test('should set the max of <Picker> to be one less than the number of children', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker.Picker, { value: 3, children: [1, 2, 3, 4] })); var arrowForward = _react.screen.getAllByRole('button')[0]; var expectedValue = 'true'; var expectedAttribute = 'aria-disabled'; expect(arrowForward).toHaveAttribute(expectedAttribute, expectedValue); }); test('should be disabled when empty', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker.PickerBase, { "data-testid": "picker", children: [] })); var picker = _react.screen.getByTestId('picker'); var expected = 'disabled'; expect(picker).toHaveAttribute(expected); }); test('should set \'data-webos-voice-disabled\' to decrement button when voice control is disabled', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker.PickerBase, { "data-webos-voice-disabled": true, children: [1, 2, 3, 4] })); var decrementButton = _react.screen.getAllByRole('button')[1]; var expected = 'data-webos-voice-disabled'; expect(decrementButton).toHaveAttribute(expected); }); test('should set \'data-webos-voice-disabled\' to increment button when voice control is disabled', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker.PickerBase, { "data-webos-voice-disabled": true, children: [1, 2, 3, 4] })); var incrementButton = _react.screen.getAllByRole('button')[0]; var expected = 'data-webos-voice-disabled'; expect(incrementButton).toHaveAttribute(expected); }); test('should have a heading element when \'title\'', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker.PickerBase, { title: "title text", children: [1, 2, 3, 4] })); var heading = _react.screen.getByText('title text'); var expected = 'heading'; var actual = heading.parentElement.parentElement; expect(heading).toBeInTheDocument(); expect(actual).toHaveClass(expected); }); test('should have a heading element with inline class when \'title\' and \'inlineTitle\'', function () { (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker.PickerBase, { inlineTitle: true, title: "title text", children: [1, 2, 3, 4] })); var heading = _react.screen.getByText('title text'); var expectedInline = 'inlineTitle'; var expectedHeader = 'heading'; var actual = heading.parentElement.parentElement; expect(heading).toBeInTheDocument(); expect(actual).toHaveClass(expectedInline); expect(actual).toHaveClass(expectedHeader); }); test('should stringify custom voice control labels and set to \'data-webos-voice-labels-ext\'', function () { var options = ['Option 1', 'The second one', 'This is the third option', '4']; (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_Picker.Picker, { "data-webos-voice-labels-ext": options, inlineTitle: true, title: "title text", children: [1, 2, 3, 4] })); var picker = _react.screen.getAllByRole('button')[0].parentElement; var expected = "[\"Option 1\",\"The second one\",\"This is the third option\",\"4\"]"; expect(picker).toHaveAttribute('data-webos-voice-labels-ext', expected); }); });