bmc_hub/tests/js/case-v5-assignment.test.cjs
Christian 85e019783b Add comprehensive test coverage for case creation, assignment, and remote recovery
- Introduced tests for case creation commands, ensuring proper handling of UUIDs and payloads.
- Added tests for v5 assignment functionality, validating employee identification and group assignment.
- Implemented tests for remote recovery scenarios, including handling network failures and response validation.
- Created tests for hardware label generation and validation, ensuring proper URL formatting and QR code generation.
- Developed extensive tests for remote control functionality, covering connection isolation, command execution, and user permissions.
- Added tests for workflow timer registration, ensuring correct handling of timer states and ownership validation.
2026-10-15 12:17:09 +02:00

28 lines
1.7 KiB
JavaScript

const test=require('node:test');
const assert=require('node:assert/strict');
const fs=require('node:fs');
const vm=require('node:vm');
const source=fs.readFileSync('static/js/case-v5.js','utf8');
function fixture(groupId){
const nodes={v5UserSearch:{value:''},v5UserOptions:{children:[],replaceChildren(){this.children=[];},append(button){this.children.push(button);}}};
const context={members:[{user_id:7,display_name:'Christian Thomas',group_ids:[2,3]},{user_id:8,display_name:'Mette Jensen',group_ids:[4]}],groupId,userId:null,busy:false,pending:null,byId:id=>nodes[id],renderGroups(){},renderActions(){},document:{createElement(){return {setAttribute(key,value){this[key]=value;},addEventListener(type,fn){this[type]=fn;}};}}};
vm.createContext(context);
vm.runInContext(source.slice(source.indexOf(' function employeeInitials('),source.indexOf(' async function loadMembers()')),context);
context.renderUsers();
return {context,nodes};
}
test('initial buttons identify employees and infer their assignment group',()=>{
const {context,nodes}=fixture(2);
const buttons=nodes.v5UserOptions.children;
assert.deepEqual(buttons.map(b=>b.textContent),['CT','MJ']);
assert.equal(buttons[0].title,'Christian Thomas');
buttons[0].click();assert.equal(context.userId,7);assert.equal(context.groupId,2);
nodes.v5UserOptions.children[1].click();assert.equal(context.userId,8);assert.equal(context.groupId,4);
});
test('initials can be searched and an unrelated group is replaced',()=>{
const {context,nodes}=fixture(99);
nodes.v5UserSearch.value='ct';context.renderUsers();
assert.equal(nodes.v5UserOptions.children.length,1);
nodes.v5UserOptions.children[0].click();assert.equal(context.groupId,2);
});