wix-style-react
Version:
wix-style-react
422 lines (382 loc) • 15.7 kB
JavaScript
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 React from 'react';
import { createUniDriverFactory } from 'wix-ui-test-utils/uni-driver-factory';
import Box, { spacingUnit } from './Box';
import { boxPrivateDriverFactory } from './Box.driver.private';
describe('Box', function () {
var createDriver = createUniDriverFactory(boxPrivateDriverFactory);
describe('API', function () {
it('should pass the inline style', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
var expectedOpacity, children, driver;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
expectedOpacity = '0.5';
children = React.createElement(
'span',
null,
'Children'
);
driver = createDriver(React.createElement(
Box,
{ style: { opacity: expectedOpacity } },
children
));
_context.t0 = expect;
_context.next = 6;
return driver.getStyle();
case 6:
_context.t1 = _context.sent;
_context.t2 = 'opacity: ' + expectedOpacity;
(0, _context.t0)(_context.t1).toContain(_context.t2);
case 9:
case 'end':
return _context.stop();
}
}
}, _callee, _this);
})));
it('should pass the class name', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
var expectedClassName, children, driver;
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
expectedClassName = 'some-selector';
children = React.createElement(
'span',
null,
'Children'
);
driver = createDriver(React.createElement(
Box,
{ className: expectedClassName },
children
));
_context2.t0 = expect;
_context2.next = 6;
return driver.hasClass(expectedClassName);
case 6:
_context2.t1 = _context2.sent;
(0, _context2.t0)(_context2.t1).toBeTruthy();
case 8:
case 'end':
return _context2.stop();
}
}
}, _callee2, _this);
})));
it('should render the passed children', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
var children, driver;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
children = React.createElement(
'span',
null,
'Children'
);
driver = createDriver(React.createElement(
Box,
{ dataHook: 'box-child' },
children
));
_context3.t0 = expect;
_context3.next = 5;
return driver.hasChild();
case 5:
_context3.t1 = _context3.sent;
(0, _context3.t0)(_context3.t1).toBeTruthy();
case 7:
case 'end':
return _context3.stop();
}
}
}, _callee3, _this);
})));
describe('Borders', function () {
it('should style the border', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
var expectedBorder, children, driver;
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
expectedBorder = '1px solid blue';
children = React.createElement(
'span',
null,
'Children'
);
driver = createDriver(React.createElement(
Box,
{ border: expectedBorder },
children
));
_context4.t0 = expect;
_context4.next = 6;
return driver.getStyle();
case 6:
_context4.t1 = _context4.sent;
_context4.t2 = 'border: ' + expectedBorder;
(0, _context4.t0)(_context4.t1).toContain(_context4.t2);
case 9:
case 'end':
return _context4.stop();
}
}
}, _callee4, _this);
})));
it('should pass the `borderColor` prop even if `border` is passed', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
var expectedBorder, children, driver;
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
expectedBorder = 'green';
children = React.createElement(
'span',
null,
'Children'
);
driver = createDriver(React.createElement(
Box,
{ border: '1px solid blue', borderColor: expectedBorder },
children
));
_context5.t0 = expect;
_context5.next = 6;
return driver.getStyle();
case 6:
_context5.t1 = _context5.sent;
_context5.t2 = 'border-color: ' + expectedBorder;
(0, _context5.t0)(_context5.t1).toContain(_context5.t2);
case 9:
case 'end':
return _context5.stop();
}
}
}, _callee5, _this);
})));
it('should style the borders specifically', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
var expectedBorderTopColor, expectedBorderRightColor, expectedBorderBottomColor, expectedBorderLeftColor, children, driver;
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
expectedBorderTopColor = '#2b81cb';
expectedBorderRightColor = '#D6453D';
expectedBorderBottomColor = '#8E21B1';
expectedBorderLeftColor = '#44823F';
children = React.createElement(
'span',
null,
'Children'
);
driver = createDriver(React.createElement(
Box,
{
borderTopColor: expectedBorderTopColor,
borderRightColor: expectedBorderRightColor,
borderBottomColor: expectedBorderBottomColor,
borderLeftColor: expectedBorderLeftColor
},
children
));
_context6.t0 = expect;
_context6.next = 9;
return driver.getStyle();
case 9:
_context6.t1 = _context6.sent;
_context6.t2 = 'border-top-color: ' + expectedBorderTopColor;
(0, _context6.t0)(_context6.t1).toContain(_context6.t2);
_context6.t3 = expect;
_context6.next = 15;
return driver.getStyle();
case 15:
_context6.t4 = _context6.sent;
_context6.t5 = 'border-right-color: ' + expectedBorderRightColor;
(0, _context6.t3)(_context6.t4).toContain(_context6.t5);
_context6.t6 = expect;
_context6.next = 21;
return driver.getStyle();
case 21:
_context6.t7 = _context6.sent;
_context6.t8 = 'border-bottom-color: ' + expectedBorderBottomColor;
(0, _context6.t6)(_context6.t7).toContain(_context6.t8);
_context6.t9 = expect;
_context6.next = 27;
return driver.getStyle();
case 27:
_context6.t10 = _context6.sent;
_context6.t11 = 'border-left-color: ' + expectedBorderLeftColor;
(0, _context6.t9)(_context6.t10).toContain(_context6.t11);
case 30:
case 'end':
return _context6.stop();
}
}
}, _callee6, _this);
})));
it('should pass the border color props even if `border` and `borderColor` are passed', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() {
var expectedBorderTopColor, expectedBorderRightColor, expectedBorderBottomColor, expectedBorderLeftColor, children, driver;
return regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
expectedBorderTopColor = '#2b81cb';
expectedBorderRightColor = '#D6453D';
expectedBorderBottomColor = '#8E21B1';
expectedBorderLeftColor = '#44823F';
children = React.createElement(
'span',
null,
'Children'
);
driver = createDriver(React.createElement(
Box,
{
border: '1px solid blue',
borderColor: 'green',
borderTopColor: expectedBorderTopColor,
borderRightColor: expectedBorderRightColor,
borderBottomColor: expectedBorderBottomColor,
borderLeftColor: expectedBorderLeftColor
},
children
));
_context7.t0 = expect;
_context7.next = 9;
return driver.getStyle();
case 9:
_context7.t1 = _context7.sent;
_context7.t2 = 'border-top-color: ' + expectedBorderTopColor;
(0, _context7.t0)(_context7.t1).toContain(_context7.t2);
_context7.t3 = expect;
_context7.next = 15;
return driver.getStyle();
case 15:
_context7.t4 = _context7.sent;
_context7.t5 = 'border-right-color: ' + expectedBorderRightColor;
(0, _context7.t3)(_context7.t4).toContain(_context7.t5);
_context7.t6 = expect;
_context7.next = 21;
return driver.getStyle();
case 21:
_context7.t7 = _context7.sent;
_context7.t8 = 'border-bottom-color: ' + expectedBorderBottomColor;
(0, _context7.t6)(_context7.t7).toContain(_context7.t8);
_context7.t9 = expect;
_context7.next = 27;
return driver.getStyle();
case 27:
_context7.t10 = _context7.sent;
_context7.t11 = 'border-left-color: ' + expectedBorderLeftColor;
(0, _context7.t9)(_context7.t10).toContain(_context7.t11);
case 30:
case 'end':
return _context7.stop();
}
}
}, _callee7, _this);
})));
});
});
describe('formatSpacingValue function', function () {
it('should render with padding when passing a numeric value', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
var expectedPadding, children, driver;
return regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
expectedPadding = spacingUnit + 'px';
children = React.createElement(
'span',
null,
'Children'
);
driver = createDriver(React.createElement(
Box,
{ padding: 1 },
children
));
_context8.t0 = expect;
_context8.next = 6;
return driver.getStyle();
case 6:
_context8.t1 = _context8.sent;
_context8.t2 = 'padding: ' + expectedPadding;
(0, _context8.t0)(_context8.t1).toContain(_context8.t2);
case 9:
case 'end':
return _context8.stop();
}
}
}, _callee8, _this);
})));
it('should render with padding when passing a predefined spacing value', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() {
var expectedPadding, children, driver;
return regeneratorRuntime.wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
expectedPadding = spacingUnit * 2 + 'px';
children = React.createElement(
'span',
null,
'Children'
);
driver = createDriver(React.createElement(
Box,
{ padding: 'small' },
children
));
_context9.t0 = expect;
_context9.next = 6;
return driver.getStyle();
case 6:
_context9.t1 = _context9.sent;
_context9.t2 = 'padding: ' + expectedPadding;
(0, _context9.t0)(_context9.t1).toContain(_context9.t2);
case 9:
case 'end':
return _context9.stop();
}
}
}, _callee9, _this);
})));
it('should render with padding when passing space-separated values', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() {
var expectedPadding, children, driver;
return regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
expectedPadding = spacingUnit * 3 + 'px ' + spacingUnit * 3 + 'px';
children = React.createElement(
'span',
null,
'Children'
);
driver = createDriver(React.createElement(
Box,
{ padding: expectedPadding },
children
));
_context10.t0 = expect;
_context10.next = 6;
return driver.getStyle();
case 6:
_context10.t1 = _context10.sent;
_context10.t2 = 'padding: ' + expectedPadding;
(0, _context10.t0)(_context10.t1).toContain(_context10.t2);
case 9:
case 'end':
return _context10.stop();
}
}
}, _callee10, _this);
})));
});
});