From 993f7be19b598b257f3272770ab4541921b9a8d6 Mon Sep 17 00:00:00 2001 From: Arvind Satyanarayan Date: Thu, 6 Jul 2023 14:49:23 -0400 Subject: [PATCH] refactor: runtime tests to use hits object + regenerate resources --- test-runtime/interval.test.ts | 6 +- .../{discrete.test.ts => point.test.ts} | 2 +- test-runtime/region.test.ts | 108 +++++------------- test-runtime/resolve.test.ts | 2 +- .../resources/region/unit/circle_0.svg | 2 +- .../unit/{cirlce_1.svg => circle_1.svg} | 2 +- .../resources/region/unit/circle_2.svg | 2 +- .../resources/region/unit/polygon_0.svg | 2 +- .../resources/region/unit/polygon_1.svg | 2 +- test-runtime/util.ts | 45 +++++++- 10 files changed, 82 insertions(+), 91 deletions(-) rename test-runtime/{discrete.test.ts => point.test.ts} (98%) rename test-runtime/resources/region/unit/{cirlce_1.svg => circle_1.svg} (50%) diff --git a/test-runtime/interval.test.ts b/test-runtime/interval.test.ts index 5c707a5661c..55cfbf3c696 100644 --- a/test-runtime/interval.test.ts +++ b/test-runtime/interval.test.ts @@ -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'; @@ -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`); }); @@ -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`); }); diff --git a/test-runtime/discrete.test.ts b/test-runtime/point.test.ts similarity index 98% rename from test-runtime/discrete.test.ts rename to test-runtime/point.test.ts index 2d0a4f3b0af..d47c2501e12 100644 --- a/test-runtime/discrete.test.ts +++ b/test-runtime/point.test.ts @@ -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++) { diff --git a/test-runtime/region.test.ts b/test-runtime/region.test.ts index 26f4aef9842..3e81258a502 100644 --- a/test-runtime/region.test.ts +++ b/test-runtime/region.test.ts @@ -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; let testRender: (filename: string) => Promise; @@ -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`); diff --git a/test-runtime/resolve.test.ts b/test-runtime/resolve.test.ts index 2f52e92fe8a..d3873dffde2 100644 --- a/test-runtime/resolve.test.ts +++ b/test-runtime/resolve.test.ts @@ -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`, () => { diff --git a/test-runtime/resources/region/unit/circle_0.svg b/test-runtime/resources/region/unit/circle_0.svg index 03cc7a7946a..b79c887b6e4 100644 --- a/test-runtime/resources/region/unit/circle_0.svg +++ b/test-runtime/resources/region/unit/circle_0.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/test-runtime/resources/region/unit/cirlce_1.svg b/test-runtime/resources/region/unit/circle_1.svg similarity index 50% rename from test-runtime/resources/region/unit/cirlce_1.svg rename to test-runtime/resources/region/unit/circle_1.svg index 0d648260053..33997b39c16 100644 --- a/test-runtime/resources/region/unit/cirlce_1.svg +++ b/test-runtime/resources/region/unit/circle_1.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/test-runtime/resources/region/unit/circle_2.svg b/test-runtime/resources/region/unit/circle_2.svg index 8a808579974..0992ffc4ac2 100644 --- a/test-runtime/resources/region/unit/circle_2.svg +++ b/test-runtime/resources/region/unit/circle_2.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/test-runtime/resources/region/unit/polygon_0.svg b/test-runtime/resources/region/unit/polygon_0.svg index be79a5a71ef..4a4baa010b5 100644 --- a/test-runtime/resources/region/unit/polygon_0.svg +++ b/test-runtime/resources/region/unit/polygon_0.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/test-runtime/resources/region/unit/polygon_1.svg b/test-runtime/resources/region/unit/polygon_1.svg index de9472e38c7..674738c620b 100644 --- a/test-runtime/resources/region/unit/polygon_1.svg +++ b/test-runtime/resources/region/unit/polygon_1.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/test-runtime/util.ts b/test-runtime/util.ts index b28f5d2a2bc..04409f18b7a 100644 --- a/test-runtime/util.ts +++ b/test-runtime/util.ts @@ -56,7 +56,7 @@ const UNIT_NAMES = { }; export const hits = { - discrete: { + point: { qq: [8, 19], qq_clear: [5, 16], @@ -69,6 +69,7 @@ export const hits = { facet: [2, 6, 9], facet_clear: [3, 4, 8] }, + interval: { drag: [ [5, 14], @@ -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 + } + ] } }; @@ -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)})`; } @@ -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) {