UNPKG

react95-native

Version:

Refreshed Windows 95 style UI components for your React Native app

132 lines (127 loc) 4.75 kB
"use strict"; var _react = _interopRequireDefault(require("react")); var _reactNative = require("@testing-library/react-native"); var _ = require("../.."); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } describe('<NumberInput />', () => { it('should call onChange on increment press', () => { const handleChange = jest.fn(); const { getByTestId } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_.NumberInput, { onChange: handleChange, defaultValue: 2 })); const spinButton = getByTestId('increment'); (0, _reactNative.fireEvent)(spinButton, 'press'); expect(handleChange).toHaveBeenCalledTimes(1); expect(handleChange).toHaveBeenCalledWith(3); }); it('should call onChange on decrement press', () => { const handleChange = jest.fn(); const { getByTestId } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_.NumberInput, { onChange: handleChange, defaultValue: 2 })); const spinButton = getByTestId('decrement'); (0, _reactNative.fireEvent)(spinButton, 'press'); expect(handleChange).toHaveBeenCalledTimes(1); expect(handleChange).toHaveBeenCalledWith(1); }); it('should reach max value', () => { const { getByTestId } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_.NumberInput, { defaultValue: 90, min: 0, max: 100, step: 10 })); const input = getByTestId('input'); const incrementButton = getByTestId('increment'); (0, _reactNative.fireEvent)(incrementButton, 'press'); expect(input.props.value).toBe('100'); }); it('should reach min value', () => { const { getByTestId } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_.NumberInput, { defaultValue: 10, min: 0, max: 100, step: 10 })); const input = getByTestId('input'); const decrementButton = getByTestId('decrement'); (0, _reactNative.fireEvent)(decrementButton, 'press'); expect(input.props.value).toBe('0'); }); describe('prop: step', () => { it('should be 1 by default', () => { const { getByTestId } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_.NumberInput, { defaultValue: 0 })); const input = getByTestId('input'); const incrementButton = getByTestId('increment'); (0, _reactNative.fireEvent)(incrementButton, 'press'); expect(input.props.value).toBe('1'); }); it('should change value by specified step', () => { const { getByTestId } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_.NumberInput, { defaultValue: 10, step: 3 })); const input = getByTestId('input'); const decrementButton = getByTestId('decrement'); (0, _reactNative.fireEvent)(decrementButton, 'press'); expect(input.props.value).toBe('7'); }); it('should handle decimal step', () => { const { getByTestId } = (0, _reactNative.render)( /*#__PURE__*/_react.default.createElement(_.NumberInput, { defaultValue: 10, step: 0.3 })); const input = getByTestId('input'); const decrementButton = getByTestId('decrement'); (0, _reactNative.fireEvent)(decrementButton, 'press'); expect(input.props.value).toBe('9.7'); }); }); describe('prop: disabled', () => {// it('should render disabled', () => { // const { getByTestId } = render( // <NumberInput defaultValue={10} disabled />, // ); // const input = getByTestId('input'); // const incrementButton = getByTestId('increment'); // const decrementButton = getByTestId('decrement'); // expect(input.props.editable).toBe(false); // expect(incrementButton.props.disabled).toBe(true); // expect(decrementButton.props.disabled).toBe(true); // }); // it('should not react to button clicks', () => { // const { getByTestId } = render( // <NumberInput defaultValue={10} disabled />, // ); // const input = getByTestId('input'); // const incrementButton = getByTestId('increment'); // const decrementButton = getByTestId('decrement'); // fireEvent(incrementButton, 'press'); // expect(input.props.value).toBe('10'); // fireEvent(decrementButton, 'press'); // expect(input.props.value).toBe('10'); // }); }); describe('prop: width', () => { it('should render component of specified width', () => {}); it('should handle %', () => {}); }); }); //# sourceMappingURL=NumberInput.spec.js.map