2021-07-12 19:25:37 +02:00
|
|
|
import "../fixtures";
|
2019-08-09 11:53:11 +02:00
|
|
|
import Config from "common/config";
|
2020-09-21 01:53:06 +02:00
|
|
|
import StorageShim from "node-storage-shim";
|
2019-08-09 11:53:11 +02:00
|
|
|
|
2020-07-02 10:03:00 +02:00
|
|
|
let chai = require("chai/chai");
|
2019-08-13 08:11:22 +02:00
|
|
|
let assert = chai.assert;
|
|
|
|
|
2020-09-21 01:53:06 +02:00
|
|
|
const config2 = new Config(new StorageShim(), window.__CONFIG__);
|
2020-06-30 16:53:12 +02:00
|
|
|
|
2019-08-12 13:00:13 +02:00
|
|
|
describe("common/config", () => {
|
2021-01-09 04:41:33 +01:00
|
|
|
it("should get all config values", () => {
|
|
|
|
const storage = new StorageShim();
|
|
|
|
const values = { siteTitle: "Foo", name: "testConfig", year: "2300" };
|
2019-08-09 11:53:11 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
const config = new Config(storage, values);
|
|
|
|
const result = config.getValues();
|
|
|
|
assert.equal(result.name, "testConfig");
|
|
|
|
});
|
2019-08-09 11:53:11 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
it("should set multiple config values", () => {
|
|
|
|
const storage = new StorageShim();
|
|
|
|
const values = {
|
|
|
|
siteTitle: "Foo",
|
|
|
|
country: "Germany",
|
|
|
|
city: "Hamburg",
|
|
|
|
settings: { ui: { language: "de", theme: "default" } },
|
|
|
|
};
|
|
|
|
const newValues = {
|
|
|
|
siteTitle: "Foo",
|
|
|
|
new: "xxx",
|
|
|
|
city: "Berlin",
|
|
|
|
debug: true,
|
|
|
|
settings: { ui: { language: "en", theme: "lavender" } },
|
|
|
|
};
|
|
|
|
const config = new Config(storage, values);
|
|
|
|
assert.equal(config.values.settings.ui.theme, "default");
|
|
|
|
assert.equal(config.values.settings.ui.language, "de");
|
|
|
|
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");
|
|
|
|
assert.equal(config.values.settings.ui.theme, "lavender");
|
|
|
|
assert.equal(config.values.settings.ui.language, "en");
|
|
|
|
});
|
2019-08-09 11:53:11 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
it("should store values", () => {
|
|
|
|
const storage = new StorageShim();
|
|
|
|
const values = { siteTitle: "Foo", country: "Germany", city: "Hamburg" };
|
|
|
|
const config = new Config(storage, values);
|
|
|
|
assert.equal(config.storage["config"], undefined);
|
|
|
|
config.storeValues();
|
|
|
|
const expected = '{"siteTitle":"Foo","country":"Germany","city":"Hamburg"}';
|
|
|
|
assert.equal(config.storage["config"], expected);
|
|
|
|
});
|
2019-08-09 11:53:11 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
it("should set and get single config value", () => {
|
|
|
|
const storage = new StorageShim();
|
2021-07-12 19:25:37 +02:00
|
|
|
const values = { siteTitle: "Foo", country: "Germany", city: "Hamburg" };
|
2019-08-09 11:53:11 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
const config = new Config(storage, values);
|
|
|
|
config.set("city", "Berlin");
|
|
|
|
const result = config.get("city");
|
|
|
|
assert.equal(result, "Berlin");
|
|
|
|
});
|
2019-08-09 11:53:11 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
it("should return settings", () => {
|
|
|
|
const result = config2.settings();
|
|
|
|
assert.equal(result.ui.theme, "default");
|
|
|
|
assert.equal(result.ui.language, "en");
|
|
|
|
});
|
2020-06-30 16:53:12 +02:00
|
|
|
|
2021-01-09 04:41:33 +01:00
|
|
|
it("should return feature", () => {
|
|
|
|
assert.equal(config2.feature("places"), true);
|
|
|
|
assert.equal(config2.feature("download"), true);
|
|
|
|
});
|
|
|
|
//TODO
|
|
|
|
/*it.only("should test onCount", () => {
|
2020-06-30 16:53:12 +02:00
|
|
|
const items = [{}, {}, {}];
|
|
|
|
assert.equal(config2.values.count.cameras, 1);
|
|
|
|
config2.onCount("add.camera", items);
|
|
|
|
assert.equal(config2.values.count.cameras, 1);
|
|
|
|
console.log(config2.values.count);
|
|
|
|
config2.onCount("add.cameras", items);
|
|
|
|
console.log(config2.values.count);
|
|
|
|
assert.equal(config2.values.count.cameras, 4);
|
|
|
|
config2.onCount("add.lenses", items);
|
|
|
|
assert.equal(config2.values.count.lenses, 3);
|
|
|
|
config2.onCount("add.countries", items);
|
|
|
|
assert.equal(config2.values.count.countries, 5);
|
|
|
|
config2.onCount("add.photos", items);
|
|
|
|
assert.equal(config2.values.count.photos, 129);
|
|
|
|
config2.onCount("add.videos", items);
|
|
|
|
assert.equal(config2.values.count.videos, 3);
|
|
|
|
config2.onCount("add.hidden", items);
|
|
|
|
assert.equal(config2.values.count.hidden, 6);
|
|
|
|
config2.onCount("add.favorites", items);
|
|
|
|
assert.equal(config2.values.count.favorites, 4);
|
|
|
|
config2.onCount("add.private", items);
|
|
|
|
assert.equal(config2.values.count.private, 3);
|
|
|
|
config2.onCount("add.review", items);
|
|
|
|
assert.equal(config2.values.count.review, 3);
|
|
|
|
config2.onCount("add.states", items);
|
|
|
|
assert.equal(config2.values.count.states, 5);
|
|
|
|
config2.onCount("add.albums", items);
|
|
|
|
assert.equal(config2.values.count.albums, 3);
|
|
|
|
config2.onCount("add.moments", items);
|
|
|
|
assert.equal(config2.values.count.moments, 3);
|
|
|
|
config2.onCount("add.months", items);
|
|
|
|
assert.equal(config2.values.count.months, 3);
|
|
|
|
config2.onCount("add.folders", items);
|
|
|
|
assert.equal(config2.values.count.folders, 3);
|
|
|
|
config2.onCount("add.files", items);
|
|
|
|
assert.equal(config2.values.count.files, 258);
|
|
|
|
config2.onCount("add.places", items);
|
|
|
|
assert.equal(config2.values.count.places, 3);
|
|
|
|
config2.onCount("add.labels", items);
|
|
|
|
assert.equal(config2.values.count.labels, 12);
|
|
|
|
});*/
|
2019-11-16 23:22:50 +01:00
|
|
|
});
|