33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const vm = require('node:vm');
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
function loadScript(scriptPath, sandbox) {
|
|
const source = fs.readFileSync(scriptPath, 'utf8');
|
|
vm.runInNewContext(source, sandbox, { filename: scriptPath });
|
|
}
|
|
|
|
test('client row keys prefer the client name', () => {
|
|
const sandbox = {
|
|
window: null,
|
|
Date,
|
|
Array,
|
|
Number,
|
|
String,
|
|
Boolean,
|
|
Object,
|
|
Math,
|
|
console
|
|
};
|
|
sandbox.window = sandbox;
|
|
|
|
loadScript(path.join(__dirname, '..', 'src', 'web', 'public', 'js', 'web-ui-helpers.js'), sandbox);
|
|
|
|
const helpers = sandbox.window.webUiHelpers;
|
|
assert.equal(helpers.getClientRowKey({ client_name: 'Conference Left', screen_slug: 'alpha', deviceId: 'device-123', id: 'conn-1', clientId: 'client-1' }), 'Conference Left');
|
|
assert.equal(helpers.getClientRowKey({ client_name: 'Conference Right', screen_slug: 'beta', deviceId: 'device-123', id: 'conn-2', clientId: 'client-2' }), 'Conference Right');
|
|
assert.equal(helpers.getClientRowKey({ screen_slug: 'alpha', id: 'conn-1', clientId: 'client-1' }), 'alpha');
|
|
assert.equal(helpers.getClientRowKey({ clientId: 'client-1' }), 'client-1');
|
|
}); |