UNPKG

wix-style-react

Version:
164 lines (136 loc) • 5.81 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 { createStoryUrl, waitForVisibilityOf, protractorUniTestkitFactoryCreator } from 'wix-ui-test-utils/protractor'; import autoExampleDriver from 'wix-storybook-utils/AutoExampleDriver'; import { eyesItInstance } from '../../test/utils/eyes-it'; import { proportionPrivateDriverFactory } from './Proportion.driver.private'; import { storySettings } from '../../stories/Proportion/storySettings'; import { PREDEFINED_RATIOS } from './ratios'; var eyes = eyesItInstance({ enableSnapshotAtBrowserGet: false }); describe('Proportion', function () { var storyUrl = createStoryUrl({ kind: storySettings.category, story: storySettings.storyName }); var createDriver = function () { var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { var dataHook = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : storySettings.dataHook; var driver; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: driver = protractorUniTestkitFactoryCreator(proportionPrivateDriverFactory)({ dataHook: dataHook }); _context.t0 = waitForVisibilityOf; _context.next = 4; return driver.element(); case 4: _context.t1 = _context.sent; _context.t2 = 'Cannot find <Proportion/> component with dataHook of ' + dataHook; _context.next = 8; return (0, _context.t0)(_context.t1, _context.t2); case 8: return _context.abrupt('return', driver); case 9: case 'end': return _context.stop(); } } }, _callee, _this); })); return function createDriver() { return _ref.apply(this, arguments); }; }(); 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 autoExampleDriver.reset(); case 2: case 'end': return _context2.stop(); } } }, _callee2, _this); }))); beforeAll(_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 browser.get(storyUrl); case 2: case 'end': return _context3.stop(); } } }, _callee3, _this); }))); describe('predefined ratios', function () { var _loop = function _loop(predefinedRatio) { if (PREDEFINED_RATIOS.hasOwnProperty(predefinedRatio)) { eyes.it('should maintain proportion with predefined ' + predefinedRatio, _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() { var expectedRatio, driver, aspectRatioResult; return regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: expectedRatio = PREDEFINED_RATIOS[predefinedRatio]; _context4.next = 3; return autoExampleDriver.setProps({ aspectRatio: expectedRatio }); case 3: _context4.next = 5; return createDriver(); case 5: driver = _context4.sent; _context4.next = 8; return driver.getAspectRatio(); case 8: aspectRatioResult = _context4.sent; expect(aspectRatioResult.toFixed(2)).toBe(expectedRatio.toFixed(2)); case 10: case 'end': return _context4.stop(); } } }, _callee4, _this); }))); } }; for (var predefinedRatio in PREDEFINED_RATIOS) { _loop(predefinedRatio); } }); describe('custom ratio', function () { eyes.it('should maintain proportion with custom ratio', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() { var expectedRatio, driver, aspectRatioResult; return regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: expectedRatio = 9.5 / 3; _context5.next = 3; return autoExampleDriver.setProps({ aspectRatio: expectedRatio }); case 3: _context5.next = 5; return createDriver(); case 5: driver = _context5.sent; _context5.next = 8; return driver.getAspectRatio(); case 8: aspectRatioResult = _context5.sent; expect(aspectRatioResult.toFixed(2)).toBe(expectedRatio.toFixed(2)); case 10: case 'end': return _context5.stop(); } } }, _callee5, _this); }))); }); });