-
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.
Merge pull request #595 from r0b1n/master
Actions code styles and tests fixed.
- Loading branch information
Showing
3 changed files
with
91 additions
and
74 deletions.
There are no files selected for viewing
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,5 @@ | ||
{ | ||
"env": { | ||
"mocha": true | ||
} | ||
} |
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 |
---|---|---|
@@ -1,81 +1,70 @@ | ||
import { expect } from 'chai'; | ||
import Actions from '../src/Actions'; | ||
import getInitialState from '../src/State'; | ||
import React from 'react-native'; | ||
import Scene from '../src/Scene'; | ||
import createReducer from '../src/Reducer'; | ||
|
||
describe('Actions', () => { | ||
it('should create needed actions', () => { | ||
let id = 0; | ||
const guid = () => id++; | ||
|
||
const scenesData = <Scene component="Modal" key="modal" getInitialState={() => ({ foo: guid() })}> | ||
<Scene key="launch" component="Launch"/> | ||
<Scene key="sideMenu" component="Drawer" initial={true}> | ||
<Scene component="CubeBar" key="cubeBar" type="tabs"> | ||
<Scene key="main" tabs={true}> | ||
<Scene key="home" component="Home"/> | ||
<Scene key="map" component="Map"/> | ||
<Scene key="myAccount" component="MyAccount"/> | ||
</Scene> | ||
<Scene key="messaging" initial={true}> | ||
<Scene key="conversations" component="Conversations" getInitialState={() => ({ foo: 'what', bar: guid() })}/> | ||
</Scene> | ||
</Scene> | ||
</Scene> | ||
<Scene key="privacyPolicy" component="PrivacyPolicy" type="modal"/> | ||
<Scene key="termsOfService" component="TermsOfService" type="modal"/> | ||
<Scene key="login"> | ||
<Scene key="loginModal1" component="Login1"/> | ||
<Scene key="loginModal2" component="Login2"/> | ||
</Scene> | ||
</Scene>; | ||
const scenes = Actions.create(scenesData); | ||
expect(scenes.conversations.component).to.equal("Conversations"); | ||
|
||
let currentScene = null; | ||
Actions.callback = scene=>{currentScene = scene}; | ||
Actions.conversations({param1: "Hello world"}); | ||
expect(currentScene.param1).equal("Hello world"); | ||
expect(currentScene.key).equal("conversations"); | ||
import React from 'react-native'; | ||
|
||
Actions.sideMenu({param2: "Hello world2"}); | ||
expect(currentScene.param1).equal(undefined); | ||
expect(currentScene.param2).equal("Hello world2"); | ||
expect(currentScene.key).equal("sideMenu"); | ||
import Actions from '../src/Actions'; | ||
import Scene from '../src/Scene'; | ||
|
||
Actions.messaging({param3: "Hello world3"}); | ||
expect(currentScene.param3).equal("Hello world3"); | ||
expect(currentScene.key).equal("messaging"); | ||
let id = 0; | ||
const guid = () => id++; | ||
|
||
const initialState = getInitialState(scenes); | ||
expect(initialState.component).equal("Modal"); | ||
expect(initialState.index).equal(0); | ||
const scenesData = ( | ||
<Scene | ||
key="root" | ||
component="Modal" | ||
getInitialState={() => ({ foo: guid() })} | ||
> | ||
<Scene key="launch" component="Launch" /> | ||
<Scene key="sideMenu" component="Drawer" initial> | ||
<Scene component="CubeBar" key="cubeBar" type="tabs"> | ||
<Scene key="main" tabs> | ||
<Scene key="home" component="Home" /> | ||
<Scene key="map" component="Map" /> | ||
<Scene key="myAccount" component="MyAccount" /> | ||
</Scene> | ||
<Scene key="messaging" initial> | ||
<Scene | ||
key="conversations" | ||
component="Conversations" | ||
getInitialState={() => ({ foo: 'what', bar: guid() })} | ||
/> | ||
</Scene> | ||
</Scene> | ||
</Scene> | ||
<Scene key="privacyPolicy" component="PrivacyPolicy" type="modal" /> | ||
<Scene key="termsOfService" component="TermsOfService" type="modal" /> | ||
<Scene key="login"> | ||
<Scene key="loginModal1" component="Login1" /> | ||
<Scene key="loginModal2" component="Login2" /> | ||
</Scene> | ||
</Scene>); | ||
|
||
const reducer = createReducer({initialState, scenes}); | ||
let state = undefined; | ||
Actions.callback = scene=>state = reducer(state, scene); | ||
expect(state).equal(undefined); | ||
Actions.init(); | ||
expect(state.key).equal("0_modal"); | ||
expect(state.children[0].children[0].children[0].children[0].bar).equal(1); | ||
expect(state.children[0].children[0].children[0].children[0].foo).equal('what'); | ||
let scenes; | ||
|
||
Actions.messaging(); | ||
expect(currentScene.key).equal("messaging"); | ||
describe('Actions', () => { | ||
before(() => { | ||
scenes = Actions.create(scenesData); | ||
}); | ||
it('should produce needed actions', () => { | ||
// check scenes | ||
expect(scenes.conversations.component).to.equal('Conversations'); | ||
|
||
Actions.login(); | ||
expect(state.children[1].key).equal("1_login"); | ||
expect(state.children[1].children.length).equal(1); | ||
expect(state.children[1].children[0].key).equal("0_loginModal1"); | ||
// set callback which will extract generated action | ||
let latestAction = null; | ||
Actions.callback = scene => { latestAction = scene; }; | ||
|
||
Actions.pop(); | ||
expect(state.from.key).equal("1_login"); | ||
// test generated actions | ||
Actions.conversations({ param1: 'Hello world' }); | ||
expect(latestAction.param1).equal('Hello world'); | ||
expect(latestAction.key).equal('conversations'); | ||
|
||
Actions.launch(); | ||
expect(state.children[1].foo).equal(3); | ||
expect(state.children[1].bar).equal(undefined); | ||
}); | ||
Actions.sideMenu({ param2: 'Hello world2' }); | ||
expect(latestAction.param1).equal(undefined); | ||
expect(latestAction.param2).equal('Hello world2'); | ||
expect(latestAction.key).equal('sideMenu'); | ||
|
||
Actions.messaging({ param3: 'Hello world3' }); | ||
expect(latestAction.param3).equal('Hello world3'); | ||
expect(latestAction.key).equal('messaging'); | ||
}); | ||
}); |