Skip to content

Commit 6f3daa8

Browse files
committed
Update tests per default fallback value
1 parent 074f8a0 commit 6f3daa8

File tree

4 files changed

+165
-54
lines changed

4 files changed

+165
-54
lines changed

test/jasmine/tests/icicle_test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ describe('Test icicle texttemplate without `values` should work at root level:',
931931
[
932932
'%{percentParent} of %{parent}',
933933
[
934-
'%{percentParent} of %{parent}',
934+
' of ',
935935
'100% of Seth',
936936
'33% of Eve',
937937
'17% of Eve',
@@ -957,7 +957,7 @@ describe('Test icicle texttemplate without `values` should work at root level:',
957957
[
958958
'label: Eve',
959959
'text: fourteen',
960-
'value: %{value}', // N.B. there is no `values` array
960+
'value: ', // N.B. there is no `values` array
961961
'17% of Eve',
962962
'17% of Eve',
963963
'17% of Eve',
@@ -1085,7 +1085,7 @@ describe('Test icicle texttemplate with *total* `values` should work at root lev
10851085
[
10861086
'%{percentParent} of %{parent}',
10871087
[
1088-
'%{percentParent} of %{parent}',
1088+
' of ',
10891089
'22% of Eve',
10901090
'18% of Eve',
10911091
'9% of Eve',

test/jasmine/tests/lib_test.js

Lines changed: 157 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,134 +2522,245 @@ describe('Test lib.js:', function () {
25222522
});
25232523

25242524
describe('hovertemplateString', function () {
2525-
var locale = false;
25262525
it('evaluates attributes', function () {
2527-
expect(Lib.hovertemplateString('foo %{bar}', {}, locale, { bar: 'baz' })).toEqual('foo baz');
2526+
expect(
2527+
Lib.hovertemplateString({
2528+
args: [{ bar: 'baz' }],
2529+
fallback: '',
2530+
string: 'foo %{bar}'
2531+
})
2532+
).toEqual('foo baz');
25282533
});
25292534

25302535
it('evaluates attributes with a dot in their name', function () {
25312536
expect(
2532-
Lib.hovertemplateString('%{marker.size}', {}, locale, { 'marker.size': 12 }, { marker: { size: 14 } })
2537+
Lib.hovertemplateString({
2538+
args: [{ 'marker.size': 12 }, { marker: { size: 14 } }],
2539+
fallback: '',
2540+
string: '%{marker.size}'
2541+
})
25332542
).toEqual('12');
25342543
});
25352544

25362545
it('evaluates nested properties', function () {
2537-
expect(Lib.hovertemplateString('foo %{bar.baz}', {}, locale, { bar: { baz: 'asdf' } })).toEqual('foo asdf');
2546+
expect(
2547+
Lib.hovertemplateString({
2548+
args: [{ bar: { baz: 'asdf' } }],
2549+
fallback: '',
2550+
string: 'foo %{bar.baz}'
2551+
})
2552+
).toEqual('foo asdf');
25382553
});
25392554

25402555
it('evaluates array nested properties', function () {
2541-
expect(Lib.hovertemplateString('foo %{bar[0].baz}', {}, locale, { bar: [{ baz: 'asdf' }] })).toEqual(
2542-
'foo asdf'
2543-
);
2556+
expect(
2557+
Lib.hovertemplateString({
2558+
args: [{ bar: [{ baz: 'asdf' }] }],
2559+
fallback: '',
2560+
string: 'foo %{bar[0].baz}'
2561+
})
2562+
).toEqual('foo asdf');
25442563
});
25452564

25462565
it('should work with the number *0*', function () {
2547-
expect(Lib.hovertemplateString('%{group}', {}, locale, { group: 0 })).toEqual('0');
2566+
expect(
2567+
Lib.hovertemplateString({
2568+
args: [{ group: 0 }],
2569+
fallback: '',
2570+
string: '%{group}'
2571+
})
2572+
).toEqual('0');
25482573
});
25492574

25502575
it('should work with the number *0* (nested case)', function () {
2551-
expect(Lib.hovertemplateString('%{x.y}', {}, locale, { x: { y: 0 } })).toEqual('0');
2576+
expect(
2577+
Lib.hovertemplateString({
2578+
args: [{ x: { y: 0 } }],
2579+
fallback: '',
2580+
string: '%{x.y}'
2581+
})
2582+
).toEqual('0');
25522583
});
25532584

25542585
it('preserves null and NaN', function () {
25552586
expect(
2556-
Lib.hovertemplateString('%{a} %{b} %{c.d} %{c.e} %{f[0]} %{f[1]}', {}, locale, {
2557-
a: null,
2558-
b: NaN,
2559-
c: { d: null, e: NaN },
2560-
f: [null, NaN]
2587+
Lib.hovertemplateString({
2588+
args: [{ a: null, b: NaN, c: { d: null, e: NaN }, f: [null, NaN] }],
2589+
fallback: '',
2590+
string: '%{a} %{b} %{c.d} %{c.e} %{f[0]} %{f[1]}'
25612591
})
25622592
).toEqual('null NaN null NaN null NaN');
25632593
});
25642594

25652595
it('subtitutes multiple matches', function () {
25662596
expect(
2567-
Lib.hovertemplateString('foo %{group} %{trace}', {}, locale, { group: 'asdf', trace: 'jkl;' })
2597+
Lib.hovertemplateString({
2598+
args: [{ group: 'asdf', trace: 'jkl;' }],
2599+
fallback: '',
2600+
string: 'foo %{group} %{trace}'
2601+
})
25682602
).toEqual('foo asdf jkl;');
25692603
});
25702604

2571-
it('replaces missing matches with template string', function () {
2572-
expect(Lib.hovertemplateString('foo %{group} %{trace}', {}, locale, { group: 1 })).toEqual(
2573-
'foo 1 %{trace}'
2574-
);
2605+
it('replaces missing matches with fallback value', function () {
2606+
expect(
2607+
Lib.hovertemplateString({
2608+
args: [{ group: 1 }],
2609+
fallback: '',
2610+
string: 'foo %{group} %{trace}'
2611+
})
2612+
).toEqual('foo 1 ');
25752613
});
25762614

25772615
it('uses the value from the first object with the specified key', function () {
25782616
var obj1 = { a: 'first' };
25792617
var obj2 = { a: 'second', foo: { bar: 'bar' } };
25802618

25812619
// Simple key
2582-
expect(Lib.hovertemplateString('foo %{a}', {}, locale, obj1, obj2)).toEqual('foo first');
2583-
expect(Lib.hovertemplateString('foo %{a}', {}, locale, obj2, obj1)).toEqual('foo second');
2620+
expect(
2621+
Lib.hovertemplateString({
2622+
args: [obj1, obj2],
2623+
fallback: '',
2624+
string: 'foo %{a}'
2625+
})
2626+
).toEqual('foo first');
2627+
expect(
2628+
Lib.hovertemplateString({
2629+
args: [obj2, obj1],
2630+
fallback: '',
2631+
string: 'foo %{a}'
2632+
})
2633+
).toEqual('foo second');
25842634

25852635
// Nested Keys
2586-
expect(Lib.hovertemplateString('foo %{foo.bar}', {}, locale, obj1, obj2)).toEqual('foo bar');
2636+
expect(
2637+
Lib.hovertemplateString({
2638+
args: [obj1, obj2],
2639+
fallback: '',
2640+
string: 'foo %{foo.bar}'
2641+
})
2642+
).toEqual('foo bar');
25872643

25882644
// Nested keys with 0
2589-
expect(Lib.hovertemplateString('y: %{y}', {}, locale, { y: 0 }, { y: 1 })).toEqual('y: 0');
2645+
expect(
2646+
Lib.hovertemplateString({
2647+
args: [{ y: 0 }, { y: 1 }],
2648+
fallback: '',
2649+
string: 'y: %{y}'
2650+
})
2651+
).toEqual('y: 0');
25902652
});
25912653

25922654
it('formats numbers using d3-format mini-language when `:`', function () {
2593-
expect(Lib.hovertemplateString('a: %{a:.0%}', {}, locale, { a: 0.123 })).toEqual('a: 12%');
2594-
expect(Lib.hovertemplateString('a: %{a:0.2%}', {}, locale, { a: 0.123 })).toEqual('a: 12.30%');
2595-
expect(Lib.hovertemplateString('b: %{b:2.2f}', {}, locale, { b: 43 })).toEqual('b: 43.00');
2655+
expect(
2656+
Lib.hovertemplateString({
2657+
args: [{ a: 0.123 }],
2658+
fallback: '',
2659+
string: 'a: %{a:.0%}'
2660+
})
2661+
).toEqual('a: 12%');
2662+
expect(
2663+
Lib.hovertemplateString({
2664+
args: [{ a: 0.123 }],
2665+
fallback: '',
2666+
string: 'a: %{a:0.2%}'
2667+
})
2668+
).toEqual('a: 12.30%');
2669+
expect(
2670+
Lib.hovertemplateString({
2671+
args: [{ b: 43 }],
2672+
fallback: '',
2673+
string: 'b: %{b:2.2f}'
2674+
})
2675+
).toEqual('b: 43.00');
25962676
});
25972677

25982678
it('formats date using d3-time-format mini-language `|`', function () {
2599-
expect(Lib.hovertemplateString('a: %{a|%A}', {}, locale, { a: '2019-05-22' })).toEqual('a: Wednesday');
2600-
expect(Lib.hovertemplateString('%{x|%b %-d, %Y}', {}, locale, { x: '2019-01-01' })).toEqual('Jan 1, 2019');
2679+
expect(
2680+
Lib.hovertemplateString({
2681+
args: [{ a: '2019-05-22' }],
2682+
fallback: '',
2683+
string: 'a: %{a|%A}'
2684+
})
2685+
).toEqual('a: Wednesday');
2686+
expect(
2687+
Lib.hovertemplateString({
2688+
args: [{ x: '2019-01-01' }],
2689+
fallback: '',
2690+
string: '%{x|%b %-d, %Y}'
2691+
})
2692+
).toEqual('Jan 1, 2019');
26012693
});
26022694

26032695
it('looks for default label if no format is provided', function () {
2604-
expect(Lib.hovertemplateString('y: %{y}', { yLabel: '0.1' }, locale, { y: 0.123 })).toEqual('y: 0.1');
2696+
expect(
2697+
Lib.hovertemplateString({
2698+
args: [{ y: 0.123 }],
2699+
fallback: '',
2700+
labels: { yLabel: '0.1' },
2701+
string: 'y: %{y}'
2702+
})
2703+
).toEqual('y: 0.1');
26052704
});
26062705

26072706
it('warns user up to 10 times if a variable cannot be found', function () {
26082707
spyOn(Lib, 'warn').and.callThrough();
2609-
Lib.hovertemplateString('%{idontexist}', {});
2708+
Lib.hovertemplateString({
2709+
fallback: '',
2710+
string: '%{idontexist}'
2711+
});
26102712
expect(Lib.warn.calls.count()).toBe(1);
26112713

26122714
for (var i = 0; i < 15; i++) {
2613-
Lib.hovertemplateString('%{idontexist}', {});
2715+
Lib.hovertemplateString({
2716+
fallback: '',
2717+
string: '%{idontexist}'
2718+
});
26142719
}
26152720
expect(Lib.warn.calls.count()).toBe(10);
26162721
});
2617-
2618-
it('does not error out when arguments are undefined', function () {
2619-
expect(function () {
2620-
Lib.hovertemplateString('y: %{y}', undefined, locale, undefined);
2621-
}).not.toThrow();
2622-
});
26232722
});
26242723

26252724
describe('texttemplateString', function () {
26262725
var locale = false;
26272726
it('evaluates attributes', function () {
2628-
expect(Lib.texttemplateString('foo %{bar}', {}, locale, { bar: 'baz' })).toEqual('foo baz');
2727+
expect(
2728+
Lib.texttemplateString({
2729+
args: [{ bar: 'baz' }],
2730+
fallback: '',
2731+
string: 'foo %{bar}'
2732+
})
2733+
).toEqual('foo baz');
26292734
});
26302735

26312736
it('looks for default label if no format is provided', function () {
2632-
expect(Lib.texttemplateString('y: %{y}', { yLabel: '0.1' }, locale, { y: 0.123 })).toEqual('y: 0.1');
2737+
expect(
2738+
Lib.texttemplateString({
2739+
args: [{ y: 0.123 }],
2740+
fallback: '',
2741+
labels: { yLabel: '0.1' },
2742+
string: 'y: %{y}'
2743+
})
2744+
).toEqual('y: 0.1');
26332745
});
26342746

26352747
it('preserves null and NaN', function () {
26362748
expect(
2637-
Lib.texttemplateString('%{a} %{b} %{c.d} %{c.e} %{f[0]} %{f[1]}', {}, locale, {
2638-
a: null,
2639-
b: NaN,
2640-
c: { d: null, e: NaN },
2641-
f: [null, NaN]
2749+
Lib.texttemplateString({
2750+
args: [{ a: null, b: NaN, c: { d: null, e: NaN }, f: [null, NaN] }],
2751+
fallback: '',
2752+
string: '%{a} %{b} %{c.d} %{c.e} %{f[0]} %{f[1]}'
26422753
})
26432754
).toEqual('null NaN null NaN null NaN');
26442755
});
26452756

26462757
it('warns user up to 10 times if a variable cannot be found', function () {
26472758
spyOn(Lib, 'warn').and.callThrough();
2648-
Lib.texttemplateString('%{idontexist}', {});
2759+
Lib.texttemplateString({ fallback: '', string: '%{idontexist}' });
26492760
expect(Lib.warn.calls.count()).toBe(1);
26502761

26512762
for (var i = 0; i < 15; i++) {
2652-
Lib.texttemplateString('%{idontexist}', {});
2763+
Lib.texttemplateString({ fallback: '', string: '%{idontexist}' });
26532764
}
26542765
expect(Lib.warn.calls.count()).toBe(11);
26552766
});

test/jasmine/tests/sunburst_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,7 @@ describe('Test sunburst texttemplate without `values` should work at root level:
22932293
[
22942294
'%{percentParent} of %{parent}',
22952295
[
2296-
'%{percentParent} of %{parent}',
2296+
' of ',
22972297
'100% of Seth',
22982298
'33% of Eve',
22992299
'17% of Eve',
@@ -2319,7 +2319,7 @@ describe('Test sunburst texttemplate without `values` should work at root level:
23192319
[
23202320
'label: Eve',
23212321
'text: fourteen',
2322-
'value: %{value}', // N.B. there is no `values` array
2322+
'value: ', // N.B. there is no `values` array
23232323
'17% of Eve',
23242324
'17% of Eve',
23252325
'17% of Eve',
@@ -2447,7 +2447,7 @@ describe('Test sunburst texttemplate with *total* `values` should work at root l
24472447
[
24482448
'%{percentParent} of %{parent}',
24492449
[
2450-
'%{percentParent} of %{parent}',
2450+
' of ',
24512451
'22% of Eve',
24522452
'18% of Eve',
24532453
'9% of Eve',
@@ -2601,7 +2601,7 @@ describe('Test sunburst texttemplate with *remainder* `values` should work at ro
26012601
[
26022602
'%{percentParent} of %{parent}',
26032603
[
2604-
'%{percentParent} of %{parent}',
2604+
' of ',
26052605
'20% of Eve',
26062606
'12% of Eve',
26072607
'6% of Eve',

test/jasmine/tests/treemap_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,7 @@ describe('Test treemap texttemplate without `values` should work:', function ()
19371937
'Eve',
19381938
'label: Cain, text: fourteen',
19391939
'Seth',
1940-
'value: %{value}', // N.B. there is no `values` array
1940+
'value: ', // N.B. there is no `values` array
19411941
'17% of Eve',
19421942
'17% of Eve',
19431943
'Awan',

0 commit comments

Comments
 (0)