bmc_hub/tests/js/company-contacts.test.cjs

11 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

const assert=require('node:assert/strict');global.window={};require('../../static/js/company-contacts.js');
const helpers={name:c=>`${c.first_name} ${c.last_name}`,phone:c=>c.phone||'',mobile:c=>c.mobile||'',actions:()=>''};
const contacts=[{id:1,first_name:'Ida',last_name:'Hansen',email:'ida@example.com',title:'Support',phone:'12345678',is_primary:true},{id:2,first_name:'Poul',last_name:'Larsen',title:'Salg'}];
assert.equal(window.CompanyContacts.filter(contacts,'support',false,helpers).length,1);
assert.equal(window.CompanyContacts.filter(contacts,'',true,helpers).length,1);
assert.equal(window.CompanyContacts.filter(contacts,'',false,helpers).length,2);
const malicious={id:3,first_name:'<script>',email:'a" onclick="bad',phone:'12" onclick="bad'};
const html=window.CompanyContacts.table(window.CompanyContacts.rows([...contacts,malicious],helpers));
assert(html.includes('Primær'));assert(html.includes('Mobil'));assert(html.includes('/contacts/1'));assert(!html.includes('<script>'));assert(!html.includes('href="mailto:a" onclick='));assert(!html.includes('href="tel:12" onclick='));
console.log('Shared customer/vendor contact table checks passed');