mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Labels are embedded in the board document, not a separate collection, but the Activities label() helper looked the label id up in the Cards collection and always returned undefined. So the addedLabel/removedLabel webhook and notification params never got a label value and the __label__ token in the message text rendered as a bare, generic "label" with no name. Resolve the label from the already-loaded board via getLabelById, and add a pure labelDisplayName() helper (name -> color -> id fallback) so a nameless label is shown by its color, matching the UI. Add a plain-Node unit test.
55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
// Plain-Node unit test (no Meteor) for the outgoing-webhook label name helper.
|
|
// Run: node tests/labelDisplayName.test.cjs
|
|
//
|
|
// Regression guard for #5442 ("outgoing webhook on add/remove label did not
|
|
// include the label name"): a label has an optional `name` and a `color`, and a
|
|
// nameless label is shown by its color in the UI. The webhook text must resolve
|
|
// a real display value (name -> color -> id) instead of a bare, generic "label".
|
|
|
|
const assert = require('assert');
|
|
const { labelDisplayName } = require('../models/lib/labelDisplayName');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
test('name present -> the name is used', () => {
|
|
assert.strictEqual(
|
|
labelDisplayName({ _id: 'l1', name: 'Bug', color: 'red' }),
|
|
'Bug',
|
|
);
|
|
});
|
|
|
|
test('empty / whitespace name -> falls back to the color', () => {
|
|
assert.strictEqual(
|
|
labelDisplayName({ _id: 'l1', name: '', color: 'green' }),
|
|
'green',
|
|
);
|
|
assert.strictEqual(
|
|
labelDisplayName({ _id: 'l1', name: ' ', color: 'blue' }),
|
|
'blue',
|
|
);
|
|
assert.strictEqual(
|
|
labelDisplayName({ _id: 'l1', color: 'yellow' }),
|
|
'yellow',
|
|
);
|
|
});
|
|
|
|
test('no name and no color -> falls back to the label id', () => {
|
|
assert.strictEqual(labelDisplayName({ _id: 'l42' }), 'l42');
|
|
assert.strictEqual(labelDisplayName({ _id: 'l42', name: '', color: '' }), 'l42');
|
|
});
|
|
|
|
test('missing / null label -> empty string, never throws', () => {
|
|
assert.strictEqual(labelDisplayName(null), '');
|
|
assert.strictEqual(labelDisplayName(undefined), '');
|
|
assert.strictEqual(labelDisplayName({}), '');
|
|
});
|
|
|
|
console.log(`\n${passed} passed`);
|