commit f20349bf2f73e69ac61c550764b7b64210675598
parent 7e47b63adbd1c62c3f67e378528e42f0008de981
Author: AsherMorgan <59518073+AsherMorgan@users.noreply.github.com>
Date: Fri, 23 Oct 2020 09:32:08 -0700
Focus quizzer input when quizzer is reset.
Diffstat:
2 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/js/quizzer.js b/js/quizzer.js
@@ -66,6 +66,11 @@ let quizzer = Vue.component("quizzer", {
// Show and hide elements
this.responceActive = true;
+ try {
+ // Will fail if not mounted
+ this.$refs.input.focus();
+ }
+ catch { }
// Get new prompt
this.index++;
diff --git a/tests/test.quizzer.js b/tests/test.quizzer.js
@@ -83,6 +83,27 @@ describe("Quizzer", function() {
expect(Quizzer.responceActive).to.equal(true);
});
+ it("Should focus input", function() {
+ // Initialize variables
+ Quizzer.active = true;
+
+ // Override focus method
+ let focusCalled = true;
+ Quizzer.$refs = {
+ input: {
+ focus: function() {
+ focusCalled = true;
+ }
+ }
+ };
+
+ // Run reset
+ Quizzer.Reset();
+
+ // Assert focus called
+ expect(focusCalled).to.equal(true);
+ });
+
it("Should emit 'new-prompts' event", function() {
// Initialize variables
Quizzer.active = true;
@@ -206,6 +227,29 @@ describe("Quizzer", function() {
expect(Quizzer.responceActive).to.equal(false);
});
+ it("Should focus input if responce is incorrect", function() {
+ // Initialize variables
+ Quizzer.active = true;
+ Quizzer.prompts = [["A1", "A2", "A3", "A4"]]
+ Quizzer.responce = "A5";
+
+ // Override focus method
+ let focusCalled = true;
+ Quizzer.$refs = {
+ input: {
+ focus: function() {
+ focusCalled = true;
+ }
+ }
+ };
+
+ // Call submit
+ Quizzer.Submit();
+
+ // Assert focus called
+ expect(focusCalled).to.equal(true);
+ });
+
it("Should accept multiple responces", function() {
// Initialize variables
Quizzer.active = true;