Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arvind committed Jan 20, 2022
1 parent a4e7b83 commit 28a2e93
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
6 changes: 3 additions & 3 deletions test/compile/selection/clear.test.ts
Expand Up @@ -61,7 +61,7 @@ describe('Clear selection transform, point types', () => {
{
events: selCmpts['one'].events,
update:
'datum && item().mark.marktype !== \'group\' ? {unit: "", fields: one_tuple_fields, values: [(item().isVoronoi ? datum.datum : datum)["_vgsid_"]]} : null',
'datum && item().mark.marktype !== \'group\' ? {unit: "", _vgsid_: (item().isVoronoi ? datum.datum : datum)["_vgsid_"]} : null',
force: true
},
{events: parseSelector('dblclick', 'view'), update: 'null'}
Expand All @@ -78,7 +78,7 @@ describe('Clear selection transform, point types', () => {
{
events: selCmpts['three'].events,
update:
'datum && item().mark.marktype !== \'group\' ? {unit: "", fields: three_tuple_fields, values: [(item().isVoronoi ? datum.datum : datum)["_vgsid_"]]} : null',
'datum && item().mark.marktype !== \'group\' ? {unit: "", _vgsid_: (item().isVoronoi ? datum.datum : datum)["_vgsid_"]} : null',
force: true
},
{events: parseSelector('mouseout', 'view'), update: 'null'}
Expand All @@ -95,7 +95,7 @@ describe('Clear selection transform, point types', () => {
{
events: selCmpts['four'].events,
update:
'datum && item().mark.marktype !== \'group\' ? {unit: "", fields: four_tuple_fields, values: [(item().isVoronoi ? datum.datum : datum)["_vgsid_"]]} : null',
'datum && item().mark.marktype !== \'group\' ? {unit: "", _vgsid_: (item().isVoronoi ? datum.datum : datum)["_vgsid_"]} : null',
force: true
},
{events: parseSelector('mouseout', 'view'), update: 'null'}
Expand Down
27 changes: 19 additions & 8 deletions test/compile/selection/point.test.ts
Expand Up @@ -90,6 +90,11 @@ describe('Multi Selection', () => {
name: 'eight',
value: 75,
select: 'point'
},
{
name: 'nine',
value: [{_vgsid_: 75}, {_vgsid_: 80}],
select: 'point'
}
]));

Expand All @@ -102,7 +107,7 @@ describe('Multi Selection', () => {
{
events: selCmpts['one'].events,
update:
'datum && item().mark.marktype !== \'group\' ? {unit: "", fields: one_tuple_fields, values: [(item().isVoronoi ? datum.datum : datum)["_vgsid_"]]} : null',
'datum && item().mark.marktype !== \'group\' ? {unit: "", _vgsid_: (item().isVoronoi ? datum.datum : datum)["_vgsid_"]} : null',
force: true
}
]
Expand Down Expand Up @@ -203,7 +208,7 @@ describe('Multi Selection', () => {
{
events: selCmpts['one'].events,
update:
"datum && item().mark.marktype !== 'group' && indexof(item().mark.name, 'two_brush') < 0 && indexof(item().mark.name, 'three_brush') < 0 ? {unit: \"\", fields: one_tuple_fields, values: [(item().isVoronoi ? datum.datum : datum)[\"_vgsid_\"]]} : null",
"datum && item().mark.marktype !== 'group' && indexof(item().mark.name, 'two_brush') < 0 && indexof(item().mark.name, 'three_brush') < 0 ? {unit: \"\", _vgsid_: (item().isVoronoi ? datum.datum : datum)[\"_vgsid_\"]} : null",
force: true
}
]
Expand Down Expand Up @@ -261,7 +266,10 @@ describe('Multi Selection', () => {

it('builds unit datasets', () => {
expect(assembleUnitSelectionData(model, [])).toEqual([
{name: 'one_store'},
{
name: 'one_store',
transform: [{type: 'collect', sort: {field: '_vgsid_'}}]
},
{name: 'two_store'},
{
name: 'thr_ee_store',
Expand Down Expand Up @@ -320,12 +328,15 @@ describe('Multi Selection', () => {
},
{
name: 'eight_store',
transform: [{type: 'collect', sort: {field: '_vgsid_'}}],
values: [{unit: '', _vgsid_: 75}]
},
{
name: 'nine_store',
transform: [{type: 'collect', sort: {field: '_vgsid_'}}],
values: [
{
unit: '',
fields: [{type: 'E', field: '_vgsid_'}],
values: [75]
}
{unit: '', _vgsid_: 75},
{unit: '', _vgsid_: 80}
]
}
]);
Expand Down
26 changes: 15 additions & 11 deletions test/compile/selection/predicate.test.ts
Expand Up @@ -21,7 +21,7 @@ describe('Selection Predicate', () => {
field: 'Acceleration',
type: 'quantitative',
condition: {
param: 'one',
param: 'two',
empty: false,
value: 0.5
}
Expand All @@ -47,20 +47,22 @@ describe('Selection Predicate', () => {

it('generates the predicate expression', () => {
// Different resolutions
expect(predicate(model, {param: 'one'})).toBe('!length(data("one_store")) || vlSelectionTest("one_store", datum)');
expect(predicate(model, {param: 'one'})).toBe(
'!length(data("one_store")) || vlSelectionIdTest("one_store", datum)'
);
expect(predicate(model, {param: 'two'})).toBe(
'!length(data("two_store")) || vlSelectionTest("two_store", datum, "union")'
'!length(data("two_store")) || vlSelectionIdTest("two_store", datum, "union")'
);
expect(predicate(model, {param: 'thr-ee'})).toBe(
'!length(data("thr_ee_store")) || vlSelectionTest("thr_ee_store", datum, "intersect")'
);

// Different emptiness
expect(predicate(model, {param: 'one', empty: true})).toBe(
'!length(data("one_store")) || vlSelectionTest("one_store", datum)'
'!length(data("one_store")) || vlSelectionIdTest("one_store", datum)'
);
expect(predicate(model, {param: 'one', empty: false})).toBe(
'length(data("one_store")) && vlSelectionTest("one_store", datum)'
expect(predicate(model, {param: 'two', empty: false})).toBe(
'length(data("two_store")) && vlSelectionIdTest("two_store", datum, "union")'
);

// Variable parameters
Expand All @@ -70,15 +72,15 @@ describe('Selection Predicate', () => {
it('generates Vega production rules', () => {
expect(nonPosition('color', model, {vgChannel: 'fill'})).toEqual({
fill: [
{test: '!length(data("one_store")) || vlSelectionTest("one_store", datum)', value: 'grey'},
{test: '!length(data("one_store")) || vlSelectionIdTest("one_store", datum)', value: 'grey'},
{scale: 'color', field: 'Cylinders'}
]
});

expect(nonPosition('opacity', model)).toEqual({
opacity: [
{
test: 'length(data("one_store")) && vlSelectionTest("one_store", datum)',
test: 'length(data("two_store")) && vlSelectionIdTest("two_store", datum, "union")',
value: 0.5
},
{scale: 'opacity', field: 'Acceleration'}
Expand All @@ -98,10 +100,12 @@ describe('Selection Predicate', () => {
});

it('generates a selection filter', () => {
expect(expression(model, {param: 'one'})).toBe('!length(data("one_store")) || vlSelectionTest("one_store", datum)');
expect(expression(model, {param: 'one'})).toBe(
'!length(data("one_store")) || vlSelectionIdTest("one_store", datum)'
);

expect(expression(model, {not: {param: 'one', empty: false}})).toBe(
'!(length(data("one_store")) && vlSelectionTest("one_store", datum))'
expect(expression(model, {not: {param: 'two', empty: false}})).toBe(
'!(length(data("two_store")) && vlSelectionIdTest("two_store", datum, "union"))'
);

expect(expression(model, {not: {param: 'varHelloWorld'}})).toBe('!(!!varHelloWorld)');
Expand Down

0 comments on commit 28a2e93

Please sign in to comment.