pict-section-form 1.3.12 → 1.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pict-section-form",
3
- "version": "1.3.12",
3
+ "version": "1.3.13",
4
4
  "description": "Pict dynamic forms",
5
5
  "main": "source/Pict-Section-Form.js",
6
6
  "directories": {
@@ -28,6 +28,16 @@ class CustomInputHandler extends libPictSectionInputExtension
28
28
 
29
29
  roundValue(pInput, pValue)
30
30
  {
31
+ // A value that is not a number must render BLANK, never a formatted stand-in.
32
+ // Formatting one produced "NaN" in a tabular cell (from a null return) and
33
+ // "0.00" from undefined -- both of which read as real measurements. A
34
+ // running average is legitimately empty until its window fills, so this is
35
+ // the common case, not an edge case.
36
+ if ((pValue === null) || (typeof (pValue) === 'undefined') || (String(pValue).trim() === ''))
37
+ {
38
+ return '';
39
+ }
40
+
31
41
  let tmpValue = pValue;
32
42
 
33
43
  if ('DecimalPrecision' in pInput.PictForm)
@@ -0,0 +1,93 @@
1
+ /*
2
+ Unit tests for source/providers/inputs/Pict-Provider-Input-PreciseNumber.js
3
+
4
+ The case that mattered: a blank value in a formatted numeric column. A running
5
+ average is legitimately empty until its trailing window fills, so a dashboard
6
+ table has blanks in the same column as real numbers. Formatting those produced
7
+ "NaN" in the rendered cell (roundValue returned null) and "0.00" from
8
+ undefined — both of which read as measurements that were never taken.
9
+ */
10
+
11
+ const libBrowserEnv = require('browser-env');
12
+ libBrowserEnv();
13
+
14
+ const Chai = require('chai');
15
+ const Expect = Chai.expect;
16
+
17
+ const libPict = require('pict');
18
+ const libPreciseNumber = require('../source/providers/inputs/Pict-Provider-Input-PreciseNumber.js');
19
+
20
+ /**
21
+ * @param {object} [pPictForm] - The input's PictForm block.
22
+ * @return {{ provider: object, input: object }}
23
+ */
24
+ function build(pPictForm)
25
+ {
26
+ const tmpPict = new libPict();
27
+ const tmpProvider = new libPreciseNumber(tmpPict, {});
28
+ return { provider: tmpProvider, input: { Hash: 'Measure', PictForm: Object.assign({ DecimalPrecision: 2 }, pPictForm || {}) } };
29
+ }
30
+
31
+ suite('Pict-Provider-Input-PreciseNumber', () =>
32
+ {
33
+ suite('blank values', () =>
34
+ {
35
+ test('an empty string renders blank, not NaN', () =>
36
+ {
37
+ const { provider, input } = build();
38
+ Expect(provider.roundValue(input, '')).to.equal('');
39
+ });
40
+
41
+ test('null renders blank', () =>
42
+ {
43
+ const { provider, input } = build();
44
+ Expect(provider.roundValue(input, null)).to.equal('');
45
+ });
46
+
47
+ test('undefined renders blank, not 0.00', () =>
48
+ {
49
+ const { provider, input } = build();
50
+ Expect(provider.roundValue(input, undefined)).to.equal('');
51
+ });
52
+
53
+ test('whitespace renders blank', () =>
54
+ {
55
+ const { provider, input } = build();
56
+ Expect(provider.roundValue(input, ' ')).to.equal('');
57
+ });
58
+
59
+ test('a blank is blank even with a prefix/postfix configured — no bare "%" in an empty cell', () =>
60
+ {
61
+ const { provider, input } = build({ DigitsPostfix: '%', DigitsPrefix: '$' });
62
+ Expect(provider.roundValue(input, '')).to.equal('');
63
+ });
64
+ });
65
+
66
+ suite('real values still format', () =>
67
+ {
68
+ test('zero-fills to the configured precision', () =>
69
+ {
70
+ const { provider, input } = build({ DecimalPrecision: 2 });
71
+ Expect(provider.roundValue(input, '5.5')).to.equal('5.50');
72
+ });
73
+
74
+ test('a value at full solver precision is rounded down to the column width', () =>
75
+ {
76
+ const { provider, input } = build({ DecimalPrecision: 5 });
77
+ Expect(provider.roundValue(input, '2.47770392749244712991')).to.equal('2.47770');
78
+ });
79
+
80
+ test('a real zero still renders as a number', () =>
81
+ {
82
+ const { provider, input } = build({ DecimalPrecision: 2 });
83
+ Expect(provider.roundValue(input, 0)).to.equal('0.00');
84
+ Expect(provider.roundValue(input, '0')).to.equal('0.00');
85
+ });
86
+
87
+ test('postfix is still applied to a real value', () =>
88
+ {
89
+ const { provider, input } = build({ DecimalPrecision: 1, DigitsPostfix: '%' });
90
+ Expect(provider.roundValue(input, '2.91')).to.equal('2.9%');
91
+ });
92
+ });
93
+ });