UNPKG

wix-style-react

Version:
353 lines (290 loc) • 12 kB
'use strict'; var _AutoExampleDriver = require('wix-storybook-utils/AutoExampleDriver'); var _AutoExampleDriver2 = _interopRequireDefault(_AutoExampleDriver); var _eyesIt = require('../../test/utils/eyes-it'); var _protractor = require('wix-ui-test-utils/protractor'); var _storybookHelpers = require('../../test/utils/storybook-helpers'); var _protractor2 = require('../../testkit/protractor'); var _storySettings = require('../../stories/components/Dropdown/storySettings'); 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"); }); }; } describe('Dropdown', function () { var eyes = (0, _eyesIt.eyesItInstance)(); var autoExampleUrl = (0, _storybookHelpers.createStoryUrl)({ kind: _storySettings.storySettings.kind, story: _storySettings.storySettings.storyName, withExamples: false }); eyes.it('should display default (no options and not focused)', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { var dataHook, driver; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: dataHook = 'story-dropdown'; _context.next = 3; return browser.get(autoExampleUrl); case 3: driver = (0, _protractor2.dropdownTestkitFactory)({ dataHook: dataHook }); _context.next = 6; return (0, _protractor.waitForVisibilityOf)(driver.element(), 'Cannot find Dropdown'); case 6: _context.t0 = expect; _context.next = 9; return driver.isOptionsShown(); case 9: _context.t1 = _context.sent; (0, _context.t0)(_context.t1).toBeFalsy(); case 11: case 'end': return _context.stop(); } } }, _callee, undefined); }))); eyes.it('should display focused and with options shown', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() { var dataHook, driver; return regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: dataHook = 'story-dropdown'; _context2.next = 3; return browser.get(autoExampleUrl); case 3: driver = (0, _protractor2.dropdownTestkitFactory)({ dataHook: dataHook }); _context2.next = 6; return (0, _protractor.waitForVisibilityOf)(driver.element(), 'Cannot find Dropdown'); case 6: _context2.t0 = expect; _context2.next = 9; return driver.isOptionsShown(); case 9: _context2.t1 = _context2.sent; (0, _context2.t0)(_context2.t1).toBeFalsy(); _context2.next = 13; return driver.getInput().click(); case 13: _context2.t2 = expect; _context2.next = 16; return driver.isOptionsShown().isDisplayed(); case 16: _context2.t3 = _context2.sent; (0, _context2.t2)(_context2.t3).toBeTruthy(); case 18: case 'end': return _context2.stop(); } } }, _callee2, undefined); }))); eyes.it('should display options with divider', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { var dataHook, driver; return regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: dataHook = 'story-dropdown'; _context3.next = 3; return browser.get(autoExampleUrl); case 3: _context3.next = 5; return _AutoExampleDriver2.default.setProps({ options: [{ id: 1, value: 'op 1' }, { id: -99, value: '-' }, { id: 2, value: 'op 2' }] }); case 5: driver = (0, _protractor2.dropdownTestkitFactory)({ dataHook: dataHook }); _context3.next = 8; return (0, _protractor.waitForVisibilityOf)(driver.element(), 'Cannot find Dropdown'); case 8: _context3.t0 = expect; _context3.next = 11; return driver.isOptionsShown(); case 11: _context3.t1 = _context3.sent; (0, _context3.t0)(_context3.t1).toBeFalsy(); _context3.next = 15; return driver.getInput().click(); case 15: _context3.t2 = expect; _context3.next = 18; return driver.isOptionsShown().isDisplayed(); case 18: _context3.t3 = _context3.sent; (0, _context3.t2)(_context3.t3).toBeTruthy(); case 20: case 'end': return _context3.stop(); } } }, _callee3, undefined); }))); describe('scrolling behaviour', function () { var options = Array(30).fill().map(function (v, i) { return { id: i, value: 'Option ' + i }; }); var driver = void 0; var repeat = function repeat(times, fn) { return Array(times).fill().reduce(function (promise) { return promise.then(function () { return fn(); }); }, Promise.resolve()); }; var pressArrowDown = function pressArrowDown() { var times = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; return repeat(times, function () { return browser.actions().sendKeys(protractor.Key.ARROW_DOWN).perform(); }); }; var pressArrowUp = function pressArrowUp() { var times = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; return repeat(times, function () { return browser.actions().sendKeys(protractor.Key.ARROW_UP).perform(); }); }; var getScrollTop = function getScrollTop(element) { return browser.executeScript('return arguments[0].scrollTop', element); }; var getRectBottom = function getRectBottom(element) { return browser.executeScript('return arguments[0].getBoundingClientRect().bottom', element); }; var getRectTop = function getRectTop(element) { return browser.executeScript('return arguments[0].getBoundingClientRect().top', element); }; beforeAll(_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() { return regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return browser.get(autoExampleUrl); case 2: case 'end': return _context4.stop(); } } }, _callee4, undefined); }))); beforeEach(_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() { return regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: driver = (0, _protractor2.dropdownTestkitFactory)({ dataHook: 'story-dropdown' }); _context5.next = 3; return (0, _protractor.waitForVisibilityOf)(driver.element(), 'Cannot find Dropdown'); case 3: _context5.next = 5; return _AutoExampleDriver2.default.setProps({ options: options }); case 5: case 'end': return _context5.stop(); } } }, _callee5, undefined); }))); afterEach(_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() { return regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: _context6.next = 2; return _AutoExampleDriver2.default.remount(); case 2: case 'end': return _context6.stop(); } } }, _callee6, undefined); }))); /* * In our example, the Drodpown can hold about 6 full items in the view. */ eyes.it('should not change scroll when hovered option is in view', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() { return regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: _context7.next = 2; return driver.getInput().click(); case 2: _context7.next = 4; return pressArrowDown(3); case 4: _context7.t0 = expect; _context7.next = 7; return getScrollTop(driver.getDropdown()); case 7: _context7.t1 = _context7.sent; (0, _context7.t0)(_context7.t1).toEqual(0); case 9: case 'end': return _context7.stop(); } } }, _callee7, undefined); }))); eyes.it('should change scroll when hovered option is below the view', _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 driver.getInput().click(); case 2: _context8.next = 4; return pressArrowDown(8); case 4: _context8.t1 = expect; _context8.next = 7; return getRectBottom(driver.getDropdown()); case 7: _context8.t2 = _context8.sent; _context8.t0 = (0, _context8.t1)(_context8.t2); _context8.next = 11; return getRectBottom(driver.getDropdownItemElement(7)); case 11: _context8.t3 = _context8.sent; _context8.t0.toEqual.call(_context8.t0, _context8.t3); case 13: case 'end': return _context8.stop(); } } }, _callee8, undefined); }))); eyes.it('should change scroll when hovered option is above the view', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() { return regeneratorRuntime.wrap(function _callee9$(_context9) { while (1) { switch (_context9.prev = _context9.next) { case 0: _context9.next = 2; return driver.getInput().click(); case 2: _context9.next = 4; return pressArrowDown(16); case 4: _context9.next = 6; return pressArrowUp(8); case 6: _context9.t1 = expect; _context9.next = 9; return getRectTop(driver.getDropdown()); case 9: _context9.t2 = _context9.sent; _context9.t0 = (0, _context9.t1)(_context9.t2); _context9.next = 13; return getRectTop(driver.getDropdownItemElement(7)); case 13: _context9.t3 = _context9.sent; _context9.t0.toEqual.call(_context9.t0, _context9.t3); case 15: case 'end': return _context9.stop(); } } }, _callee9, undefined); }))); }); });