Skip to content

Commit

Permalink
wait for quiz loading before pressing button
Browse files Browse the repository at this point in the history
doesn't do much now but is important for infinite quiz
  • Loading branch information
kavigupta committed Jan 11, 2025
1 parent b41b50e commit 62f8e70
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions react/src/components/quiz-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function QuizPanelNoResets(props: { quizDescriptor: QuizDescriptor, todayName?:
const message = index < 0 ? 'Loading quiz...' : 'Loading results...'
return (
<div>
<input type="hidden" data-test-loading-quiz={true} />
<div className={headerClass}>{message}</div>
<LongLoad />
</div>
Expand Down
5 changes: 3 additions & 2 deletions react/test/quiz_test_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { promisify } from 'util'
import { execa, execaSync } from 'execa'
import { ClientFunction, Selector } from 'testcafe'

import { safeReload, screencap, urbanstatsFixture } from './test_utils'
import { safeReload, screencap, urbanstatsFixture, waitForQuizLoading } from './test_utils'

export async function quizScreencap(t: TestController): Promise<void> {
await t.eval(() => {
Expand All @@ -27,7 +27,8 @@ export async function clickButtons(t: TestController, whichs: string[]): Promise
}
// click the kth button with id quiz-answer-button-$which

export function clickButton(t: TestController, which: string): TestControllerPromise {
export async function clickButton(t: TestController, which: string): Promise<TestControllerPromise> {
await waitForQuizLoading(t)
return t.click(Selector('div').withAttribute('id', `quiz-answer-button-${which}`))
}

Expand Down
8 changes: 8 additions & 0 deletions react/test/test_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ export async function waitForLoading(t: TestController): Promise<void> {
await t.wait(1000) // Wait for map to finish rendering
}

export async function waitForQuizLoading(t: TestController): Promise<void> {
// Wait for various components that need to load
while (await Selector(`[data-test-loading-quiz=true]`).exists) {
// this really shouldn't take that long to load, a few extra checks should be fine
await t.wait(100)
}
}

async function prepForImage(t: TestController, options: { hover: boolean, wait: boolean }): Promise<void> {
if (options.hover) {
await t.hover('#searchbox') // Ensure the mouse pointer isn't hovering over any elements that change appearance when hovered over
Expand Down

0 comments on commit 62f8e70

Please sign in to comment.