-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
packages/mixer-connection/src/lib/state/mixer-store.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { firstValueFrom, Subject } from 'rxjs'; | ||
import { MixerConnection } from '../mixer-connection'; | ||
import { MixerStore } from './mixer-store'; | ||
|
||
describe('Mixer Store', () => { | ||
let conn: { allMessages$: Subject<string> }; | ||
let mixerStore: MixerStore; | ||
|
||
function sendMessage(message: string): void { | ||
conn.allMessages$.next(message); | ||
} | ||
|
||
beforeEach(() => { | ||
conn = { | ||
allMessages$: new Subject<string>(), | ||
}; | ||
|
||
mixerStore = new MixerStore(conn as unknown as MixerConnection); | ||
}); | ||
|
||
it('should reduce channel sync state', async () => { | ||
sendMessage('BMSG^SYNC^mySyncId^5'); | ||
sendMessage('BMSG^SYNC^mySyncId^6'); | ||
sendMessage('BMSG^SYNC^mySyncId^10'); | ||
expect(await firstValueFrom(mixerStore.syncState$)).toEqual({ mySyncId: 10 }); | ||
|
||
sendMessage('BMSG^SYNC^SYNC_ID^8'); | ||
sendMessage('BMSG^SYNC^SYNC_ID^20'); | ||
expect(await firstValueFrom(mixerStore.syncState$)).toEqual({ mySyncId: 10, SYNC_ID: 20 }); | ||
|
||
sendMessage('BMSG^SYNC^mySyncId^44'); | ||
sendMessage('BMSG^SYNC^anotherSyncId^11'); | ||
expect(await firstValueFrom(mixerStore.syncState$)).toEqual({ | ||
mySyncId: 44, | ||
SYNC_ID: 20, | ||
anotherSyncId: 11, | ||
}); | ||
}); | ||
|
||
describe('state$', () => { | ||
it('should reduce SETD/SETS messages to state', async () => { | ||
sendMessage('SETD^i.3.mute^0'); | ||
sendMessage('SETD^i.4.mute^1'); | ||
sendMessage('SETS^i.10.name^channelname'); | ||
expect(await firstValueFrom(mixerStore.state$)).toEqual({ | ||
'i.3.mute': 0, | ||
'i.4.mute': 1, | ||
'i.10.name': 'channelname', | ||
}); | ||
|
||
sendMessage('SETS^i.10.name^anothername'); | ||
sendMessage('SETD^i.3.mute^1'); | ||
expect(await firstValueFrom(mixerStore.state$)).toEqual({ | ||
'i.3.mute': 1, | ||
'i.4.mute': 1, | ||
'i.10.name': 'anothername', | ||
}); | ||
}); | ||
|
||
it('should ignore messages other than SETD or SETS', async () => { | ||
sendMessage('SETD^abc^def'); | ||
|
||
sendMessage('FOO^bar^baz'); | ||
sendMessage('XYZ^xyz^xyz'); | ||
expect(await firstValueFrom(mixerStore.state$)).toEqual({ abc: 'def' }); | ||
}); | ||
}); | ||
}); |