forked from aksonov/react-native-router-flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Actions.test.js
71 lines (61 loc) · 2.7 KB
/
Actions.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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';
const scenesData = <Scene component="Modal" key="modal">
<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"/>
</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>;
describe('Actions', () => {
it('should create needed actions', () => {
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");
Actions.sideMenu({param2: "Hello world2"});
expect(currentScene.param1).equal(undefined);
expect(currentScene.param2).equal("Hello world2");
expect(currentScene.key).equal("sideMenu");
Actions.messaging({param3: "Hello world3"});
expect(currentScene.param3).equal("Hello world3");
expect(currentScene.key).equal("messaging");
const initialState = getInitialState(scenes);
expect(initialState.component).equal("Modal");
expect(initialState.index).equal(0);
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("modal");
Actions.messaging();
expect(state.scenes.current).equal("messaging");
//Actions.pop();
Actions.login();
expect(state.children[1].key).equal("login");
expect(state.children[1].children.length).equal(1);
expect(state.children[1].children[0].key).equal("loginModal1");
});
});