spanish-quizzer

An app to quiz you on Spanish vocabulary and verb conjugations
git clone https://git.ashermorgan.net/spanish-quizzer/
Log | Files | Refs | README

commit 83bd99ae1c0644daf87994bb840084f8fc1cc66d
parent 4fe96fc2de16e65a1333e0094330b69db1c92b76
Author: AsherMorgan <59518073+AsherMorgan@users.noreply.github.com>
Date:   Sun, 11 Oct 2020 15:39:42 -0700

Implement onMissedPrompt setting.

Diffstat:
Mindex.html | 10+++++++++-
Mjs/home.js | 9+++++++++
Mjs/quizzer.js | 19++++++++++++++-----
Mtests/test.quizzer.js | 38+++++++++++++++++++++++++++++++++++---
4 files changed, 67 insertions(+), 9 deletions(-)

diff --git a/index.html b/index.html @@ -148,6 +148,14 @@ </select> </div> <div> + <label for="settingsRepeatPrompts">When I miss a prompt</label> + <select id="settingsRepeatPrompts" v-model="onMissedPrompt"> + <option>Correct me</option> + <option>Tell me</option> + <option>Ignore it</option> + </select> + </div> + <div> <label for="settingsRepeatPrompts">Repeat missed prompts</label> <select id="settingsRepeatPrompts" v-model="repeatPrompts"> <option>Never</option> @@ -169,7 +177,7 @@ <quizzer id="quizzer" v-show="state === 'verbQuizzer' || state === 'vocabQuizzer'" :active="state === 'verbQuizzer' || state === 'vocabQuizzer'" hidden :starting-index="promptIndex" :starting-prompts="prompts" @new-prompt="updateProgress" - :prompt-type="promptType" :input-type="inputType" :repeat-prompts="repeatPrompts"> + :prompt-type="promptType" :input-type="inputType" :on-missed-prompt="onMissedPrompt" :repeat-prompts="repeatPrompts"> </quizzer> </main> diff --git a/js/home.js b/js/home.js @@ -19,6 +19,7 @@ function loadVue() { errorMsg: "", promptType: localStorage.getItem("promptType") || "Text", inputType: localStorage.getItem("inputType") || "Text", + onMissedPrompt: localStorage.getItem("onMissedPrompt") || "Correct me", repeatPrompts: localStorage.getItem("repeatPrompts") || "Never", prompts: [], @@ -275,6 +276,14 @@ function loadVue() { }, /** + * Update the onMissedPrompt setting in localStorage. + * @param {String} value - The onMissedPrompt setting value. + */ + onMissedPrompt: function(value) { + localStorage.setItem("onMissedPrompt", value); + }, + + /** * Update the repeatPrompts setting in localStorage. * @param {String} value - The repeat prompts setting value. */ diff --git a/js/quizzer.js b/js/quizzer.js @@ -24,6 +24,10 @@ let quizzer = Vue.component("quizzer", { type: String, default: "Text", }, + onMissedPrompt: { + type: String, + default: "Correct me", + }, repeatPrompts: { type: String, default: "Never", @@ -162,10 +166,10 @@ let quizzer = Vue.component("quizzer", { } // Give user feedback - if (!correct) { + if (!correct && (this.onMissedPrompt === "Correct me" || this.onMissedPrompt === "Tell me")) { // Show and hide elements - this.congratsActive = false; - this.responceActive = false; + this.congratsActive = false; + this.responceActive = false; try { // Will fail if not mounted this.$refs.feedback.scrollIntoView(false); @@ -288,8 +292,13 @@ let quizzer = Vue.component("quizzer", { </div> <div id="quizzerFeedback" ref="feedback" v-show="!responceActive" class="bad"> - The correct answer is - <span id="quizzerFeedbackTerm" @click="Read(prompt[3], prompt[2]);">{{ prompt[3].toLowerCase() }}</span>. + <span v-if="onMissedPrompt === 'Correct me'"> + The correct answer is + <span id="quizzerFeedbackTerm" @click="Read(prompt[3], prompt[2]);">{{ prompt[3].toLowerCase() }}</span>. + </span> + <span v-if="onMissedPrompt === 'Tell me'"> + Incorrect. + </span> </div> <div id="quizzerCongrats" class="good" v-show="congratsActive">Congratulations! You made it back to the beginning!</div> </div> diff --git a/tests/test.quizzer.js b/tests/test.quizzer.js @@ -18,15 +18,19 @@ describe("Quizzer", function() { expect(Quizzer.startingIndex).to.equal(0); }); - it("PromptType should be text", function() { + it("PromptType should be 'Text'", function() { expect(Quizzer.promptType).to.equal("Text"); }); - it("InputType should be text", function() { + it("InputType should be 'Text'", function() { expect(Quizzer.inputType).to.equal("Text"); }); - it("RepeatPrompts should be never", function() { + it("OnMissedPrompt should be 'Correct me'", function() { + expect(Quizzer.onMissedPrompt).to.equal("Correct me"); + }); + + it("RepeatPrompts should be 'Never'", function() { expect(Quizzer.repeatPrompts).to.equal("Never"); }); @@ -146,6 +150,34 @@ describe("Quizzer", function() { expect(Quizzer.congratsActive).to.equal(true); // Reset will show congrats }); + it("Should call Reset if onMissedPrompt is set to 'Ignore it'", function() { + // Initialize variables + Quizzer.active = true; + Quizzer.onMissedPrompt = "Ignore it"; + Quizzer.prompts = [["A1", "A2", "A3", "A4"]] + Quizzer.responce = "A5"; + + // Call Submit + Quizzer.Submit(); + + // Assert Reset called + expect(Quizzer.congratsActive).to.equal(true); // Reset will show congrats + }); + + it("Should not call Reset if onMissedPrompt is set to 'Tell me'", function() { + // Initialize variables + Quizzer.active = true; + Quizzer.onMissedPrompt = "Tell me"; + Quizzer.prompts = [["A1", "A2", "A3", "A4"]] + Quizzer.responce = "A5"; + + // Call Submit + Quizzer.Submit(); + + // Assert responceActive set to false + expect(Quizzer.responceActive).to.equal(false); + }); + it("Should set responceActive to false if responce is incorrect", function() { // Initialize variables Quizzer.active = true;