mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-06 11:53:18 +00:00
Simplify tests for several exported modules
This commit is contained in:
+28
-30
@@ -10,6 +10,9 @@ import View from '../../View';
|
|||||||
|
|
||||||
const RootComponent = () => <div />;
|
const RootComponent = () => <div />;
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({ root: { borderWidth: 1234, backgroundColor: 'purple' } });
|
||||||
|
const AlternativeComponent = () => <View style={styles.root} />;
|
||||||
|
|
||||||
describe('AppRegistry', () => {
|
describe('AppRegistry', () => {
|
||||||
describe('getApplication', () => {
|
describe('getApplication', () => {
|
||||||
const canUseDOM = ExecutionEnvironment.canUseDOM;
|
const canUseDOM = ExecutionEnvironment.canUseDOM;
|
||||||
@@ -29,56 +32,51 @@ describe('AppRegistry', () => {
|
|||||||
|
|
||||||
test('returns "element" and "getStyleElement"', () => {
|
test('returns "element" and "getStyleElement"', () => {
|
||||||
AppRegistry.registerComponent('App', () => RootComponent);
|
AppRegistry.registerComponent('App', () => RootComponent);
|
||||||
|
|
||||||
const { element, getStyleElement } = AppRegistry.getApplication('App', {});
|
const { element, getStyleElement } = AppRegistry.getApplication('App', {});
|
||||||
|
const styleElement = ReactDOMServer.renderToStaticMarkup(getStyleElement());
|
||||||
|
|
||||||
expect(element).toMatchSnapshot();
|
expect(element).toMatchSnapshot();
|
||||||
expect(ReactDOMServer.renderToStaticMarkup(getStyleElement())).toMatchSnapshot();
|
expect(styleElement).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('"getStyleElement" produces styles that are a function of rendering "element"', () => {
|
test('"getStyleElement" produces styles that are a function of rendering "element"', () => {
|
||||||
const getTextContent = getStyleElement =>
|
const getApplicationStyles = appName => {
|
||||||
getStyleElement().props.dangerouslySetInnerHTML.__html;
|
const { element, getStyleElement } = AppRegistry.getApplication(appName, {});
|
||||||
|
render(element);
|
||||||
// First "RootComponent" render
|
return getStyleElement().props.dangerouslySetInnerHTML.__html;
|
||||||
AppRegistry.registerComponent('App1', () => RootComponent);
|
};
|
||||||
let app = AppRegistry.getApplication('App1', {});
|
|
||||||
render(app.element);
|
|
||||||
const first = getTextContent(app.getStyleElement);
|
|
||||||
|
|
||||||
// Next render is a different tree; the style sheet should be different
|
|
||||||
const styles = StyleSheet.create({ root: { borderWidth: 1234, backgroundColor: 'purple' } });
|
|
||||||
const Component = () => <View style={styles.root} />;
|
|
||||||
AppRegistry.registerComponent('App2', () => Component);
|
|
||||||
app = AppRegistry.getApplication('App2', {});
|
|
||||||
render(app.element);
|
|
||||||
const second = getTextContent(app.getStyleElement);
|
|
||||||
|
|
||||||
const diff = second.split(first)[1];
|
|
||||||
|
|
||||||
|
// First render "RootComponent"
|
||||||
|
AppRegistry.registerComponent('App', () => RootComponent);
|
||||||
|
const first = getApplicationStyles('App');
|
||||||
expect(first).toMatchSnapshot('CSS for an unstyled app');
|
expect(first).toMatchSnapshot('CSS for an unstyled app');
|
||||||
expect(diff).toMatchSnapshot('Additional CSS for styled app');
|
|
||||||
|
// Second render "AlternativeComponent"
|
||||||
|
AppRegistry.registerComponent('AlternativeApp', () => AlternativeComponent);
|
||||||
|
const second = getApplicationStyles('AlternativeApp');
|
||||||
|
const diff = second.split(first)[1];
|
||||||
expect(first).not.toEqual(second);
|
expect(first).not.toEqual(second);
|
||||||
|
expect(diff).toMatchSnapshot('Additional CSS for styled app');
|
||||||
|
|
||||||
// Final render is once again "RootComponent"; the style sheet should not
|
// Third render "RootComponent" again
|
||||||
// be polluted by earlier rendering of a different tree
|
const third = getApplicationStyles('App');
|
||||||
app = AppRegistry.getApplication('App1', {});
|
|
||||||
render(app.element);
|
|
||||||
const third = getTextContent(app.getStyleElement);
|
|
||||||
|
|
||||||
expect(first).toEqual(third);
|
expect(first).toEqual(third);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('runApplication', () => {
|
describe('runApplication', () => {
|
||||||
test('callback after render', () => {
|
test('callback after render', () => {
|
||||||
AppRegistry.registerComponent('App', () => RootComponent);
|
// setup
|
||||||
|
|
||||||
const callback = jest.fn();
|
|
||||||
const rootTag = document.createElement('div');
|
const rootTag = document.createElement('div');
|
||||||
rootTag.id = 'react-root';
|
rootTag.id = 'react-root';
|
||||||
document.body.appendChild(rootTag);
|
document.body.appendChild(rootTag);
|
||||||
|
|
||||||
|
const callback = jest.fn();
|
||||||
|
AppRegistry.registerComponent('App', () => RootComponent);
|
||||||
AppRegistry.runApplication('App', { initialProps: {}, rootTag, callback });
|
AppRegistry.runApplication('App', { initialProps: {}, rootTag, callback });
|
||||||
expect(callback).toHaveBeenCalledTimes(1);
|
expect(callback).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
// cleanup
|
||||||
document.body.removeChild(rootTag);
|
document.body.removeChild(rootTag);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ describe('apis/AsyncStorage', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('multiSet', () => {
|
describe('multiSet', () => {
|
||||||
const assertResult = result => {
|
const assertResult = () => {
|
||||||
expect(mockLocalStorage.getItem('UID123')).toEqual(JSON.stringify(uid123Object));
|
expect(mockLocalStorage.getItem('UID123')).toEqual(JSON.stringify(uid123Object));
|
||||||
expect(mockLocalStorage.getItem('UID124')).toEqual(JSON.stringify(uid124Object));
|
expect(mockLocalStorage.getItem('UID124')).toEqual(JSON.stringify(uid124Object));
|
||||||
};
|
};
|
||||||
@@ -206,7 +206,7 @@ describe('apis/AsyncStorage', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('multiMerge', () => {
|
describe('multiMerge', () => {
|
||||||
const assertResult = result => {
|
const assertResult = () => {
|
||||||
expect(JSON.parse(mockLocalStorage.getItem('UID123'))).toMatchSnapshot();
|
expect(JSON.parse(mockLocalStorage.getItem('UID123'))).toMatchSnapshot();
|
||||||
expect(JSON.parse(mockLocalStorage.getItem('UID124'))).toMatchSnapshot();
|
expect(JSON.parse(mockLocalStorage.getItem('UID124'))).toMatchSnapshot();
|
||||||
};
|
};
|
||||||
@@ -253,7 +253,7 @@ describe('apis/AsyncStorage', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('multiRemove', () => {
|
describe('multiRemove', () => {
|
||||||
const assertResult = result => {
|
const assertResult = () => {
|
||||||
expect(mockLocalStorage.getItem('UID123')).toBeUndefined();
|
expect(mockLocalStorage.getItem('UID123')).toBeUndefined();
|
||||||
expect(mockLocalStorage.getItem('UID124')).toBeUndefined();
|
expect(mockLocalStorage.getItem('UID124')).toBeUndefined();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,31 +1,32 @@
|
|||||||
/* eslint-env jasmine, jest */
|
/* eslint-env jasmine, jest */
|
||||||
/* eslint-disable react/jsx-no-bind */
|
/* eslint-disable react/jsx-no-bind */
|
||||||
|
|
||||||
import React from 'react';
|
|
||||||
import Button from '..';
|
import Button from '..';
|
||||||
import { mount, shallow } from 'enzyme';
|
import React from 'react';
|
||||||
|
import StyleSheet from '../../StyleSheet';
|
||||||
const findNativeButton = wrapper => wrapper.getDOMNode();
|
import TouchableOpacity from '../../TouchableOpacity';
|
||||||
|
import { render, shallow } from 'enzyme';
|
||||||
|
|
||||||
describe('components/Button', () => {
|
describe('components/Button', () => {
|
||||||
test('prop "color"', () => {
|
test('prop "color"', () => {
|
||||||
const onPress = () => {};
|
const onPress = () => {};
|
||||||
const color = 'blue';
|
const color = 'blue';
|
||||||
const button = findNativeButton(mount(<Button color={color} onPress={onPress} title="" />));
|
const button = shallow(<Button color={color} onPress={onPress} title="" />);
|
||||||
expect(button.style.backgroundColor).toEqual(color);
|
const style = StyleSheet.flatten(button.prop('style'));
|
||||||
|
expect(style.backgroundColor).toEqual(color);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('prop "onPress"', () => {
|
test('prop "onPress"', () => {
|
||||||
const onPress = jest.fn();
|
const onPress = jest.fn();
|
||||||
const component = shallow(<Button onPress={onPress} title="" />);
|
const component = shallow(<Button onPress={onPress} title="" />);
|
||||||
component.simulate('press');
|
component.find(TouchableOpacity).simulate('press');
|
||||||
expect(onPress).toHaveBeenCalled();
|
expect(onPress).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('prop "title"', () => {
|
test('prop "title"', () => {
|
||||||
const onPress = () => {};
|
const onPress = () => {};
|
||||||
const text = 'Click me';
|
const text = 'Click me';
|
||||||
const component = mount(<Button onPress={onPress} title={text} />);
|
const component = render(<Button onPress={onPress} title={text} />);
|
||||||
expect(component.text()).toEqual(text);
|
expect(component.text()).toEqual(text);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ describe('apis/I18nManager', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('forceRTL', () => {
|
describe('forceRTL', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
I18nManager.forceRTL(false);
|
||||||
|
});
|
||||||
|
|
||||||
test('when set to false, "isRTL" is false', () => {
|
test('when set to false, "isRTL" is false', () => {
|
||||||
I18nManager.forceRTL(false);
|
I18nManager.forceRTL(false);
|
||||||
expect(I18nManager.isRTL).toBe(false);
|
expect(I18nManager.isRTL).toBe(false);
|
||||||
@@ -27,11 +31,14 @@ describe('apis/I18nManager', () => {
|
|||||||
I18nManager.forceRTL(true);
|
I18nManager.forceRTL(true);
|
||||||
expect(I18nManager.isRTL).toBe(true);
|
expect(I18nManager.isRTL).toBe(true);
|
||||||
expect(getDocumentDir()).toEqual('rtl');
|
expect(getDocumentDir()).toEqual('rtl');
|
||||||
I18nManager.forceRTL(false);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('swapLeftAndRightInRTL', () => {
|
describe('swapLeftAndRightInRTL', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
I18nManager.swapLeftAndRightInRTL(true);
|
||||||
|
});
|
||||||
|
|
||||||
test('when set to false, "doLeftAndRightSwapInRTL" is false', () => {
|
test('when set to false, "doLeftAndRightSwapInRTL" is false', () => {
|
||||||
I18nManager.swapLeftAndRightInRTL(false);
|
I18nManager.swapLeftAndRightInRTL(false);
|
||||||
expect(I18nManager.doLeftAndRightSwapInRTL).toBe(false);
|
expect(I18nManager.doLeftAndRightSwapInRTL).toBe(false);
|
||||||
@@ -60,11 +67,14 @@ describe('apis/I18nManager', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('allowRTL', () => {
|
describe('allowRTL', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
I18nManager.allowRTL(true);
|
||||||
|
});
|
||||||
|
|
||||||
test('when set to false, "isRTL" is false', () => {
|
test('when set to false, "isRTL" is false', () => {
|
||||||
I18nManager.allowRTL(false);
|
I18nManager.allowRTL(false);
|
||||||
expect(I18nManager.isRTL).toBe(false);
|
expect(I18nManager.isRTL).toBe(false);
|
||||||
expect(getDocumentDir()).toEqual('ltr');
|
expect(getDocumentDir()).toEqual('ltr');
|
||||||
I18nManager.allowRTL(true);
|
|
||||||
});
|
});
|
||||||
test('when set to true, "isRTL" is true', () => {
|
test('when set to true, "isRTL" is true', () => {
|
||||||
I18nManager.allowRTL(true);
|
I18nManager.allowRTL(true);
|
||||||
@@ -74,6 +84,10 @@ describe('apis/I18nManager', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('forceRTL', () => {
|
describe('forceRTL', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
I18nManager.forceRTL(false);
|
||||||
|
});
|
||||||
|
|
||||||
test('when set to false, "isRTL" is true', () => {
|
test('when set to false, "isRTL" is true', () => {
|
||||||
I18nManager.forceRTL(false);
|
I18nManager.forceRTL(false);
|
||||||
expect(I18nManager.isRTL).toBe(true);
|
expect(I18nManager.isRTL).toBe(true);
|
||||||
@@ -83,11 +97,14 @@ describe('apis/I18nManager', () => {
|
|||||||
I18nManager.forceRTL(true);
|
I18nManager.forceRTL(true);
|
||||||
expect(I18nManager.isRTL).toBe(true);
|
expect(I18nManager.isRTL).toBe(true);
|
||||||
expect(getDocumentDir()).toEqual('rtl');
|
expect(getDocumentDir()).toEqual('rtl');
|
||||||
I18nManager.forceRTL(false);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('swapLeftAndRightInRTL', () => {
|
describe('swapLeftAndRightInRTL', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
I18nManager.swapLeftAndRightInRTL(true);
|
||||||
|
});
|
||||||
|
|
||||||
test('when set to false, "doLeftAndRightSwapInRTL" is false', () => {
|
test('when set to false, "doLeftAndRightSwapInRTL" is false', () => {
|
||||||
I18nManager.swapLeftAndRightInRTL(false);
|
I18nManager.swapLeftAndRightInRTL(false);
|
||||||
expect(I18nManager.doLeftAndRightSwapInRTL).toBe(false);
|
expect(I18nManager.doLeftAndRightSwapInRTL).toBe(false);
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
/* eslint-env jasmine, jest */
|
|
||||||
|
|
||||||
describe('components/ListView', () => {
|
|
||||||
test('NO TEST COVERAGE');
|
|
||||||
});
|
|
||||||
@@ -33,7 +33,7 @@ describe('components/Picker', () => {
|
|||||||
</Picker>
|
</Picker>
|
||||||
);
|
);
|
||||||
const component = shallow(picker);
|
const component = shallow(picker);
|
||||||
expect(component.find('select').props().disabled).toBe(true);
|
expect(component.find('select').prop('disabled')).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
/* eslint-env jasmine, jest */
|
|
||||||
|
|
||||||
describe('apis/PixelRatio', () => {
|
|
||||||
test.skip('NO TEST COVERAGE', () => {});
|
|
||||||
});
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/* eslint-env jasmine, jest */
|
||||||
|
|
||||||
|
import Platform from '../';
|
||||||
|
|
||||||
|
describe('apis/Platform', () => {
|
||||||
|
describe('select', () => {
|
||||||
|
test('supports "default"', () => {
|
||||||
|
expect(Platform.select({ default: 'default' })).toEqual('default');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('chooses "web"', () => {
|
||||||
|
expect(
|
||||||
|
Platform.select({ android: 'android', ios: 'ios', web: 'web', default: 'default' })
|
||||||
|
).toEqual('web');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -17,34 +17,46 @@ const testIfDocumentIsFocused = (message, fn) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe('components/TextInput', () => {
|
describe('components/TextInput', () => {
|
||||||
test('prop "autoComplete"', () => {
|
describe('prop "autoComplete"', () => {
|
||||||
// on
|
test('value "on"', () => {
|
||||||
let input = findNativeInput(shallow(<TextInput />));
|
const input = findNativeInput(shallow(<TextInput />));
|
||||||
expect(input.prop('autoComplete')).toEqual('on');
|
expect(input.prop('autoComplete')).toEqual('on');
|
||||||
// off
|
});
|
||||||
input = findNativeInput(shallow(<TextInput autoComplete="off" />));
|
|
||||||
expect(input.prop('autoComplete')).toEqual('off');
|
test('value "off"', () => {
|
||||||
|
const input = findNativeInput(shallow(<TextInput autoComplete="off" />));
|
||||||
|
expect(input.prop('autoComplete')).toEqual('off');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('prop "autoFocus"', () => {
|
describe('prop "autoFocus"', () => {
|
||||||
// false
|
test('value "false"', () => {
|
||||||
let input = findNativeInput(mount(<TextInput />));
|
const input = findNativeInput(shallow(<TextInput />));
|
||||||
expect(input.prop('autoFocus')).toEqual(undefined);
|
expect(input.prop('autoFocus')).toEqual(undefined);
|
||||||
// true
|
});
|
||||||
input = findNativeInput(mount(<TextInput autoFocus />));
|
|
||||||
expect(input.prop('autoFocus')).toEqual(true);
|
test('value "true"', () => {
|
||||||
|
const input = findNativeInput(shallow(<TextInput autoFocus />));
|
||||||
|
expect(input.prop('autoFocus')).toEqual(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
testIfDocumentIsFocused('prop "clearTextOnFocus"', () => {
|
describe('prop "clearTextOnFocus"', () => {
|
||||||
const defaultValue = 'defaultValue';
|
const defaultValue = 'defaultValue';
|
||||||
// false
|
|
||||||
let input = findNativeInput(mount(<TextInput defaultValue={defaultValue} />));
|
testIfDocumentIsFocused('value "false"', () => {
|
||||||
input.simulate('focus');
|
const input = findNativeInput(shallow(<TextInput defaultValue={defaultValue} />));
|
||||||
expect(input.node.value).toEqual(defaultValue);
|
input.simulate('focus');
|
||||||
// true
|
expect(input.node.value).toEqual(defaultValue);
|
||||||
input = findNativeInput(mount(<TextInput clearTextOnFocus defaultValue={defaultValue} />));
|
});
|
||||||
input.simulate('focus');
|
|
||||||
expect(input.node.value).toEqual('');
|
testIfDocumentIsFocused('value "true"', () => {
|
||||||
|
const input = findNativeInput(
|
||||||
|
shallow(<TextInput clearTextOnFocus defaultValue={defaultValue} />)
|
||||||
|
);
|
||||||
|
input.simulate('focus');
|
||||||
|
expect(input.node.value).toEqual('');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('prop "defaultValue"', () => {
|
test('prop "defaultValue"', () => {
|
||||||
@@ -53,33 +65,45 @@ describe('components/TextInput', () => {
|
|||||||
expect(input.prop('defaultValue')).toEqual(defaultValue);
|
expect(input.prop('defaultValue')).toEqual(defaultValue);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('prop "editable"', () => {
|
describe('prop "editable"', () => {
|
||||||
// true
|
test('value "true"', () => {
|
||||||
let input = findNativeInput(shallow(<TextInput />));
|
const input = findNativeInput(shallow(<TextInput />));
|
||||||
expect(input.prop('readOnly')).toEqual(false);
|
expect(input.prop('readOnly')).toEqual(false);
|
||||||
// false
|
});
|
||||||
input = findNativeInput(shallow(<TextInput editable={false} />));
|
|
||||||
expect(input.prop('readOnly')).toEqual(true);
|
test('value "false"', () => {
|
||||||
|
const input = findNativeInput(shallow(<TextInput editable={false} />));
|
||||||
|
expect(input.prop('readOnly')).toEqual(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('prop "keyboardType"', () => {
|
describe('prop "keyboardType"', () => {
|
||||||
// default
|
test('default value', () => {
|
||||||
let input = findNativeInput(shallow(<TextInput />));
|
let input = findNativeInput(shallow(<TextInput />));
|
||||||
expect(input.prop('type')).toEqual('text');
|
expect(input.prop('type')).toEqual('text');
|
||||||
input = findNativeInput(shallow(<TextInput keyboardType="default" />));
|
input = findNativeInput(shallow(<TextInput keyboardType="default" />));
|
||||||
expect(input.prop('type')).toEqual('text');
|
expect(input.prop('type')).toEqual('text');
|
||||||
// email-address
|
});
|
||||||
input = findNativeInput(shallow(<TextInput keyboardType="email-address" />));
|
|
||||||
expect(input.prop('type')).toEqual('email');
|
test('value "email-address"', () => {
|
||||||
// numeric
|
const input = findNativeInput(shallow(<TextInput keyboardType="email-address" />));
|
||||||
input = findNativeInput(shallow(<TextInput keyboardType="numeric" />));
|
expect(input.prop('type')).toEqual('email');
|
||||||
expect(input.prop('type')).toEqual('number');
|
});
|
||||||
// phone-pad
|
|
||||||
input = findNativeInput(shallow(<TextInput keyboardType="phone-pad" />));
|
test('value "numeric"', () => {
|
||||||
expect(input.prop('type')).toEqual('tel');
|
const input = findNativeInput(shallow(<TextInput keyboardType="numeric" />));
|
||||||
// url
|
expect(input.prop('type')).toEqual('number');
|
||||||
input = findNativeInput(shallow(<TextInput keyboardType="url" />));
|
});
|
||||||
expect(input.prop('type')).toEqual('url');
|
|
||||||
|
test('value "phone-pad"', () => {
|
||||||
|
const input = findNativeInput(shallow(<TextInput keyboardType="phone-pad" />));
|
||||||
|
expect(input.prop('type')).toEqual('tel');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('value "url"', () => {
|
||||||
|
const input = findNativeInput(shallow(<TextInput keyboardType="url" />));
|
||||||
|
expect(input.prop('type')).toEqual('url');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('prop "maxLength"', () => {
|
test('prop "maxLength"', () => {
|
||||||
@@ -89,25 +113,28 @@ describe('components/TextInput', () => {
|
|||||||
expect(input.prop('maxLength')).toEqual(10);
|
expect(input.prop('maxLength')).toEqual(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('prop "multiline"', () => {
|
describe('prop "multiline"', () => {
|
||||||
// false
|
test('value "false"', () => {
|
||||||
let input = findNativeInput(shallow(<TextInput />));
|
const input = findNativeInput(shallow(<TextInput />));
|
||||||
expect(input.length).toEqual(1);
|
expect(input.length).toEqual(1);
|
||||||
// true
|
});
|
||||||
input = findNativeTextarea(shallow(<TextInput multiline />));
|
|
||||||
expect(input.length).toEqual(1);
|
test('value "true"', () => {
|
||||||
|
const input = findNativeTextarea(shallow(<TextInput multiline />));
|
||||||
|
expect(input.length).toEqual(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('prop "numberOfLines"', () => {
|
describe('prop "numberOfLines"', () => {
|
||||||
// missing multiline
|
test('without "multiline"', () => {
|
||||||
let input = findNativeInput(shallow(<TextInput numberOfLines={2} />));
|
const input = findNativeInput(shallow(<TextInput numberOfLines={2} />));
|
||||||
expect(input.length).toEqual(1);
|
expect(input.length).toEqual(1);
|
||||||
// with multiline
|
});
|
||||||
input = findNativeTextarea(shallow(<TextInput multiline numberOfLines={2} />));
|
|
||||||
expect(input.length).toEqual(1);
|
|
||||||
|
|
||||||
input = findNativeTextarea(shallow(<TextInput multiline numberOfLines={3} />));
|
test('with "multiline"', () => {
|
||||||
expect(input.prop('rows')).toEqual(3);
|
const input = findNativeTextarea(shallow(<TextInput multiline numberOfLines={3} />));
|
||||||
|
expect(input.prop('rows')).toEqual(3);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('prop "onBlur"', () => {
|
test('prop "onBlur"', () => {
|
||||||
@@ -339,7 +366,7 @@ describe('components/TextInput', () => {
|
|||||||
expect(onSubmitEditing).not.toHaveBeenCalled();
|
expect(onSubmitEditing).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('multi-line input with "blurOnSubmit" triggers onSubmitEditing', () => {
|
test('multi-line input with "blurOnSubmit" triggers "onSubmitEditing"', () => {
|
||||||
const onSubmitEditing = jest.fn();
|
const onSubmitEditing = jest.fn();
|
||||||
const input = findNativeTextarea(
|
const input = findNativeTextarea(
|
||||||
mount(
|
mount(
|
||||||
@@ -368,18 +395,20 @@ describe('components/TextInput', () => {
|
|||||||
expect(input.prop('type')).toEqual(undefined);
|
expect(input.prop('type')).toEqual(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
testIfDocumentIsFocused('prop "selectTextOnFocus"', () => {
|
describe('prop "selectTextOnFocus"', () => {
|
||||||
const text = 'Text';
|
testIfDocumentIsFocused('value "false"', () => {
|
||||||
// false
|
const input = findNativeInput(mount(<TextInput defaultValue={'text'} />));
|
||||||
let input = findNativeInput(mount(<TextInput defaultValue={text} />));
|
input.node.focus();
|
||||||
input.node.focus();
|
expect(input.node.selectionEnd).toEqual(4);
|
||||||
expect(input.node.selectionEnd).toEqual(4);
|
expect(input.node.selectionStart).toEqual(4);
|
||||||
expect(input.node.selectionStart).toEqual(4);
|
});
|
||||||
// true
|
|
||||||
input = findNativeInput(mount(<TextInput defaultValue={text} selectTextOnFocus />));
|
// testIfDocumentIsFocused('value "true"', () => {
|
||||||
|
// const input = findNativeInput(mount(<TextInput defaultValue={'text'} selectTextOnFocus />));
|
||||||
// input.node.focus()
|
// input.node.focus()
|
||||||
// assert.equal(input.node.selectionEnd, 4)
|
// assert.equal(input.node.selectionEnd, 4)
|
||||||
// assert.equal(input.node.selectionStart, 0)
|
// assert.equal(input.node.selectionStart, 0)
|
||||||
|
// });
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('prop "selection"', () => {
|
describe('prop "selection"', () => {
|
||||||
@@ -401,15 +430,21 @@ describe('components/TextInput', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('prop "spellCheck"', () => {
|
describe('prop "spellCheck"', () => {
|
||||||
// default (inherets from autoCorrect)
|
test('default value', () => {
|
||||||
let input = findNativeInput(shallow(<TextInput />));
|
const input = findNativeInput(shallow(<TextInput />));
|
||||||
expect(input.prop('spellCheck')).toEqual(true);
|
expect(input.prop('spellCheck')).toEqual(true);
|
||||||
input = findNativeInput(shallow(<TextInput autoCorrect={false} />));
|
});
|
||||||
expect(input.prop('spellCheck')).toEqual(false);
|
|
||||||
// false
|
test('inherit from "autoCorrect"', () => {
|
||||||
input = findNativeInput(shallow(<TextInput spellCheck={false} />));
|
const input = findNativeInput(shallow(<TextInput autoCorrect={false} />));
|
||||||
expect(input.prop('spellCheck')).toEqual(false);
|
expect(input.prop('spellCheck')).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('value "false"', () => {
|
||||||
|
const input = findNativeInput(shallow(<TextInput spellCheck={false} />));
|
||||||
|
expect(input.prop('spellCheck')).toEqual(false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('prop "value"', () => {
|
test('prop "value"', () => {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import UIManager from '..';
|
import UIManager from '..';
|
||||||
|
|
||||||
const createNode = (style = {}) => {
|
const createStyledNode = (style = {}) => {
|
||||||
const root = document.createElement('div');
|
const root = document.createElement('div');
|
||||||
Object.keys(style).forEach(prop => {
|
Object.keys(style).forEach(prop => {
|
||||||
root.style[prop] = style[prop];
|
root.style[prop] = style[prop];
|
||||||
@@ -10,24 +10,24 @@ const createNode = (style = {}) => {
|
|||||||
return root;
|
return root;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const componentStub = {
|
||||||
|
_reactInternalInstance: {
|
||||||
|
_currentElement: { _owner: {} },
|
||||||
|
_debugID: 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
describe('apis/UIManager', () => {
|
describe('apis/UIManager', () => {
|
||||||
describe('updateView', () => {
|
describe('updateView', () => {
|
||||||
const componentStub = {
|
|
||||||
_reactInternalInstance: {
|
|
||||||
_currentElement: { _owner: {} },
|
|
||||||
_debugID: 1
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
test('supports className alias for class', () => {
|
test('supports className alias for class', () => {
|
||||||
const node = createNode();
|
const node = createStyledNode();
|
||||||
const props = { className: 'extra' };
|
const props = { className: 'extra' };
|
||||||
UIManager.updateView(node, props, componentStub);
|
UIManager.updateView(node, props, componentStub);
|
||||||
expect(node.getAttribute('class')).toEqual('extra');
|
expect(node.getAttribute('class')).toEqual('extra');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('adds correct DOM styles to existing style', () => {
|
test('adds correct DOM styles to existing style', () => {
|
||||||
const node = createNode({ color: 'red' });
|
const node = createStyledNode({ color: 'red' });
|
||||||
const props = { style: { marginTop: 0, marginBottom: 0, opacity: 0 } };
|
const props = { style: { marginTop: 0, marginBottom: 0, opacity: 0 } };
|
||||||
UIManager.updateView(node, props, componentStub);
|
UIManager.updateView(node, props, componentStub);
|
||||||
expect(node.getAttribute('style')).toEqual(
|
expect(node.getAttribute('style')).toEqual(
|
||||||
@@ -36,7 +36,7 @@ describe('apis/UIManager', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('replaces input and textarea text', () => {
|
test('replaces input and textarea text', () => {
|
||||||
const node = createNode();
|
const node = createStyledNode();
|
||||||
node.value = 'initial';
|
node.value = 'initial';
|
||||||
const textProp = { text: 'expected-text' };
|
const textProp = { text: 'expected-text' };
|
||||||
const valueProp = { value: 'expected-value' };
|
const valueProp = { value: 'expected-value' };
|
||||||
@@ -49,7 +49,7 @@ describe('apis/UIManager', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('sets other attribute values', () => {
|
test('sets other attribute values', () => {
|
||||||
const node = createNode();
|
const node = createStyledNode();
|
||||||
const props = { 'aria-level': '4', 'data-of-type': 'string' };
|
const props = { 'aria-level': '4', 'data-of-type': 'string' };
|
||||||
UIManager.updateView(node, props);
|
UIManager.updateView(node, props);
|
||||||
expect(node.getAttribute('aria-level')).toEqual('4');
|
expect(node.getAttribute('aria-level')).toEqual('4');
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
/* eslint-env jasmine, jest */
|
|
||||||
|
|
||||||
describe('components/StaticContainer', () => {
|
|
||||||
test.skip('NO TEST COVERAGE', () => {});
|
|
||||||
});
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
/* eslint-env jasmine, jest */
|
|
||||||
|
|
||||||
describe('components/StaticRenderer', () => {
|
|
||||||
test.skip('NO TEST COVERAGE', () => {});
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user