Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
kateryna-ponomarova committed Sep 5, 2024
2 parents a48cd5f + 4407a19 commit 1cb0832
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
4 changes: 3 additions & 1 deletion frontend/src/pages/CreateQuestion/CreateQuestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ function QuizForm() {
{answersArray.map((_answer, index) => (
<div class="answerRow">
<input
id={`answer-text-${index + 1}`}
type="text"
placeholder={`Answer ${index + 1}`}
value={answers()[index]}
onInput={e => updateAnswer(index, (e.target as HTMLInputElement).value)}
class="answerInput"
/>
<input
id={`answer-checkbox-${index + 1}`}
type="checkbox"
checked={correctAnswer() === index}
onChange={() => setCorrectAnswer(index)}
Expand Down Expand Up @@ -132,7 +134,7 @@ function QuizForm() {
Submit
</button>{' '}
<br />
<span>{linkToQuestion()}</span>
<span id="question-link">{linkToQuestion()}</span>
</form>
)
}
Expand Down
13 changes: 12 additions & 1 deletion frontend/tests/pages/question-creation-page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Page } from '@playwright/test'

export default class QuizCreationPage {
export default class QuestionCreationPage {
constructor(private page: Page) {}

goto = async () => this.page.goto('/create-question')
Expand All @@ -10,4 +10,15 @@ export default class QuizCreationPage {
formLocator = () => this.page.locator('form.question-create-form')

enterQuestion = (question: string) => this.page.fill('#question-text-area', question)

enterAnswer = async (index: number, value: string, correct: boolean) => {
await this.page.fill(`#answer-text-${String(index + 1)}`, value)
if (correct) {
await this.page.check(`#answer-checkbox-${String(index + 1)}`)
}
}

clickSubmitButton = async () => this.page.locator('button.submitButton').click()

linkLocator = () => this.page.locator('#question-link')
}
17 changes: 17 additions & 0 deletions frontend/tests/steps/quiz-question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@ Then('I enter question {string}', async (question: string) => {
await expectInputToBe(questionLocator, question)
})

Then('I enter answers:', async (answerRawTable: TableOf<AnswerRaw>) => {
const raw = answerRawTable.raw()
const correctIndex = toCorrectAnswer(raw)
for (let i = 0; i < raw.length; i++) {
await world.questionCreationPage.enterAnswer(i, toAnswers(raw)[i], correctIndex === i)
}
})

Then('I submit question', async () => {
await world.questionCreationPage.clickSubmitButton()
})

Then('I received question link', async () => {
const linkLocator = world.questionCreationPage.linkLocator()
await expectThatIsVisible(linkLocator)
})

Then('I should see question explanation {string}', async (questionExplanation: string) => {
const questionExplanationLocator = world.quizTakingPage.questionExplanationLocator()
await expectTextToBe(questionExplanationLocator, questionExplanation)
Expand Down
13 changes: 8 additions & 5 deletions specs/CreateQuizQuestion.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ Feature: Create a quiz question
Scenario:
When I visit the create question page
Then I should see the create question form
And I enter question "What is capital of France?"
# And I enter answers
# And I mark correct answer
# When I submit question
# Then I recevied question link
And I enter question "What is capital of Italy?"
And I enter answers:
| Rome | correct | Rome is the capital of Italy |
| Naples | | Naples is not the capital of Italy |
| Florence | | Florence is not the capital of Italy |
| Palermo | | Palermo is not the capital of Italy |
When I submit question
Then I received question link

0 comments on commit 1cb0832

Please sign in to comment.