Расширение «Моё время в Битрикс24»
Часы по задачам за месяц и остаток до нормы, через REST от сессии браузера. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
// Прогон mytime.js на поддельных DOM, BX и REST: node test/test_mytime.mjs
|
||||
import fs from 'node:fs';
|
||||
|
||||
const els = {};
|
||||
const el = id => (els[id] ??= { id, value: id === 'mytime-m' ? '2026-10' : '', textContent: '', innerHTML: '', style: {}, remove() {} });
|
||||
globalThis.window = globalThis;
|
||||
globalThis.alert = m => { throw new Error('alert: ' + m); };
|
||||
globalThis.document = {
|
||||
getElementById: id => (id === 'mytime' ? null : el(id)),
|
||||
createElement: () => ({ style: {}, set innerHTML(v) {}, remove() {} }),
|
||||
body: { append() {} },
|
||||
};
|
||||
globalThis.BX = { bitrix_sessid: () => 'S' };
|
||||
globalThis.myTimeConfig = { norm: 20 };
|
||||
|
||||
// 120 записей: 60 по задаче 1 (по 10 мин), 59 по задаче 2 (по 5 мин), одна сентябрьская — должна отсеяться
|
||||
const items = [];
|
||||
for (let i = 0; i < 60; i++) items.push({ TASK_ID: '1', SECONDS: '600', CREATED_DATE: '2026-10-05T10:00:00+03:00' });
|
||||
for (let i = 0; i < 59; i++) items.push({ TASK_ID: '2', SECONDS: '300', CREATED_DATE: '2026-10-06T10:00:00+03:00' });
|
||||
items.push({ TASK_ID: '3', SECONDS: '9999', CREATED_DATE: '2026-09-30T23:00:00+03:00' });
|
||||
|
||||
const calls = [];
|
||||
globalThis.fetch = async (url, opt) => {
|
||||
const method = url.match(/rest\/(.+)\.json/)[1];
|
||||
const p = JSON.parse(opt.body);
|
||||
calls.push(method);
|
||||
let result;
|
||||
if (method === 'user.current') result = { ID: '7' };
|
||||
else if (method === 'task.elapseditem.getlist') {
|
||||
if (p.FILTER.USER_ID !== '7') throw new Error('USER_ID not passed');
|
||||
const n = p.PARAMS.NAV_PARAMS;
|
||||
result = items.slice((n.iNumPage - 1) * n.nPageSize, n.iNumPage * n.nPageSize);
|
||||
} else if (method === 'tasks.task.list') result = { tasks: p.filter.ID.map(id => ({ id, title: 'T<' + id + '>' })) };
|
||||
return { json: async () => ({ result }) };
|
||||
};
|
||||
|
||||
eval(fs.readFileSync(new URL('../extension/mytime.js', import.meta.url), 'utf8'));
|
||||
await new Promise(r => setTimeout(r, 50));
|
||||
|
||||
const html = els['mytime-out'].innerHTML;
|
||||
const must = ['>10:00<', '>4:55<', '>14:55<', 'осталось <b>5:05</b>', 'T<1>', '/user/7/tasks/task/view/1/'];
|
||||
for (const s of must) if (!html.includes(s)) throw new Error('missing ' + s + '\n' + html);
|
||||
if (html.includes('#3')) throw new Error('September record counted');
|
||||
if (calls.filter(c => c === 'task.elapseditem.getlist').length !== 3) throw new Error('pages: ' + calls);
|
||||
console.log('ok');
|
||||
Reference in New Issue
Block a user