Files
wekan/tests/cardSectionCollapse.test.cjs
T
Lauri Ojansivu c8bcc4817d Accessibility: fix the findings of the axe-core audit in the default theme.
The default theme's blue is #2573a7, so the header's white and #f2f2f2 text
passes WCAG AA; label colours, quiet greys and grey tiles have text that
passes too. The Starred menu, the user menu and initials avatars carry their
visible text in their accessible name. The card's Pomodoro field and the
comment and description editors have a name. A card section heading is an h3
holding a real button with aria-expanded, and its menu and layout toggle sit
beside it. The sign-in form is the main landmark with a level-one title, every
page has a level-one heading, and the shortcuts list is reachable by keyboard.

After the fixes axe-core finds no violation on 22 pages. Spec 45 runs the scan
and tests/accessibilityAuditFixes.test.cjs pins each fault by its shape.

Thanks to xet7 !
2026-11-02 16:08:32 +02:00

448 lines
25 KiB
JavaScript

'use strict';
// Every section of an opened card collapses, from its own caret.
// Run: node tests/cardSectionCollapse.test.cjs
//
// A card had ONE caret, in its header, which collapsed the whole card - and
// Activities had an EYE beside its heading. Everything else was a heading with
// no control at all, and the `hr`s between sections were written by hand where
// somebody remembered one.
//
// Now each section - Labels, Date Format, Members, Dependencies, Sort, Custom
// Fields, Description, Checklists, Subtasks, Attachments, Comments and
// Activities - has a caret that collapses it, and one rule above it. Both come
// from ONE template, `cardSectionHeader`, so eleven sections cannot end up with
// ten separators and nine carets.
//
// 2026-10-28: the sections are Card Settings' sections (Labels, Date, Members,
// Card, Time, Custom Fields, Description, Scrum settings, Checklists, Subtasks,
// Attachments, Comments - models/lib/cardSettingsSections.js), each with ONE
// heading of its own - the section's icon and title - and the fields under it
// with plain titles. Before, a group's heading was its FIRST field's title
// (Labels, Members, Sort); that cannot be when the fields of a section can be
// dragged into any order. Vote and Planning Poker have the same heading, with
// Edit voting / Edit Planning Poker as its hamburger and the end date under it.
//
// Activities starts CLOSED and everything else open: a card is opened to read
// the card, and its history is the thing you go looking for.
//
// THE EYE WAS NOT THE SAME AS THE CARET, which is worth writing down because it
// looks like a straight swap. `showActivities: false` - the default - subscribed
// to `activityType: 'addComment'` ONLY (server/publications/activities.js), so
// the eye chose between "comments" and "the whole history" as well as showing
// and hiding. With it gone: a closed section subscribes to nothing at all, and
// an opened one asks for the whole history.
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const ROOT = path.join(__dirname, '..');
const read = rel => fs.readFileSync(path.join(ROOT, rel), 'utf8');
const jade = read('client/components/cards/cardDetails.jade');
const customFieldsJade = read('client/components/cards/cardCustomFields.jade');
const js = read('client/components/cards/cardDetails.js');
const css = read('client/components/cards/cardDetails.css');
const activities = read('client/components/activities/activities.js');
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
console.log('cardSectionCollapse:');
const SECTIONS = [
'labels', 'date', 'members', 'card', 'time', 'customFields', 'description', 'scrum',
'checklists', 'subtasks', 'attachments', 'comments', 'activities',
];
const template = name => jade.slice(jade.indexOf(`template(name="${name}")`)).split('\ntemplate(')[0];
// The section templates whose heading is the section's own and whose fields
// all fold under it.
const FOLDING = {
labels: 'cardFieldSectionLabels', date: 'cardFieldSectionDate', members: 'cardFieldSectionMembers',
card: 'cardFieldSectionCard', time: 'cardFieldSectionTime', scrum: 'cardFieldSectionScrum',
attachments: 'cardFieldSectionAttachments',
};
test('every named section has a caret header', () => {
for (const section of SECTIONS) {
assert.ok(new RegExp(`\\+cardSectionHeader\\(section="${section}"`).test(jade),
`${section} has a section header`);
}
});
test('and its content is behind that section\'s own switch', () => {
for (const section of SECTIONS) {
if (section === 'checklists') {
// A hidden heading must not leave previously collapsed content unreachable.
assert.ok(/if checklistSectionOpen/.test(jade));
const body = js.match(/checklistSectionOpen\(\) \{([\s\S]*?)\n \}/)[1];
const open = new Function('ReactiveCache', 'isCardSectionOpen', body);
for (const allowsChecklistTitle of [undefined, true, false]) {
for (const saved of [false, true]) {
assert.strictEqual(open.call({ boardId: 'board' }, {
getBoard: id => { assert.strictEqual(id, 'board'); return { allowsChecklistTitle }; },
}, key => { assert.strictEqual(key, 'checklists'); return saved; }),
allowsChecklistTitle === false || saved);
}
}
continue;
}
assert.ok(new RegExp(`isSectionOpen "${section}"`).test(jade),
`${section} collapses`);
}
});
test('the rule and the caret come from ONE template', () => {
const header = jade.slice(jade.indexOf('template(name="cardSectionHeader")'));
assert.ok(/hr\.card-details-section-rule/.test(header.slice(0, 400)),
'the separator is part of the header');
assert.ok(/js-toggle-card-section/.test(header.slice(0, 1400)), 'and so is the toggle');
// Which is what stops a section from having a rule and no caret, or two rules.
const headers = (jade.match(/\+cardSectionHeader\(section=/g) || []).length;
assert.ok(headers >= SECTIONS.length,
`every section uses it (${headers} of ${SECTIONS.length})`);
});
test('Activities starts collapsed, everything else open', () => {
assert.ok(/COLLAPSED_BY_DEFAULT = \['activities'\]/.test(js),
'activities is the one that starts closed');
assert.ok(/state === undefined \? true : state/.test(js),
'and an unknown section defaults to OPEN - a new one must show up, not hide');
});
test('the caret mirrors in RTL, and only when closed', () => {
// The rule lives in one module, shared with the board sidebar's Activities
// heading: the same control must not point different ways in one language.
assert.ok(/caretClassFor\(isCardSectionOpen\(section\)\)/.test(js),
'the card asks the shared rule');
const caret = fs.readFileSync(
path.join(ROOT, 'client/lib/sectionCaret.js'), 'utf8');
assert.ok(/if \(isOpen\) return 'fa-caret-down'/.test(caret),
'open is always down');
assert.ok(/rtl \? 'fa-caret-left' : 'fa-caret-right'/.test(caret),
'closed points the way the reader reads');
assert.ok(/getLanguageDirection/.test(caret), 'read from the language, not guessed');
});
test('the heading is operable by keyboard, not only by mouse', () => {
const header = jade.slice(jade.indexOf('template(name="cardSectionHeader")'));
// The heading holds a real button (the WAI disclosure pattern): Enter and Space
// are its own, a screen reader gets its name and its state, and the controls of
// the heading are beside it, not inside it (WCAG 4.1.2). A click anywhere on the
// heading still folds the section: the handler is on the h3.
assert.ok(/button\.card-details-section-toggle\(type="button" aria-expanded=/.test(header.slice(0, 1800)),
'a button inside the heading, saying whether the section is open');
assert.ok(!/role="button"/.test(header.slice(0, 1800)), 'and no heading posing as a button');
assert.ok(/'click \.js-toggle-card-section'/.test(js), 'the heading folds the section');
assert.ok(/cursor: pointer/.test(css), 'while a mouse sees a button too');
});
// ── the eye ────────────────────────────────────────────────────────────────
test('the Activities eye is gone, with its handler', () => {
assert.ok(!/activities-eye-toggle/.test(jade), 'no eye in the template');
assert.ok(!/js-toggle-show-activities-card/.test(js), 'and no handler left behind');
});
test('removing it did not quietly turn the history into comments-only', () => {
// The trap: `showActivities` defaults to false, and false means
// `activityType: 'addComment'` in the publication. With the eye gone and
// nothing left to set the flag, an opened section would have shown comments
// only - a feature lost by accident rather than by decision.
assert.ok(/mode === 'card'[\s\S]{0,1400}ret = true;/.test(activities),
'a card section that is open always asks for the whole history');
assert.ok(!/card\?\.showActivities \?\?/.test(activities),
'an old persisted false value cannot reduce the opened feed to comments');
assert.ok(/comments ONLY/.test(activities),
'and the reason the default flipped is written down');
const publication = read('server/publications/activities.js');
assert.ok(/activityType: 'addComment'/.test(publication),
'the publication still has both modes; only the card default changed');
});
test('a closed Activities section subscribes to nothing at all', () => {
// The cheaper half of what the eye was for, without a control for it.
const right = jade.slice(jade.indexOf('.card-details-right'));
const open = right.indexOf('isSectionOpen "activities"');
const render = right.indexOf('+activities(card=this');
assert.ok(open !== -1 && open < render,
'the +activities templates are inside the open branch, so nothing subscribes while closed');
});
test('the sections not in the list are left alone (negative)', () => {
// Stickers, Location, the four dates, Creator, Assignees and Spent time were
// not asked for and keep the headings they had.
for (const untouched of ['card-details-item-stickers', 'card-details-item-location',
'card-details-item-received', 'card-details-item-creator']) {
const at = jade.indexOf(untouched);
assert.ok(at !== -1, `${untouched} is still there`);
const block = jade.slice(at, at + 200);
assert.ok(/h3\.card-details-item-title/.test(block),
`${untouched} keeps its plain heading`);
}
});
test('the GROUP is the full-width row, and its fields share rows inside it', () => {
// `.card-details-items` is a wrapping flex row. The group is what takes a
// whole row now, so its rule spans the card - and the fields inside it sit
// side by side, which is what puts Assignee and Creator beside Members
// rather than under them.
assert.ok(/\.card-details-items \.card-details-group \{[\s\S]{0,120}flex: 0 0 100%/.test(css),
'a group is a full-width row');
assert.ok(/\.card-details-group-body \{[\s\S]{0,140}display: flex[\s\S]{0,60}flex-wrap: wrap/.test(css),
'and its body wraps its fields');
assert.ok(/\.card-details-group-body \.card-details-item \{[\s\S]{0,60}flex-grow: 1/.test(css),
'which share the width between them');
assert.ok(/\.card-details-section-rule \{[\s\S]{0,80}width: 100%/.test(css),
'so the rule in a group spans the card');
// The class that made an individual FIELD full width is gone with the
// grouping - it is what put Assignee and Creator on the next line.
assert.ok(!/card-details-item-members\.card-details-section/.test(jade),
'no field is a full-width row of its own any more');
});
test('the Custom Fields layout toggle switches grid and one-per-row classes', () => {
const sectionAt = jade.indexOf(
'+cardSectionHeader(section="customFields"',
);
const section = jade.slice(sectionAt, jade.indexOf('\ntemplate(', sectionAt));
assert.match(section, /layoutToggle=true layoutOnePerRow=customFieldsGrid/,
'Custom Fields asks its shared header for the selector');
const headerAt = jade.indexOf('template(name="cardSectionHeader")');
const header = jade.slice(headerAt,
jade.indexOf('template(name="editCardTitleForm")', headerAt));
assert.ok(header.indexOf('if isSectionOpen section') <
header.indexOf('button.custom-fields-layout-toggle'),
'the selector is rendered only while the section is expanded');
assert.ok(header.indexOf('| {{_ label}}') <
header.indexOf('button.custom-fields-layout-toggle') &&
header.indexOf('button.custom-fields-layout-toggle') <
header.indexOf('if menuClass'),
'the selector sits between the section title and hamburger menu');
assert.match(jade,
/card-details-group-body\(class="\{\{#if customFieldsGrid\}\}custom-fields-one-per-row\{\{else\}\}custom-fields-grid\{\{\/if\}\}"\)/,
'the saved user preference reaches the custom-fields container');
assert.match(css,
/\.custom-fields-grid \{[\s\S]*?display: grid;[\s\S]*?grid-template-columns: repeat\(auto-fit, minmax\(min\(160px, 100%\), 1fr\)\)/,
'off automatically fits more grid columns when the card becomes wider');
assert.match(css,
/\.custom-fields-grid > \.card-details-item-customfield \{[\s\S]*?max-width: none[\s\S]*?min-width: 0/,
'the old per-field width ceiling cannot hold the grid to three columns');
assert.match(css,
/\.custom-fields-one-per-row > \.card-details-item-customfield \{[\s\S]*?flex: 0 0 100%[\s\S]*?max-width: 100%/,
'on makes every custom field a full row');
assert.match(js,
/'click #toggleCustomFieldsGridButton'\(event\)[\s\S]*?event\.stopPropagation\(\)[\s\S]*?Meteor\.call\('toggleCustomFieldsGrid'\)/,
'the switch still persists the preference');
const collapseAt = js.indexOf("'click .js-toggle-card-section'(event)");
const collapse = js.slice(collapseAt, js.indexOf('\n },', collapseAt));
assert.match(collapse,
/event\.target\.closest\('#toggleCustomFieldsGridButton'\)\) return/,
'the header refuses to collapse when its layout selector was clicked');
assert.match(jade,
/button\.custom-fields-layout-toggle#toggleCustomFieldsGridButton[\s\S]*?if layoutOnePerRow[\s\S]*?list-icon[\s\S]*?fa-list[\s\S]*?else[\s\S]*?grid-icon[\s\S]*?fa-th-large/,
'list mode renders only the list icon and table mode only the table icon');
assert.match(jade,
/layoutOnePerRow\}\}list-active\{\{else\}\}grid-active/,
'the control keeps the saved layout state');
assert.match(css,
/\.card-details \.custom-fields-layout-toggle \{[\s\S]*?color: #808080/,
'the current table or list icon uses the menu button grey');
assert.match(css,
/\.custom-fields-layout-toggle \.grid-icon \.fa,[\s\S]*?\.custom-fields-layout-toggle \.list-icon \.fa \{[\s\S]*?color: inherit/,
'the icon inherits the toggle colour');
assert.doesNotMatch(css,
/\.custom-fields-layout-toggle \.grid-icon\.active,[\s\S]*?background: var\(--theme-accent/,
'the icon has no blue active background');
assert.match(css,
/\.card-details \.custom-fields-layout-toggle \{[\s\S]*?background: transparent;[\s\S]*?border: 0;/,
'the layout toggle has no white background or dark border');
});
test('each section has ONE heading of its own, first in its template', () => {
// 2026-10-28: the section's heading, not its first field's title - the
// first field can be any of them since a field is dragged inside its section.
const { SECTIONS: CARD_SETTINGS } = require('../models/lib/cardSettingsSections');
for (const [id, name] of Object.entries(FOLDING)) {
const block = template(name);
const section = CARD_SETTINGS.find(sec => sec.id === id);
const first = block.split('\n').find(line => line.trim() && !line.startsWith('template(') && !line.trim().startsWith('//'));
assert.ok(first.includes(`+cardSectionHeader(section="${id}" icon="${section.icon}" label="${section.labelKey}"`),
`${id}: the heading is the first thing, with Card Settings' icon and title`);
assert.strictEqual((block.match(/\+cardSectionHeader\(/g) || []).length, 1, `${id}: one heading`);
}
});
test('the fields keep plain titles under it', () => {
// Assignee and Creator, and Card's dependencies and sorting number, which
// were headings of their own groups before: a title each, no caret.
const members = template('cardFieldSectionMembers');
for (const field of ['card-details-item-assignees', 'card-details-item-creator']) {
const at = members.indexOf(field);
assert.ok(at !== -1, `${field} is in the section`);
const block = members.slice(at, at + 200);
assert.ok(/h3\.card-details-item-title/.test(block), `${field} has a plain title`);
assert.ok(!/cardSectionHeader/.test(block), `${field} has no caret of its own`);
}
const card = template('cardFieldSectionCard');
for (const field of ['card-details-item-dependencies', 'card-details-sort-order']) {
const at = card.indexOf(field);
assert.ok(at !== -1, `${field} is in Card`);
assert.ok(/h3\.card-details-item-title/.test(card.slice(at, at + 200)), `${field} has a plain title`);
}
assert.ok(!/cardSectionHeader\(section="(dependencies|sort|date-format|text-notes)"/.test(jade),
'negative: no heading of the old groups is left');
});
test('the rule comes with the heading, and the first section has none', () => {
// The header draws the rule; whichever section the board put first, its
// rule is hidden by the stylesheet - the template cannot know.
assert.match(css, /\.card-details-items > \.card-details-section:first-child > hr\.card-details-section-rule:first-child/);
assert.match(css, /\.card-details \.card-details-items > \.card-details-section \{\s+flex: 0 0 100%;/);
});
// ── groups ────────────────────────────────────────────────────────────────
test('a section folds its whole family, from ONE caret', () => {
// "the caret at left side of Labels should hide what is below of text labels,
// like labels +, stickers, location": every field of a section is inside
// its heading's fold.
for (const [id, name] of Object.entries(FOLDING)) {
const block = template(name);
const guard = block.indexOf(`if isSectionOpen "${id}"`);
assert.ok(guard !== -1 && guard > block.indexOf('+cardSectionHeader'), `${id} folds under its heading`);
const firstField = block.indexOf('if $eq field "');
assert.ok(firstField === -1 || firstField > guard, `${id}: every field is inside the fold`);
}
const labels = template('cardFieldSectionLabels');
for (const member of ['card-details-item-stickers', 'card-details-item-location']) {
assert.ok(labels.indexOf(member) > labels.indexOf('isSectionOpen "labels"'), `${member} folds with Labels`);
}
});
test('a field has no caret and no fold of its own (negative)', () => {
// #1591 drew a caret on every .card-details-item title and hid everything
// after that title when it was clicked. The section carets replaced it, and
// for a while BOTH ran: a click on a section's heading is also a click on a
// field title, so the field the heading is drawn on was folded by the old
// handler and left that way - its own caret having been suppressed inside a
// group, there was nothing left to open it. The Date Format select is the one
// that showed it: it sits under that heading, so it disappeared for good.
assert.ok(!/\.card-details-item > \.card-details-item-title::after/.test(css),
'no per-field caret');
assert.ok(!/\.card-details-item\.is-collapsed/.test(css), 'and no per-field fold');
assert.ok(!/'click \.card-details-item > \.card-details-item-title'/.test(js),
'nor a handler to set one');
// What folds a field is its SECTION, and only the heading carries a handle.
assert.ok(/js-toggle-card-section/.test(js), 'the section heading is the handle');
});
test('Date keeps its collapsible fields without a format selector', () => {
assert.match(jade, /cardSectionHeader\(section="date" icon="fa-calendar" label="date"/);
assert.match(jade, /if isSectionOpen "date"\s+\.card-details-group-body\s+each field in orderedDateFields/);
assert.doesNotMatch(jade, /js-date-format-selector/);
});
test('Members comes first in its group, then Assignee, then Creator', () => {
const group = template('cardFieldSectionMembers');
const members = group.indexOf('allowsMembers');
const assignee = group.indexOf('allowsAssignee');
const creator = group.indexOf('allowsCreator');
assert.ok(members !== -1 && assignee !== -1 && creator !== -1, 'all three are there');
assert.ok(members < assignee && assignee < creator,
'Members, Assignee, Creator - in that order');
});
test('a collapsed section shows its caret, its icon and its name, and nothing else', () => {
// A closed section is one line - "only caret and icon and text Members":
// nothing but the heading is outside the fold.
for (const [id, name] of Object.entries(FOLDING)) {
const lines = template(name).split('\n//-')[0].split('\n').slice(1).filter(l => l.trim() && !l.trim().startsWith('//') && !/^ {4,}/.test(l));
assert.deepStrictEqual(lines.map(l => l.trim().split('(')[0]), ['+cardSectionHeader', 'if isSectionOpen "' + id + '"'],
`${id}: only the heading and the fold at the top level`);
}
});
test('Requested By and Assigned By select a member with + or edit free text', () => {
for (const [field, getter] of [['requester', 'getRequestedBy'], ['assigner', 'getAssignedBy']]) {
const at = jade.indexOf(`js-card-details-${field}`);
assert.ok(at !== -1, `${field} is there`);
const block = jade.slice(at, at + 1200);
assert.ok(new RegExp(`js-select-${field}`).test(block), `${field} + opens its picker`);
assert.ok(/i\.fa\.fa-plus/.test(block), 'with the plus in it');
assert.ok(/\.card-details-person-controls[\s\S]*js-open-inlined-form/.test(block),
`${field}: the free-text editor remains beside the member picker`);
assert.ok(new RegExp(`title="\\{\\{#if ${getter}\\}\\}\\{\\{_ 'edit'\\}\\}\\{\\{else\\}\\}\\{\\{_ 'add'\\}\\}`)
.test(block), `${field}: the tooltip says Edit or Add from the value`);
assert.ok(new RegExp(`aria-label="\\{\\{#if ${getter}\\}\\}\\{\\{_ 'edit'\\}\\}\\{\\{else\\}\\}\\{\\{_ 'add'\\}\\}`)
.test(block), `${field}: the accessible name says Edit or Add from the value`);
assert.ok(/i\.fa\.fa-pencil-square-o\(aria-hidden="true"\)[\s\S]*else[\s\S]*i\.fa\.fa-plus\(aria-hidden="true"\)/
.test(block), `${field}: pencil edits and plus adds without visible text`);
}
// And it is the class Members' button is styled by, not a new look.
const members = jade.slice(jade.indexOf('allowsMembers'), jade.indexOf('allowsAssignee'));
assert.ok(/\.member\.add-member\.card-details-item-add-button/.test(members),
'which is the button Members uses');
});
// ── what the restructuring must not have taken with it ─────────────────────
//
// Moving eleven sections around with a script is how markup disappears without
// anything failing: the file still compiles, the tests still pass, and a card is
// missing a row nobody looks at until they need it. These are the pieces that
// were lost once and put back.
test('the card button row is still there', () => {
assert.ok(/\+cardButtons\(_id=_id boardId=boardId\)/.test(jade),
'the whole button row was dropped by a slice that used it as a boundary');
});
test('a custom field still shows its NAME', () => {
// The wrapper renders the field title before selecting its type-specific
// value editor, so every value remains identifiable in either layout.
const at = jade.indexOf('.card-details-item.card-details-item-customfield');
assert.ok(/\n\s+\+cardCustomField/.test(jade.slice(at, at + 250)),
'the field wrapper is included');
const wrapperAt = customFieldsJade.indexOf('template(name="cardCustomField")');
const wrapper = customFieldsJade.slice(wrapperAt,
customFieldsJade.indexOf('template(name="customFieldCopyButton")', wrapperAt));
assert.ok(/= definition\.name/.test(wrapper), 'the field name is rendered');
assert.ok(wrapper.indexOf('= definition.name') < wrapper.indexOf('+Template.dynamic'),
'above its type-specific value');
});
test('the Attachments heading can still show its count', () => {
assert.ok(/count=attachmentCount/.test(jade), 'the header takes a count');
assert.ok(/if count\n\s+\| \(\{\{count\}\}\)/.test(jade), 'and shows it when there is one');
assert.ok(/allowsAttachmentCountOnCard/.test(js),
'only when the board asks for it, which is the setting that governed it');
});
test('the End date has ONE add button (negative)', () => {
// A stray second `i.fa.fa-plus` appeared beside it - a bare icon, not a
// button, from a slice that duplicated a line.
// The item runs to the next template; a fixed 500 characters stopped
// short once the button got its title (#337).
const at = jade.indexOf('card-details-item-end');
const block = jade.slice(at, jade.indexOf('template(name=', at));
const pluses = (block.match(/i\.fa\.fa-plus/g) || []).length;
assert.strictEqual(pluses, 1, 'one plus in the End date item');
});
test('the Copy card link button wears the theme', () => {
// It had `.btn` only, so it fell back to the plain grey button whose dark
// label is nearly invisible on a dark theme. `.primary` is the themed one -
// the board accent with white text - and it is NAMED in forms.css beside the
// other buttons that wear it rather than given a copy of those rules.
assert.ok(/button\.primary\.js-copy-card-link-to-clipboard/.test(jade),
'the button is a themed one');
const forms = read('client/components/forms/forms.css');
const rule = forms.slice(forms.indexOf('button.primary,'));
assert.ok(/background: var\(--theme-accent/.test(rule.slice(0, 200)),
'which paints it with the theme accent');
assert.ok(/color: #fff/.test(rule.slice(0, 260)), 'and writes on it in white');
});
console.log(`\ncardSectionCollapse: ${passed} tests passed`);