Merge pull request #122 from AlexanderZaytsev/tests-and-types

Add valid tests
This commit is contained in:
Mathieu Acthernoene 2017-08-27 21:23:06 +02:00 committed by GitHub
commit 5b1a37aefc
16 changed files with 1464 additions and 402 deletions

View File

@ -14,6 +14,4 @@ Pod::Spec.new do |s|
s.source = { git: "https://github.com/AlexanderZaytsev/react-native-i18n.git", tag: s.version.to_s }
s.source_files = "ios/**/*.{h,m}"
s.requires_arc = true
s.dependency "React"
end

View File

@ -26,8 +26,6 @@ emoji=true
module.system=haste
experimental.strict_type_args=true
munge_underscores=true
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
@ -36,12 +34,12 @@ suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FixMe
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-5]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-5]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
unsafe.enable_getters_and_setters=true
[version]
^0.45.0
^0.49.1

View File

@ -1,6 +1,6 @@
// @flow
import { AppRegistry } from 'react-native';
import Screen from './screen';
import App from './src/App';
AppRegistry.registerComponent('RNI18nExample', () => Screen);
AppRegistry.registerComponent('RNI18nExample', () => App);

View File

@ -1,6 +1,6 @@
// @flow
import { AppRegistry } from 'react-native';
import Screen from './screen';
import App from './src/App';
AppRegistry.registerComponent('RNI18nExample', () => Screen);
AppRegistry.registerComponent('RNI18nExample', () => App);

View File

@ -34,9 +34,9 @@
2D02E4C81E0B4AEC006451C7 /* libRCTWebSocket-tvOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3E991DF850E9000B6D8A /* libRCTWebSocket-tvOS.a */; };
2D02E4C91E0B4AEC006451C7 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DAD3EA31DF850E9000B6D8A /* libReact.a */; };
2DCD954D1E0B4F2C00145EB5 /* RNI18nExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* RNI18nExampleTests.m */; };
5204D203201A488EB107C84E /* libRNI18n.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 367B368B36A6423091D564AF /* libRNI18n.a */; };
5E9157361DD0AC6A00FF2AA8 /* libRCTAnimation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5E9157331DD0AC6500FF2AA8 /* libRCTAnimation.a */; };
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
855EB442C035440088F5F6C9 /* libRNI18n.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 97F87B300768405F92C94D3F /* libRNI18n.a */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -215,30 +215,44 @@
remoteGlobalIDString = 2D2A28201D9B03D100D4039D;
remoteInfo = "RCTAnimation-tvOS";
};
662CD1421F01A676003BD424 /* PBXContainerItemProxy */ = {
66FF464A1F5329020078EC5F /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 139D7ECE1E25DB7D00323FB7;
remoteInfo = "third-party";
};
662CD1441F01A676003BD424 /* PBXContainerItemProxy */ = {
66FF464C1F5329020078EC5F /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 3D383D3C1EBD27B6005632C8;
remoteInfo = "third-party-tvOS";
};
66FF464E1F5329020078EC5F /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 139D7E881E25C6D100323FB7;
remoteInfo = "double-conversion";
};
662CD1481F01A676003BD424 /* PBXContainerItemProxy */ = {
66FF46501F5329020078EC5F /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = E5C8EC686AB34E26ADF08129 /* RNI18n.xcodeproj */;
containerPortal = 146833FF1AC3E56700842450 /* React.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 3D383D621EBD27B9005632C8;
remoteInfo = "double-conversion-tvOS";
};
66FF46541F5329020078EC5F /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 8B32A3B71E404F6DAEEDF344 /* RNI18n.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 134814201AA4EA6300B7C361;
remoteInfo = RNI18n;
};
662CD14A1F01A676003BD424 /* PBXContainerItemProxy */ = {
66FF46561F5329020078EC5F /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = E5C8EC686AB34E26ADF08129 /* RNI18n.xcodeproj */;
containerPortal = 8B32A3B71E404F6DAEEDF344 /* RNI18n.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 6476C4051EEAA69700B10F51;
remoteInfo = "RNI18n-tvOS";
@ -281,11 +295,11 @@
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
2D02E47B1E0B4A5D006451C7 /* RNI18nExample-tvOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "RNI18nExample-tvOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
2D02E4901E0B4A5D006451C7 /* RNI18nExample-tvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "RNI18nExample-tvOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
367B368B36A6423091D564AF /* libRNI18n.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNI18n.a; sourceTree = "<group>"; };
5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = "<group>"; };
78C398B01ACF4ADC00677621 /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = "../node_modules/react-native/Libraries/LinkingIOS/RCTLinking.xcodeproj"; sourceTree = "<group>"; };
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = "../node_modules/react-native/Libraries/Text/RCTText.xcodeproj"; sourceTree = "<group>"; };
E5C8EC686AB34E26ADF08129 /* RNI18n.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNI18n.xcodeproj; path = "../node_modules/react-native-i18n/ios/RNI18n.xcodeproj"; sourceTree = "<group>"; };
8B32A3B71E404F6DAEEDF344 /* RNI18n.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNI18n.xcodeproj; path = "../node_modules/react-native-i18n/ios/RNI18n.xcodeproj"; sourceTree = "<group>"; };
97F87B300768405F92C94D3F /* libRNI18n.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNI18n.a; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -312,7 +326,7 @@
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */,
00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */,
139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */,
5204D203201A488EB107C84E /* libRNI18n.a in Frameworks */,
855EB442C035440088F5F6C9 /* libRNI18n.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -443,8 +457,10 @@
3DAD3EAB1DF850E9000B6D8A /* libcxxreact.a */,
3DAD3EAD1DF850E9000B6D8A /* libjschelpers.a */,
3DAD3EAF1DF850E9000B6D8A /* libjschelpers.a */,
662CD1431F01A676003BD424 /* libthird-party.a */,
662CD1451F01A676003BD424 /* libdouble-conversion.a */,
66FF464B1F5329020078EC5F /* libthird-party.a */,
66FF464D1F5329020078EC5F /* libthird-party.a */,
66FF464F1F5329020078EC5F /* libdouble-conversion.a */,
66FF46511F5329020078EC5F /* libdouble-conversion.a */,
);
name = Products;
sourceTree = "<group>";
@ -458,11 +474,11 @@
name = Products;
sourceTree = "<group>";
};
662CD1251F01A675003BD424 /* Products */ = {
66FF462B1F5329020078EC5F /* Products */ = {
isa = PBXGroup;
children = (
662CD1491F01A676003BD424 /* libRNI18n.a */,
662CD14B1F01A676003BD424 /* libRNI18n-tvOS.a */,
66FF46551F5329020078EC5F /* libRNI18n.a */,
66FF46571F5329020078EC5F /* libRNI18n-tvOS.a */,
);
name = Products;
sourceTree = "<group>";
@ -490,7 +506,7 @@
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */,
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */,
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
E5C8EC686AB34E26ADF08129 /* RNI18n.xcodeproj */,
8B32A3B71E404F6DAEEDF344 /* RNI18n.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
@ -683,8 +699,8 @@
ProjectRef = 146833FF1AC3E56700842450 /* React.xcodeproj */;
},
{
ProductGroup = 662CD1251F01A675003BD424 /* Products */;
ProjectRef = E5C8EC686AB34E26ADF08129 /* RNI18n.xcodeproj */;
ProductGroup = 66FF462B1F5329020078EC5F /* Products */;
ProjectRef = 8B32A3B71E404F6DAEEDF344 /* RNI18n.xcodeproj */;
},
);
projectRoot = "";
@ -859,32 +875,46 @@
remoteRef = 5E9157341DD0AC6500FF2AA8 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
662CD1431F01A676003BD424 /* libthird-party.a */ = {
66FF464B1F5329020078EC5F /* libthird-party.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = "libthird-party.a";
remoteRef = 662CD1421F01A676003BD424 /* PBXContainerItemProxy */;
remoteRef = 66FF464A1F5329020078EC5F /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
662CD1451F01A676003BD424 /* libdouble-conversion.a */ = {
66FF464D1F5329020078EC5F /* libthird-party.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = "libthird-party.a";
remoteRef = 66FF464C1F5329020078EC5F /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
66FF464F1F5329020078EC5F /* libdouble-conversion.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = "libdouble-conversion.a";
remoteRef = 662CD1441F01A676003BD424 /* PBXContainerItemProxy */;
remoteRef = 66FF464E1F5329020078EC5F /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
662CD1491F01A676003BD424 /* libRNI18n.a */ = {
66FF46511F5329020078EC5F /* libdouble-conversion.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = "libdouble-conversion.a";
remoteRef = 66FF46501F5329020078EC5F /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
66FF46551F5329020078EC5F /* libRNI18n.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRNI18n.a;
remoteRef = 662CD1481F01A676003BD424 /* PBXContainerItemProxy */;
remoteRef = 66FF46541F5329020078EC5F /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
662CD14B1F01A676003BD424 /* libRNI18n-tvOS.a */ = {
66FF46571F5329020078EC5F /* libRNI18n-tvOS.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = "libRNI18n-tvOS.a";
remoteRef = 662CD14A1F01A676003BD424 /* PBXContainerItemProxy */;
remoteRef = 66FF46561F5329020078EC5F /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
78C398B91ACF4ADC00677621 /* libRCTLinking.a */ = {
@ -950,7 +980,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export NODE_BINARY=node\n../node_modules/react-native/packager/react-native-xcode.sh";
shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";
};
2D02E4CB1E0B4B27006451C7 /* Bundle React Native Code And Images */ = {
isa = PBXShellScriptBuildPhase;
@ -964,7 +994,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export NODE_BINARY=node\n../node_modules/react-native/packager/react-native-xcode.sh";
shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";
};
/* End PBXShellScriptBuildPhase section */

View File

@ -3,14 +3,21 @@
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest --no-cache"
},
"dependencies": {
"react": "16.0.0-alpha.12",
"react-native": "0.45.1",
"react-native": "0.47.2",
"react-native-i18n": "file:../"
},
"devDependencies": {
"babel-preset-react-native": "2.0.0"
"babel-jest": "20.0.3",
"babel-preset-react-native": "2.0.1",
"jest": "20.0.4",
"react-test-renderer": "16.0.0-alpha.12"
},
"jest": {
"preset": "react-native"
}
}

View File

@ -1,16 +1,9 @@
// @ flow
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, ScrollView, View } from 'react-native';
import I18n, { getLanguages } from 'react-native-i18n';
import {
Platform,
StyleSheet,
Text,
ScrollView,
View,
} from 'react-native';
// Enable fallbacks if you want `en-US`
// and `en-GB` to fallback to `en`
I18n.fallbacks = true;
@ -23,31 +16,29 @@ I18n.translations = {
'es': require('./translations/es'),
};
console.log(I18n.locales)
export default class extends Component {
state = { languages: [] }
state = { languages: [] };
componentWillMount() {
getLanguages().then(languages => {
this.setState({ languages })
})
this.setState({ languages });
});
}
render() {
return (
<ScrollView style={styles.container}>
<ScrollView style={styles.container} bounces={false}>
<Text style={styles.title}>Additional methods</Text>
<View style={styles.line}>
<Text style={styles.label}>getLanguages (Promise): </Text>
<View style={styles.block}>
<Text style={styles.label}>getLanguages (Promise)</Text>
<Text>{JSON.stringify(this.state.languages)}</Text>
</View>
<Text style={styles.title}>Demos</Text>
<View style={styles.line}>
<Text style={styles.label}>I18n.t('hello world'): </Text>
<View style={styles.block}>
<Text style={styles.label}>I18n.t('hello world')</Text>
<Text>{I18n.t('hello world')}</Text>
</View>
</ScrollView>
@ -60,15 +51,17 @@ const styles = StyleSheet.create({
flex: 1,
backgroundColor: '#F5FCFF',
padding: 24,
paddingTop: Platform.OS === 'ios' ? 44 : 24,
...Platform.select({
ios: { paddingTop: 44 },
default: { paddingTop: 24 },
}),
},
title: {
fontSize: 20,
fontWeight: '700',
marginBottom: 8,
},
line: {
flexDirection: 'row',
block: {
marginBottom: 16,
},
label: {

View File

@ -0,0 +1,7 @@
// @flow
import I18nJs from 'i18n-js';
I18nJs.locale = 'en'; // a locale from your available translations
export const getLanguages = () => Promise.resolve('en');
export default I18nJs;

View File

@ -0,0 +1,12 @@
import 'react-native';
import React from 'react';
import App from '../App.js';
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
it('renders correctly', () => {
const tree = renderer.create(
<App />
);
});

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,8 @@
// @flow
import { NativeModules } from 'react-native';
import I18n from 'i18n-js';
const { RNI18n } = NativeModules;
I18n.locale = RNI18n.languages[0];
const RNI18n = require('react-native').NativeModules.RNI18n;
const I18nJs = require('i18n-js');
I18nJs.locale = RNI18n.languages[0];
export const getLanguages = RNI18n.getLanguages;
export default I18n;
export default I18nJs;

View File

@ -1,6 +1,6 @@
{
"name": "react-native-i18n",
"version": "2.0.4",
"version": "2.0.5",
"description": "Provide I18n to your React Native application",
"license": "MIT",
"author": "Alexander Zaytsev",