Skip to content

Commit

Permalink
test: expand runtime tests to cover faceted/repeated views
Browse files Browse the repository at this point in the history
  • Loading branch information
arvind committed Jul 7, 2023
1 parent 0b339d9 commit 7e6cee4
Show file tree
Hide file tree
Showing 37 changed files with 62 additions and 21 deletions.
9 changes: 0 additions & 9 deletions test-runtime/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@
target.dispatchEvent(type === 'wheel' ? new WheelEvent('wheel', opts) : new MouseEvent(type, opts));
}

function pureClear(id, parent, targetBrush) {
const el0 = mark(id, parent);
const [clientX, clientY] = coords(el0);

pureMouseEvt('mousedown', el0, {clientX, clientY});
pureMouseEvt('mouseup', window, {clientX, clientY});
pureMouseEvt('click', el0, {clientX, clientY});
}

function mark(id, parent) {
return document.querySelector((parent ? `g.${parent} ` : '') + `g.mark-symbol.role-mark path:nth-child(${id})`);
}
Expand Down
6 changes: 3 additions & 3 deletions test-runtime/region.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {TopLevelSpec} from '../src';
import {SELECTION_ID, SelectionType} from '../src/selection';
import {clear, embedFn, circleRegion, polygonRegion, spec, testRenderFn, hits} from './util';
import {clearRegion, embedFn, circleRegion, polygonRegion, spec, testRenderFn, hits} from './util';
import {Page} from 'puppeteer/lib/cjs/puppeteer/common/Page';

describe('region selections at runtime in unit views', () => {
Expand Down Expand Up @@ -60,8 +60,8 @@ describe('region selections at runtime in unit views', () => {
let store = await page.evaluate(circleRegion(hit.id));
expect(store).toHaveLength(hit.count);

store = await page.evaluate(clear(hits.region.circle_clear[0].id));
expect(store).toBeUndefined();
store = await page.evaluate(clearRegion(hits.region.circle_clear[0].id));
expect(store).toHaveLength(0);

await testRender(`clear_0`);
});
Expand Down
14 changes: 10 additions & 4 deletions test-runtime/resolve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
compositeTypes,
embedFn,
hits as hitsMaster,
multiviewRegion,
parentSelector,
pt,
resolutions,
Expand All @@ -14,10 +15,15 @@ import {
import {Page} from 'puppeteer/lib/cjs/puppeteer/common/Page';
import {TopLevelSpec} from '../src';

const fns = {
point: pt,
interval: brush,
region: multiviewRegion
};

for (const type of selectionTypes) {
const isInterval = type === 'interval';
const hits = hitsMaster[type];
const fn = isInterval ? brush : pt;
const fn = fns[type];

describe(`${type} selections at runtime`, () => {
let page: Page;
Expand Down Expand Up @@ -49,7 +55,7 @@ for (const type of selectionTypes) {
const selection = {
type,
resolve: 'global',
...(specType === 'facet' ? {encodings: ['y']} : {})
...(specType === 'facet' && type !== 'region' ? {encodings: ['y']} : {})
};

for (let i = 0; i < hits[specType].length; i++) {
Expand All @@ -72,7 +78,7 @@ for (const type of selectionTypes) {
const selection = {
type,
resolve,
...(specType === 'facet' ? {encodings: ['x']} : {})
...(specType === 'facet' && type !== 'region' ? {encodings: ['x']} : {})
};

/**
Expand Down
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/global_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/global_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/global_2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/global_clear_2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/intersect_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/intersect_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/intersect_2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/intersect_clear_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/intersect_clear_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/intersect_clear_2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/union_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/union_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/union_2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/union_clear_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/union_clear_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/facet/union_clear_2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/global_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/global_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/global_2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/global_clear_2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/intersect_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/intersect_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/intersect_2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/intersect_clear_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/intersect_clear_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/intersect_clear_2.svg

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/union_0.svg

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/union_1.svg

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/union_2.svg

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/union_clear_0.svg

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/union_clear_1.svg

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test-runtime/resources/region/repeat/union_clear_2.svg

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test-runtime/resources/region/unit/clear_0.svg

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions test-runtime/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const generate = process.env.VL_GENERATE_TESTS;
const output = 'test-runtime/resources';

export type ComposeType = 'unit' | 'repeat' | 'facet';
export const selectionTypes: SelectionType[] = ['point', 'interval'];
export const selectionTypes: SelectionType[] = ['point', 'interval', 'region'];
export const compositeTypes: ComposeType[] = ['repeat', 'facet'];
export const resolutions: SelectionResolution[] = ['union', 'intersect'];

Expand Down Expand Up @@ -139,7 +139,13 @@ export const hits = {
],
count: 2
}
]
],

facet: [2, 4, 7],
facet_clear: [3, 5, 8],

repeat: [5, 10, 16],
repeat_clear: [13, 14, 2]
}
};

Expand Down Expand Up @@ -294,8 +300,8 @@ export function parentSelector(compositeType: ComposeType, index: number) {
return compositeType === 'facet' ? `cell > g:nth-child(${index + 1})` : `${UNIT_NAMES.repeat[index]}_group`;
}

export function clear(idx: number, parent?: string, targetBrush?: boolean) {
return `pureClear(${idx}, ${stringValue(parent)}, ${!!targetBrush})`;
export function clearRegion(idx: number, parent?: string, targetBrush?: boolean) {
return `clear(${idx}, ${stringValue(parent)}, ${!!targetBrush})`;
}

export function circleRegion(idx: number, parent?: string, targetBrush?: boolean, radius = 40, segments = 20) {
Expand All @@ -306,6 +312,12 @@ export function polygonRegion(idx: number, polygon: number[][], parent?: string,
return `polygonRegion(${idx}, ${JSON.stringify(polygon)}, ${stringValue(parent)}, ${!!targetBrush})`;
}

export function multiviewRegion(key: string, idx: number, parent?: string, targetBrush?: boolean) {
return key.match('_clear')
? clearRegion(hits.region[key][idx], parent, targetBrush)
: circleRegion(hits.region[key][idx], parent, targetBrush, 10);
}

export function brush(key: string, idx: number, parent?: string, targetBrush?: boolean) {
const fn = key.match('_clear') ? 'clear' : 'brush';
return `${fn}(${hits.interval[key][idx].join(', ')}, ${stringValue(parent)}, ${!!targetBrush})`;
Expand Down

0 comments on commit 7e6cee4

Please sign in to comment.