mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
The opened card and the minicard now draw Card Settings' sections, in
Card Settings' order, each section's fields in the order of its rows:
- Section order is per side: cardSettingsSectionOrder for the card,
the new minicardSettingsSectionOrder for the minicard. A board that
stores none: the card starts with Labels, Date, Members, Card, ...
(the card's historical order as far as the grouping allows), the
minicard with what it drew first before.
- CARD_LAYOUT's and MINICARD_LAYOUT's reorderable sections are Card
Settings' sections, so dragging a section or a row in Card Settings
moves it on the card or the minicard. Stored field orders map: a
field keeps its place relative to the others of its new section.
- On the card every section has the shared heading (its icon, title,
caret and hamburger) - Voting and Planning Poker too, which had a
heading of their own. The minicard stays compact: no headings.
Card Settings shows both sides at once: the minicard's pane first (on
the left), the card's second, each with a caret that folds it, each
scrolling on its own, stacked when the popup is too narrow for two.
The Show radio is gone. A splitter between the panes changes their
widths by dragging, like spreadsheet columns (clamped, kept per user
as a fraction, reset by a double-click, moved by the arrow keys). The
popup is wider again for two panes and its corner grip resizes it,
the panes following.
A hamburger's content opens under its line inside the pane, not in a
popup: the hamburger shows it is open (aria-expanded, highlighted, the
panel attached to it); its button, the panel's X or Escape closes it.
A custom field's edit form and the + create form open inline the same
way and close only their panel when saved. The popup layer added in
9c9742e09d is removed, as nothing uses it now.
Docs: Card-Settings.md, Card-Fields.md and Board Settings / Card.md.
New tests cardSectionsOnCard, minicardSections, cardSettingsSplit,
cardSettingsInlinePanels and card-settings-sections-order.e2e.js; the
guards of the old layouts and orders say why they changed.
Thanks to xet7 !
186 lines
8.7 KiB
JavaScript
186 lines
8.7 KiB
JavaScript
'use strict';
|
|
|
|
// Unit test for the card-detail-view "field order" setting (#4448): a board can
|
|
// reorder the major sections of the opened card - move Description earlier
|
|
// (e.g. third) and have Custom Fields render right after it. Run:
|
|
// node tests/cardFieldOrder.test.cjs
|
|
//
|
|
// The pure decision under test is `applyCardFieldOrder()`, which turns a
|
|
// (possibly missing/partial/unknown-containing) stored order into a complete,
|
|
// valid ordering that always contains every known section exactly once - so
|
|
// the card can never render a section twice or drop one because of stale or
|
|
// corrupted board data.
|
|
|
|
const assert = require('assert');
|
|
const {
|
|
DEFAULT_CARD_FIELD_ORDER,
|
|
CARD_FIELD_ORDER_KEYS,
|
|
isValidCardFieldKey,
|
|
applyCardFieldOrder,
|
|
moveCardFieldKey,
|
|
} = require('../models/lib/cardFieldOrder');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
// --- default / fallback behaviour -------------------------------------------
|
|
// The "historical fixed order" is the section order cardDetails.jade rendered
|
|
// at 59f7d61df, before #4448 (131514d61) made it orderable: Labels, Dates,
|
|
// Members, Dependencies, Sort, Custom Fields, Vote/Poker, Description. The
|
|
// per-field sequence is pinned in
|
|
// tests/cardFieldOrderDefaultIsPreFeatureOrder.test.cjs.
|
|
test('no stored order at all falls back to the historical fixed order', () => {
|
|
// 2026-10-28: the sections are Card Settings' sections (the opened card
|
|
// draws those), in the order closest to the historical one the new grouping
|
|
// allows: Labels, Date, Members, Card (the old Dependencies and the first
|
|
// half of Sort), Time (the rest of Sort), Custom Fields, Vote, Poker,
|
|
// Description, Scrum, and the old fixed tail as sections. The order the card
|
|
// DRAWS them in is the board's cardSettingsSectionOrder now; this is still
|
|
// what the REST cardFieldOrder API returns.
|
|
assert.deepStrictEqual(DEFAULT_CARD_FIELD_ORDER,
|
|
['labels', 'date', 'members', 'card', 'time', 'customFields', 'vote', 'poker', 'description',
|
|
'scrum', 'checklists', 'subtasks', 'attachments', 'comments']);
|
|
assert.deepStrictEqual(applyCardFieldOrder(undefined), DEFAULT_CARD_FIELD_ORDER);
|
|
assert.deepStrictEqual(applyCardFieldOrder(null), DEFAULT_CARD_FIELD_ORDER);
|
|
assert.deepStrictEqual(applyCardFieldOrder([]), DEFAULT_CARD_FIELD_ORDER);
|
|
});
|
|
|
|
test('a non-array stored order falls back to the default order', () => {
|
|
assert.deepStrictEqual(applyCardFieldOrder('description'), DEFAULT_CARD_FIELD_ORDER);
|
|
assert.deepStrictEqual(applyCardFieldOrder({}), DEFAULT_CARD_FIELD_ORDER);
|
|
});
|
|
|
|
// --- the actual issue: move description earlier, custom fields after it ----
|
|
test('#4448: description can be moved to third, with custom fields right after it', () => {
|
|
const stored = ['labels', 'dates', 'description', 'customFields', 'members'];
|
|
// The five keys the first version of #4448 stored stay valid. Dependencies
|
|
// and Sort were a fixed appendage of Members then, Vote/Poker of Custom
|
|
// Fields; they are sections now (Board Settings / Card orders per field),
|
|
// so a legacy value expands to exactly what it rendered.
|
|
// 2026-10-28: the legacy keys expand to their FIELDS, which now sit in Card
|
|
// Settings' sections - Members' appendage is Card and Time, Custom Fields'
|
|
// is Vote and Poker - and the sections follow where their first field is.
|
|
assert.deepStrictEqual(applyCardFieldOrder(stored),
|
|
['labels', 'date', 'description', 'customFields', 'vote', 'poker', 'members', 'card', 'time',
|
|
// the rest, appended in default order
|
|
'scrum', 'checklists', 'subtasks', 'attachments', 'comments']);
|
|
const order = applyCardFieldOrder(stored);
|
|
assert.strictEqual(order.indexOf('description'), 2, 'description is third (0-indexed 2)');
|
|
assert.ok(
|
|
order.indexOf('customFields') > order.indexOf('description'),
|
|
'custom fields render after description',
|
|
);
|
|
});
|
|
|
|
// --- robustness: unknown / duplicate / partial values -----------------------
|
|
test('unknown keys in the stored order are dropped', () => {
|
|
const order = applyCardFieldOrder(['labels', 'bogus-section', 'date']);
|
|
assert.ok(!order.includes('bogus-section'));
|
|
assert.strictEqual(order.length, DEFAULT_CARD_FIELD_ORDER.length);
|
|
});
|
|
|
|
test('duplicate keys keep only the first occurrence', () => {
|
|
const order = applyCardFieldOrder(['description', 'description', 'labels']);
|
|
assert.strictEqual(order.filter(k => k === 'description').length, 1);
|
|
});
|
|
|
|
test('a partial stored order is completed with the missing known keys, appended in default order', () => {
|
|
const order = applyCardFieldOrder(['description', 'labels']);
|
|
assert.deepStrictEqual(order.slice(0, 2), ['description', 'labels']);
|
|
// The remaining keys (dates, members, customFields) follow, in their
|
|
// DEFAULT_CARD_FIELD_ORDER relative order.
|
|
const remaining = DEFAULT_CARD_FIELD_ORDER.filter(k => k !== 'description' && k !== 'labels');
|
|
assert.deepStrictEqual(order.slice(2), remaining);
|
|
});
|
|
|
|
test('every known section is present exactly once, regardless of input', () => {
|
|
const inputs = [
|
|
undefined,
|
|
[],
|
|
['description'],
|
|
['bogus', 'bogus', 'description', 'description'],
|
|
DEFAULT_CARD_FIELD_ORDER.slice().reverse(),
|
|
];
|
|
inputs.forEach(input => {
|
|
const order = applyCardFieldOrder(input);
|
|
assert.strictEqual(order.length, CARD_FIELD_ORDER_KEYS.length);
|
|
CARD_FIELD_ORDER_KEYS.forEach(key => {
|
|
assert.strictEqual(order.filter(k => k === key).length, 1, `key ${key} appears exactly once`);
|
|
});
|
|
});
|
|
});
|
|
|
|
// --- isValidCardFieldKey -----------------------------------------------------
|
|
test('isValidCardFieldKey recognises only the known section keys', () => {
|
|
assert.strictEqual(isValidCardFieldKey('description'), true);
|
|
assert.strictEqual(isValidCardFieldKey('customFields'), true);
|
|
// 2026-10-28: Checklists is a section of the card's order now (it was the
|
|
// fixed tail) - the sections are Card Settings'.
|
|
assert.strictEqual(isValidCardFieldKey('checklists'), true);
|
|
assert.strictEqual(isValidCardFieldKey('voteAndPoker'), false, 'a template group of before is not a section');
|
|
assert.strictEqual(isValidCardFieldKey(''), false);
|
|
assert.strictEqual(isValidCardFieldKey(undefined), false);
|
|
});
|
|
|
|
// --- moveCardFieldKey (Board Settings up/down buttons) ----------------------
|
|
test('moveCardFieldKey moves a section one step earlier', () => {
|
|
const order = moveCardFieldKey(DEFAULT_CARD_FIELD_ORDER, 'description', 'up');
|
|
assert.strictEqual(order.indexOf('description'), DEFAULT_CARD_FIELD_ORDER.indexOf('description') - 1);
|
|
});
|
|
|
|
test('moveCardFieldKey moves a section one step later', () => {
|
|
const order = moveCardFieldKey(DEFAULT_CARD_FIELD_ORDER, 'labels', 'down');
|
|
assert.strictEqual(order.indexOf('labels'), 1);
|
|
});
|
|
|
|
test('moveCardFieldKey at the top boundary is a no-op going up', () => {
|
|
const order = moveCardFieldKey(DEFAULT_CARD_FIELD_ORDER, 'labels', 'up');
|
|
assert.deepStrictEqual(order, DEFAULT_CARD_FIELD_ORDER);
|
|
});
|
|
|
|
test('moveCardFieldKey at the bottom boundary is a no-op going down', () => {
|
|
// The last section is Comments since 2026-10-28.
|
|
const order = moveCardFieldKey(DEFAULT_CARD_FIELD_ORDER, 'comments', 'down');
|
|
assert.deepStrictEqual(order, DEFAULT_CARD_FIELD_ORDER);
|
|
});
|
|
|
|
test('moveCardFieldKey with an unknown key is a no-op', () => {
|
|
const order = moveCardFieldKey(DEFAULT_CARD_FIELD_ORDER, 'bogus', 'up');
|
|
assert.deepStrictEqual(order, DEFAULT_CARD_FIELD_ORDER);
|
|
});
|
|
|
|
// --- NEGATIVE test: the jade template must not still hardcode the old fixed
|
|
// sequence for these sections - it renders from orderedCardFieldSections().
|
|
test('cardDetails.jade renders the reorderable sections from an order-driven loop, not a hardcoded sequence', () => {
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const jade = fs.readFileSync(
|
|
path.join(__dirname, '../client/components/cards/cardDetails.jade'),
|
|
'utf8',
|
|
);
|
|
// `each section in ...` rather than plain `each ...`: the plain form made the
|
|
// section name the data context and broke every section template and the
|
|
// popups opened from them (see tests/cardFieldSectionsKeepCardContext.test.cjs).
|
|
assert.ok(
|
|
jade.includes('each section in orderedCardFieldSections'),
|
|
'the card-details-items block must iterate the resolved order',
|
|
);
|
|
// Each reorderable section must be reachable only through its own named
|
|
// template (called from the order loop), not inlined at a fixed spot.
|
|
CARD_FIELD_ORDER_KEYS.forEach(key => {
|
|
// Comments keep their own template, drawn in the right column too.
|
|
const templateName = key === 'comments' ? 'cardCommentsSection'
|
|
: `cardFieldSection${key.charAt(0).toUpperCase()}${key.slice(1)}`;
|
|
assert.ok(
|
|
jade.includes(`template(name="${templateName}")`),
|
|
`${templateName} must be its own template`,
|
|
);
|
|
});
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|