Skip to content

Commit

Permalink
refactor: runtime tests to use hits object + regenerate resources
Browse files Browse the repository at this point in the history
  • Loading branch information
arvind committed Jul 6, 2023
1 parent c267cfd commit 993f7be
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 91 deletions.
6 changes: 3 additions & 3 deletions test-runtime/interval.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {TopLevelSpec} from '../src';
import {SelectionType} from '../src/selection';
import {SELECTION_ID, SelectionType} from '../src/selection';
import {brush, embedFn, geoSpec, hits as hitsMaster, spec, testRenderFn, tuples} from './util';
import {Page} from 'puppeteer/lib/cjs/puppeteer/common/Page';

Expand Down Expand Up @@ -204,7 +204,7 @@ describe('interval selections at runtime in unit views', () => {
const store: any = await page.evaluate(brush('drag', 1));
expect(store).toHaveLength(13);
for (const t of store) {
expect(t).toHaveProperty('_vgsid_');
expect(t).toHaveProperty(SELECTION_ID);
}
await testRender(`geo_1`);
});
Expand All @@ -214,7 +214,7 @@ describe('interval selections at runtime in unit views', () => {
const store: any = await page.evaluate(brush('drag', 0));
expect(store).toHaveLength(20);
for (const t of store) {
expect(t).toHaveProperty('_vgsid_');
expect(t).toHaveProperty(SELECTION_ID);
}
await testRender(`geo_0`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe(`point selections at runtime in unit views`, () => {
});

const type: SelectionType = 'point';
const hits = hitsMaster.discrete;
const hits = hitsMaster.point;

it('should add values to the store', async () => {
for (let i = 0; i < hits.qq.length; i++) {
Expand Down
108 changes: 31 additions & 77 deletions test-runtime/region.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {TopLevelSpec} from '../src';
import {SelectionType} from '../src/selection';
import {clear, embedFn, region, regionByPolygon, spec, testRenderFn} from './util';
import {SELECTION_ID, SelectionType} from '../src/selection';
import {clear, embedFn, circleRegion, polygonRegion, spec, testRenderFn, hits} from './util';
import {Page} from 'puppeteer/lib/cjs/puppeteer/common/Page';

describe('interval selections at runtime in unit views', () => {
describe('region selections at runtime in unit views', () => {
let page: Page;
let embed: (specification: TopLevelSpec) => Promise<void>;
let testRender: (filename: string) => Promise<void>;
Expand All @@ -21,92 +21,46 @@ describe('interval selections at runtime in unit views', () => {

const type: SelectionType = 'region';

it('circle region test 1', async () => {
await embed(spec('unit', 0, {type}));
const store = await page.evaluate(region(14));
it('should add values to the store for circle regions', async () => {
for (const [i, hit] of hits.region.circle.entries()) {
await embed(spec('unit', 0, {type}));
const store: any = await page.evaluate(circleRegion(hit.id));

expect(store).toHaveLength(5);
expect(store[0].fields).toBeUndefined();
expect(store[0].values).toBeUndefined();
expect(store).toHaveLength(hit.count);
expect(store[0].fields).toBeUndefined();
expect(store[0].values).toBeUndefined();
for (const t of store) {
expect(t).toHaveProperty(SELECTION_ID);
}

await testRender(`circle_0`);
await testRender(`circle_${i}`);
}
});

it('circle region test 2', async () => {
await embed(spec('unit', 0, {type}));
const store = await page.evaluate(region(3));
it('should add values to the store for complex polygons', async () => {
for (const [i, hit] of hits.region.polygon.entries()) {
await embed(spec('unit', 0, {type}));
const store: any = await page.evaluate(polygonRegion(hit.id, hit.coords));

expect(store).toHaveLength(2);
expect(store[0].fields).toBeUndefined();
expect(store[0].values).toBeUndefined();
expect(store).toHaveLength(hit.count);
expect(store[0].fields).toBeUndefined();
expect(store[0].values).toBeUndefined();
for (const t of store) {
expect(t).toHaveProperty(SELECTION_ID);
}

await testRender(`cirlce_1`);
});

it('circle region test 3', async () => {
await embed(spec('unit', 0, {type}));
const store = await page.evaluate(region(6));

expect(store).toHaveLength(4);
expect(store[0].fields).toBeUndefined();
expect(store[0].values).toBeUndefined();

await testRender(`circle_2`);
});

it('polygon region test 1', async () => {
await embed(spec('unit', 0, {type}));

const store = await page.evaluate(
regionByPolygon(6, [
[-30, -30],
[-30, 30],
[30, 30],
[30, -30]
])
);

expect(store).toHaveLength(4);
expect(store[0].fields).toBeUndefined();
expect(store[0].values).toBeUndefined();

await testRender(`polygon_0`);
});

it('polygon region test 2', async () => {
await embed(spec('unit', 0, {type}));

const l = 30;
const h = 15;

const store = await page.evaluate(
regionByPolygon(14, [
[-l, -l],
[-l, l],
[-h, h],
[-h, -h],
[h, -h],
[h, l],
[l, l],
[l, -l]
])
);

expect(store).toHaveLength(2);
expect(store[0].fields).toBeUndefined();
expect(store[0].values).toBeUndefined();

await testRender(`polygon_1`);
await testRender(`polygon_${i}`);
}
});

it('should clear out stored extents', async () => {
await embed(spec('unit', 0, {type}));
let store = await page.evaluate(region(14));

expect(store).toHaveLength(5);

store = await page.evaluate(clear(14));
const hit = hits.region.circle[0];
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();

await testRender(`clear_0`);
Expand Down
2 changes: 1 addition & 1 deletion test-runtime/resolve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {TopLevelSpec} from '../src';

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

describe(`${type} selections at runtime`, () => {
Expand Down
2 changes: 1 addition & 1 deletion test-runtime/resources/region/unit/circle_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test-runtime/resources/region/unit/circle_2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test-runtime/resources/region/unit/polygon_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test-runtime/resources/region/unit/polygon_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 41 additions & 4 deletions test-runtime/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const UNIT_NAMES = {
};

export const hits = {
discrete: {
point: {
qq: [8, 19],
qq_clear: [5, 16],

Expand All @@ -69,6 +69,7 @@ export const hits = {
facet: [2, 6, 9],
facet_clear: [3, 4, 8]
},

interval: {
drag: [
[5, 14],
Expand Down Expand Up @@ -103,6 +104,42 @@ export const hits = {
[4, 10]
],
facet_clear: [[3], [5], [7]]
},

region: {
circle: [
{id: 14, count: 5},
{id: 3, count: 2},
{id: 6, count: 4}
],
circle_clear: [{id: 14}],

polygon: [
{
id: 6,
coords: [
[-30, -30],
[-30, 30],
[30, 30],
[30, -30]
],
count: 4
},
{
id: 14,
coords: [
[-30, -30],
[-30, 30],
[-15, 15],
[-15, -15],
[15, -15],
[15, 30],
[30, 30],
[30, -30]
],
count: 2
}
]
}
};

Expand Down Expand Up @@ -261,11 +298,11 @@ export function clear(id: number, parent?: string, targetBrush?: boolean) {
return `pureClear(${id}, ${stringValue(parent)}, ${!!targetBrush})`;
}

export function region(id: number, parent?: string, targetBrush?: boolean) {
export function circleRegion(id: number, parent?: string, targetBrush?: boolean) {
return `circleRegion(${stringValue(parent)}, ${!!targetBrush}, ${id})`;
}

export function regionByPolygon(id: number, polygon: [number, number][], parent?: string, targetBrush?: boolean) {
export function polygonRegion(id: number, polygon: number[][], parent?: string, targetBrush?: boolean) {
return `polygonRegion(${stringValue(parent)}, ${!!targetBrush}, ${id}, ${JSON.stringify(polygon)})`;
}

Expand All @@ -276,7 +313,7 @@ export function brush(key: string, idx: number, parent?: string, targetBrush?: b

export function pt(key: string, idx: number, parent?: string) {
const fn = key.match('_clear') ? 'clear' : 'pt';
return `${fn}(${hits.discrete[key][idx]}, ${stringValue(parent)})`;
return `${fn}(${hits.point[key][idx]}, ${stringValue(parent)})`;
}

export function embedFn(page: Page) {
Expand Down

0 comments on commit 993f7be

Please sign in to comment.