Files
wekan/tests/descriptionListItems.test.cjs
T
Lauri Ojansivu 3cb089b8ca Checklist from description, action items, and search phrases.
The last three of the features other kanban apps call AI, done with plain
code (docs/Features/General/Assistants/Assistants.md):

- Checklists -> From description: the list lines of a card's description
  ("- ", "* ", "1. ", task boxes; never inside code blocks) previewed, then
  made into a checklist - ticked where the line was [x] - or into subtasks
  through addSubtaskCard.
- Create cards from action items, on a comment and in the card menu for its
  description: "TODO: ...", "- [ ] ..." and "@user ..." lines become cards
  at the top of the card's list, linking back to it, with the mentioned
  user as member when they are an active board member.
- Global search understands plain phrases in the reader's language - "my
  overdue cards", "due this week", "unassigned cards" and seven more - and
  runs them as its operators, saying which; a query with an operator in it
  is never rewritten.

Checklist from description and Action items are Show on Card rows of Board
Settings / Card and of the Admin Panel's Card fields; Search phrases is an
Admin Panel / Settings / Visibility / Features tick. Translated in every
language.

Thanks to xet7 !
2026-10-17 16:25:51 +03:00

46 lines
2.4 KiB
JavaScript

'use strict';
// Checklist or subtasks from a card's description
// (docs/Features/Cards/Checklist-From-Description.md).
//
// Run: node tests/descriptionListItems.test.cjs
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const { descriptionListItems, MAX_ITEMS } = require('../models/lib/descriptionListItems.js');
const ROOT = path.join(__dirname, '..');
const read = rel => fs.readFileSync(path.join(ROOT, rel), 'utf8');
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
console.log('descriptionListItems:');
test('every list form, with the task boxes ticked where written', () => {
const items = descriptionListItems('Plan\n- one\n* [x] two\n+ three\n1. four\n2) [ ] five\n[X] six\n - nested');
assert.deepStrictEqual(items.map(i => i.title), ['one', 'two', 'three', 'four', 'five', 'six', 'nested']);
assert.deepStrictEqual(items.map(i => i.checked), [false, true, false, false, false, true, false]);
});
test('paragraphs, headings, code blocks and empty items are not items (negative)', () => {
const md = 'Just text\n# Heading\n-not a list\n- \n```\n- inside code\n```\n~~~\n1. also code\n~~~\nafter';
assert.deepStrictEqual(descriptionListItems(md), []);
assert.deepStrictEqual(descriptionListItems(undefined), []);
assert.strictEqual(descriptionListItems(Array.from({ length: 300 }, (_, i) => `- ${i}`).join('\n')).length, MAX_ITEMS);
});
test('the Checklists section offers it behind Board Settings / Card, and makes items as the form does', () => {
const jade = read('client/components/cards/checklists.jade');
assert.match(jade, /if descriptionChecklistItemsOf card\n\s+a\.checklist-from-description\.js-checklist-from-description/);
const js = read('client/components/cards/fromText.js');
assert.match(js, /boardFlagOn\('allowsChecklistFromDescriptionOnCard', real\.boardId\)/);
assert.match(js, /ChecklistItems\.insert\(\{ title: item\.title, checklistId, cardId: card\._id, sort: itemSort, isFinished: item\.checked \}\)/);
assert.match(js, /Meteor\.callAsync\('addSubtaskCard', card\._id, item\.title, false\)/, 'subtasks through the server method');
const { CARD_SETTINGS_ROWS } = require('../models/lib/cardSettingsRows.js');
assert.ok(CARD_SETTINGS_ROWS.find(r => r.key === 'checklistFromDescription').card.field === 'allowsChecklistFromDescriptionOnCard');
});
console.log(`\ndescriptionListItems: ${passed} tests passed`);