photoprism/frontend/tests/unit/common/config_test.js

57 lines
2 KiB
JavaScript
Raw Normal View History

2019-08-09 09:53:11 +00:00
import Config from "common/config";
2019-08-09 14:00:52 +00:00
import MockAdapter from "axios-mock-adapter";
import Api from "common/api";
2019-08-09 09:53:11 +00:00
2019-08-13 06:11:22 +00:00
let chai = require('../../../node_modules/chai/chai');
let assert = chai.assert;
2019-08-12 11:00:13 +00:00
describe("common/config", () => {
2019-08-09 14:00:52 +00:00
2019-08-12 11:00:13 +00:00
const mock = new MockAdapter(Api);
2019-08-09 09:53:11 +00:00
it("should get all config values", () => {
const storage = window.localStorage;
const values = {name: "testConfig", year: "2300"};
const config = new Config(storage, values);
const result = config.getValues();
assert.equal(result.name, "testConfig");
});
it("should set multiple config values", () => {
const storage = window.localStorage;
const values = {country: "Germany", city: "Hamburg"};
const newValues = {new: "xxx", city: "Berlin"};
const config = new Config(storage, values);
assert.equal(config.values.new, undefined);
assert.equal(config.values.city, "Hamburg");
config.setValues();
assert.equal(config.values.new, undefined);
assert.equal(config.values.city, "Hamburg");
config.setValues(newValues);
const result = config.getValues();
assert.equal(result.city, "Berlin");
assert.equal(result.new, "xxx");
assert.equal(result.country, "Germany");
});
it("should store values", () => {
const storage = window.localStorage;
const values = {country: "Germany", city: "Hamburg"};
const config = new Config(storage, values);
assert.equal(config.storage["config"], undefined);
config.storeValues();
assert.equal(config.storage["config"], "{\"country\":\"Germany\",\"city\":\"Hamburg\"}");
});
it("should set and get single config value", () => {
const storage = window.localStorage;
const values = {};
const config = new Config(storage, values);
config.set("city", "Berlin");
const result = config.get("city");
2019-08-09 09:53:11 +00:00
assert.equal(result, "Berlin");
});
});