UNPKG

wix-style-react

Version:
237 lines (196 loc) • 8.76 kB
'use strict'; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _eyes = require('eyes.it'); var _eyes2 = _interopRequireDefault(_eyes); var _protractor = require('../../../testkit/protractor'); var _protractor2 = require('wix-ui-test-utils/protractor'); var _storybookHelpers = require('../../../test/utils/storybook-helpers'); var _StorySettings = require('../../../stories/FieldWithSelectionComposite/StorySettings'); var _StorySettings2 = _interopRequireDefault(_StorySettings); var _InputProtractor = require('../../Input/Input.protractor.driver'); var _InputProtractor2 = _interopRequireDefault(_InputProtractor); var _CheckboxProtractor = require('../../Checkbox/Checkbox.protractor.driver'); var _CheckboxProtractor2 = _interopRequireDefault(_CheckboxProtractor); var _DropdownProtractor = require('../../Dropdown/Dropdown.protractor.driver'); var _DropdownProtractor2 = _interopRequireDefault(_DropdownProtractor); 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 fieldWithSelectionCompositeTestkitE2EFactory = function fieldWithSelectionCompositeTestkitE2EFactory(driver) { var inputDriver = function inputDriver() { return (0, _InputProtractor2.default)(driver.getInput()); }; var checkboxDriver = function checkboxDriver() { return (0, _CheckboxProtractor2.default)(driver.element().$('[data-hook="' + _StorySettings2.default.dataHookCheckbox + '"]')); }; var dropdownDriver = function dropdownDriver() { return (0, _DropdownProtractor2.default)(driver.getSelection()); }; return _extends({}, driver, { checkboxType: { isFocusedFirst: function isFocusedFirst() { return inputDriver().isFocused(); }, isFocusedLast: function isFocusedLast() { return checkboxDriver().isFocused(); }, clickFirst: function clickFirst() { return inputDriver().click(); }, clickLast: function clickLast() { return checkboxDriver().click(); } }, dropdownType: { isFocusedFirst: function isFocusedFirst() { return inputDriver().isFocused(); }, isFocusedLast: function isFocusedLast() { return dropdownDriver().isFocused(); }, clickFirst: function clickFirst() { return inputDriver().click(); }, clickLast: function clickLast() { return dropdownDriver().click(); } } }); }; describe('FieldWithSelectionComposite', function () { var storyUrl = (0, _storybookHelpers.getStoryUrl)(_StorySettings2.default.kind, _StorySettings2.default.storyName); var driverCheckbox = fieldWithSelectionCompositeTestkitE2EFactory((0, _protractor.fieldWithSelectionCompositeTestkitFactory)({ dataHook: _StorySettings2.default.dataHookExampleCheckbox })); var driverDropdown = fieldWithSelectionCompositeTestkitE2EFactory((0, _protractor.fieldWithSelectionCompositeTestkitFactory)({ dataHook: _StorySettings2.default.dataHookExampleDropdown })); var pressTab = function pressTab() { return browser.actions().sendKeys(protractor.Key.TAB).perform(); }; beforeAll(_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 (0, _protractor2.waitForVisibilityOf)(driverCheckbox.element(), 'Cannot find FieldWithSelectionComposite - checkbox'); case 4: _context.next = 6; return (0, _protractor2.waitForVisibilityOf)(driverDropdown.element(), 'Cannot find FieldWithSelectionComposite - dropdown'); case 6: case 'end': return _context.stop(); } } }, _callee, undefined); }))); describe('Checkbox type', function () { var driver = driverCheckbox.checkboxType; _eyes2.default.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: expect(driver.isFocusedFirst()).toBe(false, 'isFocused'); expect(driver.isFocusedLast()).toBe(false, 'isFocused'); case 2: case 'end': return _context2.stop(); } } }, _callee2, undefined); }))); _eyes2.default.it('should show focused styles for first item', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { return regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: expect(driver.isFocusedFirst()).toBe(false); _context3.next = 3; return driver.clickFirst(); case 3: expect(driver.isFocusedFirst()).toBe(true); case 4: case 'end': return _context3.stop(); } } }, _callee3, undefined); }))); _eyes2.default.it('should show focused styles for last item', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() { return regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: expect(driver.isFocusedLast()).toBe(false); _context4.next = 3; return pressTab(); case 3: expect(driver.isFocusedLast()).toBe(true); case 4: case 'end': return _context4.stop(); } } }, _callee4, undefined); }))); }); describe('Dropdown type', function () { var driver = driverDropdown.dropdownType; _eyes2.default.it('should have default props', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() { return regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: expect(driver.isFocusedFirst()).toBe(false, 'isFocusedFirst'); expect(driver.isFocusedLast()).toBe(false, 'isFocusedLast'); case 2: case 'end': return _context5.stop(); } } }, _callee5, undefined); }))); _eyes2.default.it('should show focused styles for first item', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() { return regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: expect(driver.isFocusedFirst()).toBe(false); _context6.next = 3; return driver.clickFirst(); case 3: expect(driver.isFocusedFirst()).toBe(true); case 4: case 'end': return _context6.stop(); } } }, _callee6, undefined); }))); _eyes2.default.it('should show focused styles for last item', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() { return regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: expect(driver.isFocusedLast()).toBe(false); _context7.next = 3; return driver.clickLast(); case 3: _context7.next = 5; return driver.clickLast(); case 5: // TODO: temporary :) expect(driver.isFocusedLast()).toBe(true); case 6: case 'end': return _context7.stop(); } } }, _callee7, undefined); }))); }); });