-
Notifications
You must be signed in to change notification settings - Fork 20
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
1 parent
10dbf34
commit f5afd01
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
packages/timeline-state-resolver/src/service/__tests__/ConnectionManager.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,54 @@ | ||
import { DeviceType, OSCDeviceType } from 'timeline-state-resolver-types' | ||
import { ConstructedMockDevices, MockDeviceInstanceWrapper } from '../../__tests__/mockDeviceInstanceWrapper' | ||
import { ConnectionManager } from '../ConnectionManager' | ||
|
||
// Mock explicitly the 'dist' version, as that is what threadedClass is being told to load | ||
jest.mock('../../../dist/service/DeviceInstance', () => ({ | ||
DeviceInstanceWrapper: MockDeviceInstanceWrapper, | ||
})) | ||
jest.mock('../DeviceInstance', () => ({ | ||
DeviceInstanceWrapper: MockDeviceInstanceWrapper, | ||
})) | ||
|
||
describe('ConnectionManager', () => { | ||
const connManager = new ConnectionManager() | ||
|
||
test('adding/removing a device', async () => { | ||
let resolveAdded: undefined | (() => void) = undefined | ||
const psAdded = new Promise<void>((resolveCb) => (resolveAdded = resolveCb)) | ||
connManager.on('connectionAdded', () => { | ||
if (resolveAdded) resolveAdded() | ||
}) | ||
|
||
let resolveRemoved: undefined | (() => void) = undefined | ||
const psRemoved = new Promise<void>((resolveCb) => (resolveRemoved = resolveCb)) | ||
connManager.on('connectionRemoved', () => { | ||
if (resolveRemoved) resolveRemoved() | ||
}) | ||
|
||
connManager.setConnections( | ||
new Map( | ||
Object.entries({ | ||
osc0: { | ||
type: DeviceType.OSC, | ||
options: { | ||
host: '127.0.0.1', | ||
port: 5250, | ||
type: OSCDeviceType.UDP, | ||
}, | ||
}, | ||
}) | ||
) | ||
) | ||
|
||
await psAdded | ||
|
||
expect(ConstructedMockDevices['osc0']).toBeTruthy() | ||
|
||
connManager.setConnections(new Map()) | ||
|
||
await psRemoved | ||
|
||
expect(ConstructedMockDevices['osc0']).toBeFalsy() | ||
}) | ||
}) |