UNPKG

@roo-ui/components

Version:

99 lines (77 loc) 3.45 kB
'use strict'; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _themes = require('@roo-ui/themes'); var _testUtils = require('@roo-ui/test-utils'); var _jestAxe = require('jest-axe'); var _ = require('.'); 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('<Calendar />', function () { var wrapper = void 0; var childrenWrapper = void 0; var props = { date: new Date('2018-07-03'), minDate: new Date('2018-06-01'), maxDate: new Date('2018-08-20'), selected: new Date('2018-07-03'), onDateSelected: jest.fn(), monthsToDisplay: 1, stacked: true, weekdayNames: ['S', 'M', 'T', 'W', 'T', 'F', 'S'] }; beforeEach(function () { wrapper = (0, _testUtils.shallowWithTheme)(_react2.default.createElement(_.Calendar, props), _themes.qantas); childrenWrapper = wrapper.dive(); }); it('renders correctly', function () { expect(wrapper).toMatchSnapshot(); }); it('renders children correctly', function () { expect(childrenWrapper).toMatchSnapshot(); }); it('has no accessibility errors', _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.t0 = expect; _context.next = 3; return (0, _jestAxe.axe)(wrapper.html()); case 3: _context.t1 = _context.sent; (0, _context.t0)(_context.t1).toHaveNoViolations(); case 5: case 'end': return _context.stop(); } } }, _callee, undefined); }))); describe('props', function () { it('uses monthNames to pass each calendar month name to <CalendarMonth />', function () { expect(childrenWrapper.find('CalendarMonth').prop('month')).toEqual('Jul'); }); it('passes renders a <CalendarWeekday /> for each weekdayNames', function () { expect(childrenWrapper.find('CalendarWeekday')).toHaveLength(props.weekdayNames.length); }); it('passes monthsToDisplay to <CalendarMonth />', function () { expect(childrenWrapper.find('CalendarMonth').prop('monthsToDisplay')).toEqual(props.monthsToDisplay); }); it('passes stacked to <CalendarMonth />', function () { expect(childrenWrapper.find('CalendarMonth').prop('stacked')).toEqual(props.stacked); }); it('passes monthsToDisplay to <Dayzed />', function () { expect(wrapper.find('Dayzed').prop('monthsToDisplay')).toEqual(props.monthsToDisplay); }); it('assigns the rest of the props to <Dayzed />', function () { expect(wrapper.props()).toEqual(expect.objectContaining({ date: props.date, minDate: props.minDate, maxDate: props.maxDate, selected: props.selected, onDateSelected: props.onDateSelected })); }); }); });