Skip to content

Commit

Permalink
Merge pull request #122 from AlexanderZaytsev/tests-and-types
Browse files Browse the repository at this point in the history
Add valid tests
  • Loading branch information
zoontek authored Aug 27, 2017
2 parents 27455aa + ab1edf2 commit 5b1a37a
Show file tree
Hide file tree
Showing 16 changed files with 1,466 additions and 404 deletions.
4 changes: 1 addition & 3 deletions RNI18n.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '7.0'
s.tvos.deployment_target = '9.0'
s.source = { git: "https://github.com/AlexanderZaytsev/react-native-i18n.git", tag: s.version.to_s }
s.source_files = "ios/**/*.{h,m}"
s.source_files = "ios/**/*.{h,m}"
s.requires_arc = true

s.dependency "React"
end
8 changes: 3 additions & 5 deletions example/.flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
4 changes: 2 additions & 2 deletions example/index.android.js
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 2 additions & 2 deletions example/index.ios.js
Original file line number Diff line number Diff line change
@@ -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);
86 changes: 58 additions & 28 deletions example/ios/RNI18nExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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 */
Expand All @@ -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;
};
Expand Down Expand Up @@ -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>";
Expand All @@ -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>";
Expand Down Expand Up @@ -490,7 +506,7 @@
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */,
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */,
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
E5C8EC686AB34E26ADF08129 /* RNI18n.xcodeproj */,
8B32A3B71E404F6DAEEDF344 /* RNI18n.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
Expand Down Expand Up @@ -683,8 +699,8 @@
ProjectRef = 146833FF1AC3E56700842450 /* React.xcodeproj */;
},
{
ProductGroup = 662CD1251F01A675003BD424 /* Products */;
ProjectRef = E5C8EC686AB34E26ADF08129 /* RNI18n.xcodeproj */;
ProductGroup = 66FF462B1F5329020078EC5F /* Products */;
ProjectRef = 8B32A3B71E404F6DAEEDF344 /* RNI18n.xcodeproj */;
},
);
projectRoot = "";
Expand Down Expand Up @@ -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 = 66FF464A1F5329020078EC5F /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
66FF464D1F5329020078EC5F /* libthird-party.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = "libthird-party.a";
remoteRef = 662CD1421F01A676003BD424 /* PBXContainerItemProxy */;
remoteRef = 66FF464C1F5329020078EC5F /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
66FF464F1F5329020078EC5F /* libdouble-conversion.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = "libdouble-conversion.a";
remoteRef = 66FF464E1F5329020078EC5F /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
662CD1451F01A676003BD424 /* libdouble-conversion.a */ = {
66FF46511F5329020078EC5F /* libdouble-conversion.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = "libdouble-conversion.a";
remoteRef = 662CD1441F01A676003BD424 /* PBXContainerItemProxy */;
remoteRef = 66FF46501F5329020078EC5F /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
662CD1491F01A676003BD424 /* libRNI18n.a */ = {
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 */ = {
Expand Down Expand Up @@ -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;
Expand All @@ -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 */

Expand Down
13 changes: 10 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
35 changes: 14 additions & 21 deletions example/screen.js → example/src/App.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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>
Expand All @@ -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: {
Expand Down
7 changes: 7 additions & 0 deletions example/src/__mocks__/react-native-i18n.js
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions example/src/__tests__/App.js
Original file line number Diff line number Diff line change
@@ -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 renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 5b1a37a

Please sign in to comment.