Add multi-player and remote bridge support
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const vm = require('node:vm');
|
||||
|
||||
test('system status shows connected player count in the live feed label', () => {
|
||||
const script = fs.readFileSync(require.resolve('../src/web/public/js/system-status.js'), 'utf8');
|
||||
const elements = {
|
||||
'sidebar-status-dot': {
|
||||
classList: {
|
||||
remove() {},
|
||||
add() {}
|
||||
},
|
||||
setAttribute() {}
|
||||
},
|
||||
'sidebar-status-text': {
|
||||
textContent: ''
|
||||
}
|
||||
};
|
||||
const sockets = [];
|
||||
|
||||
const context = {
|
||||
document: {
|
||||
getElementById(id) {
|
||||
return elements[id] || null;
|
||||
}
|
||||
},
|
||||
window: {
|
||||
WebSocket: true,
|
||||
location: {
|
||||
protocol: 'http:',
|
||||
host: 'example.test'
|
||||
},
|
||||
setTimeout() {
|
||||
return 1;
|
||||
},
|
||||
clearTimeout() {},
|
||||
webHandleDashboardState() {}
|
||||
},
|
||||
WebSocket: function MockWebSocket(url) {
|
||||
this.url = url;
|
||||
sockets.push(this);
|
||||
this.close = function () {};
|
||||
},
|
||||
JSON: JSON,
|
||||
Number: Number,
|
||||
String: String,
|
||||
Boolean: Boolean,
|
||||
Array: Array,
|
||||
Object: Object,
|
||||
Math: Math,
|
||||
setTimeout() {},
|
||||
clearTimeout() {},
|
||||
console: console
|
||||
};
|
||||
context.window.document = context.document;
|
||||
context.window.WebSocket = context.WebSocket;
|
||||
|
||||
vm.runInNewContext(script, context);
|
||||
|
||||
assert.equal(sockets.length, 1);
|
||||
sockets[0].onmessage({
|
||||
data: JSON.stringify({
|
||||
type: 'dashboard-state',
|
||||
state: {
|
||||
screens: [{ slug: 'alpha' }],
|
||||
playerServiceConnected: true,
|
||||
connectedPlayersCount: 4
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
assert.equal(elements['sidebar-status-text'].textContent, 'Live player feed - 4 players connected');
|
||||
});
|
||||
|
||||
test('system status shows an explicit idle label when no players are connected', () => {
|
||||
const script = fs.readFileSync(require.resolve('../src/web/public/js/system-status.js'), 'utf8');
|
||||
const elements = {
|
||||
'sidebar-status-dot': {
|
||||
classList: {
|
||||
remove() {},
|
||||
add() {}
|
||||
},
|
||||
setAttribute() {}
|
||||
},
|
||||
'sidebar-status-text': {
|
||||
textContent: ''
|
||||
}
|
||||
};
|
||||
const sockets = [];
|
||||
|
||||
const context = {
|
||||
document: {
|
||||
getElementById(id) {
|
||||
return elements[id] || null;
|
||||
}
|
||||
},
|
||||
window: {
|
||||
WebSocket: true,
|
||||
location: {
|
||||
protocol: 'http:',
|
||||
host: 'example.test'
|
||||
},
|
||||
setTimeout() {
|
||||
return 1;
|
||||
},
|
||||
clearTimeout() {},
|
||||
webHandleDashboardState() {}
|
||||
},
|
||||
WebSocket: function MockWebSocket(url) {
|
||||
this.url = url;
|
||||
sockets.push(this);
|
||||
this.close = function () {};
|
||||
},
|
||||
JSON: JSON,
|
||||
Number: Number,
|
||||
String: String,
|
||||
Boolean: Boolean,
|
||||
Array: Array,
|
||||
Object: Object,
|
||||
Math: Math,
|
||||
setTimeout() {},
|
||||
clearTimeout() {},
|
||||
console: console
|
||||
};
|
||||
context.window.document = context.document;
|
||||
context.window.WebSocket = context.WebSocket;
|
||||
|
||||
vm.runInNewContext(script, context);
|
||||
|
||||
assert.equal(sockets.length, 1);
|
||||
sockets[0].onmessage({
|
||||
data: JSON.stringify({
|
||||
type: 'dashboard-state',
|
||||
state: {
|
||||
screens: [{ slug: 'alpha' }],
|
||||
playerServiceConnected: true,
|
||||
connectedPlayersCount: 0
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
assert.equal(elements['sidebar-status-text'].textContent, 'Player feed online - no players connected');
|
||||
});
|
||||
Reference in New Issue
Block a user