wix-style-react
Version:
wix-style-react
218 lines (190 loc) • 8.07 kB
JavaScript
var _this = this;
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; };
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 eyes from 'eyes.it';
import { fieldWithSelectionCompositeTestkitFactory } from '../../../testkit/protractor';
import { waitForVisibilityOf } from 'wix-ui-test-utils/protractor';
import { getStoryUrl } from '../../../test/utils/storybook-helpers';
import settings from '../../../stories/FieldWithSelectionComposite/StorySettings';
import inputDriverFactory from '../../Input/Input.protractor.driver';
import checkboxDriverFactory from '../../Checkbox/Checkbox.protractor.driver';
import dropdownDriverFactory from '../../Dropdown/Dropdown.protractor.driver';
var fieldWithSelectionCompositeTestkitE2EFactory = function fieldWithSelectionCompositeTestkitE2EFactory(driver) {
var inputDriver = function inputDriver() {
return inputDriverFactory(driver.getInput());
};
var checkboxDriver = function checkboxDriver() {
return checkboxDriverFactory(driver.element().$('[data-hook="' + settings.dataHookCheckbox + '"]'));
};
var dropdownDriver = function dropdownDriver() {
return dropdownDriverFactory(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 = getStoryUrl(settings.kind, settings.storyName);
var driverCheckbox = fieldWithSelectionCompositeTestkitE2EFactory(fieldWithSelectionCompositeTestkitFactory({
dataHook: settings.dataHookExampleCheckbox
}));
var driverDropdown = fieldWithSelectionCompositeTestkitE2EFactory(fieldWithSelectionCompositeTestkitFactory({
dataHook: settings.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 waitForVisibilityOf(driverCheckbox.element(), 'Cannot find FieldWithSelectionComposite - checkbox');
case 4:
_context.next = 6;
return waitForVisibilityOf(driverDropdown.element(), 'Cannot find FieldWithSelectionComposite - dropdown');
case 6:
case 'end':
return _context.stop();
}
}
}, _callee, _this);
})));
describe('Checkbox type', function () {
var driver = driverCheckbox.checkboxType;
eyes.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, _this);
})));
eyes.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, _this);
})));
eyes.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, _this);
})));
});
describe('Dropdown type', function () {
var driver = driverDropdown.dropdownType;
eyes.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, _this);
})));
eyes.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, _this);
})));
eyes.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, _this);
})));
});
});