Skip to content

Commit 6a32746

Browse files
fix tests
1 parent 9099fff commit 6a32746

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

boilerplate/util/j5Redux.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ var J5Redux = function(spec) {
191191
this.unsubscribe = store.subscribe(listeners);
192192
listeners();
193193
}
194-
195194
};
196195

197196
J5Redux.prototype = {
@@ -210,10 +209,11 @@ J5Redux.prototype = {
210209
* @returns {object} - redux state
211210
*/
212211
getState: function(j5_object_id) {
212+
var state = store.getState('J5');
213213
if (j5_object_id) {
214-
return store.getState('J5')[this.store_name][j5_object_id];
214+
return state.J5[this.store_name][j5_object_id];
215215
}
216-
return store.getState('J5')[this.store_name];
216+
return state.J5[this.store_name];
217217
},
218218
/**
219219
* log out state for debugging

test/boilerplate/j5Redux.util.test.js

+11-20
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,14 @@ describe("j5Redux class", () => {
100100
}
101101
},
102102
listenersSubscribe: {
103-
status: function(status, j5){
103+
status: function(state, j5){
104104
var data = {
105105
on: false,
106106
blink: false
107107
};
108-
if (status === 'monkey'){
108+
if (state.status === 'monkey'){
109109
callback();
110110
}
111-
if (status === 'testInteraction'){
112-
data.color = j5.id;
113-
data.on = true;
114-
store.dispatch(setJ5Components('rgb', data, 'game_light'));
115-
}
116111
}
117112
}
118113
});
@@ -132,13 +127,17 @@ describe("j5Redux class", () => {
132127
});
133128

134129
it("buttons.getj5Objects() will return 2 j5 buttons ", function() {
135-
var j5Objects = buttons.getj5Objects();
136-
expect(j5Objects.length).to.equal(2);
130+
var j5Objects = buttons.getJ5Objects();
131+
expect(j5Objects).to.have.property("white");
132+
expect(j5Objects).to.have.property("black");
133+
var allKeys = Object.keys(j5Objects);
134+
expect(allKeys.length).to.equal(2);
137135
});
138136

139137
it("buttons.getState() returns the button state in redux ", function() {
140138
var getState = buttons.getState();
141139
var reduxState = store.getState().J5.game_buttons;
140+
142141
expect(getState).to.be.eql(reduxState);
143142
});
144143

@@ -165,8 +164,8 @@ describe("j5Redux class", () => {
165164
expect(spies.setUpEvents.callCount).to.equal(2);
166165
});
167166

168-
it("setUpListeners to be called twice for each????? BUG???", function() {
169-
expect(spies.setUpListeners.callCount).to.equal(2);
167+
it("setUpListeners to be called once", function() {
168+
expect(spies.setUpListeners.callCount).to.equal(1);
170169
});
171170

172171
it("if the dispatcher changes the state in redux, then the listener will fire", function() {
@@ -178,18 +177,10 @@ describe("j5Redux class", () => {
178177

179178
it("buttons.resetReduxState() will reset the state of each button in redux to original state", function() {
180179
store.dispatch(setJ5Components('white', { status: 'monkey' }, 'game_buttons'));
180+
181181
buttons.resetReduxState();
182182
var state = store.getState().J5.game_buttons.white;
183183
expect(state.status).to.equal(null);
184184
});
185185

186-
it("button listener will dispatch to light state, light listener will fire", function() {
187-
store.dispatch(setJ5Components('white', { status: 'testInteraction' }, 'game_buttons'));
188-
var state = store.getState().J5.game_buttons.white;
189-
expect(state.status).to.equal('testInteraction');
190-
191-
var lightState = store.getState().J5.game_light.rgb;
192-
expect(lightState.color).to.equal('white');
193-
expect(lightCallback.called).to.be.true;
194-
});
195186
});

0 commit comments

Comments
 (0)