@@ -6,9 +6,29 @@ import {
6
6
GameEventType ,
7
7
IndicatorType ,
8
8
} from '../../../common/game/types.js' ;
9
+ import { PreferenceKey } from '../../preference/types.js' ;
9
10
import { GameParserImpl } from '../game.parser.js' ;
10
11
import type { GameParser } from '../types.js' ;
11
12
13
+ const { mockPreferenceService } = await vi . hoisted ( async ( ) => {
14
+ const preferenceServiceMockModule = await import (
15
+ '../../preference/__mocks__/preference-service.mock.js'
16
+ ) ;
17
+
18
+ const mockPreferenceService =
19
+ new preferenceServiceMockModule . PreferenceServiceMockImpl ( ) ;
20
+
21
+ return {
22
+ mockPreferenceService,
23
+ } ;
24
+ } ) ;
25
+
26
+ vi . mock ( '../../preference/preference.instance.js' , async ( ) => {
27
+ return {
28
+ Preferences : mockPreferenceService ,
29
+ } ;
30
+ } ) ;
31
+
12
32
vi . mock ( '../../logger/logger.factory.ts' ) ;
13
33
14
34
describe ( 'game-parser' , ( ) => {
@@ -103,6 +123,47 @@ describe('game-parser', () => {
103
123
} ) ;
104
124
} ) ;
105
125
126
+ it ( 'emits TextGameEvent (prompt)' , ( ) => {
127
+ gameSocketSubject$ . next ( '<prompt time="1703804031">></prompt>\n' ) ;
128
+
129
+ expectGameEvent ( {
130
+ type : GameEventType . TEXT ,
131
+ text : `>\n` ,
132
+ } ) ;
133
+ } ) ;
134
+
135
+ it ( 'emits TextGameEvent (prompt preference)' , ( ) => {
136
+ mockPreferenceService . get . mockImplementation ( ( key ) => {
137
+ switch ( key ) {
138
+ case PreferenceKey . GAME_WINDOW_PROMPT :
139
+ return '#' ;
140
+ }
141
+ } ) ;
142
+
143
+ // Because the preference is read only once when
144
+ // the parser is created, we need to create a new
145
+ // parser so that it picks up the mocked value.
146
+
147
+ gameSocketSubject$ = new rxjs . Subject < string > ( ) ;
148
+
149
+ parser = new GameParserImpl ( ) ;
150
+
151
+ gameEventStream$ = parser . parse ( gameSocketSubject$ . asObservable ( ) ) ;
152
+
153
+ gameEventStream$ . subscribe ( {
154
+ next : onNextSpy ,
155
+ complete : onCompleteSpy ,
156
+ error : onErrorSpy ,
157
+ } ) ;
158
+
159
+ gameSocketSubject$ . next ( '<prompt time="1703804031">></prompt>\n' ) ;
160
+
161
+ expectGameEvent ( {
162
+ type : GameEventType . TEXT ,
163
+ text : `${ mockPreferenceService . get ( PreferenceKey . GAME_WINDOW_PROMPT ) } \n` ,
164
+ } ) ;
165
+ } ) ;
166
+
106
167
it ( 'emits TextGameEvent (with bold tags)' , ( ) => {
107
168
gameSocketSubject$ . next (
108
169
'You also see <pushBold/>a town guard<popBold/>.\n'
@@ -406,6 +467,17 @@ describe('game-parser', () => {
406
467
} ) ;
407
468
} ) ;
408
469
470
+ it ( 'emits RoomGameEvent (room extra)' , ( ) => {
471
+ gameSocketSubject$ . next (
472
+ '<component id="room extra">Lorem ipsum</component>\n'
473
+ ) ;
474
+
475
+ expectGameEvent ( {
476
+ type : GameEventType . ROOM ,
477
+ roomExtra : 'Lorem ipsum' ,
478
+ } ) ;
479
+ } ) ;
480
+
409
481
it ( 'emits ServerTimeGameEvent' , ( ) => {
410
482
gameSocketSubject$ . next ( '<prompt time="1703804031">></prompt>\n' ) ;
411
483
0 commit comments