From 08cca09f22af5e79e46a57d8775cd96dbd587b75 Mon Sep 17 00:00:00 2001 From: theresa Date: Tue, 5 Oct 2021 19:20:03 +0200 Subject: [PATCH] Frontend: Add unit tests --- frontend/tests/unit/fixtures.js | 2 + .../tests/unit/model/config-options_test.js | 52 +++++++++++++++++++ frontend/tests/unit/model/subject_test.js | 4 ++ 3 files changed, 58 insertions(+) create mode 100644 frontend/tests/unit/model/config-options_test.js diff --git a/frontend/tests/unit/fixtures.js b/frontend/tests/unit/fixtures.js index 5ba340438..9994d3ad7 100644 --- a/frontend/tests/unit/fixtures.js +++ b/frontend/tests/unit/fixtures.js @@ -331,6 +331,8 @@ Mock.onPut("api/v1/faces/f123ghytrfggd", { Hidden: true }).reply( ); Mock.onPost("api/v1/subjects/s123ghytrfggd/like").reply(200, { status: "ok" }, mockHeaders); Mock.onDelete("api/v1/subjects/s123ghytrfggd/like").reply(200, { status: "ok" }, mockHeaders); +Mock.onGet("api/v1/config/options").reply(200, { success: "ok" }, mockHeaders); +Mock.onPost("api/v1/config/options").reply(200, { success: "ok" }, mockHeaders); //Mock.onPost().reply(200); //Mock.onDelete().reply(200); diff --git a/frontend/tests/unit/model/config-options_test.js b/frontend/tests/unit/model/config-options_test.js new file mode 100644 index 000000000..8b9f00131 --- /dev/null +++ b/frontend/tests/unit/model/config-options_test.js @@ -0,0 +1,52 @@ +import "../fixtures"; +import ConfigOptions from "model/config-options"; + +let chai = require("chai/chai"); +let assert = chai.assert; + +describe("model/config-options", () => { + it("should get options defaults", () => { + const values = {}; + const options = new ConfigOptions(values); + const result = options.getDefaults(); + assert.equal(result.Debug, false); + assert.equal(result.ReadOnly, false); + assert.equal(result.ThumbSize, 0); + }); + + it("should test changed", () => { + const values = {}; + const options = new ConfigOptions(values); + assert.equal(options.changed(), false); + }); + + it("should load options", (done) => { + const values = {}; + const options = new ConfigOptions(values); + options + .load() + .then((response) => { + assert.equal(response.success, "ok"); + done(); + }) + .catch((error) => { + done(error); + }); + assert.equal(options.changed(), false); + }); + + it("should save options", (done) => { + const values = { Debug: true }; + const options = new ConfigOptions(values); + options + .save() + .then((response) => { + assert.equal(response.success, "ok"); + done(); + }) + .catch((error) => { + done(error); + }); + assert.equal(options.changed(), false); + }); +}); diff --git a/frontend/tests/unit/model/subject_test.js b/frontend/tests/unit/model/subject_test.js index 80387a00d..3d91501b0 100644 --- a/frontend/tests/unit/model/subject_test.js +++ b/frontend/tests/unit/model/subject_test.js @@ -200,6 +200,10 @@ describe("model/subject", () => { assert.equal(subject.Favorite, true); }); + it("should return batch size", () => { + assert.equal(Subject.batchSize(), 60); + }); + it("should get collection resource", () => { const result = Subject.getCollectionResource(); assert.equal(result, "subjects");