-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
153 lines (122 loc) · 5.38 KB
/
index.html
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>StateMachine - qUnit test</title>
<script id="sap-ui-bootstrap"
type="text/javascript"
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-noConflict="true"
data-sap-ui-libs="sap.m"
data-sap-ui-resourceroots='{"test": "./stateMachine"}'
>
</script>
<link rel="stylesheet" href="https://openui5.hana.ondemand.com/resources/sap/ui/thirdparty/qunit.css" type="text/css" media="screen" />
<script type="text/javascript" src="https://openui5.hana.ondemand.com/resources/sap/ui/thirdparty/qunit.js"></script>
<script type="text/javascript" src="https://openui5.hana.ondemand.com/resources/sap/ui/qunit/qunit-junit.js"></script>
<script type="text/javascript" src="https://openui5.hana.ondemand.com/resources/sap/ui/qunit/QUnitUtils.js"></script>
<script type="text/javascript" src="https://openui5.hana.ondemand.com/resources/sap/ui/thirdparty/sinon.js"></script>
<script type="text/javascript" src="https://openui5.hana.ondemand.com/resources/sap/ui/thirdparty/sinon-qunit.js"></script>
<script>
sinon.config.useFakeTimers = false;
//debugger
jQuery.sap.require("test.StateMachine");
QUnit.module("StateMachine", {
beforeEach: function() {
var mStates = {
Stopped: "Stopped",
Playing: "Playing",
Paused: "Paused"
};
var mTrigger = {
Play: "Play",
Pause: "Pause",
Stop: "Stop"
};
this._oStateMachine = new test.StateMachine(mStates, mTrigger);
//Stopped + "Play" ==> Playing
this._oStateMachine.configure(this._oStateMachine.getStates().Stopped)
.permit(this._oStateMachine.getTriggers().Play, this._oStateMachine.getStates().Playing);
//Playing + "Stop" ==> Stopped
//Playing + "Pause" ==> Paused
this._oStateMachine.configure(this._oStateMachine.getStates().Playing)
.permit(this._oStateMachine.getTriggers().Stop, this._oStateMachine.getStates().Stopped)
.permit(this._oStateMachine.getTriggers().Pause, this._oStateMachine.getStates().Paused);
//Paused + "Play" ==> Playing
//Paused + "Stop" ==> Stopped
this._oStateMachine.configure(this._oStateMachine.getStates().Paused)
.permit(this._oStateMachine.getTriggers().Play, this._oStateMachine.getStates().Playing)
.permit(this._oStateMachine.getTriggers().Stop, this._oStateMachine.getStates().Stopped);
//start the machine in Stopped state
this._oStateMachine.setInitialState(this._oStateMachine.getStates().Stopped);
},
afterEach: function() {
}
});
QUnit.test("Instantiation", 1, function(assert) {
assert.ok(this._oStateMachine , "StateMachine instance created");
});
QUnit.test("Get initial state", 1, function(assert) {
var sState = this._oStateMachine.getState();
assert.ok(sState == this._oStateMachine.getStates().Stopped);
});
QUnit.test("Fire state and check resulting state", 1, function(assert) {
this._oStateMachine.fire(this._oStateMachine.getTriggers().Play);
var sState = this._oStateMachine.getState();
assert.ok(sState === this._oStateMachine.getStates().Playing);
});
QUnit.test("Fire state and check onEntry call", 1, function(assert) {
this._oStateMachine.configure(this._oStateMachine.getStates().Playing)
.onEntry(function() {
assert.ok(true, "playing onEntry called");
});
this._oStateMachine.fire(this._oStateMachine.getTriggers().Play);
});
QUnit.test("Fire state and check beforeExit call", 1, function(assert) {
this._oStateMachine.configure(this._oStateMachine.getStates().Stopped)
.beforeExit(function() {
assert.ok(true, "stopped beforeExit called");
});
this._oStateMachine.fire(this._oStateMachine.getTriggers().Play);
});
QUnit.test("Reset to initial state", 1, function(assert) {
this._oStateMachine.fire(this._oStateMachine.getTriggers().Play);
this._oStateMachine.reset();
var sState = this._oStateMachine.getState();
assert.ok(sState === this._oStateMachine.getStates().Stopped);
});
QUnit.test("Exception on invalid trigger called", 1, function(assert) {
assert.throws(
function() {
this._oStateMachine.fire(this._oStateMachine.getTriggers().Stop);
}, "invalid trigger"
);
});
QUnit.test("State change Eventhandler", 2, function(assert) {
this._oStateMachine.onStateChanged(function(oStateConfig){
assert.ok(true, "onStateChanged called");
assert.ok(oStateConfig.getState() === this._oStateMachine.getStates().Playing, "correct stateConfig state returned");
}.bind(this));
this._oStateMachine.fire(this._oStateMachine.getTriggers().Play);
});
QUnit.test("Set data to state and retrieve", 1, function(assert) {
var sSomeData = "someData";
this._oStateMachine.configure(this._oStateMachine.getStates().Playing)
.setData(sSomeData);
this._oStateMachine.onStateChanged(function(oStateConfig){
assert.ok(oStateConfig.getData() === sSomeData, "correct stateConfig data returned");
}.bind(this));
this._oStateMachine.fire(this._oStateMachine.getTriggers().Play);
});
</script>
</head>
<body>
<h1 id="qunit-header">qUnit Page for StateMachine</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div>
<div id="uiArea1"></div>
</body>
</html>