Compare commits

...

6 Commits

Author SHA1 Message Date
Evan
d5a7491d42 fix(big-number): wrap tests in describe to fix TS2451 global scope conflict
The const helper at top level was processed as a global script by TypeScript's
root tsconfig (which includes ./plugins/**/*), causing TS2451 when the same
symbol appeared multiple times in the global scope. A describe block makes the
variable block-scoped, resolving the lint-frontend CI failure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-29 23:43:32 -07:00
Evan
0ff66f84da fix(big-number): use const arrow fn in test to avoid TS2393 global scope conflict
The helper function was declared with the function keyword, which in
TypeScript script mode (no imports/exports) participates in the global
namespace. The root tsconfig includes ./plugins/**/* with no test
exclusion, so after plugins:build generates lib/ artifacts this caused
TS2393 (duplicate function implementation) during npm run type.

Switching to a const arrow function avoids global declaration merging
while keeping identical test behaviour.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-29 21:13:06 -07:00
Evan Rusackas
f852fc5349 Merge branch 'master' into fix-bignumber-color-format 2026-05-29 20:49:49 -07:00
Joe Li
9689b32547 Merge branch 'master' into fix-bignumber-color-format 2026-03-18 10:19:16 -07:00
Claude Code
11de202e65 test(big-number): add unit tests for color threshold formatter with zero value
Adds tests to verify that color threshold formatting is applied
when bigNumber === 0, covering the falsy-zero bug fixed in the
previous commit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-11 13:40:21 -07:00
mtrentz
0b88f524f8 fix: color formats big numbers when value is 0 2026-03-11 13:36:51 -07:00
2 changed files with 87 additions and 5 deletions

View File

@@ -0,0 +1,85 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Tests for the color threshold formatter logic in BigNumberViz.
*
* The key fix: bigNumber === 0 is falsy, so the original code
* `const result = bigNumber ? formatter.getColorFromValue(bigNumber) : false`
* would skip formatting for zero. The fix uses an explicit type check instead.
*/
// describe block makes applyColorFormatters block-scoped, avoiding TS2451
// when TypeScript's root tsconfig includes this file as a global script.
describe('BigNumberViz color formatters', () => {
const applyColorFormatters = (
bigNumber: number | null | undefined,
formatters: Array<{ getColorFromValue: (v: number) => string | undefined }>,
): string | undefined => {
let numberColor: string | undefined;
const hasFormatters = Array.isArray(formatters) && formatters.length > 0;
if (hasFormatters) {
formatters.forEach(formatter => {
// Fixed: use explicit type check instead of falsy check
if (typeof bigNumber === 'number' && !isNaN(bigNumber)) {
numberColor = formatter.getColorFromValue(bigNumber);
}
});
}
return numberColor;
};
test('applies color formatter when bigNumber is 0', () => {
const getColorFromValue = jest.fn(() => 'red');
const color = applyColorFormatters(0, [{ getColorFromValue }]);
expect(getColorFromValue).toHaveBeenCalledWith(0);
expect(color).toBe('red');
});
test('applies color formatter when bigNumber is positive', () => {
const getColorFromValue = jest.fn(() => 'green');
const color = applyColorFormatters(42, [{ getColorFromValue }]);
expect(getColorFromValue).toHaveBeenCalledWith(42);
expect(color).toBe('green');
});
test('applies color formatter when bigNumber is negative', () => {
const getColorFromValue = jest.fn(() => 'blue');
const color = applyColorFormatters(-5, [{ getColorFromValue }]);
expect(getColorFromValue).toHaveBeenCalledWith(-5);
expect(color).toBe('blue');
});
test('does not call color formatter when bigNumber is null', () => {
const getColorFromValue = jest.fn();
applyColorFormatters(null, [{ getColorFromValue }]);
expect(getColorFromValue).not.toHaveBeenCalled();
});
test('does not call color formatter when bigNumber is undefined', () => {
const getColorFromValue = jest.fn();
applyColorFormatters(undefined, [{ getColorFromValue }]);
expect(getColorFromValue).not.toHaveBeenCalled();
});
});

View File

@@ -204,11 +204,8 @@ function BigNumberVis({
let numberColor;
if (hasThresholdColorFormatter) {
colorThresholdFormatters!.forEach(formatter => {
const formatterResult = bigNumber
? formatter.getColorFromValue(bigNumber as number)
: false;
if (formatterResult) {
numberColor = formatterResult;
if (typeof bigNumber === 'number' && !isNaN(bigNumber)) {
numberColor = formatter.getColorFromValue(bigNumber);
}
});
} else {