From adf425d9d8754cbe00ca15b6fe807f74ffd99f19 Mon Sep 17 00:00:00 2001 From: Luke Brody Date: Mon, 16 Sep 2024 15:26:28 -0400 Subject: [PATCH] Remove manual naming from screencaps, --- react/test/article_test.ts | 42 +++++++++++++++++------------------ react/test/comparison_test.ts | 14 ++++++------ react/test/histogram_test.ts | 14 ++++++------ react/test/mapper_test.ts | 4 ++-- react/test/quiz_test.ts | 18 +++++++-------- react/test/search_test.ts | 10 ++++----- react/test/settings_test.ts | 4 ++-- react/test/statistics_test.ts | 10 ++++----- react/test/test_utils.ts | 29 ++++++++++++++---------- 9 files changed, 75 insertions(+), 70 deletions(-) diff --git a/react/test/article_test.ts b/react/test/article_test.ts index f6d346afa..7cc3405ef 100644 --- a/react/test/article_test.ts +++ b/react/test/article_test.ts @@ -14,12 +14,12 @@ fixture('longer article test') test('california-article-test', async (t) => { // screenshot path: images/first_test.png - await screencap(t, 'article/california') + await screencap(t) }) test('neighboring-state-test', async (t) => { await t.wait(1000) - await screencap(t, 'article/california-with-neighbors') + await screencap(t) await t .click(Selector('path').withAttribute('class', /tag-Arizona,_USA/)) await t.expect(getLocation()) @@ -33,7 +33,7 @@ fixture('shorter article test') }) test('san-marino-article-test', async (t) => { - await screencap(t, 'article/san-marino') + await screencap(t) }) test('editable-number', async (t) => { @@ -86,7 +86,7 @@ test('lr-buttons', async (t) => { test('san-marino-2010-health', async (t) => { await check_textboxes(t, ['2010 Census', 'Health']) - await screencap(t, 'article/san-marino-2010-health') + await screencap(t) }) test('uncheck-box-mobile', async (t) => { @@ -98,10 +98,10 @@ test('uncheck-box-mobile', async (t) => { await t.wait(1000) await check_textboxes(t, ['Race']) - await screencap(t, 'article/remove_race_initial_mobile') + await screencap(t) // refresh await t.eval(() => { location.reload() }) - await screencap(t, 'article/remove_race_refresh_mobile') + await screencap(t) }) test('uncheck-box-desktop', async (t) => { @@ -111,10 +111,10 @@ test('uncheck-box-desktop', async (t) => { await t.wait(1000) await check_textboxes(t, ['Race']) - await screencap(t, 'article/remove_race_initial_desktop') + await screencap(t) // refresh await t.eval(() => { location.reload() }) - await screencap(t, 'article/remove_race_refresh_desktop') + await screencap(t) }) test('simple', async (t) => { @@ -124,11 +124,11 @@ test('simple', async (t) => { await t.wait(1000) await check_textboxes(t, ['Simple Ordinals']) - await screencap(t, 'article/simple-ordinals') + await screencap(t) }) test('download-article', async (t) => { - await download_image(t, 'article/download-article') + await download_image(t) }) test('create-comparison-from-article', async (t) => { @@ -151,7 +151,7 @@ fixture('article universe selector test') test('article-universe-selector-test', async (t) => { await t .click(Selector('img').withAttribute('class', 'universe-selector')) - await screencap(t, 'article-dropped-down-universe-selector') + await screencap(t) await t .click( Selector('img') @@ -171,7 +171,7 @@ fixture('article universe selector test international') test('article-universe-selector-test', async (t) => { await t .click(Selector('img').withAttribute('class', 'universe-selector')) - await screencap(t, 'article-dropped-down-universe-selector-international') + await screencap(t) await t .click( Selector('img') @@ -179,7 +179,7 @@ test('article-universe-selector-test', async (t) => { .withAttribute('alt', 'India')) await t.expect(getLocation()) .eql(`${TARGET}/article.html?longname=Delhi+%5BNew+Delhi%5D+Urban+Center%2C+India&universe=India`) - await screencap(t, 'article/delhi-india') + await screencap(t) }) fixture('article universe navigation test') @@ -216,7 +216,7 @@ test('article-universe-statistic-page', async (t) => { .click(Selector('a').withText(/^Area$/)) await t.expect(getLocation()) .eql(`${TARGET}/statistic.html?statname=Area&article_type=City&start=821&amount=20&universe=California%2C+USA`) - await screencap(t, 'statistics/universe-statistic-page') + await screencap(t) }) test('article-universe-related-button', async (t) => { @@ -246,7 +246,7 @@ test('article-universe-compare', async (t) => { .eql( `${TARGET}/comparison.html?longnames=%5B%22San+Marino+city%2C+California%2C+USA%22%2C%22San+Francisco+city%2C+California%2C+USA%22%5D&universe=California%2C+USA`, ) - await screencap(t, 'comparison/universe-compare') + await screencap(t) }) test('article-universe-compare-different', async (t) => { @@ -259,7 +259,7 @@ test('article-universe-compare-different', async (t) => { .eql( `${TARGET}/comparison.html?longnames=%5B%22San+Marino+city%2C+California%2C+USA%22%2C%22Chicago+city%2C+Illinois%2C+USA%22%5D`, ) - await screencap(t, 'comparison/universe-compare-different') + await screencap(t) }) fixture('article universe state test') @@ -281,7 +281,7 @@ test('article-universe-state-world', async (t) => { await t.expect(getLocation()) .eql(`${TARGET}/article.html?longname=California%2C+USA&universe=world`) // screenshot - await screencap(t, 'article/california-world') + await screencap(t) }) fixture('article universe state from subnational test') @@ -292,13 +292,13 @@ fixture('article universe state from subnational test') }) test('article-universe-state-from-subnational', async (t) => { - await screencap(t, 'article/kerala-india') + await screencap(t) // click the > button await t .click(Selector('a').withText('>')) await t.expect(getLocation()) .eql(`${TARGET}/article.html?longname=California%2C+USA&universe=world`) - await screencap(t, 'article/california-world-from-kerala') + await screencap(t) }) fixture('all stats test') @@ -312,7 +312,7 @@ test('california-all-stats', async (t) => { await t.resizeWindow(1400, 800) await t.eval(() => { location.reload() }) await check_all_category_boxes(t) - await screencap(t, 'article/california-all-stats') + await screencap(t) }) // selected because the gz changed in statistic classes @@ -327,5 +327,5 @@ test('charlotte-all-stats', async (t) => { await t.resizeWindow(1400, 800) await t.eval(() => { location.reload() }) await check_all_category_boxes(t) - await screencap(t, 'article/charlotte-all-stats') + await screencap(t) }) diff --git a/react/test/comparison_test.ts b/react/test/comparison_test.ts index c2b2cb944..52b099059 100644 --- a/react/test/comparison_test.ts +++ b/react/test/comparison_test.ts @@ -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() }) - await screencap(t, 'comparison/heterogenous-comparison-desktop') + await screencap(t) }) test('comparison-3-mobile-heterogenous', async (t) => { await t.resizeWindow(400, 800) await t.eval(() => { location.reload() }) - await screencap(t, 'comparison/heterogenous-comparison-mobile') + await screencap(t) }) fixture('comparison test homogenous (2)') @@ -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() }) - await screencap(t, 'comparison/basic-comparison-2-mobile') + await screencap(t) }) fixture('comparison test homogenous (3)') @@ -47,19 +47,19 @@ fixture('comparison test homogenous (3)') test('comparison-3-desktop', async (t) => { await t.resizeWindow(1400, 800) await t.eval(() => { location.reload() }) - await screencap(t, 'comparison/basic-comparison-desktop') + await screencap(t) }) test('comparison-3-mobile', async (t) => { await t.resizeWindow(400, 800) await t.eval(() => { location.reload() }) - await screencap(t, 'comparison/basic-comparison-mobile') + await screencap(t) }) test('comparison-3-download', async (t) => { await t.resizeWindow(1400, 800) await t.eval(() => { location.reload() }) - await download_image(t, 'comparison/download-comparison') + await download_image(t) }) test('comparison-3-add', async (t) => { @@ -123,5 +123,5 @@ fixture('plotted-across-180') test('comparison-3-plotted-across-180', async (t) => { await t.resizeWindow(1400, 800) await t.eval(() => { location.reload() }) - await screencap(t, 'comparison/plotted-across-180') + await screencap(t) }) diff --git a/react/test/histogram_test.ts b/react/test/histogram_test.ts index 8d986bc5e..e2f081471 100644 --- a/react/test/histogram_test.ts +++ b/react/test/histogram_test.ts @@ -43,7 +43,7 @@ test('histogram-basic-article', async (t) => { 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') + await screencap(t) }) test('histogram-basic-article-multi', async (t) => { @@ -56,8 +56,8 @@ test('histogram-basic-article-multi', async (t) => { for (let i = 0; i < count; i++) { await t.click(Selector('.expand-toggle').nth(i)) } - await screencap(t, 'histogram/histogram-basic-article-multi') - await download_image(t, 'histogram/histogram-basic-article-multi-screenshot') + await screencap(t) + await download_image(t) await download_histogram(t, 'histogram/histogram-basic-article-multi-histogram-0', 0) await download_histogram(t, 'histogram/histogram-basic-article-multi-histogram-1', 1) }) @@ -74,7 +74,7 @@ test('histogram-basic-comparison', async (t) => { // select element with class name `expand-toggle` await t.click(Selector('.expand-toggle')) await download_or_check_histogram(t, 'histogram-basic-comparison') - await screencap(t, 'histogram/histogram-basic-comparison') + await screencap(t) }) fixture('comparison test heterogenous with nan') @@ -89,7 +89,7 @@ test('histogram-basic-comparison-nan', async (t) => { // select element with class name `expand-toggle` await t.click(Selector('.expand-toggle')) await download_or_check_histogram(t, 'histogram-basic-comparison-nan') - await screencap(t, 'histogram/histogram-basic-comparison-nan') + await screencap(t) }) fixture('comparison test heterogenous with nan in the middle') @@ -104,7 +104,7 @@ test('histogram-basic-comparison-nan-middle', async (t) => { // select element with class name `expand-toggle` await t.click(Selector('.expand-toggle')) await download_or_check_histogram(t, 'histogram-basic-comparison-nan-middle') - await screencap(t, 'histogram/histogram-basic-comparison-nan-middle') + await screencap(t) }) fixture('comparison ordering test') @@ -116,5 +116,5 @@ fixture('comparison ordering test') test('histogram-ordering', async (t) => { await t.click(Selector('.expand-toggle')) await download_or_check_histogram(t, 'histogram-ordering') - await screencap(t, 'histogram/histogram-ordering') + await screencap(t) }) diff --git a/react/test/mapper_test.ts b/react/test/mapper_test.ts index 4b0721514..27043c03c 100644 --- a/react/test/mapper_test.ts +++ b/react/test/mapper_test.ts @@ -21,7 +21,7 @@ fixture('mapping') }) test('state-map', async (t) => { - await screencap(t, 'state-map') + await screencap(t) await check_geojson(t, 'state-map-geojson') }) @@ -36,6 +36,6 @@ test('mapping-more-complex', async (t) => { await t.resizeWindow(1400, 800) await t.eval(() => { location.reload() }) await t.wait(5000) - await screencap(t, 'mapping-more-complex') + await screencap(t) await check_geojson(t, 'mapping-more-complex-geojson') }) diff --git a/react/test/quiz_test.ts b/react/test/quiz_test.ts index 983160688..6f952c1f5 100644 --- a/react/test/quiz_test.ts +++ b/react/test/quiz_test.ts @@ -122,21 +122,21 @@ quiz_fixture( test('quiz-clickthrough-test', async (t) => { await click_button(t, 'a') await t.wait(2000) - await quiz_screencap(t, 'quiz/clickthrough-1') + await quiz_screencap(t) await click_button(t, 'b') await t.wait(2000) - await quiz_screencap(t, 'quiz/clickthrough-2') + await quiz_screencap(t) await click_button(t, 'a') await t.wait(2000) - await quiz_screencap(t, 'quiz/clickthrough-3') + await quiz_screencap(t) await click_button(t, 'b') await t.wait(2000) - await quiz_screencap(t, 'quiz/clickthrough-4') + await quiz_screencap(t) await click_button(t, 'a') await t.wait(2000) await t.eval(() => { document.getElementById('quiz-timer')!.remove() }) await t.wait(3000) - await quiz_screencap(t, 'quiz/clickthrough-5') + await quiz_screencap(t) const quiz_history: unknown = await t.eval(() => { return JSON.stringify(JSON.parse(localStorage.getItem('quiz_history')!)) }) @@ -215,7 +215,7 @@ quiz_fixture( test('quiz-percentage-correct', async (t) => { await t.eval(() => { location.reload() }) await click_buttons(t, ['a', 'a', 'a', 'a', 'a']) - await quiz_screencap(t, 'quiz/percentage-correct') + await quiz_screencap(t) await t.expect(await juxtastat_table()).eql( `${Array.from(Array(30).keys()).map(i => `${i + 30}|99|101`).join('\n')}\n` + `7|99|15\n`, ) @@ -228,7 +228,7 @@ test('quiz-percentage-correct', async (t) => { }) await t.eval(() => { location.reload() }) await click_buttons(t, ['a', 'a', 'a', 'a', 'a']) - await quiz_screencap(t, 'quiz/percentage-correct-2') + await quiz_screencap(t) await t.expect(await juxtastat_table()).eql( `${Array.from(Array(30).keys()).map(i => `${i + 30}|99|101`).join('\n')}\n` + `7|99|15\n` + `8|99|15\n`, ) @@ -339,7 +339,7 @@ test('quiz-results-test', async (t) => { await t.eval(() => { location.reload() }) await t.wait(1000) await t.eval(() => { location.reload() }) - await quiz_screencap(t, 'quiz/results-page') + await quiz_screencap(t) await check_text(t, 'Excellent! 😊 4/5', '🟩🟩🟩🟩🟥') }) @@ -380,7 +380,7 @@ fixture('several quiz results') test('several-quiz-results-test', async (t) => { await t.eval(() => { location.reload() }) - await quiz_screencap(t, 'quiz/results-page-several') + await quiz_screencap(t) // true true true true false await check_text(t, 'Excellent! 😊 4/5', '🟩🟩🟩🟩🟥') // go to the next quiz via changing the href diff --git a/react/test/search_test.ts b/react/test/search_test.ts index 65afcc947..7c4c6798d 100644 --- a/react/test/search_test.ts +++ b/react/test/search_test.ts @@ -12,7 +12,7 @@ test('search-test', async (t) => { await t .click(SEARCH_FIELD) .typeText(SEARCH_FIELD, 'Pasadena') - await screencap(t, 'search/san-marino-search-pasadena') + await screencap(t) await t .pressKey('enter') await t.expect(getLocation()) @@ -23,21 +23,21 @@ test('search-test-with-extra-char', async (t) => { await t .click(SEARCH_FIELD) .typeText(SEARCH_FIELD, 'Pasadena c') - await screencap(t, 'search/san-marino-search-pasadena-c') + await screencap(t) }) test('search-test-with-special-chars', async (t) => { await t .click(SEARCH_FIELD) .typeText(SEARCH_FIELD, 'Utt') - await screencap(t, 'search/san-marino-search-Utt') + await screencap(t) }) test('search-test-different-first-char', async (t) => { await t .click(SEARCH_FIELD) .typeText(SEARCH_FIELD, 'hina') - await screencap(t, 'search/san-marino-search-hina') + await screencap(t) }) test('search-test-arrows', async (t) => { @@ -50,7 +50,7 @@ test('search-test-arrows', async (t) => { await t .pressKey('down') .pressKey('down') - await screencap(t, 'search/san-marino-search-pasadena-down-down') + await screencap(t) await t .pressKey('enter') await t.expect(getLocation()) diff --git a/react/test/settings_test.ts b/react/test/settings_test.ts index ad8fb5a00..048c47849 100644 --- a/react/test/settings_test.ts +++ b/react/test/settings_test.ts @@ -19,7 +19,7 @@ fixture('settings regression test') test('check-settings-loaded', async (t) => { // screenshot path: images/first_test.png - await screencap(t, 'settings/check-settings-loaded') + await screencap(t) // check there's an element containing class Huntington_Library await t.expect(Selector('path').withAttribute('class', /tag-Huntington_Library/).exists).ok() // check that there's no element Pasadena_city or 91101 @@ -31,7 +31,7 @@ test('check-settings-loaded-desktop', async (t) => { // screenshot path: images/first_test.png await t.resizeWindow(1400, 800) await t.eval(() => { location.reload() }) - await screencap(t, 'settings/check-settings-loaded-desktop') + await screencap(t) }) test('check-settings-persistent', async (t) => { diff --git a/react/test/statistics_test.ts b/react/test/statistics_test.ts index 5ab9c711f..4a2901521 100644 --- a/react/test/statistics_test.ts +++ b/react/test/statistics_test.ts @@ -17,7 +17,7 @@ test('statistics-page', async (t) => { // assert url is https://urbanstats.org/statistic.html?statname=Population&article_type=Hospital+Referral+Region&start=21&amount=20 await t.expect(getLocation()) .eql(`${TARGET}/statistic.html?statname=Population&article_type=Hospital+Referral+Region&start=21&amount=20&universe=USA`) - await screencap(t, 'statistics/population') + await screencap(t) const count = Selector('div').withAttribute('style', /background-color: rgb\(212, 181, 226\);/) .withText(/Indianapolis IN HRR, USA/) await t.expect(count.count).gte(1, 'Need highlighting') @@ -62,14 +62,14 @@ test('statistics-navigation-amount', async (t) => { .click(Selector('option').withText('50')) await t.expect(getLocation()) .eql(`${TARGET}/statistic.html?statname=Population&article_type=Hospital+Referral+Region&start=1&amount=50`) - await screencap(t, 'statistics/amount-50') + await screencap(t) // set to All await t .click(amount) .click(Selector('option').withText('All')) await t.expect(getLocation()) .eql(`${TARGET}/statistic.html?statname=Population&article_type=Hospital+Referral+Region&start=1&amount=All`) - await screencap(t, 'statistics/amount-all') + await screencap(t) }) test('statistics-navigation-last-page', async (t) => { @@ -86,7 +86,7 @@ test('statistics-navigation-last-page', async (t) => { await t.expect(getLocation()) .eql(url) - await screencap(t, 'statistics/last-page') + await screencap(t) // going right again does nothing await t .click(Selector('button').withText('>')) @@ -104,7 +104,7 @@ fixture('statistic universe selector test') test('statistic-universe-selector-test', async (t) => { await t .click(Selector('img').withAttribute('class', 'universe-selector')) - await screencap(t, 'statistic-dropped-down-universe-selector') + await screencap(t) await t .click( Selector('img') diff --git a/react/test/test_utils.ts b/react/test/test_utils.ts index 0313a7df0..bc8d257d0 100644 --- a/react/test/test_utils.ts +++ b/react/test/test_utils.ts @@ -89,35 +89,40 @@ function test_file_name(): string { throw new Error(`Test file not found in args: ${process.argv}`) } -function screenshot_path(t: TestController, name: string): string { - return `${test_file_name()}/${t.browser.name}/${name}.png` +function screenshot_path(t: TestController): string { + let number = 0 + const resultPath = (): string => `${test_file_name()}/${t.browser.name}/${t.test.name}-${number}.png` + while (fs.existsSync(resultPath())) { + number++ + } + return resultPath() } -export async function screencap(t: TestController, name: string): Promise { +export async function screencap(t: TestController): Promise { await prep_for_image(t) return t.takeScreenshot({ // include the browser name in the screenshot path - path: screenshot_path(t, name), + path: screenshot_path(t), fullPage: true, }) } -export async function grab_download(t: TestController, name: string, button: Selector): Promise { +export async function grab_download(t: TestController, button: Selector): Promise { await prep_for_image(t) await t .click(button) await t.wait(3000) - copy_most_recent_file(t, name) + copy_most_recent_file(t) } -export async function download_image(t: TestController, name: string): Promise { +export async function download_image(t: TestController): Promise { const download = Selector('img').withAttribute('src', '/screenshot.png') - await grab_download(t, name, download) + await grab_download(t, download) } -export async function download_histogram(t: TestController, name: string, nth: number): Promise { +export async function download_histogram(t: TestController, nth: number): Promise { const download = Selector('img').withAttribute('src', '/download.png').nth(nth) - await grab_download(t, name, download) + await grab_download(t, download) } export function most_recent_download_path(): string { @@ -127,10 +132,10 @@ export function most_recent_download_path(): string { return sorted[0] } -function copy_most_recent_file(t: TestController, name: string): void { +function copy_most_recent_file(t: TestController): void { // copy the file to the screenshots folder const screenshotsFolder = path.join(__dirname, '..', 'screenshots') - fs.copyFileSync(most_recent_download_path(), path.join(screenshotsFolder, screenshot_path(t, name))) + fs.copyFileSync(most_recent_download_path(), path.join(screenshotsFolder, screenshot_path(t))) } export async function download_or_check_string(t: TestController, string: string, name: string): Promise {