Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait for quiz loading before pressing button #873

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading