Skip to content

Commit

Permalink
Convert tests to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Brody committed Sep 2, 2024
1 parent 7399628 commit 4348a52
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 110 deletions.
16 changes: 8 additions & 8 deletions react/test/article_test.js → react/test/article_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Selector } from 'testcafe';
import {
TARGET, SEARCH_FIELD, getLocation, comparison_page, check_textboxes, check_all_category_boxes,
screencap, download_image
} from './test_utils.js';
} from './test_utils';

fixture('longer article test')
.page(TARGET + '/article.html?longname=California%2C+USA')
Expand Down Expand Up @@ -99,33 +99,33 @@ test('uncheck-box-mobile', async t => {
// and a checkbox, then find the checkbox
await t.resizeWindow(400, 800);
// refresh
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await t.wait(1000);
await check_textboxes(t, ['Race']);

await screencap(t, "article/remove_race_initial_mobile");
// refresh
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await screencap(t, "article/remove_race_refresh_mobile");
})

test('uncheck-box-desktop', async t => {
await t.resizeWindow(1400, 800);
// refresh
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await t.wait(1000);
await check_textboxes(t, ['Race']);

await screencap(t, "article/remove_race_initial_desktop");
// refresh
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await screencap(t, "article/remove_race_refresh_desktop");
})

test('simple', async t => {
await t.resizeWindow(1400, 800);
// refresh
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await t.wait(1000);
await check_textboxes(t, ['Simple Ordinals']);

Expand Down Expand Up @@ -317,7 +317,7 @@ fixture('all stats test')

test('california-all-stats', async t => {
await t.resizeWindow(1400, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await check_all_category_boxes(t);
await screencap(t, "article/california-all-stats");
});
Expand All @@ -332,7 +332,7 @@ fixture('all stats test regression')

test('charlotte-all-stats', async t => {
await t.resizeWindow(1400, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await check_all_category_boxes(t);
await screencap(t, "article/charlotte-all-stats");
});
14 changes: 7 additions & 7 deletions react/test/comparison_test.js → react/test/comparison_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ fixture('comparison test heterogenous')

test('comparison-3-desktop-heterogenous', async t => {
await t.resizeWindow(1400, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await screencap(t, "comparison/heterogenous-comparison-desktop");
})

test('comparison-3-mobile-heterogenous', async t => {
await t.resizeWindow(400, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await screencap(t, "comparison/heterogenous-comparison-mobile");
})

Expand All @@ -35,7 +35,7 @@ fixture('comparison test homogenous (2)')

test('comparison-2-mobile', async t => {
await t.resizeWindow(400, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await screencap(t, "comparison/basic-comparison-2-mobile");
})

Expand All @@ -48,19 +48,19 @@ fixture('comparison test homogenous (3)')

test('comparison-3-desktop', async t => {
await t.resizeWindow(1400, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await screencap(t, "comparison/basic-comparison-desktop");
})

test('comparison-3-mobile', async t => {
await t.resizeWindow(400, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await screencap(t, "comparison/basic-comparison-mobile");
})

test('comparison-3-download', async t => {
await t.resizeWindow(1400, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await download_image(t, "comparison/download-comparison");
})

Expand Down Expand Up @@ -124,7 +124,7 @@ fixture('plotted-across-180')

test('comparison-3-plotted-across-180', async t => {
await t.resizeWindow(1400, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await screencap(t, "comparison/plotted-across-180");
});

18 changes: 8 additions & 10 deletions react/test/histogram_test.js → react/test/histogram_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
import { Selector } from 'testcafe';
import { TARGET, check_textboxes, comparison_page, download_histogram, download_image, download_or_check_string, screencap } from './test_utils';

const fs = require('fs');

export const upper_sgv = "Upper San Gabriel Valley CCD [CCD], Los Angeles County, California, USA"
export const pasadena = "Pasadena CCD [CCD], Los Angeles County, California, USA"
export const sw_sgv = "Southwest San Gabriel Valley CCD [CCD], Los Angeles County, California, USA"
export const east_sgv = "East San Gabriel Valley CCD [CCD], Los Angeles County, California, USA"
export const chicago = "Chicago city [CCD], Cook County, Illinois, USA"

async function download_or_check_histogram(t, name) {
async function download_or_check_histogram(t: TestController, name: string) {
const output = await t.eval(() => {
return document.getElementsByClassName("histogram-svg-panel")[0].innerHTML;
});
Expand All @@ -25,7 +23,7 @@ fixture('article check and uncheck test')

test("histogram-article-check-uncheck", async t => {
await t.resizeWindow(800, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
// count the number of `histogram-svg-panel` elements
await t.expect(Selector('.histogram-svg-panel').count).eql(0);
await t.click(Selector('.expand-toggle'));
Expand All @@ -42,7 +40,7 @@ fixture('article test')

test('histogram-basic-article', async t => {
await t.resizeWindow(800, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await t.click(Selector('.expand-toggle'));
await download_or_check_histogram(t, 'histogram-basic-article');
await screencap(t, "histogram/histogram-basic-article");
Expand All @@ -51,9 +49,9 @@ test('histogram-basic-article', async t => {

test('histogram-basic-article-multi', async t => {
await t.resizeWindow(800, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await check_textboxes(t, ["Other Density Metrics"]);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await t.wait(1000);
Selector('.expand-toggle').count.then(async count => {
for (let i = 0; i < count; i++) {
Expand All @@ -74,7 +72,7 @@ fixture('comparison test heterogenous')

test('histogram-basic-comparison', async t => {
await t.resizeWindow(800, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
// select element with class name `expand-toggle`
await t.click(Selector('.expand-toggle'));
await download_or_check_histogram(t, 'histogram-basic-comparison');
Expand All @@ -90,7 +88,7 @@ fixture('comparison test heterogenous with nan')

test('histogram-basic-comparison-nan', async t => {
await t.resizeWindow(800, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
// select element with class name `expand-toggle`
await t.click(Selector('.expand-toggle'));
await download_or_check_histogram(t, 'histogram-basic-comparison-nan');
Expand All @@ -106,7 +104,7 @@ fixture('comparison test heterogenous with nan in the middle')

test('histogram-basic-comparison-nan-middle', async t => {
await t.resizeWindow(800, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
// select element with class name `expand-toggle`
await t.click(Selector('.expand-toggle'));
await download_or_check_histogram(t, 'histogram-basic-comparison-nan-middle');
Expand Down
7 changes: 3 additions & 4 deletions react/test/mapper_test.js → react/test/mapper_test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

import { Selector } from 'testcafe';
import { TARGET, download_or_check_string, most_recent_download_path, screencap } from './test_utils';
import fs from 'fs';

const fs = require('fs');

async function check_geojson(t, path) {
async function check_geojson(t: TestController, path: string) {
// download the geojson by clicking the button
await t.click(Selector('button').withText('Export as GeoJSON'));
await t.wait(3000);
Expand Down Expand Up @@ -34,7 +33,7 @@ fixture('mapping-more-complex')

test("mapping-more-complex", async t => {
await t.resizeWindow(1400, 800);
await t.eval(() => location.reload(true));
await t.eval(() => location.reload());
await t.wait(5000);
await screencap(t, "mapping-more-complex");
await check_geojson(t, "mapping-more-complex-geojson");
Expand Down
Loading

0 comments on commit 4348a52

Please sign in to comment.