bmc_hub/tests/js/case-command-suggestions.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

13 lines
2.2 KiB
JavaScript

const test=require('node:test');const assert=require('node:assert/strict');const {suggest}=require('../../static/js/case-command-suggestions.js');
const users=[{user_id:3,username:'ct',full_name:'Christian Thomas'}];
test('command choice continues with values rather than a full canned example',()=>{const rows=suggest('/ti',3);assert.equal(rows.find(r=>r.label==='/tid').value,'/tid ');assert.ok(suggest('/tid ',5).some(r=>r.value==='30m '));});
test('completion follows time category and description',()=>{assert.ok(suggest('/tid 30m re',11).some(r=>r.value==='research '));assert.ok(suggest('/tid 30m research ',18).some(r=>r.value==='"" ' && r.caret===1));});
test('employee completion filters initials and uses an unambiguous identifier',()=>{const row=suggest('/tildel ct',10,{users})[0];assert.equal(row.label,'Christian Thomas');assert.equal(row.value,'ct ');});
test('replacement preserves existing explanation and handles mid-command caret',()=>{let line='/tildel ct "Bestil varer"';const row=suggest(line,10,{users})[0];assert.equal(line.slice(0,row.from)+row.value+line.slice(row.to),'/tildel ct "Bestil varer"');const command=suggest('/tildel',3)[0];assert.equal(command.to,7);});
test('subcase groups, dates and todo employee choices',()=>{assert.equal(suggest('//gruppe Sup',12,{groups:[{name:'Support'}]})[0].value,'"Support" ');assert.equal(suggest('/udsat i m',10)[0].value,'i morgen');assert.equal(suggest('/todo "Bestil" @ct',18,{users})[0].value,'@ct ');});
test('text commands insert quotes with the caret between them, including child scope',()=>{for(const prefix of ['/', '//'])for(const name of ['todo','undersag','note','mail','løsning']){const row=suggest(prefix+name,(prefix+name).length).find(r=>r.label===prefix+name);assert.equal(row.value,prefix+name+' ""');assert.equal(row.value[row.caret-1],'"');assert.equal(row.value[row.caret],'"');}});
test('child assignment inserts initials, never the numeric user ID',()=>{const row=suggest('//tildel ct',11,{users})[0];assert.equal(row.value,'ct ');});
test('duplicate initials use a unique username',()=>{const people=[...users,{user_id:4,username:'carlt',full_name:'Carl Thomsen'}];const row=suggest('/tildel Carl',12,{users:people})[0];assert.equal(row.value,'carlt ');});