-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pavlo Aksonov
authored and
Pavlo Aksonov
committed
Oct 1, 2015
1 parent
b1d23ab
commit 756d7e0
Showing
11 changed files
with
719 additions
and
56 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
var React = require('react'); | ||
|
||
var ReactNative = React; | ||
ReactNative.StyleSheet = { | ||
create: function(styles) { | ||
return styles; | ||
} | ||
}; | ||
class View extends React.Component { | ||
render(){ | ||
return <div {...this.props}/> | ||
} | ||
} | ||
|
||
class Navigator extends React.Component { | ||
constructor(props){ | ||
super(props); | ||
this._currentRoutes = [props.initialRoute]; | ||
this.state = {route : props.initialRoute}; | ||
} | ||
getCurrentRoutes(){ | ||
return this._currentRoutes; | ||
} | ||
push(route){ | ||
this._currentRoutes.push(route); | ||
this.setState({route: route}); | ||
} | ||
immediatelyResetRouteStack(routes){ | ||
this._currentRoutes = routes; | ||
} | ||
popToRoute(route){ | ||
while (this._currentRoutes[this._currentRoutes.length-1] != route){ | ||
this._currentRoutes.pop(); | ||
} | ||
this.setState({route: route}); | ||
} | ||
render(){ | ||
return this.props.renderScene(this.state.route, this); | ||
} | ||
} | ||
ReactNative.View = View; | ||
ReactNative.Navigator = Navigator; | ||
|
||
module.exports = ReactNative; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
jest.setMock('../Animations', {FlatFloatFromRight:{}, FlatFloatFromBottom:{}, None:{}}); | ||
jest.setMock('alt/components/AltNativeContainer'); | ||
var React = require('react/addons'); | ||
var TestUtils = React.addons.TestUtils; | ||
jest.dontMock('../store'); | ||
jest.dontMock('../actions'); | ||
jest.dontMock('../index'); | ||
|
||
var Actions = require('../actions'); | ||
|
||
var {Router, Route, Schema, Action} = require('../index'); | ||
|
||
describe('Router', function() { | ||
it('route', function () { | ||
var router = TestUtils.renderIntoDocument( | ||
<Router> | ||
<Schema name="default" navBar="navBar1" customProp="a"/> | ||
<Schema name="modal" navBar="navBar2" customProp="b" ownProp="c"/> | ||
|
||
<Route name="launch" component="launchComponent" hideNavBar={true} customProp="a"/> | ||
<Route name="signin" component="signinComponent" schema="modal"/> | ||
<Route name="signup" component="signupComponent"/> | ||
<Route name="main" component="mainComponent"/> | ||
</Router> | ||
); | ||
expect(router.refs.nav.props.initialRoute.name).toEqual('launch'); | ||
var len = router.refs.nav.getCurrentRoutes().length; | ||
expect(len).toEqual(1); | ||
var launchComponent = TestUtils.findRenderedDOMComponentWithTag( | ||
router, 'launchComponent'); | ||
|
||
expect(launchComponent.props.customProp).toEqual("a"); | ||
|
||
expect(function(){TestUtils.findRenderedDOMComponentWithTag( | ||
router, 'navBar1')}).toThrow(new Error("Did not find exactly one match for tag:navBar1")); | ||
expect(function(){TestUtils.findRenderedDOMComponentWithTag( | ||
router, 'signinComponent')}).toThrow(new Error("Did not find exactly one match for tag:signinComponent")); | ||
|
||
Actions.signin("Hello world!"); | ||
len = router.refs.nav.getCurrentRoutes().length; | ||
expect(len).toEqual(2); | ||
expect(router.refs.nav.getCurrentRoutes()[len-1].name).toEqual('signin'); | ||
expect(router.refs.nav.getCurrentRoutes()[len-1].passProps.data).toEqual("Hello world!"); | ||
|
||
Actions.signin({data:"Hello world2!", id:1}); | ||
len = router.refs.nav.getCurrentRoutes().length; | ||
expect(len).toEqual(3); | ||
expect(router.refs.nav.getCurrentRoutes()[len-1].name).toEqual('signin'); | ||
expect(router.refs.nav.getCurrentRoutes()[len-1].passProps.data).toEqual("Hello world2!"); | ||
expect(router.refs.nav.getCurrentRoutes()[len-1].passProps.id).toEqual(1); | ||
|
||
var signinComponent = TestUtils.findRenderedDOMComponentWithTag( | ||
router, 'signinComponent'); | ||
|
||
var navBar = TestUtils.findRenderedDOMComponentWithTag( | ||
router, 'navBar2'); | ||
|
||
expect(React.findDOMNode(signinComponent).data).toEqual('Hello world2!'); | ||
expect(navBar.props.customProp).toEqual("b"); | ||
expect(navBar.props.ownProp).toEqual("c"); | ||
expect(navBar.props.data).toEqual('Hello world2!'); | ||
expect(navBar.props.id).toEqual(1); | ||
|
||
Actions.main(); | ||
len = router.refs.nav.getCurrentRoutes().length; | ||
expect(len).toEqual(4); | ||
expect(router.refs.nav.getCurrentRoutes()[len-1].name).toEqual('main'); | ||
expect(router.refs.nav.getCurrentRoutes()[len-1].passProps.data).toEqual(undefined); | ||
expect(router.refs.nav.getCurrentRoutes()[len-1].passProps.id).toEqual(undefined); | ||
|
||
expect(function(){TestUtils.findRenderedDOMComponentWithTag( | ||
router, 'navBar2')}).toThrow(new Error("Did not find exactly one match for tag:navBar2")); | ||
navBar = TestUtils.findRenderedDOMComponentWithTag( | ||
router, 'navBar1'); | ||
|
||
expect(navBar.props.customProp).toEqual("a"); | ||
expect(navBar.props.ownProp).toEqual(undefined); | ||
|
||
Actions.pop(2); | ||
len = router.refs.nav.getCurrentRoutes().length; | ||
expect(len).toEqual(2); | ||
|
||
expect(router.refs.nav.getCurrentRoutes()[len-1].name).toEqual('signin'); | ||
expect(router.refs.nav.getCurrentRoutes()[len-1].passProps.data).toEqual("Hello world!"); | ||
expect(router.refs.nav.getCurrentRoutes()[len-1].passProps.id).toEqual(undefined); | ||
|
||
Actions.pop(); | ||
len = router.refs.nav.getCurrentRoutes().length; | ||
expect(len).toEqual(1); | ||
|
||
expect(router.refs.nav.getCurrentRoutes()[len-1].name).toEqual('launch'); | ||
launchComponent = TestUtils.findRenderedDOMComponentWithTag( | ||
router, 'launchComponent'); | ||
|
||
expect(launchComponent.props.customProp).toEqual("a"); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
jest.dontMock('../store'); | ||
jest.dontMock('../actions'); | ||
var actions = require('../actions'); | ||
var alt = require('../alt'); | ||
var PageStore = require('../store'); | ||
|
||
describe('PageStore', function() { | ||
it('init action', function() { | ||
var state = PageStore.getState(); | ||
expect(state.routes.length).toBe(0); | ||
expect(state.currentRoute).toBe(null); | ||
|
||
actions.init("launch"); | ||
state = PageStore.getState(); | ||
expect(state.routes.length).toBe(1); | ||
expect(state.routes[0]).toBe("launch"); | ||
expect(state.currentRoute).toBe("launch"); | ||
|
||
actions.init("home"); | ||
state = PageStore.getState(); | ||
expect(state.routes.length).toBe(1); | ||
expect(state.routes[0]).toBe("home"); | ||
expect(state.currentRoute).toBe("home"); | ||
}); | ||
|
||
it('push action', function() { | ||
actions.init("init"); | ||
|
||
var state = PageStore.getState(); | ||
expect(state.routes.length).toBe(1); | ||
expect(state.currentRoute).toBe("init"); | ||
|
||
actions.push({name: "launch", data: "test"}); | ||
state = PageStore.getState(); | ||
expect(state.routes.length).toBe(2); | ||
expect(state.routes[1]).toBe("launch"); | ||
expect(state.currentRoute).toBe("launch"); | ||
expect(state.mode).toBe("push"); | ||
expect(state.data).toBe("test"); | ||
|
||
actions.push({name: "home", data: "homeData"}); | ||
state = PageStore.getState(); | ||
expect(state.routes.length).toBe(3); | ||
expect(state.routes[2]).toBe("home"); | ||
expect(state.mode).toBe("push"); | ||
expect(state.data).toBe("homeData"); | ||
expect(state.currentRoute).toBe("home"); | ||
}); | ||
|
||
it('pop action', function() { | ||
actions.push({name: "launch", data: "test"}); | ||
actions.push({name: "home"}); | ||
actions.push({name: "home2"}); | ||
actions.push({name: "home3"}); | ||
actions.push({name: "home4"}); | ||
var state = PageStore.getState(); | ||
expect(state.currentRoute).toBe("home4"); | ||
actions.pop(); | ||
state = PageStore.getState(); | ||
expect(state.currentRoute).toBe("home3"); | ||
expect(state.mode).toBe("pop"); | ||
expect(state.num).toBe(1); | ||
|
||
actions.pop(2); | ||
state = PageStore.getState(); | ||
expect(state.currentRoute).toBe("home"); | ||
expect(state.mode).toBe("pop"); | ||
expect(state.num).toBe(2); | ||
|
||
expect(state.customData).toBe(undefined); | ||
actions.pop({customData: 'customData'}); | ||
state = PageStore.getState(); | ||
expect(state.currentRoute).toBe("launch"); | ||
expect(state.customData).toBe("customData"); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
'use strict'; | ||
|
||
window.__DEV__ = true; | ||
window.Env = {}; | ||
|
||
require.requireActual('./setupEnvPolyfills'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
// Babel is an ES6 transpiler. Read more about it at https://babeljs.io/ | ||
var babel = require('babel-core'); | ||
|
||
module.exports = { | ||
process: function (src, filename) { | ||
// Don't transpile node modules. | ||
if (filename.match(/node_modules/)) { | ||
return src; | ||
} | ||
|
||
var result = babel.transform(src, {filename: filename}); | ||
return result.code; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* This pipes all of our console logging functions to native logging so that | ||
* JavaScript errors in required modules show up in Xcode via NSLog. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// WARNING: This is an optimized version that fails on hasOwnProperty checks | ||
// and non objects. It's not spec-compliant. It's a perf optimization. | ||
|
||
Object.assign = function(target, sources) { | ||
if (__DEV__) { | ||
if (target == null) { | ||
throw new TypeError('Object.assign target cannot be null or undefined'); | ||
} | ||
if (typeof target !== 'object' && typeof target !== 'function') { | ||
throw new TypeError( | ||
'In this environment the target of assign MUST be an object.' + | ||
'This error is a performance optimization and not spec compliant.' | ||
); | ||
} | ||
} | ||
|
||
for (var nextIndex = 1; nextIndex < arguments.length; nextIndex++) { | ||
var nextSource = arguments[nextIndex]; | ||
if (nextSource == null) { | ||
continue; | ||
} | ||
|
||
if (__DEV__) { | ||
if (typeof nextSource !== 'object' && | ||
typeof nextSource !== 'function') { | ||
throw new TypeError( | ||
'In this environment the target of assign MUST be an object.' + | ||
'This error is a performance optimization and not spec compliant.' | ||
); | ||
} | ||
} | ||
|
||
// We don't currently support accessors nor proxies. Therefore this | ||
// copy cannot throw. If we ever supported this then we must handle | ||
// exceptions and side-effects. | ||
|
||
for (var key in nextSource) { | ||
if (__DEV__) { | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
if (!hasOwnProperty.call(nextSource, key)) { | ||
throw new TypeError( | ||
'One of the sources to assign has an enumerable key on the ' + | ||
'prototype chain. This is an edge case that we do not support. ' + | ||
'This error is a performance optimization and not spec compliant.' | ||
); | ||
} | ||
} | ||
target[key] = nextSource[key]; | ||
} | ||
} | ||
|
||
return target; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env bash | ||
npm test |