Skip to content

Commit

Permalink
random better test (#940)
Browse files Browse the repository at this point in the history
  • Loading branch information
kavigupta authored Feb 10, 2025
1 parent 80b1869 commit 168fa05
Showing 1 changed file with 45 additions and 10 deletions.
55 changes: 45 additions & 10 deletions react/test/random_test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,49 @@
import { target, getLocation, urbanstatsFixture } from './test_utils'

urbanstatsFixture('random', `${target}/random.html?sampleby=population&us_only=true`)
const repeats = 15

test('random-usa', async (t) => {
// wait for load
async function assertIsArticle(t: TestController): Promise<void> {
await t.expect(await getLocation()).contains('/article.html?longname=')
}

async function assertNoSetUniverse(t: TestController): Promise<void> {
await t.expect(await getLocation()).notContains('&universe=')
}

async function assertNoSpecials(t: TestController): Promise<void> {
const location = await getLocation()
await t.expect(location).notMatch(/.*Historical\+Congressional.*/)
}

async function assertCorrect(t: TestController): Promise<void> {
await t.wait(1000)
// contains article
await t.expect(getLocation())
.contains('/article.html?longname=')
// location should not include &universe=
await t.expect(getLocation())
.notContains('&universe=')
})
console.warn(`location: ${await getLocation()}`)
await assertIsArticle(t)
await assertNoSetUniverse(t)
await assertNoSpecials(t)
}

urbanstatsFixture('random-usa-by-population', `${target}/random.html?sampleby=population&us_only=true`)

for (let count = 0; count < repeats; count++) {
test(`random-usa-by-population-${count}`, async (t) => {
await assertCorrect(t)
await t.expect(await getLocation()).match(/.*USA.*/)
})
}

urbanstatsFixture('random-uniformly', `${target}/random.html?sampleby=uniform`)

for (let count = 0; count < repeats; count++) {
test(`random-uniformly-${count}`, async (t) => {
await assertCorrect(t)
})
}

urbanstatsFixture('random-by-population', `${target}/random.html?sampleby=population`)

for (let count = 0; count < repeats; count++) {
test(`random-by-population-${count}`, async (t) => {
await assertCorrect(t)
})
}

0 comments on commit 168fa05

Please sign in to comment.