-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow linking settings on comparison pages (#519)
Closes #504 Mostly a refactor Share the same link component on both article and comparison pages Share the tests, but genericize them by base page
- Loading branch information
Showing
17 changed files
with
205 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,172 +1,3 @@ | ||
import { Selector } from 'testcafe' | ||
import { linkSettingsTests } from './link_settings_test_template' | ||
|
||
import { arrayFromSelector, getLocation, screencap, TARGET, urbanstatsFixture } from './test_utils' | ||
|
||
const baseLink = '/article.html?longname=California%2C+USA' | ||
|
||
urbanstatsFixture('generate link', baseLink, async (t) => { | ||
await t.click('.expandButton[data-category-id=main]') | ||
}) | ||
|
||
const defaultLink = '/article.html?longname=California%2C+USA&s=3t2X5xvsKo' | ||
const expectedLink = '/article.html?longname=California%2C+USA&s=jBXza8t6SU9' | ||
|
||
test('formulates correct link', async (t) => { | ||
// Check imperial, uncheck population | ||
await t.click('input[data-test-id=use_imperial]') | ||
await t.click('input[data-test-id=group_population]:not([inert] *)') | ||
|
||
await t.expect(getLocation()) | ||
.eql(`${TARGET}${expectedLink}`) | ||
}) | ||
|
||
urbanstatsFixture('paste link new visitor', expectedLink) | ||
|
||
async function expectInputTestIdValues(t: TestController, mapping: Record<string, boolean>): Promise<void> { | ||
for (const [testId, value] of Object.entries(mapping)) { | ||
const selector = `input[data-test-id=${testId}]:not([inert] *)` | ||
const isChecked = await Selector(selector).checked | ||
await t.expect(isChecked).eql(value, `expected selector '${selector}' to have 'checked' value ${value}, but instead had ${isChecked}`) | ||
} | ||
} | ||
|
||
test('settings are applied correctly to new visitor', async (t) => { | ||
// assuming localstorage is cleared (happens in the fixture) | ||
await t.click('.expandButton[data-category-id=main]') | ||
|
||
// Should be no staging menu as this was first visit so we steal the settings from the vector | ||
await t.expect(Selector('[data-test-id=staging_controls]').exists).notOk() | ||
|
||
await expectInputTestIdValues(t, { | ||
use_imperial: true, | ||
group_population: false, | ||
}) | ||
|
||
await screencap(t) | ||
}) | ||
|
||
test('settings are not saved for new visitor if they do not make any modifications', async (t) => { | ||
await t.navigateTo(baseLink) | ||
|
||
await t.click('.expandButton[data-category-id=main]') | ||
|
||
await expectInputTestIdValues(t, { | ||
use_imperial: false, | ||
group_population: true, | ||
}) | ||
|
||
await t.expect(getLocation()) | ||
.eql(`${TARGET}${defaultLink}`) | ||
|
||
await screencap(t) | ||
}) | ||
|
||
test('settings are saved for new visitor if they do make a modification', async (t) => { | ||
await t.click('input[data-test-id=year_2010]') | ||
|
||
await t.navigateTo(baseLink) | ||
|
||
await t.click('.expandButton[data-category-id=main]') | ||
|
||
await expectInputTestIdValues(t, { | ||
use_imperial: true, | ||
group_population: false, | ||
year_2010: true, | ||
}) | ||
|
||
await screencap(t) | ||
}) | ||
|
||
urbanstatsFixture('paste link previous visitor', baseLink, async (t) => { | ||
await t.click('input[data-test-id=year_2010]') // change a setting so settings are saved | ||
await t.navigateTo(expectedLink) | ||
await t.click('.expandButton[data-category-id=main]') | ||
}) | ||
|
||
async function expectHighlightedInputTestIds(t: TestController, testIds: string[]): Promise<void> { | ||
const highlightedInputs = await arrayFromSelector(Selector('input[data-test-highlight=true]:not([inert] *)')) | ||
|
||
await t.expect(await Promise.all(highlightedInputs.map(input => input.getAttribute('data-test-id')))).eql(testIds) | ||
} | ||
|
||
test('should have the staging controls', async (t) => { | ||
await t.expect(Selector('[data-test-id=staging_controls]').exists).ok() | ||
|
||
await expectHighlightedInputTestIds(t, ['use_imperial', 'year_2010', 'category_main', 'group_population']) | ||
|
||
await screencap(t) | ||
}) | ||
|
||
test('discard staged settings', async (t) => { | ||
await t.click('button[data-test-id=discard]') | ||
await t.expect(Selector('[data-test-id=staging_controls]').exists).notOk() | ||
await expectHighlightedInputTestIds(t, []) | ||
await expectInputTestIdValues(t, { | ||
use_imperial: false, | ||
group_population: true, | ||
year_2010: true, | ||
}) | ||
|
||
await screencap(t) | ||
}) | ||
|
||
test('apply staged settings', async (t) => { | ||
await t.click('button[data-test-id=apply]') | ||
await t.expect(Selector('[data-test-id=staging_controls]').exists).notOk() | ||
await expectHighlightedInputTestIds(t, []) | ||
await expectInputTestIdValues(t, { | ||
use_imperial: true, | ||
group_population: false, | ||
year_2010: false, | ||
}) | ||
|
||
await t.eval(() => { location.reload() }) | ||
|
||
// Settings persist after reload without staging | ||
await t.expect(Selector('[data-test-id=staging_controls]').exists).notOk() | ||
await expectInputTestIdValues(t, { | ||
use_imperial: true, | ||
group_population: false, | ||
year_2010: false, | ||
}) | ||
|
||
await screencap(t) | ||
}) | ||
|
||
test('manually discard changes', async (t) => { | ||
await t.click('input[data-test-id=use_imperial]') | ||
await t.click('input[data-test-id=group_population]:not([inert] *)') | ||
|
||
await expectHighlightedInputTestIds(t, ['year_2010']) // category is unhighlighted because its groups aren't highlighted | ||
|
||
await t.click('input[data-test-id=year_2010]') | ||
|
||
await t.expect(Selector('[data-test-id=staging_controls]').exists).notOk() | ||
|
||
await expectInputTestIdValues(t, { | ||
use_imperial: false, | ||
group_population: true, | ||
year_2010: true, | ||
}) | ||
|
||
await screencap(t) | ||
}) | ||
|
||
test('apply some changes', async (t) => { | ||
// Apply everything but use_imperial | ||
await t.click('input[data-test-id=use_imperial]') | ||
|
||
await expectHighlightedInputTestIds(t, ['year_2010', 'category_main', 'group_population']) | ||
|
||
await t.click('button[data-test-id=apply]') | ||
|
||
await t.expect(Selector('[data-test-id=staging_controls]').exists).notOk() | ||
|
||
await expectInputTestIdValues(t, { | ||
use_imperial: false, | ||
group_population: false, | ||
year_2010: false, | ||
}) | ||
|
||
await screencap(t) | ||
}) | ||
linkSettingsTests('/article.html?longname=California%2C+USA') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { linkSettingsTests } from './link_settings_test_template' | ||
|
||
linkSettingsTests('/comparison.html?longnames=%5B%22Knoxville+%5BUrban+Area%5D%2C+TN%2C+USA%22%2C%22Louisville+KY+HSA%2C+Louisville+KY+HRR%2C+USA%22%5D') |
Oops, something went wrong.