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 3dc3c57588308f3946d67235202636e8bc2dbe25
parent 9d862226126e38533dabf131ec5a3c7f7b56ae09
Author: AsherMorgan <59518073+AsherMorgan@users.noreply.github.com>
Date:   Fri, 16 Oct 2020 19:19:21 -0700

Move getLang method to global.js.

Diffstat:
Mjs/global.js | 16++++++++++++++++
Mjs/home.js | 14--------------
Mjs/quizzer.js | 20+++-----------------
Mjs/reference.js | 16----------------
Mtests/index.html | 4+++-
Mtests/test.app.js | 17-----------------
Atests/test.global.js | 18++++++++++++++++++
Mtests/test.quizzer.js | 17-----------------
8 files changed, 40 insertions(+), 82 deletions(-)

diff --git a/js/global.js b/js/global.js @@ -47,3 +47,19 @@ function LoadPage() { // Update theme SetTheme(null); } + + + +/** + * Get the language code that matches a label. + * @param {String} label - The label. + * @returns {String} - The language code ("en", "es", etc.) + */ +function getLang(label) { + if (label.toLowerCase().includes("spanish")) { + return "es"; + } + else { + return "en"; + } +} diff --git a/js/home.js b/js/home.js @@ -214,20 +214,6 @@ function loadVue() { }, /** - * Get the language code that matches a label. - * @param {String} label - The label. - * @returns {String} - The language code ("en", "es", etc.) - */ - getLang: function(label) { - if (label.toLowerCase().includes("spanish")) { - return "es"; - } - else { - return "en"; - } - }, - - /** * Update the user's progress in localStorage. * @param {Array} prompts - The list of prompts. * @param {Number} index - The index of the current prompt. diff --git a/js/quizzer.js b/js/quizzer.js @@ -238,20 +238,6 @@ let quizzer = Vue.component("quizzer", { this.Continue(); } }, - - /** - * Get the language code that matches a label. - * @param {String} label - The label. - * @returns {String} - The language code ("en", "es", etc.) - */ - getLang: function(label) { - if (label.toLowerCase().includes("spanish")) { - return "es"; - } - else { - return "en"; - } - }, }, computed: { @@ -270,12 +256,12 @@ let quizzer = Vue.component("quizzer", { }, template: ` - <div> + <div> <p id="quizzerProgress">{{ index }} / {{ prompts.length }}</p> <section> - <label id="quizzerPromptType" for="quizzerPrompt" :lang="getLang(prompt[0])">{{ prompt[0] }}</label> - <span id="quizzerPrompt" @click="Read(prompt[1], prompt[0]);">{{ prompt[1] }}</span> + <label id="quizzerPromptType" for="quizzerPrompt">{{ prompt[0] }}</label> + <span id="quizzerPrompt" :lang="getLang(prompt[0])" @click="Read(prompt[1], prompt[0]);">{{ prompt[1] }}</span> </section> <section> diff --git a/js/reference.js b/js/reference.js @@ -14,22 +14,6 @@ function loadVue() { set: "Choose a vocab set", sets: {"Choose a vocab set":[]}, query: "" - }, - - methods: { - /** - * Get the language code that matches a label. - * @param {String} label - The label. - * @returns {String} - The language code ("en", "es", etc.) - */ - getLang: function(label) { - if (label.toLowerCase().includes("spanish")) { - return "es"; - } - else { - return "en"; - } - } } }); } diff --git a/tests/index.html b/tests/index.html @@ -17,6 +17,7 @@ <div id="app" hidden></div> <!-- Scripts being tested --> + <script src="../js/global.js"></script> <script src="../js/home.js"></script> <script src="../js/quizzer.js"></script> <script src="../js/settings.js"></script> @@ -29,9 +30,10 @@ </script> <!-- Tests --> + <script src="test.global.js"></script> <script src="test.app.js"></script> - <script src="test.quizzer.js"></script> <script src="test.settings.js"></script> + <script src="test.quizzer.js"></script> <!-- Run tests --> <script class="mocha-exec"> diff --git a/tests/test.app.js b/tests/test.app.js @@ -382,23 +382,6 @@ describe("App", function() { }); }); - describe("GetLang method", function () { - it("Should return English by default", function() { - expect(app.getLang("")).to.equal("en"); - expect(app.getLang("test")).to.equal("en"); - }); - - it("Should return English for English labels", function() { - expect(app.getLang("test english test")).to.equal("en"); - expect(app.getLang("ENGLISH")).to.equal("en"); - }) - - it("Should return Spanish for Spanish labels", function() { - expect(app.getLang("test spanish test")).to.equal("es"); - expect(app.getLang("SPANISH")).to.equal("es"); - }) - }); - describe("PromptType watch", function() { it("Should update setting in localStorage", async function() { // Save original setting from localStorage diff --git a/tests/test.global.js b/tests/test.global.js @@ -0,0 +1,18 @@ +describe("Global.js", function() { + describe("GetLang method", function () { + it("Should return English by default", function() { + expect(getLang("")).to.equal("en"); + expect(getLang("test")).to.equal("en"); + }); + + it("Should return English for English labels", function() { + expect(getLang("test english test")).to.equal("en"); + expect(getLang("ENGLISH")).to.equal("en"); + }) + + it("Should return Spanish for Spanish labels", function() { + expect(getLang("test spanish test")).to.equal("es"); + expect(getLang("SPANISH")).to.equal("es"); + }) + }); +}); diff --git a/tests/test.quizzer.js b/tests/test.quizzer.js @@ -447,23 +447,6 @@ describe("Quizzer", function() { }); }); - describe("GetLang method", function () { - it("Should return English by default", function() { - expect(Quizzer.getLang("")).to.equal("en"); - expect(Quizzer.getLang("test")).to.equal("en"); - }); - - it("Should return English for English labels", function() { - expect(Quizzer.getLang("test english test")).to.equal("en"); - expect(Quizzer.getLang("ENGLISH")).to.equal("en"); - }); - - it("Should return Spanish for Spanish labels", function() { - expect(Quizzer.getLang("test spanish test")).to.equal("es"); - expect(Quizzer.getLang("SPANISH")).to.equal("es"); - }); - }); - describe("Active watch", function() { it("Should update prompts and index", async function() { // Initialize variables