Files
wekan/server/lib/tests/customNumberFormat.tests.js
T
Lauri OjansivuandClaude Opus 4.8 98315c26cd Fix #2091: custom number field shows NaN when cleared after being set
A number-type Custom Field rendered the literal 'NaN' once its value was cleared.
The submit handler now stores '' instead of NaN for empty input, and a shared
formatNumberValue helper normalizes empty/null/non-numeric values to an empty
string for display. Helper unit-tested.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-20 19:17:01 +03:00

42 lines
1.3 KiB
JavaScript

/* eslint-env mocha */
import { expect } from 'chai';
import { formatNumberValue } from '../customNumberFormat';
/**
* Unit tests for custom-field number formatting (#2091).
*
* "Custom number field displays as NaN if set blank after already being set":
* once a number Custom Field is given a value and then cleared, the blank /
* non-numeric value must render as an empty string rather than "NaN".
*/
describe('custom number field formatting (#2091)', function() {
it('renders an empty string for blank input', function() {
expect(formatNumberValue('')).to.equal('');
});
it('renders an empty string for null', function() {
expect(formatNumberValue(null)).to.equal('');
});
it('renders an empty string for undefined', function() {
expect(formatNumberValue(undefined)).to.equal('');
});
it('renders an empty string for non-numeric text (never "NaN")', function() {
expect(formatNumberValue('abc')).to.equal('');
expect(formatNumberValue(NaN)).to.equal('');
});
it('renders zero as "0"', function() {
expect(formatNumberValue(0)).to.equal('0');
});
it('renders a decimal number unchanged', function() {
expect(formatNumberValue(12.5)).to.equal('12.5');
});
it('accepts numeric strings', function() {
expect(formatNumberValue('42')).to.equal('42');
});
});