Files
wekan/tests/chartExportRows.test.cjs
T
Lauri Ojansivu 3abc1078c2 Implement the 10 board report charts and Gantt/chart PDF+Excel export.
The Board View menu's Dashboard, Burndown, Burnup, Cumulative Flow, Control
Chart, Lead/Cycle Time, Flow Efficiency, Throughput Histogram and WIP Run
entries opened a plain "not implemented yet" page. Each now computes and
renders its chart from this board's own Cards/Lists/Activities, per
docs/Features/Reports/charts.tsv's calculation descriptions - plain HTML/CSS
bars and a data table, no new charting dependency.

Every chart page, and the Gantt view, gets "Export to PDF" / "Export to
Excel" buttons that reuse the existing card/board export renderers
(pdfDocument's line/bar builder, createWorkbook's Excel styling) through the
same public-board / authToken / logged-in-user auth gate every other export
route already uses.

Completion date is card.endAt || card.archivedAt (WeKan has no dedicated
"Done" list flag); WIP Run's limit line only draws when a list's own WIP
limit is enabled (no invented board-level schema); Flow Efficiency's
"active" time is card.spentTime (WeKan does not track per-list queue time).
Each deviation from charts.tsv is documented where the calculation is.

models/lib/chartCalculations.js (20 tests), models/lib/chartExportRows.js
(8 tests) and the export routes' auth shape (10 tests) are covered by
tests/chartCalculations.test.cjs, tests/chartExportRows.test.cjs and
tests/chartExportRoutesAuth.test.cjs; tests/boardViewMenu.test.cjs is
updated for the now-real views. Not verified here: actual Blaze rendering
and generated PDF/XLSX bytes (no browser/Meteor runtime in this
environment) - matched syntactically against statsView/timeView and the
existing exporters.
2026-09-10 15:04:05 +03:00

71 lines
2.7 KiB
JavaScript

'use strict';
// The chart-export table shape (models/lib/chartExportRows.js), shared by the
// chart PDF and Excel exporters (models/server/ExporterChartPDF.js,
// models/server/ExporterChartExcel.js).
//
// Run: node tests/chartExportRows.test.cjs
const assert = require('assert');
const { chartExportRows, chartTitle } = require('../models/lib/chartExportRows');
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
console.log('chartExportRows:');
test('chartTitle falls back to English when no translator is given', () => {
assert.strictEqual(chartTitle('burndown'), 'Burndown');
});
test('chartTitle calls the translator with the i18n key and fallback', () => {
const title = chartTitle('burndown', (key, fallback) => `${key}/${fallback}`);
assert.strictEqual(title, 'board-view-burndown/Burndown');
});
test('cumulativeFlow rows have one column per list, in list order', () => {
const data = {
lists: [{ _id: 'l1', title: 'Todo' }, { _id: 'l2', title: 'Done' }],
series: [{ day: '2026-01-01', counts: { l1: 2, l2: 1 } }],
};
const { headers, rows } = chartExportRows('cumulativeFlow', data);
assert.deepStrictEqual(headers, ['Date', 'Todo', 'Done']);
assert.deepStrictEqual(rows[0], ['2026-01-01', 2, 1]);
});
test('wipRun rows show a dash when no WIP limit was set on the board', () => {
const { rows } = chartExportRows('wipRun', { series: [{ day: '2026-01-01', count: 3, limit: null }] });
assert.deepStrictEqual(rows[0], ['2026-01-01', 3, '-']);
});
test('burndown table has an empty-board row with zero remaining', () => {
const { rows } = chartExportRows('burndown', { series: [{ day: '2026-01-01', remaining: 0, ideal: 0 }] });
assert.deepStrictEqual(rows[0], ['2026-01-01', 0, 0]);
});
test('dashboard table groups sections with a blank separator row', () => {
const { rows } = chartExportRows('dashboard', {
byAssignee: [{ label: 'Alice', count: 2, percent: 100 }],
byLabel: [],
byList: [],
});
assert.strictEqual(rows[0][0], 'Assignees');
assert.deepStrictEqual(rows[1], ['Alice', '2 (100%)']);
});
test('gantt rows carry the card title and its three dates', () => {
const { headers, rows } = chartExportRows('gantt', {
cards: [{ title: 'Task 1', startAt: '2026-01-01', dueAt: '2026-01-05', endAt: null }],
});
assert.strictEqual(headers.length, 4);
assert.deepStrictEqual(rows[0], ['Task 1', '2026-01-01', '2026-01-05', '-']);
});
test('an unknown chart key returns an empty table rather than throwing', () => {
const { headers, rows } = chartExportRows('notAChart', {});
assert.deepStrictEqual(headers, []);
assert.deepStrictEqual(rows, []);
});
console.log(`chartExportRows: ${passed} passed`);