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-10-06 12:21:52 +02:00
|
|
|
it("should test constructor with empty values", () => {
|
|
|
|
const storage = new StorageShim();
|
|
|
|
const values = {};
|
|
|
|
const config = new Config(storage, values);
|
|
|
|
assert.equal(config.debug, true);
|
|
|
|
assert.equal(config.demo, false);
|
|
|
|
assert.equal(config.apiUri, "/api/v1");
|
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
});
|
2021-10-06 12:21:52 +02:00
|
|
|
|
|
|
|
it("should test get name", () => {
|
|
|
|
const result = config2.getPerson("a");
|
|
|
|
assert.equal(result, null);
|
|
|
|
|
|
|
|
const result2 = config2.getPerson("Andrea Sander");
|
|
|
|
assert.equal(result2.UID, "jr0jgyx2viicdnf7");
|
|
|
|
|
|
|
|
const result3 = config2.getPerson("Otto Sander");
|
|
|
|
assert.equal(result3.UID, "jr0jgyx2viicdn88");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should create, update and delete people", () => {
|
|
|
|
const storage = new StorageShim();
|
|
|
|
const values = { Debug: true, siteTitle: "Foo", country: "Germany", city: "Hamburg" };
|
|
|
|
|
|
|
|
const config = new Config(storage, values);
|
|
|
|
config.onPeople(".created");
|
|
|
|
assert.empty(config.values.people);
|
|
|
|
config.onPeople(".created", {
|
|
|
|
entities: [
|
|
|
|
{
|
|
|
|
UID: "abc123",
|
|
|
|
Name: "Test Name",
|
|
|
|
Keywords: ["Test", "Name"],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
assert.equal(config.values.people[0].Name, "Test Name");
|
|
|
|
config.onPeople(".updated", {
|
|
|
|
entities: [
|
|
|
|
{
|
|
|
|
UID: "abc123",
|
|
|
|
Name: "New Name",
|
|
|
|
Keywords: ["New", "Name"],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
assert.equal(config.values.people[0].Name, "New Name");
|
|
|
|
config.onPeople(".deleted", {
|
|
|
|
entities: [
|
|
|
|
{
|
|
|
|
UID: "abc123",
|
|
|
|
Name: "New Name",
|
|
|
|
Keywords: ["New", "Name"],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
assert.equal(config.values.people[0].Name, "New Name");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should return if language is rtl", () => {
|
2021-10-06 15:13:41 +02:00
|
|
|
const myConfig = new Config(new StorageShim(), Object.assign({}, window.__CONFIG__));
|
|
|
|
const result = myConfig.rtl();
|
2021-10-06 12:21:52 +02:00
|
|
|
assert.equal(result, false);
|
2021-10-06 15:13:41 +02:00
|
|
|
const newValues = {
|
2021-10-06 12:21:52 +02:00
|
|
|
Debug: true,
|
|
|
|
siteTitle: "Foo",
|
|
|
|
country: "Germany",
|
|
|
|
city: "Hamburg",
|
|
|
|
settings: {
|
|
|
|
ui: {
|
|
|
|
language: "he",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2021-10-06 15:13:41 +02:00
|
|
|
myConfig.setValues(newValues);
|
|
|
|
const result2 = myConfig.rtl();
|
2021-10-06 12:21:52 +02:00
|
|
|
assert.equal(result2, true);
|
2021-10-06 15:13:41 +02:00
|
|
|
const values2 = { siteTitle: "Foo" };
|
|
|
|
const storage = new StorageShim();
|
2021-10-06 12:21:52 +02:00
|
|
|
const config3 = new Config(storage, values2);
|
|
|
|
const result3 = config3.rtl();
|
|
|
|
assert.equal(result3, false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should return album categories", () => {
|
|
|
|
const myConfig = new Config(new StorageShim(), Object.assign({}, window.__CONFIG__));
|
|
|
|
const result = myConfig.albumCategories();
|
|
|
|
assert.equal(result[0], "Animal");
|
|
|
|
const newValues = {
|
|
|
|
albumCategories: ["Mouse"],
|
|
|
|
};
|
|
|
|
myConfig.setValues(newValues);
|
|
|
|
const result2 = myConfig.albumCategories();
|
|
|
|
assert.equal(result2[0], "Mouse");
|
|
|
|
});
|
|
|
|
|
2021-10-06 15:13:41 +02:00
|
|
|
it("should update counts", () => {
|
|
|
|
const myConfig = new Config(new StorageShim(), Object.assign({}, window.__CONFIG__));
|
|
|
|
assert.equal(myConfig.values.count.all, 133);
|
|
|
|
assert.equal(myConfig.values.count.photos, 132);
|
|
|
|
myConfig.onCount("add.photos", {
|
|
|
|
count: 2,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.all, 135);
|
|
|
|
assert.equal(myConfig.values.count.photos, 134);
|
|
|
|
assert.equal(myConfig.values.count.videos, 1);
|
|
|
|
myConfig.onCount("add.videos", {
|
|
|
|
count: 1,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.all, 136);
|
|
|
|
assert.equal(myConfig.values.count.videos, 2);
|
|
|
|
assert.equal(myConfig.values.count.cameras, 6);
|
|
|
|
myConfig.onCount("add.cameras", {
|
|
|
|
count: 3,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.all, 136);
|
|
|
|
assert.equal(myConfig.values.count.cameras, 9);
|
|
|
|
assert.equal(myConfig.values.count.lenses, 5);
|
|
|
|
myConfig.onCount("add.lenses", {
|
|
|
|
count: 1,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.lenses, 6);
|
|
|
|
assert.equal(myConfig.values.count.countries, 6);
|
|
|
|
myConfig.onCount("add.countries", {
|
|
|
|
count: 2,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.countries, 8);
|
|
|
|
assert.equal(myConfig.values.count.states, 8);
|
|
|
|
myConfig.onCount("add.states", {
|
|
|
|
count: 1,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.states, 9);
|
|
|
|
assert.equal(myConfig.values.count.people, 5);
|
|
|
|
myConfig.onCount("add.people", {
|
|
|
|
count: 4,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.people, 9);
|
|
|
|
assert.equal(myConfig.values.count.places, 17);
|
|
|
|
myConfig.onCount("add.places", {
|
|
|
|
count: 1,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.places, 18);
|
|
|
|
assert.equal(myConfig.values.count.labels, 22);
|
|
|
|
myConfig.onCount("add.labels", {
|
|
|
|
count: 2,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.labels, 24);
|
|
|
|
assert.equal(myConfig.values.count.albums, 2);
|
|
|
|
myConfig.onCount("add.albums", {
|
|
|
|
count: 3,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.albums, 5);
|
|
|
|
assert.equal(myConfig.values.count.moments, 4);
|
|
|
|
myConfig.onCount("add.moments", {
|
|
|
|
count: 1,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.moments, 5);
|
|
|
|
assert.equal(myConfig.values.count.months, 27);
|
|
|
|
myConfig.onCount("add.months", {
|
|
|
|
count: 4,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.months, 31);
|
|
|
|
assert.equal(myConfig.values.count.folders, 23);
|
|
|
|
myConfig.onCount("add.folders", {
|
|
|
|
count: 2,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.folders, 25);
|
|
|
|
assert.equal(myConfig.values.count.files, 136);
|
|
|
|
myConfig.onCount("add.files", {
|
|
|
|
count: 14,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.files, 150);
|
|
|
|
assert.equal(myConfig.values.count.favorites, 1);
|
|
|
|
myConfig.onCount("add.favorites", {
|
|
|
|
count: 4,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.favorites, 5);
|
|
|
|
assert.equal(myConfig.values.count.review, 22);
|
|
|
|
myConfig.onCount("add.review", {
|
|
|
|
count: 1,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.review, 23);
|
|
|
|
assert.equal(myConfig.values.count.private, 0);
|
|
|
|
myConfig.onCount("add.private", {
|
|
|
|
count: 3,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.private, 3);
|
|
|
|
assert.equal(myConfig.values.count.all, 136);
|
|
|
|
myConfig.onCount("add.xxxphotos", {
|
|
|
|
count: 4,
|
|
|
|
});
|
|
|
|
assert.equal(myConfig.values.count.all, 136);
|
|
|
|
});
|
2019-11-16 23:22:50 +01:00
|
|
|
});
|