Skip to content

Commit

Permalink
feat: score page api connection
Browse files Browse the repository at this point in the history
  • Loading branch information
jcejchan-cen56160 committed Dec 6, 2024
1 parent d49765d commit d56889f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
26 changes: 24 additions & 2 deletions frontend/src/components/QuizScore/QuizScore.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import './QuizScore.css'

import { fetchJson } from 'utils/apiUtils'
import { createSignal, onMount } from 'solid-js'

type Score = {
question_count: number
success_count: number
score: number
}

export function QuizScore() {
const [score, setScore] = createSignal({
question_count: 0,
success_count: 0,
score: 0,
})

onMount(async () => {
const data = await fetchJson<Score>('/api/quiz/score/1')
setScore(data)
})

return (
<div id="quiz-score" class="quiz-score">
<h3>Score</h3>
<p>6 z 5</p>
<p>120%</p>
<p data-test="success_count">
{score().success_count} z {score().question_count}
</p>
<p data-test="success_score">{score().score}%</p>
</div>
)
}
2 changes: 2 additions & 0 deletions frontend/tests/pages/quiz-result-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ export class QuizResultPage {
scoreLocator = () => this.page.locator('#quiz-score')

resultsTableLocator = () => this.page.locator('#results-table')

attributeLocator = (attr: string) => this.page.locator(`[data-test="${attr}"]`)
}
6 changes: 6 additions & 0 deletions frontend/tests/steps/quiz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ Then('I see score', async () => {
await expectThatIsVisible(world.quizResultPage.scoreLocator())
})

Then('I see attribute {string} with value {string}', async (element: string, value: string) => {
const attributeLocator = world.quizResultPage.attributeLocator(element)
await expectThatIsVisible(attributeLocator)
await expectTextToBe(attributeLocator, value)
})

Given('I am on the results page', async function () {
await this.quizResultPage.goto() // Replace with your actual URL
})
Expand Down
6 changes: 6 additions & 0 deletions specs/QuizResultPage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ Feature: Display Results Page
| A | B | C | D |
| D | D | D | D |

Scenario: Score check
When I finish quiz
Then I see the page identifier
And I see score
And I see attribute 'success_count' with value '5 z 6'
And I see attribute 'success_score' with value '83%'

0 comments on commit d56889f

Please sign in to comment.