Skip to content

Commit 22b655c

Browse files
committed
Merge pull request itinance#5 from agenthunt/master
Added Integration tests
2 parents fb40835 + 1a57ef0 commit 22b655c

File tree

25 files changed

+1366
-117
lines changed

25 files changed

+1366
-117
lines changed

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
11
node_modules
22
workbench
3+
*.log
4+
# Xcode
5+
.DS_Store
6+
build/
7+
*.pbxuser
8+
!default.pbxuser
9+
*.mode1v3
10+
!default.mode1v3
11+
*.mode2v3
12+
!default.mode2v3
13+
*.perspectivev3
14+
!default.perspectivev3
15+
*.xcworkspace
16+
!default.xcworkspace
17+
xcuserdata
18+
profile
19+
*.moved-aside
20+
DerivedData
21+
.idea/
22+
# Pods - for those of you who use CocoaPods
23+
Pods

IntegrationTests/AppDelegate.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import <UIKit/UIKit.h>
11+
12+
@interface AppDelegate : UIResponder <UIApplicationDelegate>
13+
14+
@property (nonatomic, strong) UIWindow *window;
15+
16+
@end
17+

IntegrationTests/AppDelegate.m

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import "AppDelegate.h"
11+
12+
#import "RCTRootView.h"
13+
14+
@implementation AppDelegate
15+
16+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
17+
{
18+
NSURL *jsCodeLocation;
19+
20+
// Loading JavaScript code - uncomment the one you want.
21+
22+
// OPTION 1
23+
// Load from development server. Start the server from the repository root:
24+
//
25+
// $ npm start
26+
//
27+
// To run on device, change `localhost` to the IP address of your computer, and make sure your computer and
28+
// iOS device are on the same Wi-Fi network.
29+
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/IntegrationTests/IntegrationTestsApp.includeRequire.runModule.bundle?dev=true"];
30+
31+
// OPTION 2
32+
// Load from pre-bundled file on disk. To re-generate the static bundle, run
33+
//
34+
// $ curl http://localhost:8081/IntegrationTests/IntegrationTestsApp.includeRequire.runModule.bundle -o main.jsbundle
35+
//
36+
// and uncomment the next following line
37+
// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
38+
39+
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
40+
moduleName:@"IntegrationTestsApp"
41+
launchOptions:launchOptions];
42+
43+
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
44+
UIViewController *rootViewController = [[UIViewController alloc] init];
45+
rootViewController.view = rootView;
46+
self.window.rootViewController = rootViewController;
47+
[self.window makeKeyAndVisible];
48+
return YES;
49+
}
50+
51+
@end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="13F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
3+
<dependencies>
4+
<deployment identifier="iOS"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
6+
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
7+
</dependencies>
8+
<objects>
9+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
10+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
11+
<view contentMode="scaleToFill" id="iN0-l3-epB">
12+
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
13+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
14+
<subviews>
15+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 Facebook. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
16+
<rect key="frame" x="20" y="439" width="441" height="21"/>
17+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
18+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
19+
<nil key="highlightedColor"/>
20+
</label>
21+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="IntegrationTests" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
22+
<rect key="frame" x="20" y="140" width="441" height="43"/>
23+
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
24+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
25+
<nil key="highlightedColor"/>
26+
</label>
27+
</subviews>
28+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
29+
<constraints>
30+
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
31+
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
32+
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/>
33+
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/>
34+
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
35+
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
36+
</constraints>
37+
<nil key="simulatedStatusBarMetrics"/>
38+
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
39+
<point key="canvasLocation" x="548" y="455"/>
40+
</view>
41+
</objects>
42+
</document>

IntegrationTests/FSTest.js

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
2+
'use strict';
3+
4+
var RCTTestModule = require('NativeModules').TestModule;
5+
var React = require('react-native');
6+
var {
7+
Text,
8+
View,
9+
} = React;
10+
var RNFS = require('react-native-fs');
11+
var DEBUG = false;
12+
13+
14+
// setup in componentDidMount
15+
var done;
16+
var updateMessage;
17+
18+
function runTestCase(description, fn) {
19+
updateMessage(description);
20+
fn();
21+
}
22+
23+
function expectTrue(condition, message) {
24+
if (!condition) {
25+
throw new Error(message);
26+
}
27+
}
28+
29+
function expectEqual(lhs, rhs, testname) {
30+
expectTrue(
31+
lhs === rhs,
32+
'Error in test ' + testname + ': expected ' + rhs + ', got ' + lhs
33+
);
34+
}
35+
36+
function expectFSNoError(err) {
37+
expectTrue(err === null, 'Unexpected FS error: ' + JSON.stringify(err));
38+
}
39+
40+
function testWriteAndReadFile() {
41+
var path = RNFS.DocumentDirectoryPath + '/test.txt';
42+
43+
var text = 'Lorem ipsum dolor sit amet';
44+
var readText;
45+
46+
RNFS.writeFile(path, text)
47+
.then((success) => {
48+
updateMessage('FILE WRITTEN!');
49+
return RNFS.readFile(path);
50+
})
51+
.then((contents) => {
52+
updateMessage('FILE READ! Contents:');
53+
readText = contents;
54+
expectEqual(text, readText, 'testWriteAndReadFile');
55+
updateMessage('readFile correctly returned' + readText);
56+
})
57+
.finally(() => {
58+
runTestCase('testCreateAndDeleteFile', testCreateAndDeleteFile);
59+
})
60+
.done();//promise done needed to throw exception so that in case test fails,error is propagated
61+
}
62+
63+
64+
65+
function testCreateAndDeleteFile() {
66+
var path = RNFS.DocumentDirectoryPath + '/test.txt';
67+
var text = 'Lorem ipsum dolor sit amet';
68+
var readText;
69+
70+
RNFS.writeFile(path, text)
71+
.then((success) => {
72+
updateMessage('FILE CREATED!');
73+
return RNFS.unlink(path);
74+
})
75+
.spread((success, path) => {
76+
updateMessage('FILE DELETED!' + success + ',' + path);
77+
return RNFS.stat(path);
78+
})
79+
.then((statResult) => {
80+
updateMessage('*****' + statResult);
81+
if (statResult.isFile()) {
82+
updateMessage('FILE STILL EXISTS');
83+
}
84+
})
85+
.catch((err) => {
86+
updateMessage('catch' + err);
87+
expectTrue(true,'File is deleted');
88+
})
89+
.finally(() => {
90+
done(); //testrunners done
91+
})
92+
.done(); //promise done needed to throw exception so that in case test fails,error is propagated
93+
}
94+
95+
96+
97+
98+
var FSTest = React.createClass({
99+
getInitialState() {
100+
return {
101+
messages: 'Initializing...',
102+
done: false,
103+
};
104+
},
105+
106+
componentDidMount() {
107+
done = () => this.setState({
108+
done: true
109+
}, RCTTestModule.markTestCompleted);
110+
updateMessage = (msg) => {
111+
this.setState({
112+
messages: this.state.messages.concat('\n' + msg)
113+
});
114+
DEBUG && console.log(msg);
115+
};
116+
testWriteAndReadFile();
117+
},
118+
119+
render() {
120+
return (
121+
<View style={{backgroundColor: 'white', padding: 40}}>
122+
<Text>
123+
{this.constructor.displayName + ': '}
124+
{this.state.done ? 'Done' : 'Testing...'}
125+
{'\n\n' + this.state.messages}
126+
</Text>
127+
</View>
128+
);
129+
}
130+
});
131+
132+
module.exports = FSTest;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"images" : [
3+
{
4+
"size" : "29x29",
5+
"idiom" : "iphone",
6+
"filename" : "[email protected]",
7+
"scale" : "2x"
8+
},
9+
{
10+
"size" : "29x29",
11+
"idiom" : "iphone",
12+
"filename" : "[email protected]",
13+
"scale" : "3x"
14+
},
15+
{
16+
"size" : "40x40",
17+
"idiom" : "iphone",
18+
"filename" : "[email protected]",
19+
"scale" : "2x"
20+
},
21+
{
22+
"size" : "40x40",
23+
"idiom" : "iphone",
24+
"filename" : "[email protected]",
25+
"scale" : "3x"
26+
},
27+
{
28+
"size" : "60x60",
29+
"idiom" : "iphone",
30+
"filename" : "[email protected]",
31+
"scale" : "2x"
32+
},
33+
{
34+
"size" : "60x60",
35+
"idiom" : "iphone",
36+
"filename" : "[email protected]",
37+
"scale" : "3x"
38+
}
39+
],
40+
"info" : {
41+
"version" : 1,
42+
"author" : "xcode"
43+
}
44+
}
Loading
Loading
Loading
Loading
Loading
Loading

IntegrationTests/Info.plist

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>com.facebook.$(PRODUCT_NAME:rfc1034identifier)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>APPL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleSignature</key>
20+
<string>????</string>
21+
<key>CFBundleVersion</key>
22+
<string>1</string>
23+
<key>LSRequiresIPhoneOS</key>
24+
<true/>
25+
<key>UILaunchStoryboardName</key>
26+
<string>LaunchScreen</string>
27+
<key>UIRequiredDeviceCapabilities</key>
28+
<array>
29+
<string>armv7</string>
30+
</array>
31+
<key>UISupportedInterfaceOrientations</key>
32+
<array>
33+
<string>UIInterfaceOrientationPortrait</string>
34+
<string>UIInterfaceOrientationLandscapeLeft</string>
35+
<string>UIInterfaceOrientationLandscapeRight</string>
36+
</array>
37+
<key>NSLocationWhenInUseUsageDescription</key>
38+
<string>You need to add NSLocationWhenInUseUsageDescription key in Info.plist to enable geolocation, otherwise it is going to *fail silently*!</string>
39+
<key>UIViewControllerBasedStatusBarAppearance</key>
40+
<false/>
41+
</dict>
42+
</plist>

0 commit comments

Comments
 (0)