UNPKG

react-native-easy-calendar

Version:

Customizable, easy-to-use, performant calendar components for React Native

135 lines (120 loc) 3.86 kB
"use strict"; var _react = _interopRequireDefault(require("react")); var _reactNative = require("@testing-library/react-native"); var _Contexts = require("../Contexts"); var _Themes = require("../Themes"); var _Arrow = _interopRequireDefault(require("./Arrow")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } test('Arrow renders without error', () => { const arrow = new ArrowPage({ direction: 'left' }); expect(arrow.component).toBeTruthy(); }); test('Component calls onPress callback when clicked', () => { const onPress = jest.fn(); const month = new ArrowPage({ onPress }); _reactNative.fireEvent.press(month.component); expect(onPress).toHaveBeenCalledTimes(1); }); describe('Enabling and disabling', () => { test('Disable clicking if prop ´isDisabled´ is true', () => { const arrow = new ArrowPage({ isDisabled: true }); expect(arrow.component).toBeDisabled(); }); test('Enable clicking if prop ´isDisabled´ is false', () => { const arrow = new ArrowPage({ isDisabled: false }); expect(arrow.component).toBeEnabled(); }); }); describe('Theme context', () => { test('Container applies normal theme in enabled state', () => { const arrow = new ArrowPage({}); expect(arrow.component).toHaveStyle(theme.normalArrowContainer); expect(arrow.component).not.toHaveStyle(theme.disabledArrowContainer); }); test('Container applies isDisabled theme in isDisabled state', () => { const arrow = new ArrowPage({ isDisabled: true }); expect(arrow.component).toHaveStyle([theme.normalArrowContainer, theme.disabledArrowContainer]); }); test('Image applies normal theme in enabled state', () => { const arrow = new ArrowPage({}); expect(arrow.image).toHaveStyle(theme.normalArrowImage); expect(arrow.image).not.toHaveStyle(theme.disabledArrowImage); }); test('Image applies isDisabled theme in isDisabled state', () => { const arrow = new ArrowPage({ isDisabled: true }); expect(arrow.image).toHaveStyle([theme.normalArrowImage, theme.disabledArrowImage]); }); }); describe('Automatic image rotation', () => { const rotation = { transform: [{ rotate: '180deg' }] }; test('Rotate "right" arrow towards the right', () => { const arrow = new ArrowPage({ direction: 'right' }); expect(arrow.image).toHaveStyle(rotation); }); test('Do not rotate "left" arrows', () => { const arrow = new ArrowPage({ direction: 'left' }); expect(arrow.image).not.toHaveStyle(rotation); }); }); class ArrowPage { constructor({ direction = 'left', isDisabled = false, onPress = () => {} }) { _defineProperty(this, "component", void 0); _defineProperty(this, "image", void 0); const { getByLabelText, getByTestId } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_Contexts.ThemeContext.Provider, { value: theme }, /*#__PURE__*/_react.default.createElement(_Arrow.default, { direction, isDisabled, onPress }))); this.component = getByLabelText("".concat(direction, " arrow")); this.image = getByTestId('arrow-image'); } } const theme = { ..._Themes.DefaultTheme, normalArrowContainer: { marginTop: 10, backgroundColor: 'green' }, disabledArrowContainer: { marginBottom: 10, backgroundColor: 'gray' }, normalArrowImage: { marginTop: 10, tintColor: 'green' }, disabledArrowImage: { marginBottom: 10, tintColor: 'gray' } }; //# sourceMappingURL=Arrow.test.js.map