UNPKG

wix-style-react

Version:
347 lines (289 loc) • 11.9 kB
'use strict'; var _eyesIt = require('../../test/utils/eyes-it'); var _protractor = require('../../testkit/protractor'); var _protractor2 = require('wix-ui-test-utils/protractor'); var _storybookHelpers = require('../../test/utils/storybook-helpers'); var _AutoExampleDriver = require('wix-storybook-utils/AutoExampleDriver'); var _AutoExampleDriver2 = _interopRequireDefault(_AutoExampleDriver); var _FocusableTestsE2E = require('../common/Focusable/FocusableTestsE2E'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } var NO_DESCRIPTION = ''; describe('Checkbox', function () { var storyUrl = (0, _storybookHelpers.getStoryUrl)('4. Selection', '4.2 Checkbox'); var checkboxDriver = (0, _protractor.checkboxTestkitFactory)({ dataHook: 'storybook-checkbox' }); var eyes = (0, _eyesIt.eyesItInstance)(); describe(NO_DESCRIPTION, function () { var waitForCheckbox = function waitForCheckbox() { return (0, _protractor2.waitForVisibilityOf)(checkboxDriver.element(), 'Cannot find Checkbox'); }; var clickTab = function clickTab() { return browser.actions().sendKeys(protractor.Key.TAB).perform(); }; beforeEach(_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return browser.get(storyUrl); case 2: _context.next = 4; return waitForCheckbox(); case 4: case 'end': return _context.stop(); } } }, _callee, undefined); }))); eyes.it('should have default props', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() { return regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.t0 = expect; _context2.next = 3; return checkboxDriver.hasError(); case 3: _context2.t1 = _context2.sent; (0, _context2.t0)(_context2.t1).toBe(false, 'hasError'); _context2.t2 = expect; _context2.next = 8; return checkboxDriver.isChecked(); case 8: _context2.t3 = _context2.sent; (0, _context2.t2)(_context2.t3).toBe(false, 'isChecked'); _context2.t4 = expect; _context2.next = 13; return checkboxDriver.isFocused(); case 13: _context2.t5 = _context2.sent; (0, _context2.t4)(_context2.t5).toBe(false, 'isFocused'); _context2.t6 = expect; _context2.next = 18; return checkboxDriver.isDisabled(); case 18: _context2.t7 = _context2.sent; (0, _context2.t6)(_context2.t7).toBe(false, 'isDisabled'); case 20: case 'end': return _context2.stop(); } } }, _callee2, undefined); }))); eyes.it('should set checked state when clicked', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { return regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.t0 = expect; _context3.next = 3; return checkboxDriver.isChecked(); case 3: _context3.t1 = _context3.sent; (0, _context3.t0)(_context3.t1).toBe(false); _context3.next = 7; return checkboxDriver.click(); case 7: _context3.t2 = expect; _context3.next = 10; return checkboxDriver.isChecked(); case 10: _context3.t3 = _context3.sent; (0, _context3.t2)(_context3.t3).toBe(true); case 12: case 'end': return _context3.stop(); } } }, _callee3, undefined); }))); eyes.it('should show focused styles', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() { return regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _context4.t0 = expect; _context4.next = 3; return checkboxDriver.isFocused(); case 3: _context4.t1 = _context4.sent; (0, _context4.t0)(_context4.t1).toBe(false); _context4.next = 7; return clickTab(); case 7: _context4.t2 = expect; _context4.next = 10; return checkboxDriver.isFocused(); case 10: _context4.t3 = _context4.sent; (0, _context4.t2)(_context4.t3).toBe(true); case 12: case 'end': return _context4.stop(); } } }, _callee4, undefined); }))); describe('has error', function () { beforeEach(_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() { return regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _context5.next = 2; return _AutoExampleDriver2.default.setProps({ hasError: true }); case 2: case 'end': return _context5.stop(); } } }, _callee5, undefined); }))); eyes.it('should show error styles', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() { return regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: _context6.t0 = expect; _context6.next = 3; return checkboxDriver.hasError(); case 3: _context6.t1 = _context6.sent; (0, _context6.t0)(_context6.t1).toBe(true); case 5: case 'end': return _context6.stop(); } } }, _callee6, undefined); }))); eyes.it('should show focused styles', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() { return regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: _context7.t0 = expect; _context7.next = 3; return checkboxDriver.hasError(); case 3: _context7.t1 = _context7.sent; (0, _context7.t0)(_context7.t1).toBe(true); _context7.t2 = expect; _context7.next = 8; return checkboxDriver.isFocused(); case 8: _context7.t3 = _context7.sent; (0, _context7.t2)(_context7.t3).toBe(false); _context7.next = 12; return clickTab(); case 12: _context7.t4 = expect; _context7.next = 15; return checkboxDriver.isFocused(); case 15: _context7.t5 = _context7.sent; (0, _context7.t4)(_context7.t5).toBe(true); case 17: case 'end': return _context7.stop(); } } }, _callee7, undefined); }))); }); describe('is disabled', function () { beforeEach(_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() { return regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: _context8.next = 2; return _AutoExampleDriver2.default.setProps({ disabled: true }); case 2: case 'end': return _context8.stop(); } } }, _callee8, undefined); }))); eyes.it('should be disabled', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() { return regeneratorRuntime.wrap(function _callee9$(_context9) { while (1) { switch (_context9.prev = _context9.next) { case 0: _context9.t0 = expect; _context9.next = 3; return checkboxDriver.isDisabled(); case 3: _context9.t1 = _context9.sent; (0, _context9.t0)(_context9.t1).toBe(true); case 5: case 'end': return _context9.stop(); } } }, _callee9, undefined); }))); eyes.it('should not be focusable', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() { return regeneratorRuntime.wrap(function _callee10$(_context10) { while (1) { switch (_context10.prev = _context10.next) { case 0: _context10.t0 = expect; _context10.next = 3; return checkboxDriver.isDisabled(); case 3: _context10.t1 = _context10.sent; (0, _context10.t0)(_context10.t1).toBe(true); _context10.t2 = expect; _context10.next = 8; return checkboxDriver.isFocused(); case 8: _context10.t3 = _context10.sent; (0, _context10.t2)(_context10.t3).toBe(false); _context10.next = 12; return clickTab(); case 12: _context10.t4 = expect; _context10.next = 15; return checkboxDriver.isFocused(); case 15: _context10.t5 = _context10.sent; (0, _context10.t4)(_context10.t5).toBe(false); case 17: case 'end': return _context10.stop(); } } }, _callee10, undefined); }))); }); describe('within FormField', function () { eyes.it('should be rendered', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11() { var checkboxFormFieldDriver; return regeneratorRuntime.wrap(function _callee11$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: checkboxFormFieldDriver = (0, _protractor.checkboxTestkitFactory)({ dataHook: 'storybook-checkbox-formfield' }); expect(checkboxFormFieldDriver.element().isDisplayed()).toBeTruthy(); case 2: case 'end': return _context11.stop(); } } }, _callee11, undefined); }))); }); }); describe('Generic', function () { (0, _FocusableTestsE2E.runFocusTests)(checkboxDriver, storyUrl); }); });