Files
wekan/tests/customFieldVisibilitySettings.test.cjs
T
Lauri Ojansivu 15b2b6c533 Board Settings / Card: one "Card field order" heading over two lists, with arrows on every row.
Board Settings / Card was a three-column table (Show on Card, Show on
Minicard, the name) with a separate "Card field order" list of arrows at the
bottom that reordered five sections of the opened card. It is one heading,
"Card field order", over two lists now: "Show on Minicard" in the board's
minicard order and "Show on Card" in its card order, every row of either
`[checkbox] [up] [down] icon label`. The checkbox is whether that side shows
the field, the arrows move it on that side only, and the icon and name are
the field's own. The two lists are independent because the two orders are: a
field can be third on the minicard and last on the card.

models/lib/cardFieldOrder.js is the arithmetic, pure and tested without
Meteor: each surface is a fixed head, reorderable sections of fields, and a
fixed tail. A field moves within its section; at the section's edge it moves
the whole section; a section's header (Labels, Members, Sort number,
Description title) stays first. What is stored is one flat array of field
keys per surface - `cardFieldOrder`, which the first #4448 filled with five
section keys that stay valid and expand to what they rendered (Members
carried Dependencies and Sort, Custom Fields carried Vote/Poker), and the new
`minicardFieldOrder`. Two board setters normalise before storing; the update
allow rule keeps them to a board admin. The REST cardFieldOrder endpoints
still speak in section keys, eight now.

cardDetails.jade renders its eight sections in the board's order and, inside
Labels, Dates, Members, Sort and Vote/Poker, the fields in theirs;
Dependencies and Sort are their own templates. minicard.jade renders every
block under the title through the minicard order, with the dates line and
the badge strip ordering their own fields. Every gate is unchanged.

The popup's rows are a table, models/lib/cardSettingsRows.js, that the
template draws twice, so no row is written out by hand and each checkbox
reads the helper it always read. The tests that looked for a row's class in
the template look in the table now; tests/cardSettingsCoverage.test.cjs
derives each layout's default order from the templates and pins the popup's
shape; tests/cardFieldOrderLayout.test.cjs pins the arithmetic and its
negatives. No new translation keys: the heading and arrow keys already
existed in every locale.

Thanks to xet7 !
2026-09-11 21:18:35 +03:00

47 lines
2.3 KiB
JavaScript

const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');
const test = require('node:test');
const root = path.resolve(__dirname, '..');
const read = file => fs.readFileSync(path.join(root, file), 'utf8');
const boards = read('models/boards.js');
const sidebar = read('client/components/sidebar/sidebar.js');
const sidebarTemplate = read('client/components/sidebar/sidebar.jade');
const details = read('client/components/cards/cardDetails.js');
const detailsTemplate = read('client/components/cards/cardDetails.jade');
const minicard = read('client/components/cards/minicard.js');
const minicardTemplate = read('client/components/cards/minicard.jade');
test('custom fields default on for cards and off for minicards', () => {
const cardSetting = boards.slice(boards.indexOf('allowsCustomFields: {'));
assert.match(cardSetting.slice(0, cardSetting.indexOf('},') + 2),
/defaultValue: true/);
const miniSetting = boards.slice(boards.indexOf('allowsCustomFieldsOnMinicard: {'));
assert.match(miniSetting.slice(0, miniSetting.indexOf('},') + 2),
/defaultValue: false/);
assert.match(details, /board\?\.allowsCustomFields !== false/);
assert.match(minicard, /board\?\.allowsCustomFieldsOnMinicard === true/);
});
test('card and minicard menus expose independent Custom Fields rows', () => {
// The rows of Board Settings / Card are a table the template draws from
// (models/lib/cardSettingsRows.js), not hand-written markup, so the
// handler classes and the label key are looked for there.
const rows = read('models/lib/cardSettingsRows.js');
assert.match(rows, /js-field-has-custom-fields'/);
assert.match(rows, /js-field-has-custom-fields-on-minicard/);
assert.match(rows, /label: \['custom-fields'\]/);
assert.match(sidebar, /'click \.js-field-has-custom-fields'/);
assert.match(sidebar, /\$set: \{ allowsCustomFields: !currentValue \}/);
assert.match(sidebar, /'click \.js-field-has-custom-fields-on-minicard'/);
assert.match(sidebar,
/\$set: \{ allowsCustomFieldsOnMinicard: !currentValue \}/);
});
test('each card surface is gated only by its matching setting', () => {
assert.match(detailsTemplate, /if canShowCustomFieldsOnCard[\s\S]*each customFieldsWD/);
assert.match(minicardTemplate,
/if showCustomFieldsOnMinicard[\s\S]*each customFieldsWD/);
});