Files
wekan/tests/importExportDocsCoverage.test.cjs
T
Lauri Ojansivu 7e1f9e89eb Docs: every feature topic in one folder under docs/Features, each with README.md as its main page.
- The General/ level is gone: its 109 files moved up into the folders of the
  same name, and its topic table is the "Shared topics" section of
  Features.md.
- Accessibility is one folder, docs/Features/Accessibility/, with the Admin
  Panel's accessibility page in it.
- Every folder's main page is README.md (110 X/X.md pages renamed with git mv,
  five merged with an existing README.md, 26 index pages added for folders
  that had none), so a folder opened on GitHub shows its page.
- The 73 "# Moved" forwarding pages are deleted, with the folders that held
  only them; every link that went to one goes to its final page.
- docs/Features/README.md has the website's "Features in WeKan" overview,
  each feature linking to its page here.

1,129 Markdown links in 262 files and 352 doc paths in code, tests, compose,
snap and release files follow. tests/docsFeaturesLayout.test.cjs fails when
General/ or a "# Moved" page comes back, a folder has no README.md, or a
relative link in the docs or README.md does not resolve.

Thanks to xet7 !
2026-11-24 20:02:06 +02:00

124 lines
8.7 KiB
JavaScript

'use strict';
// docs/Features/Board-Sidebar/Board-Settings/Import-Export/External-Tools.md is the page the README links
// for "what can WeKan import and export". It went stale once (ten tools when
// WeKan read fifty), so every source on the import page and every format in
// the export menu has to be named on it. Run:
// node tests/importExportDocsCoverage.test.cjs
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const read = file => fs.readFileSync(path.join(__dirname, '..', file), 'utf8');
const doc = read('docs/Features/Board-Sidebar/Board-Settings/Import-Export/External-Tools.md');
// The import page's sources are the one list it reads (models/lib/importSources.js).
const importPage = read('models/lib/importSources.js');
const exportMenu = read('client/components/boards/exportScope.js');
let passed = 0;
const test = (name, fn) => { fn(); passed += 1; console.log(' ok -', name); };
// How a name in the code is written on the page, when it differs.
const ON_PAGE = { 'CSV / TSV': 'CSV / TSV', 'NextCloud Deck': 'Nextcloud Deck', '(,)': 'CSV', '(;)': 'CSV', 'Org mode': 'Org mode' };
const named = name => doc.includes(ON_PAGE[name] || name);
test('every import source is on the page', () => {
const sources = [...importPage.matchAll(/\{ key: '([a-z]+)', name: '([^']+)'/g)].map(m => m[2]);
assert.ok(sources.length >= 40, `the import sources are found (${sources.length})`);
assert.deepEqual(sources.filter(name => !named(name)), []);
});
test('every export format is on the page', () => {
const labels = [
...[...exportMenu.matchAll(/key: '[a-z-]+', icon: '[^']+', label: '([^']+)', path: 'export\//g)].map(m => m[1]),
...[...exportMenu.matchAll(/\['[a-z]+', '([^']+)'\]/g)].map(m => m[1]),
];
assert.ok(labels.length >= 40, `the export formats are found (${labels.length})`);
assert.deepEqual(labels.filter(label => !named(label)), []);
assert.match(doc, /\| \[Wrike workflow\]\(\.\/Wrike\/README\.md\) \|/, 'the Wrike workflow has its own row, linking its page');
});
test('the README links the page from its import and export lists', () => {
const readme = read('README.md');
assert.match(readme, /Add Board \/ Import \(\[all import and export formats\]\(docs\/Features\/Board-Sidebar\/Board-Settings\/Import-Export\/External-Tools\.md\)\):/);
assert.match(readme, /Export to \(\[all formats\]\(docs\/Features\/Board-Sidebar\/Board-Settings\/Import-Export\/External-Tools\.md\)\):/);
});
// Each import source and export format has a directory of its own under
// docs/Features/Board-Sidebar/Board-Settings/Import-Export, with the steps and the details, linked from the
// coverage index (which used to hold every format's details in one table).
const DIRECTORY = {
wekan: 'WeKan', json: 'WeKan', 'json-no-attachments': 'WeKan', zip: 'WeKan', trello: 'Trello', 'trello-api': 'Trello', trellozip: 'Trello', csv: 'CSV', scsv: 'CSV', tsv: 'CSV',
excel: 'Excel', pdf: 'PDF', html: 'HTML', ical: 'iCalendar', 'dep-json': 'Dependencies', 'dep-svg': 'Dependencies', jira: 'Jira',
kanboard: 'Kanboard', deck: 'Nextcloud-Deck', openproject: 'OpenProject', github: 'GitHub', gitlab: 'GitLab', gitea: 'Gitea',
forgejo: 'Forgejo', asana: 'Asana', zenkit: 'ZenKit', markdown: 'Markdown', leo: 'Leo', opml: 'OPML', orgmode: 'Org-mode',
todotxt: 'Todo-txt', taskwarrior: 'Taskwarrior', focalboard: 'Focalboard', todoist: 'Todoist', planner: 'Microsoft-Planner',
meistertask: 'MeisterTask', obsidian: 'Obsidian-Kanban', linear: 'Linear', ticktick: 'TickTick', clickup: 'ClickUp',
nullboard: 'Nullboard', kanri: 'Kanri', pivotal: 'Pivotal-Tracker', redmine: 'Redmine', tasksorg: 'Tasks-org',
monday: 'monday-com', superproductivity: 'Super-Productivity', taiga: 'Taiga', vikunja: 'Vikunja', wrike: 'Wrike',
wrikeworkflow: 'Wrike', teamwork: 'Teamwork', businessmap: 'Businessmap', quire: 'Quire', notion: 'Notion', plane: 'Plane',
planka: 'Planka', mstodo: 'Microsoft-To-Do', kanbanflow: 'KanbanFlow', basecamp: 'Basecamp', googletasks: 'Google-Tasks',
googlekeep: 'Google-Keep',
mail: 'Mail', mbox: 'Mail', googletakeout: 'Google-Takeout', slack: 'Slack', mattermost: 'Mattermost',
telegram: 'Telegram', whatsapp: 'WhatsApp', discord: 'Discord', evernote: 'Evernote', enex: 'Evernote',
rocketchat: 'Rocket-Chat', fizzy: 'Fizzy',
wordpress: 'Website', wordpressjson: 'Website', ghost: 'Website', blogger: 'Website', markdownsite: 'Website',
htmlsite: 'Website', substack: 'Website',
azuredevops: 'Azure-DevOps', mslists: 'Microsoft-Lists', msproject: 'Microsoft-Project', outlook: 'Microsoft-Outlook',
teams: 'Microsoft-Teams', onenote: 'Microsoft-OneNote',
sandstormwekan: 'Sandstorm', sandstormprioritize: 'Sandstorm', sandstormyatl: 'Sandstorm', sandstormmutodo: 'Sandstorm', sandstormsandchat: 'Sandstorm', sandstormethercalc: 'Sandstorm', sandstormradicalecalendar: 'Sandstorm', sandstormradicalecontacts: 'Sandstorm', sandstormdavros: 'Sandstorm', sandstormhackercms: 'Sandstorm', sandstormgogs: 'Sandstorm', sandstormwordpress: 'Sandstorm',
};
// Every feature page in docs/Features follows one structure: What it is, Read
// more, How to use it, How the numbers are calculated, How it works in WeKan,
// Commits. A format page keeps its own steps and details as subsections of
// that structure: the import and export steps and the REST API under How to
// use it, the format details and what is and is not kept under How it works in
// WeKan. (They were top-level sections, with the sources in a section of their
// own, until the pages took the shared structure; the sources are now under
// Read more.) The order is pinned, so a page cannot drift back to a shape of
// its own.
const HEADINGS = ['## What it is', '## Read more', '## How to use it', '### How to import',
'### How to import many boards at once', '### How to export', '### How to export all boards at once',
'### REST API', '## How the numbers are calculated', '## How it works in WeKan', '### Format details',
'### What is kept', '### What is not kept', '### How it is built and tested', '## Commits'];
test('every import source and export format has its own page, with the steps and details, linked from the index', () => {
const keys = [
...[...importPage.matchAll(/\{ key: '([a-z]+)', (?:name: '[^']+'|product: true)/g)].map(m => m[1]),
...[...exportMenu.matchAll(/\{ key: '([a-z-]+)', icon: '[^']+'/g)].map(m => m[1]),
...[...exportMenu.matchAll(/\['([a-z]+)', '[^']+'\]/g)].map(m => m[1]),
...[...exportMenu.matchAll(/^\s+key: '([a-z-]+)',$/gm)].map(m => m[1]).filter(key => !['files', 'calendar', 'dependencies', 'csv', 'json', 'tools'].includes(key) || key === 'zip'),
];
const unmapped = [...new Set(keys)].filter(key => !DIRECTORY[key] && !['files', 'calendar', 'dependencies', 'json', 'tools', 'other'].includes(key));
assert.deepEqual(unmapped, [], 'a format with no directory page');
const index = read('docs/Features/Board-Sidebar/Board-Settings/Import-Export/Format-Coverage.md');
for (const dir of new Set(Object.values(DIRECTORY))) {
const page = read(`docs/Features/Board-Sidebar/Board-Settings/Import-Export/${dir}/README.md`);
// A heading is matched as text: its characters are escaped, not read as
// regular-expression syntax.
const at = HEADINGS.map(h => page.search(new RegExp(`^${h.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`, 'm')));
assert.ok(at.every(i => i !== -1), `${dir}.md has every section: ${HEADINGS.filter((h, i) => at[i] === -1).join(', ')}`);
assert.deepEqual([...at].sort((x, y) => x - y), at, `${dir}.md has them in order`);
assert.ok(index.includes(`](./${dir}/README.md)`), `the coverage index links ${dir}`);
assert.doesNotMatch(page, /\/api\/boards\/export-all\//, `${dir}.md names the mass export route as it is`);
const commits = page.slice(page.search(/^## Commits$/m));
assert.match(commits, /^ - \[[^\]]+\]\(https:\/\/github\.com\/wekan\/wekan\/commit\/[0-9a-f]{40}\)$/m, `${dir}.md links its commits`);
assert.doesNotMatch(page, /TODO_(?:WHAT|READMORE|NUMBERS|WORKS|COMMITS)/, `${dir}.md has no placeholder left`);
}
});
test('the coverage index holds no format\'s details any more, only the index and the shared contract', () => {
const index = read('docs/Features/Board-Sidebar/Board-Settings/Import-Export/Format-Coverage.md');
assert.doesNotMatch(index, /^\| Format \| Current authoritative shape/m);
assert.doesNotMatch(index, /^## Current external adapter checkpoint/m);
assert.match(index, /^## Formats$/m);
assert.match(index, /^## Many boards at once$/m);
assert.match(index, /^## One validation and sanitization boundary$/m);
});
test('negative: a name missing from the page is caught', () => {
assert.equal(named('Some Tool WeKan Does Not Know'), false);
});
console.log(`\nimportExportDocsCoverage: ${passed} checks passed`);