|
8 | 8 |
|
9 | 9 | import { createStore } from 'redux'; |
10 | 10 | import { CreateGameReducer } from '../core/reducer'; |
11 | | -import { |
12 | | - Client, |
13 | | - GetOpts, |
14 | | - createEventDispatchers, |
15 | | - createMoveDispatchers, |
16 | | -} from './client'; |
| 11 | +import { Client, GetOpts, createMoveDispatchers } from './client'; |
17 | 12 | import { Local } from './transport/local'; |
18 | 13 | import { SocketIO } from './transport/socketio'; |
19 | 14 | import { update, sync, makeMove, gameEvent } from '../core/action-creators'; |
@@ -193,68 +188,46 @@ test('accepts enhancer for store', () => { |
193 | 188 | expect(spyDispatcher.mock.calls).toHaveLength(1); |
194 | 189 | }); |
195 | 190 |
|
196 | | -test('event dispatchers', () => { |
197 | | - { |
| 191 | +describe('event dispatchers', () => { |
| 192 | + test('default', () => { |
198 | 193 | const game = Game({}); |
199 | | - const reducer = CreateGameReducer({ game, numPlayers: 2 }); |
200 | | - const store = createStore(reducer); |
201 | | - const api = createEventDispatchers(game.flow.eventNames, store); |
202 | | - expect(Object.getOwnPropertyNames(api)).toEqual(['endTurn']); |
203 | | - expect(store.getState().ctx.turn).toBe(0); |
204 | | - api.endTurn(); |
205 | | - expect(store.getState().ctx.turn).toBe(1); |
206 | | - } |
207 | | - |
208 | | - { |
| 194 | + const client = Client({ game }); |
| 195 | + expect(Object.keys(client.events)).toEqual(['endTurn']); |
| 196 | + expect(client.getState().ctx.turn).toBe(0); |
| 197 | + client.events.endTurn(); |
| 198 | + expect(client.getState().ctx.turn).toBe(1); |
| 199 | + }); |
| 200 | + |
| 201 | + test('all events', () => { |
209 | 202 | const game = Game({ |
210 | 203 | flow: { |
211 | 204 | endPhase: true, |
212 | 205 | endGame: true, |
213 | 206 | setActionPlayers: true, |
214 | 207 | }, |
215 | 208 | }); |
216 | | - const reducer = CreateGameReducer({ game, numPlayers: 2 }); |
217 | | - const store = createStore(reducer); |
218 | | - const api = createEventDispatchers(game.flow.eventNames, store); |
219 | | - expect(Object.getOwnPropertyNames(api)).toEqual([ |
| 209 | + const client = Client({ game }); |
| 210 | + expect(Object.keys(client.events)).toEqual([ |
220 | 211 | 'endTurn', |
221 | 212 | 'endPhase', |
222 | 213 | 'endGame', |
223 | 214 | 'setActionPlayers', |
224 | 215 | ]); |
225 | | - expect(store.getState().ctx.turn).toBe(0); |
226 | | - api.endTurn(); |
227 | | - expect(store.getState().ctx.turn).toBe(1); |
228 | | - } |
| 216 | + expect(client.getState().ctx.turn).toBe(0); |
| 217 | + client.events.endTurn(); |
| 218 | + expect(client.getState().ctx.turn).toBe(1); |
| 219 | + }); |
229 | 220 |
|
230 | | - { |
| 221 | + test('no events', () => { |
231 | 222 | const game = Game({ |
232 | 223 | flow: { |
233 | 224 | endPhase: false, |
234 | 225 | endTurn: false, |
235 | 226 | }, |
236 | 227 | }); |
237 | | - const reducer = CreateGameReducer({ game, numPlayers: 2 }); |
238 | | - const store = createStore(reducer); |
239 | | - const api = createEventDispatchers(game.flow.eventNames, store); |
240 | | - expect(Object.getOwnPropertyNames(api)).toEqual([]); |
241 | | - } |
242 | | - |
243 | | - { |
244 | | - const game = Game({ |
245 | | - flow: { |
246 | | - endPhase: true, |
247 | | - undoableMoves: ['A'], |
248 | | - }, |
249 | | - }); |
250 | | - const reducer = CreateGameReducer({ game, numPlayers: 2 }); |
251 | | - const store = createStore(reducer); |
252 | | - const api = createEventDispatchers(game.flow.eventNames, store); |
253 | | - expect(Object.getOwnPropertyNames(api)).toEqual(['endTurn', 'endPhase']); |
254 | | - expect(store.getState().ctx.turn).toBe(0); |
255 | | - api.endTurn(); |
256 | | - expect(store.getState().ctx.turn).toBe(1); |
257 | | - } |
| 228 | + const client = Client({ game }); |
| 229 | + expect(Object.keys(client.events)).toEqual([]); |
| 230 | + }); |
258 | 231 | }); |
259 | 232 |
|
260 | 233 | describe('move dispatchers', () => { |
|
0 commit comments