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

Add quiz clickthrough test #290

Merged
merged 2 commits into from
Aug 14, 2024
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
4 changes: 2 additions & 2 deletions react/src/quiz/quiz-question.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class QuizQuestion extends React.Component {
<div className="gap"></div>
<div style={row_style}>
<div style={{ width: "50%", padding: "0.5em" }}>
<div role='button' className={button_a} onClick={() => this.props.on_select("A")} style={button_style}>
<div role='button' id="quiz-answer-button-a" className={button_a} onClick={() => this.props.on_select("A")} style={button_style}>
<span style={{ margin: "auto" }}>
<div className={"centered_text " + quiztext_css}>
{this.get_option_a()}
Expand All @@ -113,7 +113,7 @@ class QuizQuestion extends React.Component {
</div>
</div>
<div style={{ width: "50%", padding: "0.5em" }}>
<div role='button' className={button_b} onClick={() => this.props.on_select("B")} style={button_style}>
<div role='button' id="quiz-answer-button-b" className={button_b} onClick={() => this.props.on_select("B")} style={button_style}>
<span style={{ margin: "auto" }}>
<div className={"centered_text " + quiztext_css}>
{this.get_option_b()}
Expand Down
42 changes: 41 additions & 1 deletion react/test/quiz_test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,48 @@
import { Selector } from 'testcafe';
import { TARGET, screencap } from './test_utils';

fixture('quiz clickthrough test')
.page(TARGET + '/quiz.html?date=99')
// no local storage
.beforeEach(async t => {
await t.eval(() => {
localStorage.clear()
});
});

// click the kth button with id quiz-answer-button-$which
function click_button(t, which) {
return t.click(Selector("div").withAttribute("id", "quiz-answer-button-" + which));
}

test('quiz-clickthrough-test', async t => {
await click_button(t, "a");
await t.wait(2000);
await screencap(t, "quiz/clickthrough-1");
await click_button(t, "b");
await t.wait(2000);
await screencap(t, "quiz/clickthrough-2");
await click_button(t, "a");
await t.wait(2000);
await screencap(t, "quiz/clickthrough-3");
await click_button(t, "b");
await t.wait(2000);
await screencap(t, "quiz/clickthrough-4");
await click_button(t, "a");
await t.wait(2000);
await t.eval(() => document.getElementById("quiz-timer").remove());
await t.wait(3000);
await screencap(t, "quiz/clickthrough-5");
let quiz_history = await t.eval(() => {
return JSON.stringify(JSON.parse(localStorage.getItem("quiz_history")));
});
await t.expect(quiz_history).eql('{"99":{"choices":["A","B","A","B","A"],"correct_pattern":[true,false,true,false,false]}}');

});

fixture('quiz result test')
.page(TARGET + '/quiz.html?date=100')
// no local storage
// very specific local storage
.beforeEach(async t => {
await t.eval(() => {
localStorage.clear()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.