UNPKG

wix-style-react

Version:
415 lines (333 loc) • 13.2 kB
var _this = this; 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"); }); }; } import { inputAreaTestkitFactory } from '../../testkit/protractor'; import { eyesItInstance } from '../../test/utils/eyes-it'; import { waitForVisibilityOf } from 'wix-ui-test-utils/protractor'; import { createStoryUrl } from '../../test/utils/storybook-helpers'; import autoExampleDriver from 'wix-storybook-utils/AutoExampleDriver'; import { storySettings } from '../../stories/InputArea/storySettings'; import InputArea from './InputArea'; var LONG_INPUT = 'all work and no play makes jack a dull boy\n'; describe('input area page', function () { var eyes = eyesItInstance({ enableSnapshotAtBrowserGet: false }); var storyUrl = createStoryUrl({ kind: storySettings.category, story: storySettings.storyName, withExamples: false }); var inputAreaTestkit = inputAreaTestkitFactory({ dataHook: 'storybook-inputarea' }); 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 waitForVisibilityOf(inputAreaTestkit.element()); case 4: _context.next = 6; return autoExampleDriver.reset(); case 6: case 'end': return _context.stop(); } } }, _callee, _this); }))); eyes.it('should render 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 inputAreaTestkit.isFocused(); case 3: _context2.t1 = _context2.sent; (0, _context2.t0)(_context2.t1).toBe(false, 'isFocused'); case 5: case 'end': return _context2.stop(); } } }, _callee2, _this); }))); eyes.it('should show focus styles', _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 inputAreaTestkit.isFocused(); case 3: _context3.t1 = _context3.sent; (0, _context3.t0)(_context3.t1).toBeFalsy(); _context3.next = 7; return browser.actions().sendKeys(protractor.Key.TAB).perform(); case 7: _context3.t2 = expect; _context3.next = 10; return inputAreaTestkit.isFocused(); case 10: _context3.t3 = _context3.sent; (0, _context3.t2)(_context3.t3).toBeTruthy(); case 12: case 'end': return _context3.stop(); } } }, _callee3, _this); }))); eyes.it('should show hover 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 inputAreaTestkit.isHovered(); case 3: _context4.t1 = _context4.sent; (0, _context4.t0)(_context4.t1).toBeFalsy(); _context4.next = 7; return inputAreaTestkit.hover(); case 7: _context4.t2 = expect; _context4.next = 10; return inputAreaTestkit.isHovered(); case 10: _context4.t3 = _context4.sent; (0, _context4.t2)(_context4.t3).toBeTruthy(); case 12: case 'end': return _context4.stop(); } } }, _callee4, _this); }))); eyes.it('should show hover and focus styles', _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 inputAreaTestkit.isHovered(); case 3: _context5.t1 = _context5.sent; (0, _context5.t0)(_context5.t1).toBeFalsy(); _context5.t2 = expect; _context5.next = 8; return inputAreaTestkit.isFocused(); case 8: _context5.t3 = _context5.sent; (0, _context5.t2)(_context5.t3).toBeFalsy(); _context5.next = 12; return inputAreaTestkit.click(); case 12: _context5.t4 = expect; _context5.next = 15; return inputAreaTestkit.isFocused(); case 15: _context5.t5 = _context5.sent; (0, _context5.t4)(_context5.t5).toBeTruthy(); _context5.t6 = expect; _context5.next = 20; return inputAreaTestkit.isHovered(); case 20: _context5.t7 = _context5.sent; (0, _context5.t6)(_context5.t7).toBeTruthy(); case 22: case 'end': return _context5.stop(); } } }, _callee5, _this); }))); eyes.it('should grow automatically with input', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() { var longValue, offsetHeight, scrollHeight; return regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: _context6.next = 2; return autoExampleDriver.setProps({ autoGrow: true }); case 2: longValue = LONG_INPUT.repeat(10); _context6.next = 5; return inputAreaTestkit.sendKeys(longValue); case 5: _context6.next = 7; return inputAreaTestkit.getOffsetHeight(); case 7: offsetHeight = _context6.sent; _context6.next = 10; return inputAreaTestkit.getScrollHeight(); case 10: scrollHeight = _context6.sent; expect(offsetHeight).toBe(scrollHeight); case 12: case 'end': return _context6.stop(); } } }, _callee6, _this); }))); eyes.it('should shrink automatically with input', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() { var longValue, previousOffsetHeight, currentOffsetHeight; return regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: _context7.next = 2; return autoExampleDriver.setProps({ autoGrow: true }); case 2: longValue = LONG_INPUT.repeat(10); _context7.next = 5; return inputAreaTestkit.sendKeys(longValue); case 5: _context7.next = 7; return inputAreaTestkit.getOffsetHeight(); case 7: previousOffsetHeight = _context7.sent; _context7.next = 10; return inputAreaTestkit.sendKeys(protractor.Key.BACK_SPACE.repeat(LONG_INPUT.length * 4)); case 10: _context7.next = 12; return inputAreaTestkit.getOffsetHeight(); case 12: currentOffsetHeight = _context7.sent; expect(currentOffsetHeight < previousOffsetHeight).toBeTruthy(); case 14: case 'end': return _context7.stop(); } } }, _callee7, _this); }))); eyes.it('should give precedence to rows prop', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() { var previousOffsetHeight, longValue, currentOffsetHeight; return regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: _context8.next = 2; return autoExampleDriver.setProps({ autoGrow: true, rows: 3 }); case 2: _context8.next = 4; return inputAreaTestkit.getOffsetHeight(); case 4: previousOffsetHeight = _context8.sent; longValue = LONG_INPUT.repeat(10); _context8.next = 8; return inputAreaTestkit.sendKeys(longValue); case 8: _context8.next = 10; return inputAreaTestkit.getOffsetHeight(); case 10: currentOffsetHeight = _context8.sent; expect(currentOffsetHeight).toBe(previousOffsetHeight); case 12: case 'end': return _context8.stop(); } } }, _callee8, _this); }))); eyes.it('should grow according to input when line-height is set to "normal"', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() { var longValue, offsetHeight, scrollHeight; return regeneratorRuntime.wrap(function _callee9$(_context9) { while (1) { switch (_context9.prev = _context9.next) { case 0: _context9.next = 2; return inputAreaTestkit.setLineHeight('normal'); case 2: _context9.next = 4; return autoExampleDriver.setProps({ autoGrow: true }); case 4: longValue = LONG_INPUT.repeat(10); _context9.next = 7; return inputAreaTestkit.sendKeys(longValue); case 7: _context9.next = 9; return inputAreaTestkit.getOffsetHeight(); case 9: offsetHeight = _context9.sent; _context9.next = 12; return inputAreaTestkit.getScrollHeight(); case 12: scrollHeight = _context9.sent; expect(offsetHeight).toBe(scrollHeight); case 14: case 'end': return _context9.stop(); } } }, _callee9, _this); }))); eyes.it('should begin with miminum ammount of rows', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() { var rowCount; return regeneratorRuntime.wrap(function _callee10$(_context10) { while (1) { switch (_context10.prev = _context10.next) { case 0: _context10.next = 2; return autoExampleDriver.setProps({ autoGrow: true }); case 2: _context10.next = 4; return inputAreaTestkit.getRowCount(); case 4: rowCount = _context10.sent; expect(rowCount).toBe(InputArea.MIN_ROWS); case 6: case 'end': return _context10.stop(); } } }, _callee10, _this); }))); eyes.it('it does not shrink below allowed minimum rows', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11() { var rowCount, numRowsToInsert, rowCountAfterInput, rowCountAfterDelete; return regeneratorRuntime.wrap(function _callee11$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: _context11.next = 2; return autoExampleDriver.setProps({ autoGrow: true }); case 2: _context11.next = 4; return inputAreaTestkit.getRowCount(); case 4: rowCount = _context11.sent; expect(rowCount).toBe(InputArea.MIN_ROWS); numRowsToInsert = 5; _context11.next = 9; return inputAreaTestkit.sendKeys('\n'.repeat(numRowsToInsert - 1)); case 9: _context11.next = 11; return inputAreaTestkit.getRowCount(); case 11: rowCountAfterInput = _context11.sent; expect(rowCountAfterInput).toBe(numRowsToInsert); _context11.next = 15; return inputAreaTestkit.sendKeys(protractor.Key.BACK_SPACE.repeat(numRowsToInsert)); case 15: _context11.next = 17; return inputAreaTestkit.getRowCount(); case 17: rowCountAfterDelete = _context11.sent; expect(rowCountAfterDelete).toBe(InputArea.MIN_ROWS); case 19: case 'end': return _context11.stop(); } } }, _callee11, _this); }))); });