UNPKG

wix-style-react

Version:
527 lines (432 loc) • 17.1 kB
'use strict'; var _eyes = require('eyes.it'); var _eyes2 = _interopRequireDefault(_eyes); var _protractor = require('../../testkit/protractor'); var _storybookHelpers = require('../../test/utils/storybook-helpers'); var _AutoExampleDriver = require('wix-storybook-utils/AutoExampleDriver'); var _AutoExampleDriver2 = _interopRequireDefault(_AutoExampleDriver); 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('DatePicker', function () { var storyUrl = (0, _storybookHelpers.getStoryUrl)('3. Inputs', '3.6 DatePicker'); var _datePickerTestkitFac = (0, _protractor.datePickerTestkitFactory)({ dataHook: 'storybook-datepicker' }), inputDriver = _datePickerTestkitFac.inputDriver, calendarDriver = _datePickerTestkitFac.calendarDriver; 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: case 'end': return _context.stop(); } } }, _callee, undefined); }))); beforeEach(_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() { return regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return _AutoExampleDriver2.default.reset(); case 2: case 'end': return _context2.stop(); } } }, _callee2, undefined); }))); _eyes2.default.it('should not open calendar when disabled', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { return regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return _AutoExampleDriver2.default.setProps({ disabled: true }); case 2: _context3.next = 4; return inputDriver.click(); case 4: _context3.t0 = expect; _context3.next = 7; return calendarDriver.exists(); case 7: _context3.t1 = _context3.sent; (0, _context3.t0)(_context3.t1).toBe(false); case 9: case 'end': return _context3.stop(); } } }, _callee3, undefined); }))); _eyes2.default.it('should not close calendar on selecting date with click when shouldCloseOnSelect prop set to false', _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 _AutoExampleDriver2.default.setProps({ shouldCloseOnSelect: false }); case 2: _context4.next = 4; return inputDriver.click(); case 4: _context4.next = 6; return calendarDriver.clickOnNthAvailableDay(10); case 6: _context4.t0 = expect; _context4.next = 9; return calendarDriver.exists(); case 9: _context4.t1 = _context4.sent; (0, _context4.t0)(_context4.t1).toBe(true); _context4.t2 = expect; _context4.next = 14; return calendarDriver.isVisible(); case 14: _context4.t3 = _context4.sent; (0, _context4.t2)(_context4.t3).toBe(true); case 16: case 'end': return _context4.stop(); } } }, _callee4, undefined); }))); describe('default', function () { _eyes2.default.it('should show inputDriver', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() { return regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: _context5.t0 = expect; _context5.next = 3; return inputDriver.isVisible(); case 3: _context5.t1 = _context5.sent; (0, _context5.t0)(_context5.t1).toBe(true); case 5: case 'end': return _context5.stop(); } } }, _callee5, undefined); }))); _eyes2.default.it('should open calendar when click on inputDriver', _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 inputDriver.click(); case 2: _context6.t0 = expect; _context6.next = 5; return calendarDriver.exists(); case 5: _context6.t1 = _context6.sent; (0, _context6.t0)(_context6.t1).toBe(true); _context6.t2 = expect; _context6.next = 10; return calendarDriver.isVisible(); case 10: _context6.t3 = _context6.sent; (0, _context6.t2)(_context6.t3).toBe(true); case 12: case 'end': return _context6.stop(); } } }, _callee6, undefined); })), { version: '<Input/> - On text click - select all' }); _eyes2.default.it('should close calendar on selecting date with click', _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 inputDriver.click(); case 2: _context7.next = 4; return calendarDriver.clickOnNthAvailableDay(1); case 4: _context7.t0 = expect; _context7.next = 7; return calendarDriver.exists(); case 7: _context7.t1 = _context7.sent; (0, _context7.t0)(_context7.t1).toBe(false); case 9: case 'end': return _context7.stop(); } } }, _callee7, undefined); }))); _eyes2.default.it('should close calendar on Escape key', _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 inputDriver.click(); case 2: _context8.t0 = expect; _context8.next = 5; return calendarDriver.exists(); case 5: _context8.t1 = _context8.sent; (0, _context8.t0)(_context8.t1).toBe(true); _context8.next = 9; return calendarDriver.pressEscKey(); case 9: _context8.t2 = expect; _context8.next = 12; return calendarDriver.exists(); case 12: _context8.t3 = _context8.sent; (0, _context8.t2)(_context8.t3).toBe(false); case 14: case 'end': return _context8.stop(); } } }, _callee8, undefined); })), { version: '<Input/> - On text click - select all' }); _eyes2.default.it('should close calendar on Tab key', _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 inputDriver.click(); case 2: _context9.t0 = expect; _context9.next = 5; return calendarDriver.exists(); case 5: _context9.t1 = _context9.sent; (0, _context9.t0)(_context9.t1).toBe(true); _context9.next = 9; return calendarDriver.pressTabKey(); case 9: _context9.t2 = expect; _context9.next = 12; return calendarDriver.exists(); case 12: _context9.t3 = _context9.sent; (0, _context9.t2)(_context9.t3).toBe(false); case 14: case 'end': return _context9.stop(); } } }, _callee9, undefined); }))); _eyes2.default.it('should not change date', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() { return regeneratorRuntime.wrap(function _callee10$(_context10) { while (1) { switch (_context10.prev = _context10.next) { case 0: _context10.next = 2; return _AutoExampleDriver2.default.setProps({ value: new Date('2017/05/01') }); case 2: _context10.next = 4; return inputDriver.click(); case 4: _context10.next = 6; return calendarDriver.pressEnterKey(); case 6: _context10.t0 = expect; _context10.next = 9; return inputDriver.getValue(); case 9: _context10.t1 = _context10.sent; (0, _context10.t0)(_context10.t1).toBe('2017/05/01'); case 11: case 'end': return _context10.stop(); } } }, _callee10, undefined); })), { version: '<Input/> - On text click - select all' }); _eyes2.default.it('should select next day date', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11() { return regeneratorRuntime.wrap(function _callee11$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: _context11.next = 2; return _AutoExampleDriver2.default.setProps({ value: new Date('2017/05/01') }); case 2: _context11.next = 4; return inputDriver.click(); case 4: _context11.next = 6; return calendarDriver.pressArrowRightKey(); case 6: _context11.next = 8; return calendarDriver.pressEnterKey(); case 8: _context11.t0 = expect; _context11.next = 11; return inputDriver.getValue(); case 11: _context11.t1 = _context11.sent; (0, _context11.t0)(_context11.t1).toBe('2017/05/02'); case 13: case 'end': return _context11.stop(); } } }, _callee11, undefined); }))); }); describe('with year and month dropdown', function () { beforeEach(_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12() { return regeneratorRuntime.wrap(function _callee12$(_context12) { while (1) { switch (_context12.prev = _context12.next) { case 0: _context12.next = 2; return _AutoExampleDriver2.default.setProps({ showYearDropdown: true, showMonthDropdown: true, value: new Date('2017/05/01') }); case 2: return _context12.abrupt('return', _context12.sent); case 3: case 'end': return _context12.stop(); } } }, _callee12, undefined); }))); _eyes2.default.it('should be scrolled to current year', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13() { return regeneratorRuntime.wrap(function _callee13$(_context13) { while (1) { switch (_context13.prev = _context13.next) { case 0: _context13.next = 2; return inputDriver.click(); case 2: _context13.next = 4; return calendarDriver.openYearDropdownOptions(); case 4: _context13.t0 = expect; _context13.next = 7; return calendarDriver.isYearInViewPort('2017'); case 7: _context13.t1 = _context13.sent; (0, _context13.t0)(_context13.t1).toBeTruthy(); case 9: case 'end': return _context13.stop(); } } }, _callee13, undefined); }))); _eyes2.default.it('should select 2027 year', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14() { return regeneratorRuntime.wrap(function _callee14$(_context14) { while (1) { switch (_context14.prev = _context14.next) { case 0: _context14.next = 2; return inputDriver.click(); case 2: _context14.next = 4; return calendarDriver.openYearDropdownOptions(); case 4: _context14.next = 6; return calendarDriver.clickOnNthYear(); case 6: _context14.next = 8; return calendarDriver.clickOnNthAvailableDay(); case 8: _context14.t0 = expect; _context14.next = 11; return inputDriver.getValue(); case 11: _context14.t1 = _context14.sent; (0, _context14.t0)(_context14.t1).toBe('2027/05/01'); case 13: case 'end': return _context14.stop(); } } }, _callee14, undefined); }))); _eyes2.default.it('should select February', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee15() { return regeneratorRuntime.wrap(function _callee15$(_context15) { while (1) { switch (_context15.prev = _context15.next) { case 0: _context15.next = 2; return inputDriver.click(); case 2: _context15.next = 4; return calendarDriver.openMonthDropdownOptions(); case 4: _context15.next = 6; return calendarDriver.clickOnNthMonth(2); case 6: _context15.next = 8; return calendarDriver.clickOnNthAvailableDay(); case 8: _context15.t0 = expect; _context15.next = 11; return inputDriver.getValue(); case 11: _context15.t1 = _context15.sent; (0, _context15.t0)(_context15.t1).toBe('2017/02/01'); case 13: case 'end': return _context15.stop(); } } }, _callee15, undefined); }))); _eyes2.default.it('should select February and 2026 year', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee16() { return regeneratorRuntime.wrap(function _callee16$(_context16) { while (1) { switch (_context16.prev = _context16.next) { case 0: _context16.next = 2; return inputDriver.click(); case 2: _context16.next = 4; return calendarDriver.openYearDropdownOptions(); case 4: _context16.next = 6; return calendarDriver.clickOnNthYear(2); case 6: _context16.next = 8; return calendarDriver.openMonthDropdownOptions(); case 8: _context16.next = 10; return calendarDriver.clickOnNthMonth(2); case 10: _context16.next = 12; return calendarDriver.clickOnNthAvailableDay(); case 12: _context16.t0 = expect; _context16.next = 15; return inputDriver.getValue(); case 15: _context16.t1 = _context16.sent; (0, _context16.t0)(_context16.t1).toBe('2026/02/01'); case 17: case 'end': return _context16.stop(); } } }, _callee16, undefined); }))); }); });