Tests: Remove Karma / Mocha and switch to Vitest #4995 #5014 #5087

* Tests: Remove unused Karma configuration and test files

This commit deletes the Karma configuration file and  test files that are no longer needed

* Tests: Refactor setup file for Vitest and remove legacy vue-setup.js

* Tests: Update truncate test case to use Vitest string

* Tests: Add unit tests for PLocationInput component using Vitest

* Tests: Improve unit tests for PLoadingBar component

* Tests: Move karma test to vitest

* Frontend: Update deps in package-lock.json

* Tests: Adapt test to vitest

* Tests: Refactor Makefile and package.json for test commands
This commit is contained in:
Ömer Duran
2025-09-07 15:29:01 +02:00
committed by GitHub
parent 22863b8b0f
commit 95c6743b2c
37 changed files with 466 additions and 8741 deletions

View File

@@ -334,7 +334,7 @@ watch-js:
(cd frontend && env BUILD_ENV=development NODE_ENV=production npm run watch)
test-js:
$(info Running JS unit tests...)
(cd frontend && env TZ=UTC BUILD_ENV=development NODE_ENV=development BABEL_ENV=test npm run test)
(cd frontend && npm run test)
acceptance:
$(info Running public-mode tests in Chrome...)
(cd frontend && npm run testcafe -- "chrome --headless=new" --test-grep "^(Multi-Window)\:*" --test-meta mode=public --config-file ./testcaferc.json --experimental-multiple-windows "tests/acceptance" && npm run testcafe -- "chrome --headless=new" --test-grep "^(Common|Core)\:*" --test-meta mode=public --config-file ./testcaferc.json "tests/acceptance")
@@ -353,21 +353,15 @@ acceptance-auth-short:
acceptance-auth-firefox:
$(info Running JS acceptance-auth tests in Firefox...)
(cd frontend && npm run testcafe -- firefox:headless --test-grep "^(Common|Core)\:*" --test-meta mode=auth --config-file ./testcaferc.json --disable-native-automation "tests/acceptance")
vitest:
$(info Running Vitest unit tests...)
(cd frontend && npm run vitest)
vitest-watch:
$(info Running Vitest unit tests in watch mode...)
(cd frontend && npm run vitest-watch)
(cd frontend && npm run test-watch)
vitest-coverage:
$(info Running Vitest unit tests with coverage...)
(cd frontend && npm run vitest-coverage)
(cd frontend && npm run test-coverage)
vitest-component:
$(info Running Vitest component tests...)
(cd frontend && npm run vitest-component)
vitest-ui:
$(info Opening Vitest UI...)
(cd frontend && npm run vitest-ui)
(cd frontend && npm run test-component)
reset-mariadb:
$(info Resetting photoprism database...)
mysql < scripts/sql/reset-photoprism.sql

File diff suppressed because it is too large Load Diff

View File

@@ -17,12 +17,10 @@
"gettext-compile": "vue-gettext-compile",
"gettext-extract": "gettext-extract --output src/locales/translations.pot $(find ${SRC:-src} -type f \\( -iname \\*.vue -o -iname \\*.js \\) -not -path src/common/gettext.js)",
"lint": "eslint --cache src/ *.js",
"test": "karma start",
"vitest": "env TZ=UTC vitest run",
"vitest-watch": "env TZ=UTC vitest --watch",
"vitest-coverage": "env TZ=UTC vitest run --coverage",
"vitest-component": "env TZ=UTC vitest run tests/vitest/component",
"vitest-ui": "env TZ=UTC vitest --ui --watch",
"test": "cross-env TZ=UTC BUILD_ENV=development NODE_ENV=development BABEL_ENV=test vitest run",
"test-watch": "cross-env TZ=UTC BUILD_ENV=development NODE_ENV=development BABEL_ENV=test vitest --watch",
"test-coverage": "cross-env TZ=UTC BUILD_ENV=development NODE_ENV=development BABEL_ENV=test vitest run --coverage",
"test-component": "cross-env TZ=UTC BUILD_ENV=development NODE_ENV=development BABEL_ENV=test vitest run tests/vitest/component",
"testcafe": "testcafe",
"trace": "webpack --stats-children",
"update": "npm update --save --package-lock && npm install --no-update-notifier --no-audit",
@@ -58,12 +56,10 @@
"babel-loader": "^10.0.0",
"babel-plugin-istanbul": "^7.0.0",
"babel-plugin-polyfill-corejs3": "^0.13.0",
"browserslist": "^4.25.4",
"chai": "^5.3.3",
"browserslist": "^4.25.0",
"cheerio": "1.0.0-rc.12",
"chrome-finder": "^1.0.7",
"core-js": "^3.45.1",
"cross-env": "^10.0.0",
"core-js": "^3.43.0",
"cross-env": "^7.0.3",
"css-loader": "^7.1.2",
"cssnano": "^7.1.1",
"easygettext": "^2.17.0",
@@ -85,19 +81,11 @@
"hls.js": "^1.6.11",
"i": "^0.3.7",
"jsdom": "^26.1.0",
"karma": "^6.4.4",
"karma-chrome-launcher": "^3.2.0",
"karma-coverage-istanbul-reporter": "^3.0.3",
"karma-htmlfile-reporter": "^0.3.8",
"karma-mocha": "^2.0.1",
"karma-verbose-reporter": "^0.0.8",
"karma-webpack": "^5.0.1",
"luxon": "^3.7.1",
"maplibre-gl": "^5.7.0",
"luxon": "^3.6.1",
"maplibre-gl": "^5.6.1",
"memoize-one": "^6.0.0",
"mini-css-extract-plugin": "^2.9.4",
"minimist": "^1.2.8",
"mocha": "^11.7.2",
"mini-css-extract-plugin": "^2.9.2",
"minimist": ">=1.2.8",
"node-storage-shim": "^2.0.1",
"passive-events-support": "^1.1.0",
"photoswipe": "^5.4.4",

View File

@@ -1,104 +0,0 @@
import { $api } from "../fixtures";
let chai = require("chai/chai");
let assert = chai.assert;
describe("common/api", () => {
const getCollectionResponse = [
{ id: 1, name: "John Smith" },
{ id: 1, name: "John Smith" },
];
const getEntityResponse = {
id: 1,
name: "John Smith",
};
const postEntityResponse = {
users: [{ id: 1, name: "John Smith" }],
};
const putEntityResponse = {
users: [{ id: 2, name: "John Foo" }],
};
const deleteEntityResponse = null;
it("get should return a list of results and return with HTTP code 200", (done) => {
$api
.get("foo")
.then((response) => {
assert.equal(200, response.status);
assert.deepEqual(getCollectionResponse, response.data);
done();
})
.catch((error) => {
done(error);
});
});
it("get should return one item and return with HTTP code 200", (done) => {
$api
.get("foo/123")
.then((response) => {
assert.equal(200, response.status);
assert.deepEqual(getEntityResponse, response.data);
done();
})
.catch((error) => {
done(error);
});
});
it("post should create one item and return with HTTP code 201", (done) => {
$api
.post("foo", postEntityResponse)
.then((response) => {
assert.equal(201, response.status);
assert.deepEqual(postEntityResponse, response.data);
done();
})
.catch((error) => {
done(error);
});
});
it("put should update one item and return with HTTP code 200", (done) => {
$api
.put("foo/2", putEntityResponse)
.then((response) => {
assert.equal(200, response.status);
assert.deepEqual(putEntityResponse, response.data);
done();
})
.catch((error) => {
done(error);
});
});
it("delete should delete one item and return with HTTP code 204", (done) => {
$api
.delete("foo/2", deleteEntityResponse)
.then((response) => {
assert.equal(204, response.status);
assert.deepEqual(deleteEntityResponse, response.data);
done();
})
.catch((error) => {
done(error);
});
});
/*
it("get error", function () {
return Api.get("error")
.then(function (m) {
return Promise.reject("error expected");
})
.catch(function (m) {
assert.equal(m.message, "Request failed with status code 401");
return Promise.resolve();
});
});
*/
});

View File

@@ -1,59 +0,0 @@
import "../fixtures";
import * as can from "common/can";
let chai = require("chai/chai");
let assert = chai.assert;
describe("common/can", () => {
it("useVideo", () => {
assert.equal(can.useVideo, true);
});
it("useMp4Avc", () => {
assert.equal(can.useMp4Avc, true);
});
it("useMp4Hvc", () => {
assert.equal(can.useMp4Hvc, false);
});
it("useMp4Hev", () => {
assert.equal(can.useMp4Hev, false);
});
it("useMp4Vvc", () => {
assert.equal(can.useMp4Vvc, false);
});
it("useMp4Evc", () => {
assert.equal(can.useMp4Evc, false);
});
it("useMp4Av1", () => {
assert.equal(can.useMp4Av1, true);
});
it("useVP8", () => {
assert.equal(can.useVP8, true);
});
it("useVP9", () => {
assert.equal(can.useVP9, true);
});
it("useWebmAv1", () => {
assert.equal(can.useWebmAv1, true);
});
it("useMkvAv1", () => {
assert.equal(can.useMkvAv1, false);
});
it("useWebM", () => {
assert.equal(can.useWebM, true);
});
it("useTheora", () => {
assert.equal(can.useTheora, true);
});
});

View File

@@ -1,197 +0,0 @@
import "../fixtures";
import { Clipboard } from "common/clipboard";
import Photo from "model/photo";
import Album from "model/album";
import StorageShim from "node-storage-shim";
let chai = require("chai/chai");
let assert = chai.assert;
describe("common/clipboard", () => {
it("should construct clipboard", () => {
const storage = new StorageShim();
const key = "clipboard";
const clipboard = new Clipboard(storage, key);
assert.equal(clipboard.storageKey, "clipboard");
assert.equal(clipboard.selection, "");
});
it("should toggle model", () => {
const storage = new StorageShim();
const key = "clipboard";
const clipboard = new Clipboard(storage, key);
clipboard.clear();
clipboard.toggle();
assert.equal(clipboard.storageKey, "clipboard");
assert.equal(clipboard.selection, "");
const values = { ID: 5, UID: "ABC123", Title: "Crazy Cat" };
const photo = new Photo(values);
clipboard.toggle(photo);
assert.equal(clipboard.selection[0], "ABC123");
const values2 = { ID: 8, UID: "ABC124", Title: "Crazy Cat" };
const photo2 = new Photo(values2);
clipboard.toggle(photo2);
assert.equal(clipboard.selection[0], "ABC123");
assert.equal(clipboard.selection[1], "ABC124");
clipboard.toggle(photo);
assert.equal(clipboard.selection[0], "ABC124");
});
it("should toggle id", () => {
const storage = new StorageShim();
const key = "clipboard";
const clipboard = new Clipboard(storage, key);
clipboard.clear();
clipboard.toggleId(3);
assert.equal(clipboard.selection[0], 3);
clipboard.toggleId(3);
assert.equal(clipboard.selection, "");
});
it("should add model", () => {
const storage = new StorageShim();
const key = "clipboard";
const clipboard = new Clipboard(storage, key);
clipboard.clear();
clipboard.add();
assert.equal(clipboard.storageKey, "clipboard");
assert.equal(clipboard.selection, "");
const values = { ID: 5, UID: "ABC124", Title: "Crazy Cat" };
const photo = new Photo(values);
clipboard.add(photo);
assert.equal(clipboard.selection[0], "ABC124");
clipboard.add(photo);
assert.equal(clipboard.selection[0], "ABC124");
});
it("should add id", () => {
const storage = new StorageShim();
const key = "clipboard";
const clipboard = new Clipboard(storage, key);
clipboard.clear();
clipboard.addId(99);
assert.equal(clipboard.selection[0], 99);
});
it("should test whether clipboard has model", () => {
const storage = new StorageShim();
const key = "clipboard";
const clipboard = new Clipboard(storage, key);
clipboard.clear();
clipboard.has();
assert.equal(clipboard.storageKey, "clipboard");
assert.equal(clipboard.selection, "");
const values = { ID: 5, UID: "ABC124", Title: "Crazy Cat" };
const photo = new Photo(values);
clipboard.add(photo);
assert.equal(clipboard.selection[0], "ABC124");
const result = clipboard.has(photo);
assert.equal(result, true);
const values2 = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values2);
const result2 = clipboard.has(album);
assert.equal(result2, false);
});
it("should test whether clipboard has id", () => {
const storage = new StorageShim();
const key = "clipboard";
const clipboard = new Clipboard(storage, key);
clipboard.clear();
clipboard.addId(77);
assert.equal(clipboard.hasId(77), true);
assert.equal(clipboard.hasId(78), false);
});
it("should remove model", () => {
const storage = new StorageShim();
const key = "clipboard";
const clipboard = new Clipboard(storage, key);
clipboard.clear();
clipboard.remove();
assert.equal(clipboard.storageKey, "clipboard");
assert.equal(clipboard.selection, "");
const values = { ID: 5, UID: "ABC123", Title: "Crazy Cat" };
const photo = new Photo(values);
clipboard.add(photo);
assert.equal(clipboard.selection[0], "ABC123");
clipboard.remove(photo);
assert.equal(clipboard.selection, "");
const values2 = { ID: 5, Name: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values2);
clipboard.remove(album);
assert.equal(clipboard.selection, "");
});
it("should set and get ids", () => {
const storage = new StorageShim();
const key = "clipboard";
const clipboard = new Clipboard(storage, key);
clipboard.clear();
clipboard.setIds(8);
assert.equal(clipboard.selection, "");
clipboard.setIds([5, 6, 9]);
assert.equal(clipboard.selection[0], 5);
assert.equal(clipboard.selection[2], 9);
const result = clipboard.getIds();
assert.equal(result[1], 6);
assert.equal(result.length, 3);
});
it("should clear", () => {
const storage = new StorageShim();
const key = "clipboard";
const clipboard = new Clipboard(storage, key);
clipboard.clear();
clipboard.setIds([5, 6, 9]);
assert.equal(clipboard.selection[0], 5);
clipboard.clear();
assert.equal(clipboard.selection, "");
});
it("should add range", () => {
const storage = new StorageShim();
const key = "clipboard";
const clipboard = new Clipboard(storage, key);
clipboard.clear();
const values = { ID: 5, UID: "ABC124", Title: "Crazy Cat" };
const photo = new Photo(values);
const values2 = { ID: 6, UID: "ABC125", Title: "Crazy Dog" };
const photo2 = new Photo(values2);
const values3 = { ID: 7, UID: "ABC128", Title: "Cute Dog" };
const photo3 = new Photo(values3);
const values4 = { ID: 8, UID: "ABC129", Title: "Turtle" };
const photo4 = new Photo(values4);
const Photos = [photo, photo2, photo3, photo4];
clipboard.addRange(2);
assert.equal(clipboard.selection.length, 0);
clipboard.clear();
clipboard.addRange(2, Photos);
assert.equal(clipboard.selection[0], "ABC128");
assert.equal(clipboard.selection.length, 1);
clipboard.addRange(1, Photos);
assert.equal(clipboard.selection.length, 2);
assert.equal(clipboard.selection[0], "ABC128");
assert.equal(clipboard.selection[1], "ABC125");
clipboard.clear();
clipboard.add(photo);
assert.equal(clipboard.selection.length, 1);
clipboard.addRange(3, Photos);
assert.equal(clipboard.selection.length, 4);
});
});

View File

@@ -1,322 +0,0 @@
import "../fixtures";
import Config from "common/config";
import StorageShim from "node-storage-shim";
let chai = require("chai/chai");
let assert = chai.assert;
const defaultConfig = new Config(new StorageShim(), window.__CONFIG__);
describe("common/config", () => {
it("should get all config values", () => {
const storage = new StorageShim();
const values = { siteTitle: "Foo", name: "testConfig", year: "2300" };
const cfg = new Config(storage, values);
const result = cfg.getValues();
assert.equal(result.name, "testConfig");
});
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 cfg = new Config(storage, values);
assert.equal(cfg.values.settings.ui.theme, "default");
assert.equal(cfg.values.settings.ui.language, "de");
assert.equal(cfg.values.new, undefined);
assert.equal(cfg.values.city, "Hamburg");
cfg.setValues();
assert.equal(cfg.values.new, undefined);
assert.equal(cfg.values.city, "Hamburg");
cfg.setValues(newValues);
const result = cfg.getValues();
assert.equal(result.city, "Berlin");
assert.equal(result.new, "xxx");
assert.equal(result.country, "Germany");
assert.equal(cfg.values.settings.ui.theme, "lavender");
assert.equal(cfg.values.settings.ui.language, "en");
});
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");
});
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);
});
it("should return the develop feature flag value", () => {
assert.equal(defaultConfig.featDevelop(), true);
});
it("should return the experimental feature flag value", () => {
assert.equal(defaultConfig.featExperimental(), true);
});
it("should return the preview feature flag value", () => {
assert.equal(defaultConfig.featPreview(), true);
});
it("should set and get single config value", () => {
const storage = new StorageShim();
const values = { siteTitle: "Foo", country: "Germany", city: "Hamburg" };
const config = new Config(storage, values);
config.set("city", "Berlin");
const result = config.get("city");
assert.equal(result, "Berlin");
});
it("should return app about", () => {
assert.equal(defaultConfig.getAbout(), "PhotoPrism® CE");
});
it("should return app edition", () => {
assert.equal(defaultConfig.getEdition(), "ce");
});
it("should return settings", () => {
const result = defaultConfig.getSettings();
assert.equal(result.ui.theme, "default");
assert.equal(result.ui.language, "en");
});
it("should return feature", () => {
assert.equal(defaultConfig.feature("places"), true);
assert.equal(defaultConfig.feature("download"), true);
});
it("should test get name", () => {
const result = defaultConfig.getPerson("a");
assert.equal(result, null);
const result2 = defaultConfig.getPerson("Andrea Sander");
assert.equal(result2.UID, "jr0jgyx2viicdnf7");
const result3 = defaultConfig.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 cfg = new Config(storage, values);
cfg.onPeople("people.created", { entities: {} });
assert.empty(cfg.values.people);
cfg.onPeople("people.created", {
entities: [
{
UID: "abc123",
Name: "Test Name",
Keywords: ["Test", "Name"],
},
],
});
assert.equal(cfg.values.people[0].Name, "Test Name");
cfg.onPeople("people.updated", {
entities: [
{
UID: "abc123",
Name: "New Name",
Keywords: ["New", "Name"],
},
],
});
assert.equal(cfg.values.people[0].Name, "New Name");
cfg.onPeople("people.deleted", {
entities: ["abc123"],
});
assert.empty(cfg.values.people);
});
it("should return language locale", () => {
const cfg = new Config(new StorageShim(), Object.assign({}, window.__CONFIG__));
assert.equal(cfg.getLanguageLocale(), "en");
});
it("should return user time zone", () => {
const cfg = new Config(new StorageShim(), Object.assign({}, window.__CONFIG__));
assert.equal(cfg.getTimeZone(), "Local");
});
it("should return if language is rtl", () => {
const cfg = new Config(new StorageShim(), Object.assign({}, window.__CONFIG__));
const result = cfg.isRtl();
assert.equal(result, false);
const newValues = {
Debug: true,
siteTitle: "Foo",
country: "Germany",
city: "Hamburg",
settings: {
ui: {
language: "he",
},
},
};
cfg.setValues(newValues);
const result2 = cfg.isRtl();
assert.equal(result2, true);
const values2 = { siteTitle: "Foo" };
const storage = new StorageShim();
const config3 = new Config(storage, values2);
const result3 = config3.isRtl();
assert.equal(result3, false);
cfg.setLanguage("en");
});
it("should return album categories", () => {
const cfg = new Config(new StorageShim(), Object.assign({}, window.__CONFIG__));
const result = cfg.albumCategories();
assert.equal(result[0], "Animal");
const newValues = {
albumCategories: ["Mouse"],
};
cfg.setValues(newValues);
const result2 = cfg.albumCategories();
assert.equal(result2[0], "Mouse");
});
it("should update counts", () => {
const cfg = new Config(new StorageShim(), Object.assign({}, window.__CONFIG__));
assert.equal(cfg.values.count.all, 133);
assert.equal(cfg.values.count.photos, 132);
cfg.onCount("add.photos", {
count: 2,
});
assert.equal(cfg.values.count.all, 135);
assert.equal(cfg.values.count.photos, 134);
assert.equal(cfg.values.count.videos, 1);
cfg.onCount("add.videos", {
count: 1,
});
assert.equal(cfg.values.count.all, 136);
assert.equal(cfg.values.count.videos, 2);
assert.equal(cfg.values.count.cameras, 6);
cfg.onCount("add.cameras", {
count: 3,
});
assert.equal(cfg.values.count.all, 136);
assert.equal(cfg.values.count.cameras, 9);
assert.equal(cfg.values.count.lenses, 5);
cfg.onCount("add.lenses", {
count: 1,
});
assert.equal(cfg.values.count.lenses, 6);
assert.equal(cfg.values.count.countries, 6);
cfg.onCount("add.countries", {
count: 2,
});
assert.equal(cfg.values.count.countries, 8);
assert.equal(cfg.values.count.states, 8);
cfg.onCount("add.states", {
count: 1,
});
assert.equal(cfg.values.count.states, 9);
assert.equal(cfg.values.count.people, 5);
cfg.onCount("add.people", {
count: 4,
});
assert.equal(cfg.values.count.people, 9);
assert.equal(cfg.values.count.places, 17);
cfg.onCount("add.places", {
count: 1,
});
assert.equal(cfg.values.count.places, 18);
assert.equal(cfg.values.count.labels, 22);
cfg.onCount("add.labels", {
count: 2,
});
assert.equal(cfg.values.count.labels, 24);
assert.equal(cfg.values.count.albums, 2);
cfg.onCount("add.albums", {
count: 3,
});
assert.equal(cfg.values.count.albums, 5);
assert.equal(cfg.values.count.moments, 4);
cfg.onCount("add.moments", {
count: 1,
});
assert.equal(cfg.values.count.moments, 5);
assert.equal(cfg.values.count.months, 27);
cfg.onCount("add.months", {
count: 4,
});
assert.equal(cfg.values.count.months, 31);
assert.equal(cfg.values.count.folders, 23);
cfg.onCount("add.folders", {
count: 2,
});
assert.equal(cfg.values.count.folders, 25);
assert.equal(cfg.values.count.files, 136);
cfg.onCount("add.files", {
count: 14,
});
assert.equal(cfg.values.count.files, 150);
assert.equal(cfg.values.count.favorites, 1);
cfg.onCount("add.favorites", {
count: 4,
});
assert.equal(cfg.values.count.favorites, 5);
assert.equal(cfg.values.count.review, 22);
cfg.onCount("add.review", {
count: 1,
});
assert.equal(cfg.values.count.all, 135);
assert.equal(cfg.values.count.review, 23);
assert.equal(cfg.values.count.private, 0);
cfg.onCount("add.private", {
count: 3,
});
assert.equal(cfg.values.count.private, 3);
assert.equal(cfg.values.count.all, 135);
cfg.onCount("add.photos", {
count: 4,
});
assert.equal(cfg.values.count.all, 139);
});
it("should return user interface direction string", async () => {
const cfg = new Config(new StorageShim(), Object.assign({}, window.__CONFIG__));
await cfg.setLanguage("en", true);
assert.equal(document.dir, "ltr", "document.dir should be ltr");
assert.equal(cfg.dir(), "ltr");
assert.equal(cfg.dir(true), "rtl");
assert.equal(cfg.dir(false), "ltr");
await cfg.setLanguage("he", false);
assert.equal(document.dir, "ltr", "document.dir should still be ltr");
await cfg.setLanguage("he", true);
assert.equal(cfg.dir(), "rtl");
assert.equal(document.dir, "rtl", "document.dir should now be rtl");
assert.equal(cfg.dir(), "rtl");
assert.equal(cfg.dir(true), "rtl");
assert.equal(cfg.dir(false), "ltr");
await cfg.setLanguage("en", true);
assert.equal(document.dir, "ltr", "document.dir should be ltr again");
assert.equal(cfg.dir(), "ltr");
});
});

View File

@@ -1,132 +0,0 @@
import "../fixtures";
import { Form, FormPropertyType } from "common/form";
let chai = require("chai/chai");
let assert = chai.assert;
describe("common/form", () => {
it("setting and getting definition", () => {
const def = { foo: { type: FormPropertyType.String, caption: "Foo" } };
const form = new Form();
form.setDefinition(def);
const result = form.getDefinition();
assert.equal(result, def);
});
it("setting and getting a value according to type", () => {
const def = {
foo: { type: FormPropertyType.String, caption: "Foo" },
};
const form = new Form();
form.setDefinition(def);
form.setValue("foo", "test");
const result = form.getValue("foo");
assert.equal(result, "test");
});
it("setting a value not according to type", () => {
const def = {
foo: { type: FormPropertyType.String, caption: "Foo" },
};
const form = new Form();
form.setDefinition(def);
assert.throws(() => {
form.setValue("foo", 3);
});
});
it("setting and getting a value for missing property throws exception", () => {
const def = {
foo: { type: FormPropertyType.String, caption: "Foo" },
};
const form = new Form();
form.setDefinition(def);
assert.throws(() => {
form.setValue("bar", 3);
});
assert.throws(() => {
form.getValue("bar");
});
});
it("setting and getting a complex value", () => {
const complexValue = {
something: "abc",
another: "def",
};
const def = {
foo: {
type: FormPropertyType.Object,
caption: "Foo",
},
};
const form = new Form();
form.setDefinition(def);
form.setValue("foo", complexValue);
const result = form.getValue("foo");
assert.deepEqual(result, complexValue);
});
it("setting and getting more values at once", () => {
const def = {
foo: { type: FormPropertyType.String, caption: "Foo" },
baz: { type: FormPropertyType.String, caption: "XX" },
};
const form = new Form();
form.setDefinition(def);
form.setValues({ foo: "test", baz: "yyy" });
const result = form.getValues();
assert.equal(result.foo, "test");
assert.equal(result.baz, "yyy");
});
it("getting options of fieldname", () => {
const def = {
search: {
type: FormPropertyType.String,
caption: "Search",
label: { options: "tiles", text: "Tiles" },
options: [
{ value: "tiles", text: "Tiles" },
{ value: "mosaic", text: "Mosaic" },
],
},
};
const form = new Form();
form.setDefinition(def);
const result = form.getOptions("search");
assert.equal(result[0].value, "tiles");
assert.equal(result[1].text, "Mosaic");
});
it("getting not existing options returns empty object", () => {
const def = {
foo: {
type: FormPropertyType.Object,
caption: "Foo",
},
};
const form = new Form();
form.setDefinition(def);
const result = form.getOptions("foo");
assert.equal(result[0].option, "");
assert.equal(result[0].label, "");
});
});

View File

@@ -1,24 +0,0 @@
import "../fixtures";
import $notify from "common/notify";
describe("common/alert", () => {
it("should call alert.info", () => {
$notify.info("message");
});
it("should call alert.warning", () => {
$notify.warn("message");
});
it("should call alert.error", () => {
$notify.error("message");
});
it("should call alert.success", () => {
$notify.success("message");
});
it("should call wait", () => {
$notify.wait();
});
});

View File

@@ -1,271 +0,0 @@
import "../fixtures";
import { $config } from "app/session";
import Session from "common/session";
import StorageShim from "node-storage-shim";
let chai = require("chai/chai");
let assert = chai.assert;
describe("common/session", () => {
beforeEach(() => {
window.onbeforeunload = () => "Oh no!";
});
it("should construct session", () => {
const storage = new StorageShim();
const session = new Session(storage, $config);
assert.equal(session.authToken, null);
});
it("should set, get and delete token", () => {
const storage = new StorageShim();
const session = new Session(storage, $config);
assert.equal(session.hasToken("2lbh9x09"), false);
session.setAuthToken("999900000000000000000000000000000000000000000000");
assert.equal(session.authToken, "999900000000000000000000000000000000000000000000");
const result = session.getAuthToken();
assert.equal(result, "999900000000000000000000000000000000000000000000");
session.reset();
assert.equal(session.authToken, null);
});
it("should set, get and delete user", () => {
const storage = new StorageShim();
const session = new Session(storage, $config);
assert.isFalse(session.user.hasId());
const user = {
ID: 5,
NickName: "Foo",
GivenName: "Max",
DisplayName: "Max Example",
Email: "test@test.com",
SuperAdmin: true,
Role: "admin",
};
const data = {
user,
};
assert.equal(session.hasId(), false);
assert.equal(session.hasAuthToken(), false);
assert.equal(session.isAuthenticated(), false);
assert.equal(session.hasProvider(), false);
session.setData();
assert.equal(session.user.DisplayName, "");
session.setData(data);
assert.equal(session.hasId(), false);
assert.equal(session.hasAuthToken(), false);
assert.equal(session.hasProvider(), false);
session.setId("a9b8ff820bf40ab451910f8bbfe401b2432446693aa539538fbd2399560a722f");
session.setAuthToken("234200000000000000000000000000000000000000000000");
session.setProvider("public");
assert.equal(session.hasId(), true);
assert.equal(session.hasAuthToken(), true);
assert.equal(session.isAuthenticated(), true);
assert.equal(session.hasProvider(), true);
assert.equal(session.user.DisplayName, "Max Example");
assert.equal(session.user.SuperAdmin, true);
assert.equal(session.user.Role, "admin");
session.reset();
assert.equal(session.user.DisplayName, "");
assert.equal(session.user.SuperAdmin, false);
assert.equal(session.user.Role, "");
session.setUser(user);
assert.equal(session.user.DisplayName, "Max Example");
assert.equal(session.user.SuperAdmin, true);
assert.equal(session.user.Role, "admin");
const result = session.getUser();
assert.equal(result.DisplayName, "Max Example");
assert.equal(result.SuperAdmin, true);
assert.equal(result.Role, "admin");
assert.equal(result.Email, "test@test.com");
assert.equal(result.ID, 5);
session.deleteData();
assert.isTrue(session.user.hasId());
session.deleteUser();
assert.isFalse(session.user.hasId());
});
it("should get user email", () => {
const storage = new StorageShim();
const session = new Session(storage, $config);
session.setId("a9b8ff820bf40ab451910f8bbfe401b2432446693aa539538fbd2399560a722f");
session.setAuthToken("234200000000000000000000000000000000000000000000");
session.setProvider("public");
const values = {
user: {
ID: 5,
Name: "foo",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
},
};
session.setData(values);
const result = session.getEmail();
assert.equal(result, "test@test.com");
const values2 = {
user: {
Name: "foo",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
},
};
session.setData(values2);
const result2 = session.getEmail();
assert.equal(result2, "");
session.deleteData();
});
it("should get user display name", () => {
const storage = new StorageShim();
const session = new Session(storage, $config);
const values = {
user: {
ID: 5,
Name: "foo",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
},
};
session.setData(values);
const result = session.getDisplayName();
assert.equal(result, "Max Last");
const values2 = {
id: "a9b8ff820bf40ab451910f8bbfe401b2432446693aa539538fbd2399560a722f",
access_token: "234200000000000000000000000000000000000000000000",
provider: "public",
data: {},
user: {
ID: 5,
Name: "bar",
DisplayName: "",
Email: "test@test.com",
Role: "admin",
},
};
session.setData(values2);
const result2 = session.getDisplayName();
assert.equal(result2, "Bar");
session.deleteData();
});
it("should get user full name", () => {
const storage = new StorageShim();
const session = new Session(storage, $config);
const values = {
user: {
ID: 5,
Name: "foo",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
},
};
session.setData(values);
const result = session.getDisplayName();
assert.equal(result, "Max Last");
const values2 = {
user: {
Name: "bar",
DisplayName: "Max New",
Email: "test@test.com",
Role: "admin",
},
};
session.setData(values2);
const result2 = session.getDisplayName();
assert.equal(result2, "");
session.deleteData();
});
it("should test whether user is set", () => {
const storage = new StorageShim();
const session = new Session(storage, $config);
const values = {
user: {
ID: 5,
Name: "foo",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
},
};
session.setData(values);
const result = session.isUser();
assert.equal(result, true);
session.deleteData();
});
it("should test whether user is admin", () => {
const storage = new StorageShim();
const session = new Session(storage, $config);
const values = {
user: {
ID: 5,
Name: "foo",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
},
};
session.setData(values);
const result = session.isAdmin();
assert.equal(result, true);
session.deleteData();
});
it("should test whether user is anonymous", () => {
const storage = new StorageShim();
const session = new Session(storage, $config);
const values = {
user: {
ID: 5,
DisplayName: "Foo",
FullName: "Max Last",
Email: "test@test.com",
Role: "admin",
},
};
session.setData(values);
const result = session.isAnonymous();
assert.equal(result, false);
session.deleteData();
});
it("should use session storage", () => {
const storage = new StorageShim();
const session = new Session(storage, $config);
assert.equal(storage.getItem("session"), null);
session.useSessionStorage();
assert.equal(storage.getItem("session"), "true");
session.deleteData();
});
it("should use local storage", () => {
const storage = new StorageShim();
const session = new Session(storage, $config);
assert.equal(storage.getItem("session"), null);
session.useLocalStorage();
assert.equal(storage.getItem("session"), "false");
session.deleteData();
});
it("should test redeem token", async () => {
const storage = new StorageShim();
const session = new Session(storage, $config);
assert.equal(session.data, null);
await session.redeemToken("token123");
assert.equal(session.data.token, "123token");
session.deleteData();
});
});

View File

@@ -1,223 +0,0 @@
import "../fixtures";
import $util from "common/util";
import { tokenRegexp, tokenLength } from "common/util";
import * as can from "common/can";
import { ContentTypeMp4AvcMain, ContentTypeMp4HvcMain } from "common/media";
let chai = require("chai/chai");
let assert = chai.assert;
describe("common/util", () => {
it("should return size in KB", () => {
const s = $util.formatBytes(10 * 1024);
assert.equal(s, "10 KB");
});
it("should return size in GB", () => {
const s = $util.formatBytes(10 * 1024 * 1024 * 1024);
assert.equal(s, "10.0 GB");
});
it("should convert bytes in GB", () => {
const b = $util.gigaBytes(10 * 1024 * 1024 * 1024);
assert.equal(b, 10);
});
it("should return duration 3ns", () => {
const duration = $util.formatDuration(-3);
assert.equal(duration, "3ns");
});
it("should return duration 0s", () => {
const duration = $util.formatDuration(0);
assert.equal(duration, "0s");
});
it("should return duration 2µs", () => {
const duration = $util.formatDuration(2000);
assert.equal(duration, "2µs");
});
it("should return duration 4ms", () => {
const duration = $util.formatDuration(4000000);
assert.equal(duration, "4ms");
});
it("should return duration 6s", () => {
const duration = $util.formatDuration(6000000000);
assert.equal(duration, "0:06");
});
it("should return duration 10min", () => {
const duration = $util.formatDuration(600000000000);
assert.equal(duration, "10:00");
});
it("should return formatted seconds", () => {
const floor = $util.formatSeconds(Math.floor(65.4));
assert.equal(floor, "1:05");
const ceil = $util.formatSeconds(Math.ceil(65.4));
assert.equal(ceil, "1:06");
const unknown = $util.formatSeconds(0);
assert.equal(unknown, "0:00");
const negative = $util.formatSeconds(-1);
assert.equal(negative, "0:00");
});
it("should return remaining seconds", () => {
const t = 23.3;
const d = 42.6;
const time = $util.formatSeconds(Math.floor(t));
assert.equal(time, "0:23");
const duration = $util.formatRemainingSeconds(0.0, d);
assert.equal(duration, "0:43");
const difference = $util.formatRemainingSeconds(t, d);
assert.equal(difference, "0:20");
const dotTime = $util.formatSeconds(Math.floor(9.5));
assert.equal(dotTime, "0:09");
const dotDiff = $util.formatRemainingSeconds(9.5, 12);
assert.equal(dotDiff, "0:03");
const smallDiff = $util.formatRemainingSeconds(7.959863, 8.033);
assert.equal(smallDiff, "0:02");
});
it("should return formatted milliseconds", () => {
const short = $util.formatNs(45065875);
assert.equal(short, "45 ms");
const long = $util.formatNs(45065875453454);
assert.equal(long, "45,065,875 ms");
});
it("should return formatted camera name", () => {
const iPhone15Pro = $util.formatCamera(
{ Make: "Apple", Model: "iPhone 15 Pro" },
23,
"Apple",
"iPhone 15 Pro",
false
);
assert.equal(iPhone15Pro, "iPhone 15 Pro");
const iPhone15ProLong = $util.formatCamera(
{ Make: "Apple", Model: "iPhone 15 Pro" },
23,
"Apple",
"iPhone 15 Pro",
true
);
assert.equal(iPhone15ProLong, "Apple iPhone 15 Pro");
const iPhone14 = $util.formatCamera({ Make: "Apple", Model: "iPhone 14" }, 22, "Apple", "iPhone 14", false);
assert.equal(iPhone14, "iPhone 14");
const iPhone13 = $util.formatCamera(null, 21, "Apple", "iPhone 13", false);
assert.equal(iPhone13, "iPhone 13");
});
it("should return best matching thumbnail", () => {
const thumbs = {
fit_720: {
w: 720,
h: 481,
src: "/api/v1/t/bfdcf45e58b1978af66bbf6212c195851dc65814/174usyd0/fit_720",
},
fit_1280: {
w: 1280,
h: 854,
src: "/api/v1/t/bfdcf45e58b1978af66bbf6212c195851dc65814/174usyd0/fit_1280",
},
fit_1920: {
w: 1800,
h: 1200,
src: "/api/v1/t/bfdcf45e58b1978af66bbf6212c195851dc65814/174usyd0/fit_1920",
},
fit_2560: {
w: 2400,
h: 1600,
src: "/api/v1/t/bfdcf45e58b1978af66bbf6212c195851dc65814/174usyd0/fit_2560",
},
fit_4096: {
w: 4096,
h: 2732,
src: "/api/v1/t/bfdcf45e58b1978af66bbf6212c195851dc65814/174usyd0/fit_4096",
},
fit_5120: {
w: 5120,
h: 3415,
src: "/api/v1/t/bfdcf45e58b1978af66bbf6212c195851dc65814/174usyd0/fit_5120",
},
fit_7680: {
w: 5120,
h: 3415,
src: "/api/v1/t/bfdcf45e58b1978af66bbf6212c195851dc65814/174usyd0/fit_5120",
},
};
assert.equal($util.thumb(thumbs, 1200, 900).size, "fit_1280");
assert.equal($util.thumb(thumbs, 1300, 900).size, "fit_1920");
assert.equal($util.thumb(thumbs, 1300, 900).w, 1800);
assert.equal($util.thumb(thumbs, 1300, 900).h, 1200);
assert.equal(
$util.thumb(thumbs, 1300, 900).src,
"/api/v1/t/bfdcf45e58b1978af66bbf6212c195851dc65814/174usyd0/fit_1920"
);
assert.equal($util.thumb(thumbs, 1400, 1200).size, "fit_1920");
assert.equal($util.thumb(thumbs, 100000, 120000).size, "fit_7680");
});
it("should return the approximate best thumbnail size name", () => {
assert.equal($util.thumbSize(1300, 900), "fit_1280");
assert.equal($util.thumbSize(1400, 1200), "fit_1920");
assert.equal($util.thumbSize(100000, 120000), "fit_7680");
});
it("should return matching video format name", () => {
const avc = $util.videoFormat("avc1", ContentTypeMp4AvcMain);
assert.equal(avc, "avc");
const hevc = $util.videoFormat("hvc1", ContentTypeMp4HvcMain);
if (can.useMp4Hvc) {
assert.equal(hevc, "hevc");
} else {
assert.equal(hevc, "avc");
}
const webm = $util.videoFormat("", "video/webm");
if (can.useWebM) {
assert.equal(webm, "webm");
} else {
assert.equal(webm, "avc");
}
});
it("should convert -1 to roman", () => {
const roman = $util.arabicToRoman(-1);
assert.equal(roman, "");
});
it("should convert 2500 to roman", () => {
const roman = $util.arabicToRoman(2500);
assert.equal(roman, "MMD");
});
it("should convert 112 to roman", () => {
const roman = $util.arabicToRoman(112);
assert.equal(roman, "CXII");
});
it("should convert 9 to roman", () => {
const roman = $util.arabicToRoman(9);
assert.equal(roman, "IX");
});
it("should truncate xxx", () => {
const result = $util.truncate("teststring");
assert.equal(result, "teststring");
});
it("should truncate xxx", () => {
const result = $util.truncate("teststring for mocha", 5, "ng");
assert.equal(result, "tesng");
});
it("should encode html", () => {
const result = $util.encodeHTML("Micha & Theresa > < 'Lilly'");
assert.equal(result, "Micha &amp; Theresa &gt; &lt; &apos;Lilly&apos;");
});
it("should encode link", () => {
const result = $util.encodeHTML("Try this: https://photoswipe.com/options/?foo=bar&bar=baz. It's a link!");
assert.equal(
result,
`Try this: <a href="https://photoswipe.com/options/" target="_blank">https://photoswipe.com/options/</a> It&apos;s a link!`
);
});
it("should generate tokens reliably", () => {
const tokens = new Set();
const numTokens = 100;
for (let i = 0; i < numTokens; i++) {
const token = $util.generateToken();
assert.lengthOf(token, tokenLength);
assert.match(token, tokenRegexp);
tokens.add(token);
}
// Check they are all unique
assert.lengthOf(tokens, numTokens);
});
});

View File

@@ -1,25 +0,0 @@
import { $view } from "common/view";
let chai = require("chai/chai");
let assert = chai.assert;
describe("common/view", () => {
it("should return parent", () => {
assert.equal($view.getParent(), null);
});
it("should return parent name", () => {
assert.equal($view.getParentName(), "");
});
it("should return data", () => {
assert.containsSubset($view.getData(), {});
});
it("should return number of layers", () => {
assert.containsSubset($view.len(), 0);
});
it("should return if root view is active", () => {
assert.equal($view.isRoot(), true);
});
it("should return if view is app", () => {
assert.equal($view.isApp(), true);
});
});

View File

@@ -1,518 +0,0 @@
const clientConfig = {
mode: "user",
name: "PhotoPrism",
about: "PhotoPrism® CE",
edition: "ce",
version: "210710-bae1f2d7-Linux-x86_64-DEBUG",
copyright: "(c) 2018-2025 PhotoPrism UG. All rights reserved.",
flags: "public debug develop experimental settings",
baseUri: "",
staticUri: "/static",
apiUri: "/api/v1",
contentUri: "/api/v1",
siteUrl: "http://localhost:2342/",
sitePreview: "http://localhost:2342/static/img/preview.jpg",
siteTitle: "PhotoPrism",
siteCaption: "AI-Powered Photos App",
siteDescription: "Open-Source Photo Management",
siteAuthor: "@photoprism_app",
debug: false,
readonly: false,
uploadNSFW: false,
public: false,
develop: true,
experimental: true,
disableSettings: false,
test: true,
demo: false,
sponsor: true,
albumCategories: ["Animal", "Holiday"],
albums: [
{
ID: 69,
UID: "aqw0vmr32zb4560f",
CoverUID: "",
FolderUID: "",
Slug: "test-album-1",
Path: "",
Type: "album",
Title: "Test Album 1",
Location: "",
Category: "",
Caption: "",
Description: "",
Notes: "",
Filter: "",
Order: "oldest",
Template: "",
Country: "zz",
Year: 0,
Month: 0,
Day: 0,
Favorite: true,
Private: false,
CreatedAt: "2021-07-10T09:28:03Z",
UpdatedAt: "2021-07-10T09:28:03Z",
DeletedAt: null,
},
{
ID: 70,
UID: "aqw0vmzrkc202vty",
CoverUID: "",
FolderUID: "",
Slug: "test-album-2",
Path: "",
Type: "album",
Title: "Test Album 2",
Location: "",
Category: "",
Caption: "",
Description: "",
Notes: "",
Filter: "",
Order: "oldest",
Template: "",
Country: "zz",
Year: 0,
Month: 0,
Day: 0,
Favorite: true,
Private: false,
CreatedAt: "2021-07-10T09:28:12Z",
UpdatedAt: "2021-07-10T09:28:12Z",
DeletedAt: null,
},
],
cameras: [
{
ID: 7,
Slug: "apple-iphone-se",
Name: "Apple iPhone SE",
Make: "Apple",
Model: "iPhone SE",
},
{
ID: 2,
Slug: "canon-eos-6d",
Name: "Canon EOS 6D",
Make: "Canon",
Model: "EOS 6D",
},
{
ID: 3,
Slug: "canon-eos-7d",
Name: "Canon EOS 7D",
Make: "Canon",
Model: "EOS 7D",
},
{
ID: 6,
Slug: "hmd-global-nokia-x71",
Name: "HMD Global Nokia X71",
Make: "HMD Global",
Model: "Nokia X71",
},
{
ID: 4,
Slug: "huawei-mate-20-lite",
Name: "HUAWEI Mate 20 lite",
Make: "HUAWEI",
Model: "Mate 20 lite",
},
{
ID: 5,
Slug: "huawei-p30",
Name: "HUAWEI P30",
Make: "HUAWEI",
Model: "P30",
},
{
ID: 1,
Slug: "zz",
Name: "Unknown",
Make: "",
Model: "Unknown",
},
],
lenses: [
{
ID: 6,
Slug: "apple-iphone-se-back-camera-4-15mm-f-2-2",
Name: "Apple iPhone SE back camera 4.15mm f/2.2",
Make: "Apple",
Model: "iPhone SE back camera 4.15mm f/2.2",
Type: "",
},
{
ID: 3,
Slug: "ef100mm-f-2-8l-macro-is-usm",
Name: "EF100mm f/2.8L Macro IS USM",
Make: "",
Model: "EF100mm f/2.8L Macro IS USM",
Type: "",
},
{
ID: 5,
Slug: "ef16-35mm-f-2-8l-ii-usm",
Name: "EF16-35mm f/2.8L II USM",
Make: "",
Model: "EF16-35mm f/2.8L II USM",
Type: "",
},
{
ID: 2,
Slug: "ef24-105mm-f-4l-is-usm",
Name: "EF24-105mm f/4L IS USM",
Make: "",
Model: "EF24-105mm f/4L IS USM",
Type: "",
},
{
ID: 4,
Slug: "ef70-200mm-f-4l-is-usm",
Name: "EF70-200mm f/4L IS USM",
Make: "",
Model: "EF70-200mm f/4L IS USM",
Type: "",
},
{
ID: 1,
Slug: "zz",
Name: "Unknown",
Make: "",
Model: "Unknown",
Type: "",
},
],
countries: [
{
ID: "bw",
Slug: "botswana",
Name: "Botswana",
},
{
ID: "fr",
Slug: "france",
Name: "France",
},
{
ID: "de",
Slug: "germany",
Name: "Germany",
},
{
ID: "gr",
Slug: "greece",
Name: "Greece",
},
{
ID: "za",
Slug: "south-africa",
Name: "South Africa",
},
{
ID: "gb",
Slug: "united-kingdom",
Name: "United Kingdom",
},
{
ID: "zz",
Slug: "zz",
Name: "Unknown",
},
],
people: [
{
UID: "jr0jgyx2viicdnf7",
Name: "Andrea Sander",
Keywords: ["andrea"],
},
{
UID: "jr0jgyx2viicdn88",
Name: "Otto Sander",
Keywords: ["andrea"],
},
{
UID: "jr0jgzi2qmp5wt97",
Name: "Otto Sander",
Keywords: ["otto", "sander"],
},
],
thumbs: [
{ size: "fit_720", usage: "SD TV, Mobile", w: 720, h: 720 },
{ size: "fit_1280", usage: "HD TV, SXGA", w: 1280, h: 1024 },
{ size: "fit_1920", usage: "Full HD", w: 1920, h: 1200 },
{ size: "fit_2560", usage: "Quad HD, Notebooks", w: 2560, h: 1600 },
{ size: "fit_4096", usage: "DCI 4K, Retina 4K", w: 4096, h: 4096 },
{ size: "fit_7680", usage: "8K Ultra HD 2", w: 7680, h: 4320 },
],
status: "unregistered",
mapKey: "D9ve6edlcVR2mEsNvCXa",
downloadToken: "2lbh9x09",
previewToken: "public",
cssUri: "/static/build/app.2259c0edcc020e7af593.css",
jsUri: "/static/build/app.9bd7132eaee8e4c7c7e3.js",
manifestUri: "/manifest.json",
settings: {
ui: {
scrollbar: true,
zoom: false,
theme: "default",
language: "en",
},
search: {
batchSize: 90,
},
maps: {
animate: 0,
style: "streets",
},
features: {
upload: true,
download: true,
private: true,
review: false,
files: true,
videos: true,
folders: true,
albums: true,
moments: true,
estimates: true,
people: true,
labels: true,
places: true,
edit: true,
archive: true,
delete: false,
share: true,
library: true,
import: true,
logs: true,
},
import: {
path: "/",
move: false,
},
index: {
path: "/",
convert: true,
rescan: false,
},
stack: {
uuid: true,
meta: true,
name: false,
},
share: {
title: "",
},
download: {
name: "file",
},
templates: {
default: "index.gohtml",
},
},
disable: {
backups: false,
webdav: false,
settings: false,
places: false,
exiftool: false,
darktable: false,
rawtherapee: false,
sips: true,
heifconvert: false,
ffmpeg: false,
tensorflow: false,
},
count: {
all: 133,
photos: 132,
videos: 1,
cameras: 6,
lenses: 5,
countries: 6,
hidden: 0,
favorites: 1,
private: 0,
private_albums: 0,
private_folders: 0,
private_moments: 0,
private_months: 0,
private_states: 0,
review: 22,
stories: 0,
albums: 2,
moments: 4,
months: 27,
folders: 23,
files: 136,
places: 17,
states: 8,
people: 5,
labels: 22,
labelMaxPhotos: 118,
},
pos: {
uid: "pqu0xswtrlixbcjp",
cid: "s2:149c947fca4c",
utc: "2021-06-01T09:46:52Z",
lat: 35.2847,
lng: 23.8122,
},
years: [2021, 2020, 2019, 2018, 2017, 2015, 2013, 2012],
colors: [
{
Example: "#AB47BC",
Name: "Purple",
Slug: "purple",
},
{
Example: "#FF00FF",
Name: "Magenta",
Slug: "magenta",
},
{
Example: "#EC407A",
Name: "Pink",
Slug: "pink",
},
{
Example: "#EF5350",
Name: "Red",
Slug: "red",
},
{
Example: "#FFA726",
Name: "Orange",
Slug: "orange",
},
{
Example: "#D4AF37",
Name: "Gold",
Slug: "gold",
},
{
Example: "#FDD835",
Name: "Yellow",
Slug: "yellow",
},
{
Example: "#CDDC39",
Name: "Lime",
Slug: "lime",
},
{
Example: "#66BB6A",
Name: "Green",
Slug: "green",
},
{
Example: "#009688",
Name: "Teal",
Slug: "teal",
},
{
Example: "#00BCD4",
Name: "Cyan",
Slug: "cyan",
},
{
Example: "#2196F3",
Name: "Blue",
Slug: "blue",
},
{
Example: "#A1887F",
Name: "Brown",
Slug: "brown",
},
{
Example: "#F5F5F5",
Name: "White",
Slug: "white",
},
{
Example: "#9E9E9E",
Name: "Grey",
Slug: "grey",
},
{
Example: "#212121",
Name: "Black",
Slug: "black",
},
],
categories: [
{
UID: "lqw0teu1kndplci9",
Slug: "animal",
Name: "Animal",
},
{
UID: "lqw0tfrbx6e6flcx",
Slug: "bird",
Name: "Bird",
},
{
UID: "lqw0tfw28lz7hcpq",
Slug: "food",
Name: "Food",
},
{
UID: "lqw0tfqhgq2fr0ga",
Slug: "insect",
Name: "Insect",
},
{
UID: "lqw0tfr144mh3jrd",
Slug: "nature",
Name: "Nature",
},
{
UID: "lqw0tf72t04mgecr",
Slug: "outdoor",
Name: "Outdoor",
},
{
UID: "lqw0teu1jpuk8310",
Slug: "people",
Name: "People",
},
{
UID: "lqw0teufc81nxvqt",
Slug: "portrait",
Name: "Portrait",
},
{
UID: "lqw0tft3e5qjlfcz",
Slug: "vehicle",
Name: "Vehicle",
},
{
UID: "lqw0tft315xza8bk",
Slug: "water",
Name: "Water",
},
{
UID: "lqw0tfs1dfgra72o",
Slug: "wildlife",
Name: "Wildlife",
},
],
clip: 160,
server: {
cores: 16,
routines: 26,
memory: {
used: 81586008,
reserved: 148459544,
info: "Used 82 MB / Reserved 148 MB",
},
},
};
window.__CONFIG__ = clientConfig;
export default clientConfig;

View File

@@ -1,379 +0,0 @@
import { Settings } from "luxon";
Settings.defaultLocale = "en";
Settings.defaultZoneName = "UTC";
import clientConfig from "./config";
import { $config } from "app/session";
$config.setValues(clientConfig);
import MockAdapter from "axios-mock-adapter";
import $api from "common/api";
const Mock = new MockAdapter($api, { onNoMatch: "throwException" });
const mockHeaders = {
"Content-Type": "application/json; charset=utf-8",
};
const getCollectionResponse = [
{ id: 1, name: "John Smith" },
{ id: 1, name: "John Smith" },
];
const getEntityResponse = {
id: 1,
name: "John Smith",
};
const postEntityResponse = {
users: [{ id: 1, name: "John Smith" }],
};
const putEntityResponse = {
users: [{ id: 2, name: "John Foo" }],
};
const deleteEntityResponse = null;
Mock.onPost("api/v1/users/urii20d30w2wqzjf/profile").reply(200, { DisplayName: "Max New" }, mockHeaders);
Mock.onPost("api/v1/users/52/avatar").reply(200, { Thumb: "abc", ThumbSrc: "manual" }, mockHeaders);
Mock.onGet("api/v1/foo").reply(200, getCollectionResponse, mockHeaders);
Mock.onGet("api/v1/foo/123").reply(200, getEntityResponse, mockHeaders);
Mock.onPost("api/v1/foo").reply(201, postEntityResponse, mockHeaders);
Mock.onPut("api/v1/foo/2").reply(200, putEntityResponse, mockHeaders);
Mock.onDelete("api/v1/foo/2").reply(204, deleteEntityResponse, mockHeaders);
Mock.onGet("api/v1/error").reply(401, "custom error cat", mockHeaders);
Mock.onPost("api/v1/batch/photos/archive").reply(200, { photos: [1, 3] }, mockHeaders);
Mock.onPost("api/v1/photos/pqbemz8276mhtobh/approve").reply(200, {}, mockHeaders);
Mock.onPost("api/v1/photos/pqbemz8276mhtobh/files/fqbfk181n4ca5sud/primary").reply(
200,
{
ID: 10,
UID: "pqbemz8276mhtobh",
Files: [
{
UID: "fqbfk181n4ca5sud",
Name: "1980/01/superCuteKitten.mp4",
Primary: true,
FileType: "mp4",
Hash: "1xxbgdt55",
},
],
},
mockHeaders
);
Mock.onPut("api/v1/photos/pqbemz8276mhtobh").reply(
200,
{
ID: 10,
UID: "pqbemz8276mhtobh",
TitleSrc: "manual",
Files: [
{
UID: "fqbfk181n4ca5sud",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
FileType: "mp4",
Hash: "1xxbgdt55",
},
],
},
mockHeaders
);
Mock.onDelete("api/v1/photos/abc123/unlike").reply(200);
Mock.onDelete("api/v1/photos/pqbemz8276mhtobh/files/fqbfk181n4ca5sud").reply(
200,
{
success: "successfully deleted",
},
mockHeaders
);
Mock.onPost("api/v1/photos/pqbemz8276mhtobh/files/fqbfk181n4ca5sud/unstack").reply(
200,
{
success: "ok",
},
mockHeaders
);
Mock.onPost("api/v1/photos/pqbemz8276mhtobh/label", { Name: "Cat", Priority: 10 }).reply(
200,
{
success: "ok",
},
mockHeaders
);
Mock.onPut("api/v1/photos/pqbemz8276mhtobh/label/12345", { Uncertainty: 0 }).reply(
200,
{
success: "ok",
},
mockHeaders
);
Mock.onPut("api/v1/photos/pqbemz8276mhtobh/label/12345", { Label: { Name: "Sommer" } }).reply(
200,
{
success: "ok",
},
mockHeaders
);
Mock.onDelete("api/v1/photos/pqbemz8276mhtobh/label/12345").reply(200, { success: "ok" }, mockHeaders);
Mock.onPost("api/v1/session").reply(
200,
{
session_id: "5aa770f2a1ef431628d9f17bdf82a0d16865e99d4a1ddd9356e1aabfe6464683",
access_token: "999900000000000000000000000000000000000000000000",
token_type: "Bearer",
provider: "test",
data: { token: "123token" },
user: { ID: 1, UID: "urjysof3b9v7lgex", Name: "test", Email: "test@test.com" },
},
mockHeaders
);
Mock.onGet("api/v1/session/a9b8ff820bf40ab451910f8bbfe401b2432446693aa539538fbd2399560a722f").reply(
200,
{
session_id: "a9b8ff820bf40ab451910f8bbfe401b2432446693aa539538fbd2399560a722f",
access_token: "234200000000000000000000000000000000000000000000",
token_type: "Bearer",
provider: "public",
data: { token: "123token" },
user: { ID: 1, UID: "urjysof3b9v7lgex", Name: "test", Email: "test@test.com" },
},
mockHeaders
);
Mock.onGet("api/v1/session/5aa770f2a1ef431628d9f17bdf82a0d16865e99d4a1ddd9356e1aabfe6464683").reply(
200,
{
session_id: "5aa770f2a1ef431628d9f17bdf82a0d16865e99d4a1ddd9356e1aabfe6464683",
access_token: "999900000000000000000000000000000000000000000000",
token_type: "Bearer",
provider: "test",
data: { token: "123token" },
user: { ID: 1, UID: "urjysof3b9v7lgex", Name: "test", Email: "test@test.com" },
},
mockHeaders
);
Mock.onDelete("api/v1/session/5aa770f2a1ef431628d9f17bdf82a0d16865e99d4a1ddd9356e1aabfe6464683").reply(200);
Mock.onDelete("api/v1/session/a9b8ff820bf40ab451910f8bbfe401b2432446693aa539538fbd2399560a722f").reply(200);
Mock.onGet("api/v1/settings").reply(200, { download: true, language: "de" }, mockHeaders);
Mock.onPost("api/v1/settings").reply(200, { download: true, language: "en" }, mockHeaders);
Mock.onGet("api/v1/services/123/folders").reply(200, { foo: "folders" }, mockHeaders);
Mock.onPost("api/v1/services/123/upload").reply(200, { foo: "upload" }, mockHeaders);
Mock.onGet("api/v1/folders/2011/10-Halloween", {
params: { recursive: true, uncached: true },
}).reply(
200,
{ folders: [1, 2], files: [1] },
{
"Content-Type": "application/json; charset=utf-8",
"x-count": "3",
"x-limit": "100",
"x-offset": "0",
}
);
Mock.onGet("api/v1/folders/2011/10-Halloween", { params: { recursive: true } }).reply(
200,
{
folders: [1, 2, 3],
files: [1],
},
mockHeaders
);
Mock.onGet("api/v1/folders/originals/2011/10-Halloween", { params: { recursive: true } }).reply(
200,
{
folders: [1, 2, 3],
files: [1],
},
mockHeaders
);
Mock.onPut("albums/66/links/5").reply(
200,
{
UID: 5,
Slug: "friends",
Expires: 80000,
UpdatedAt: "2012-07-08T14:45:39Z",
},
mockHeaders
);
Mock.onGet("api/v1/albums/66").reply(200, { Success: "ok" }, mockHeaders);
Mock.onPost("api/v1/albums/66/links").reply(
200,
{
Password: "passwd",
Expires: 8000,
Slug: "christmas-2019",
Comment: "",
Perm: 0,
},
mockHeaders
);
Mock.onDelete("api/v1/albums/66/links/5").reply(200, { Success: "ok" }, mockHeaders);
Mock.onGet("api/v1/albums/66/links").reply(
200,
[
{ UID: "sqcwh80ifesw74ht", ShareUID: "aqcwh7weohhk49q2", Slug: "july-2020" },
{ UID: "sqcwhxh1h58rf3c2", ShareUID: "aqcwh7weohhk49q2" },
],
mockHeaders
);
Mock.onPut("/api/v1/albums/66").reply(
200,
{
Description: "Test description",
},
mockHeaders
);
Mock.onGet("api/v1/albums").reply(
200,
{
ID: 51,
CreatedAt: "2019-07-03T18:48:07Z",
UpdatedAt: "2019-07-25T01:04:44Z",
DeletedAt: "0001-01-01T00:00:00Z",
Slug: "tabby-cat",
Name: "tabby cat",
Priority: 5,
LabelCount: 9,
Favorite: false,
Description: "",
Notes: "",
},
{
"Content-Type": "application/json; charset=utf-8",
"x-count": "3",
"x-limit": "100",
"x-offset": "0",
}
);
Mock.onOptions("api/v1/albums").reply(
200,
{
foo: "bar",
},
mockHeaders
);
Mock.onOptions("api/v1/albums/abc").reply(
200,
{
foo: "edit",
},
mockHeaders
);
Mock.onDelete("api/v1/albums/abc").reply(
200,
{
status: "ok",
},
mockHeaders
);
Mock.onPut("api/v1/albums/abc").reply(
200,
{
Description: "Test description",
},
mockHeaders
);
//Mock.onPost("api/v1/users/55/profile").reply(200, { DisplayName: "Max New" }, mockHeaders);
//Mock.onPost("users/55/profile").reply(200, { DisplayName: "Max New" }, mockHeaders);
//Mock.onPost("api/v1/users/55/profile").reply(200, { DisplayName: "Max New" }, mockHeaders);
Mock.onAny("api/v1/users/52/register").reply(200, { foo: "register" }, mockHeaders);
Mock.onAny("api/v1/users/53/profile").reply(200, { foo: "profile" }, mockHeaders);
Mock.onPut("api/v1/users/54/password").reply(200, { password: "old", new_password: "new" }, mockHeaders);
Mock.onGet("api/v1/link/5").reply(200, "get success", mockHeaders);
Mock.onPut("api/v1/link/5").reply(200, "put success", mockHeaders);
Mock.onDelete("api/v1/link/5").reply(200, "delete success", mockHeaders);
Mock.onPost("api/v1/photos/55/like").reply(200, { status: "ok" }, mockHeaders);
Mock.onDelete("api/v1/photos/55/like").reply(200, { status: "ok" }, mockHeaders);
Mock.onGet("api/v1/albums/5").reply(200, { UID: "5" }, mockHeaders);
Mock.onPut("api/v1/photos/5").reply(200, { UID: "5" }, mockHeaders);
Mock.onDelete("api/v1/photos/abc123/like").reply(200, { status: "ok" }, mockHeaders);
Mock.onPost("api/v1/photos/5/like").reply(200, { status: "ok" }, mockHeaders);
Mock.onPost("api/v1/labels/ABC123/like").reply(200, { status: "ok" }, mockHeaders);
Mock.onDelete("api/v1/labels/ABC123/like").reply(200, { status: "ok" }, mockHeaders);
Mock.onPost("api/v1/folders/dqbevau2zlhxrxww/like").reply(200, { status: "ok" }, mockHeaders);
Mock.onDelete("api/v1/folders/dqbevau2zlhxrxww/like").reply(200, { status: "ok" }, mockHeaders);
Mock.onPost("api/v1/photos/undefined/like").reply(200, { status: "ok" }, mockHeaders);
Mock.onDelete("api/v1/photos/undefined/like").reply(200, { status: "ok" }, mockHeaders);
Mock.onPost("api/v1/albums/5/like").reply(200, { status: "ok" }, mockHeaders);
Mock.onDelete("api/v1/albums/5/like").reply(200, { status: "ok" }, mockHeaders);
Mock.onGet("api/v1/config").reply(200, clientConfig, mockHeaders);
Mock.onPut("api/v1/markers/mBC123ghytr", { Review: false, Invalid: false }).reply(
200,
{
success: "ok",
},
mockHeaders
);
Mock.onPut("api/v1/markers/mCC123ghytr", { Review: false, Invalid: true }).reply(
200,
{
success: "ok",
},
mockHeaders
);
Mock.onPut("api/v1/markers/mDC123ghytr", { SubjSrc: "manual", Name: "testname" }).reply(
200,
{
success: "ok",
Name: "testname",
},
mockHeaders
);
Mock.onDelete("api/v1/markers/mEC123ghytr/subject").reply(200, { success: "ok" }, mockHeaders);
Mock.onPut("api/v1/faces/f123ghytrfggd", { Hidden: false }).reply(
200,
{
success: "ok",
},
mockHeaders
);
Mock.onPut("api/v1/faces/f123ghytrfggd", { Hidden: true }).reply(
200,
{
success: "ok",
},
mockHeaders
);
Mock.onPost("api/v1/subjects/s123ghytrfggd/like").reply(200, { status: "ok" }, mockHeaders);
Mock.onPut("api/v1/subjects/s123ghytrfggd").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("api/v1/albums").reply(200, { success: "ok" }, mockHeaders);
//Mock.onPost().reply(200);
//Mock.onDelete().reply(200);
/*
Mock.onPost().reply(200).onDelete().reply(200);
Mock.onDelete().reply(200);
Mock.onAny().reply(200, "editForm");
Mock.onPut().reply(200, { Description: "Test description" });
Mock.onPut().reply(200, { Description: "Test description" });
Mock.onPost().reply(200, { Description: "Test description" });
*/
export { $api, Mock };

View File

@@ -1,345 +0,0 @@
import "../fixtures";
import { Album, BatchSize } from "model/album";
let chai = require("chai/chai");
let assert = chai.assert;
describe("model/album", () => {
it("should get route view", () => {
const values = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019" };
const album = new Album(values);
const result = album.route("test");
assert.equal(result.name, "test");
assert.equal(result.params.slug, "view");
});
it("should return classes", () => {
const values = {
UID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
Type: "moment",
Favorite: true,
Private: true,
};
const album = new Album(values);
const result = album.classes(true);
assert.include(result, "is-album");
assert.include(result, "uid-5");
assert.include(result, "type-moment");
assert.include(result, "is-selected");
assert.include(result, "is-favorite");
assert.include(result, "is-private");
});
it("should get album entity name", () => {
const values = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019" };
const album = new Album(values);
const result = album.getEntityName();
assert.equal(result, "christmas-2019");
});
it("should get album id", () => {
const values = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values);
const result = album.getId();
assert.equal(result, "66");
});
it("should get album title", () => {
const values = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019" };
const album = new Album(values);
const result = album.getTitle();
assert.equal(result, "Christmas 2019");
});
it("should get album country", () => {
const values = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019", Country: "at" };
const album = new Album(values);
const result = album.getCountry();
assert.equal(result, "Austria");
const values2 = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019", Country: "zz" };
const album2 = new Album(values2);
const result2 = album2.getCountry();
assert.equal(result2, "");
const values3 = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019", Country: "xx" };
const album3 = new Album(values3);
const result3 = album3.getCountry();
assert.equal(result3, "");
});
it("should check if album has location", () => {
const values = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
Country: "zz",
State: "",
Location: "",
};
const album = new Album(values);
const result = album.hasLocation();
assert.equal(result, false);
const values2 = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019", Country: "at" };
const album2 = new Album(values2);
const result2 = album2.hasLocation();
assert.equal(result2, true);
});
it("should get album location", () => {
const values = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
Country: "at",
State: "Salzburg",
Location: "",
};
const album = new Album(values);
const result = album.getLocation();
assert.equal(result, "Salzburg, Austria");
const values2 = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
Country: "zz",
State: "",
Location: "",
};
const album2 = new Album(values2);
const result2 = album2.getLocation();
assert.equal(result2, "");
const values3 = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
Country: "zz",
State: "",
Location: "Austria",
};
const album3 = new Album(values3);
const result3 = album3.getLocation();
assert.equal(result3, "Austria");
const values5 = {
ID: 5,
Title: "Salzburg",
Slug: "salzburg",
Country: "at",
State: "Salzburg",
Location: "",
};
const album5 = new Album(values5);
const result5 = album5.getLocation();
assert.equal(result5, "Austria");
const values6 = {
ID: 5,
Title: "Austria",
Slug: "austria",
Country: "at",
State: "Salzburg",
Location: "",
};
const album6 = new Album(values6);
const result6 = album6.getLocation();
assert.equal(result6, "Salzburg");
});
it("should get thumbnail url", () => {
const values = {
ID: 5,
Thumb: "d6b24d688564f7ddc7b245a414f003a8d8ff5a67",
Title: "Christmas 2019",
Slug: "christmas-2019",
UID: 66,
};
const album = new Album(values);
const result = album.thumbnailUrl("xyz");
assert.equal(result, "/api/v1/t/d6b24d688564f7ddc7b245a414f003a8d8ff5a67/public/xyz");
const values2 = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
UID: 66,
};
const album2 = new Album(values2);
const result2 = album2.thumbnailUrl("xyz");
assert.equal(result2, "/api/v1/albums/66/t/public/xyz");
const values3 = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
};
const album3 = new Album(values3);
const result3 = album3.thumbnailUrl("xyz");
assert.equal(result3, "/api/v1/svg/album");
});
it("should get created date string", () => {
const values = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
CreatedAt: "2012-07-08T14:45:39Z",
};
const album = new Album(values);
const result = album.getCreatedString();
assert.equal(result.replaceAll("\u202f", " "), "Jul 8, 2012, 2:45 PM");
});
it("should get album date string with invalid day", () => {
const values = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
CreatedAt: "2012-07-08T14:45:39Z",
Day: -1,
Month: 5,
Year: 2019,
};
const album = new Album(values);
const result = album.getDateString();
assert.equal(result, "May 2019");
});
it("should get album date string with invalid month", () => {
const values = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
CreatedAt: "2012-07-08T14:45:39Z",
Day: 1,
Month: -5,
Year: 2000,
};
const album = new Album(values);
const result = album.getDateString();
assert.equal(result, "2000");
});
it("should get album date string with invalid year", () => {
const values = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
CreatedAt: "2012-07-08T14:45:39Z",
Day: 1,
Month: 5,
Year: 800,
};
const album = new Album(values);
const result = album.getDateString();
assert.equal(result, "Unknown");
});
it("should get album date string", () => {
const values = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
CreatedAt: "2012-07-08T14:45:39Z",
Day: 1,
Month: 5,
Year: 2000,
};
const album = new Album(values);
const result = album.getDateString();
assert.equal(result, "Monday, May 1, 2000");
});
it("should get day string", () => {
const values = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
CreatedAt: "2012-07-08T14:45:39Z",
Day: 8,
Month: 5,
Year: 2019,
};
const album = new Album(values);
const result = album.dayString();
assert.equal(result, "08");
});
it("should get month string", () => {
const values = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
CreatedAt: "2012-07-08T14:45:39Z",
Day: 8,
Month: -5,
Year: 2019,
};
const album = new Album(values);
const result = album.monthString();
assert.equal(result, "01");
});
it("should get year string", () => {
const values = {
ID: 5,
Title: "Christmas 2019",
Slug: "christmas-2019",
CreatedAt: "2012-07-08T14:45:39Z",
Day: 8,
Month: -5,
Year: 800,
};
const album = new Album(values);
const result = album.yearString();
assert.equal(result, new Date().getFullYear().toString().padStart(4, "0"));
});
it("should get model name", () => {
const result = Album.getModelName();
assert.equal(result, "Album");
});
it("should get collection resource", () => {
const result = Album.getCollectionResource();
assert.equal(result, "albums");
});
it("should return batch size", () => {
assert.equal(Album.batchSize(), BatchSize);
Album.setBatchSize(30);
assert.equal(Album.batchSize(), 30);
Album.setBatchSize(BatchSize);
});
it("should like album", () => {
const values = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019", Favorite: false };
const album = new Album(values);
assert.equal(album.Favorite, false);
album.like();
assert.equal(album.Favorite, true);
});
it("should unlike album", () => {
const values = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019", Favorite: true };
const album = new Album(values);
assert.equal(album.Favorite, true);
album.unlike();
assert.equal(album.Favorite, false);
});
it("should toggle like", () => {
const values = { ID: 5, Title: "Christmas 2019", Slug: "christmas-2019", Favorite: true };
const album = new Album(values);
assert.equal(album.Favorite, true);
album.toggleLike();
assert.equal(album.Favorite, false);
album.toggleLike();
assert.equal(album.Favorite, true);
});
});

View File

@@ -1,52 +0,0 @@
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);
});
});

View File

@@ -1,177 +0,0 @@
import "../fixtures";
import { Face, BatchSize } from "model/face";
let chai = require("chai/chai");
let assert = chai.assert;
describe("model/face", () => {
it("should get face defaults", () => {
const values = {};
const face = new Face(values);
const result = face.getDefaults();
assert.equal(result.ID, "");
assert.equal(result.SampleRadius, 0.0);
});
it("should get route view", () => {
const values = { ID: "f123ghytrfggd", Samples: 5 };
const face = new Face(values);
const result = face.route("test");
assert.equal(result.name, "test");
assert.equal(result.query.q, "face:f123ghytrfggd");
});
it("should return classes", () => {
const values = { ID: "f123ghytrfggd", Samples: 5 };
const face = new Face(values);
const result = face.classes(true);
assert.include(result, "is-face");
assert.include(result, "uid-f123ghytrfggd");
assert.include(result, "is-selected");
assert.notInclude(result, "is-hidden");
const result2 = face.classes(false);
assert.include(result2, "is-face");
assert.include(result2, "uid-f123ghytrfggd");
assert.notInclude(result2, "is-selected");
assert.notInclude(result2, "is-hidden");
const values2 = { ID: "f123ghytrfggd", Samples: 5, Hidden: true };
const face2 = new Face(values2);
const result3 = face2.classes(true);
assert.include(result3, "is-face");
assert.include(result3, "uid-f123ghytrfggd");
assert.include(result3, "is-selected");
assert.include(result3, "is-hidden");
});
it("should get face entity name", () => {
const values = { ID: "f123ghytrfggd", Samples: 5 };
const face = new Face(values);
const result = face.getEntityName();
assert.equal(result, "f123ghytrfggd");
});
it("should get face title", () => {
const values = { ID: "f123ghytrfggd", Samples: 5 };
const face = new Face(values);
const result = face.getTitle();
assert.equal(result, undefined);
});
it("should get thumbnail url", () => {
const values = {
ID: "f123ghytrfggd",
Samples: 5,
MarkerUID: "ABC123ghytr",
FileUID: "fhjouohnnmnd",
Name: "",
Thumb: "7ca759a2b788cc5bcc08dbbce9854ff94a2f94d1",
};
const face = new Face(values);
const result = face.thumbnailUrl("xyz");
assert.equal(result, "/api/v1/t/7ca759a2b788cc5bcc08dbbce9854ff94a2f94d1/public/xyz");
const values2 = {
ID: "f123ghytrfggd",
Samples: 5,
Thumb: "7ca759a2b788cc5bcc08dbbce9854ff94a2f94d1",
};
const face2 = new Face(values2);
const result2 = face2.thumbnailUrl();
assert.equal(result2, "/api/v1/t/7ca759a2b788cc5bcc08dbbce9854ff94a2f94d1/public/tile_160");
const values3 = {
ID: "f123ghytrfggd",
Samples: 5,
Thumb: "",
};
const face3 = new Face(values3);
const result3 = face3.thumbnailUrl("tile_240");
assert.equal(result3, "/api/v1/svg/portrait");
});
it("should get date string", () => {
const values = {
ID: "f123ghytrfggd",
Samples: 5,
CreatedAt: "2012-07-08T14:45:39Z",
};
const face = new Face(values);
const result = face.getDateString();
assert.equal(result.replaceAll("\u202f", " "), "Jul 8, 2012, 2:45 PM");
});
it("show and hide face", () => {
const values = {
ID: "f123ghytrfggd",
Samples: 5,
CreatedAt: "2012-07-08T14:45:39Z",
Hidden: true,
};
const face = new Face(values);
assert.equal(face.Hidden, true);
face.show();
assert.equal(face.Hidden, false);
face.hide();
assert.equal(face.Hidden, true);
});
it("should toggle hidden", () => {
const values = {
ID: "f123ghytrfggd",
Samples: 5,
CreatedAt: "2012-07-08T14:45:39Z",
Hidden: true,
};
const face = new Face(values);
assert.equal(face.Hidden, true);
face.toggleHidden();
assert.equal(face.Hidden, false);
face.toggleHidden();
assert.equal(face.Hidden, true);
});
it("should set name", (done) => {
const values = { ID: "f123ghytrfggd", Samples: 5, MarkerUID: "mDC123ghytr", Name: "Jane" };
const face = new Face(values);
face
.setName("testname")
.then((response) => {
assert.equal(response.Name, "testname");
done();
})
.catch((error) => {
done(error);
});
face
.setName("")
.then((response) => {
assert.equal(response.Name, "Jane");
done();
})
.catch((error) => {
done(error);
});
});
it("should return batch size", () => {
assert.equal(Face.batchSize(), BatchSize);
Face.setBatchSize(30);
assert.equal(Face.batchSize(), 30);
Face.setBatchSize(BatchSize);
});
it("should get collection resource", () => {
const result = Face.getCollectionResource();
assert.equal(result, "faces");
});
it("should get model name", () => {
const result = Face.getModelName();
assert.equal(result, "Face");
});
});

View File

@@ -1,461 +0,0 @@
import "../fixtures";
import File from "model/file";
let chai = require("chai/chai");
let assert = chai.assert;
describe("model/file", () => {
it("should return classes", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Name: "1/2/IMG123.jpg",
Primary: true,
Sidecar: true,
Video: true,
};
const file = new File(values);
const result = file.classes(true);
assert.include(result, "is-file");
assert.include(result, "uid-ABC123");
assert.include(result, "is-primary");
assert.include(result, "is-sidecar");
assert.include(result, "is-video");
assert.include(result, "is-selected");
});
it("should get file defaults", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
};
const file = new File(values);
const result = file.getDefaults();
assert.equal(result.UID, "");
assert.equal(result.Size, 0);
});
it("should get file base name", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Name: "1/2/IMG123.jpg",
};
const file = new File(values);
const result = file.baseName();
assert.equal(result, "IMG123.jpg");
const result2 = file.baseName(8);
assert.equal(result2, "IMG123.…");
});
it("should return true", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Name: "1/2/IMG123.jpg",
};
const file = new File(values);
assert.equal(file.isFile(), true);
});
it("should return entity name", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Root: "",
Name: "1/2/IMG123.jpg",
};
const file = new File(values);
assert.equal(file.getEntityName(), "/1/2/IMG123.jpg");
});
it("should return thumbnail url", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Name: "1/2/IMG123.jpg",
};
const file = new File(values);
assert.equal(file.thumbnailUrl("tile_224"), "/api/v1/t/54ghtfd/public/tile_224");
const values2 = {
InstanceID: 5,
UID: "ABC123",
Name: "1/2/IMG123.jpg",
Error: true,
};
const file2 = new File(values2);
assert.equal(file2.thumbnailUrl("tile_224"), "/api/v1/svg/broken");
const values3 = {
InstanceID: 5,
UID: "ABC123",
Hash: "bd66bd2c304f45f6c160df375f34b49eb7aef321",
Name: "1/2/IMG123.jpg",
FileType: "raw",
};
const file3 = new File(values3);
assert.equal(file3.thumbnailUrl("tile_224"), "/api/v1/t/bd66bd2c304f45f6c160df375f34b49eb7aef321/public/tile_224");
const values4 = {
InstanceID: 5,
UID: "ABC123",
Hash: "0e437256ec20da874318b64027750b320548378c",
FileType: "jpg",
Name: "1/2/IMG123.jpg",
Sidecar: true,
};
const file4 = new File(values4);
assert.equal(file4.thumbnailUrl("tile_224"), "/api/v1/svg/file");
});
it("should return download url", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Name: "1/2/IMG123.jpg",
};
const file = new File(values);
assert.equal(file.getDownloadUrl("abc"), "/api/v1/dl/54ghtfd?t=2lbh9x09");
});
it("should not download as hash is missing", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
FileType: "jpg",
Name: "1/2/IMG123.jpg",
};
const file = new File(values);
assert.equal(file.download(), undefined);
});
it("should calculate size", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Width: 500,
Height: 700,
Name: "1/2/IMG123.jpg",
};
const file = new File(values);
assert.equal(file.calculateSize(600, 800).width, 500);
assert.equal(file.calculateSize(600, 800).height, 700);
const values2 = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Width: 900,
Height: 850,
Name: "1/2/IMG123.jpg",
};
const file2 = new File(values2);
assert.equal(file2.calculateSize(600, 800).width, 600);
assert.equal(file2.calculateSize(600, 800).height, 567);
const values3 = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Width: 750,
Height: 850,
Name: "1/2/IMG123.jpg",
};
const file3 = new File(values3);
assert.equal(file3.calculateSize(900, 450).width, 398);
assert.equal(file3.calculateSize(900, 450).height, 450);
});
it("should get date string", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Name: "1/2/IMG123.jpg",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file = new File(values);
assert.equal(file.getDateString().replaceAll("\u202f", " "), "Jul 8, 2012, 2:45 PM");
});
it("should get info", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Name: "1/2/IMG123.jpg",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file = new File(values);
assert.equal(file.getInfo(), "JPG");
const values2 = {
InstanceID: 6,
UID: "ABC124",
Hash: "54ghtfd",
FileType: "mp4",
Duration: 8009,
FPS: 60,
Name: "1/2/IMG123.mp4",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file2 = new File(values2);
assert.equal(file2.getInfo(), "MP4, 8µs, 60.0 FPS");
});
it("should return storage location", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Name: "1/2/IMG123.jpg",
Root: "sidecar",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file = new File(values);
assert.equal(file.storageInfo(), "Sidecar");
const values2 = {
InstanceID: 6,
UID: "ABC124",
Hash: "54ghtfd",
FileType: "mp4",
Duration: 8009,
FPS: 60,
Root: "/",
Name: "1/2/IMG123.mp4",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file2 = new File(values2);
assert.equal(file2.storageInfo(), "Originals");
const values3 = {
InstanceID: 6,
UID: "ABC124",
Hash: "54ghtfd",
FileType: "mp4",
Duration: 8009,
FPS: 60,
Root: "",
Name: "1/2/IMG123.mp4",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file3 = new File(values3);
assert.equal(file3.storageInfo(), "");
});
it("should return whether file is animated", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
MediaType: "image",
Duration: 500,
};
const file = new File(values);
assert.equal(file.isAnimated(), true);
});
it("should get type info", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Primary: true,
Name: "1/2/IMG123.jpg",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file = new File(values);
assert.equal(file.typeInfo(), "Image");
const values2 = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "mp4",
Duration: 8009,
FPS: 60,
Name: "1/2/IMG123.mp4",
Video: true,
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file2 = new File(values2);
assert.equal(file2.typeInfo(), "Video");
const values3 = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Name: "1/2/IMG123.jpg",
Sidecar: true,
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file3 = new File(values3);
assert.equal(file3.typeInfo(), "Sidecar JPEG");
const values4 = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "gif",
MediaType: "image",
Duration: 8009,
Name: "1/2/IMG123.jpg",
Sidecar: true,
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file4 = new File(values4);
assert.equal(file4.typeInfo(), "Sidecar GIF Image");
const values5 = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "svg",
MediaType: "vector",
Name: "1/2/IMG123.svg",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file5 = new File(values5);
assert.equal(file5.typeInfo(), "SVG");
});
it("should get size info", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Size: 8009,
Name: "1/2/IMG123.jpg",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file = new File(values);
assert.equal(file.sizeInfo(), "8 KB");
const values2 = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Size: 8009999987,
Name: "1/2/IMG123.jpg",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file2 = new File(values2);
assert.equal(file2.sizeInfo(), "7.5 GB");
const values3 = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Size: 8009999987,
Name: "1/2/IMG123.jpg",
Width: 500,
Height: 800,
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file3 = new File(values3);
assert.equal(file3.sizeInfo(), "500 × 800, 7.5 GB");
});
it("should like file", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Duration: 8009,
Favorite: false,
Name: "1/2/IMG123.jpg",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file = new File(values);
assert.equal(file.Favorite, false);
file.like();
assert.equal(file.Favorite, true);
});
it("should unlike file", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Duration: 8009,
Favorite: true,
Name: "1/2/IMG123.jpg",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file = new File(values);
assert.equal(file.Favorite, true);
file.unlike();
assert.equal(file.Favorite, false);
});
it("should toggle like", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Duration: 8009,
Favorite: true,
Name: "1/2/IMG123.jpg",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file = new File(values);
assert.equal(file.Favorite, true);
file.toggleLike();
assert.equal(file.Favorite, false);
file.toggleLike();
assert.equal(file.Favorite, true);
});
it("should get photo resource", () => {
const values = {
InstanceID: 5,
PhotoUID: "bgad457",
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Duration: 8009,
Favorite: true,
Name: "1/2/IMG123.jpg",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file = new File(values);
assert.equal(file.getPhotoResource(), "photos/bgad457");
});
it("should get collection resource", () => {
const result = File.getCollectionResource();
assert.equal(result, "files");
});
it("should get model name", () => {
const result = File.getModelName();
assert.equal(result, "File");
});
});

View File

@@ -1,247 +0,0 @@
import "../fixtures";
import Folder from "model/folder";
let chai = require("chai/chai");
let assert = chai.assert;
describe("model/folder", () => {
it("should return classes", () => {
const values = {
Folder: true,
Path: "2011/10-Halloween",
UID: "dqbevau2zlhxrxww",
Title: "Halloween Party",
Favorite: true,
Private: true,
Ignore: false,
Watch: false,
FileCount: 0,
};
const folder = new Folder(values);
const result = folder.classes(true);
assert.include(result, "is-folder");
assert.include(result, "uid-dqbevau2zlhxrxww");
assert.include(result, "is-favorite");
assert.include(result, "is-private");
assert.include(result, "is-selected");
});
it("should get folder defaults", () => {
const values = {
Folder: true,
Path: "2011/10-Halloween",
Root: "",
UID: "dqbevau2zlhxrxww",
Type: "",
Title: "Halloween Party",
Category: "",
Description: "",
Order: "",
Country: "",
Year: "",
Month: "",
Favorite: false,
Private: false,
Ignore: false,
Watch: false,
FileCount: 0,
CreatedAt: "",
UpdatedAt: "",
};
const model = new Folder(values);
const result = model.getDefaults();
assert.equal(result.Folder, true);
assert.equal(result.Path, "");
assert.equal(result.Favorite, false);
});
it("should get folder base name", () => {
const values = {
Folder: true,
Path: "2011/10-Halloween",
Root: "",
UID: "dqbevau2zlhxrxww",
Type: "",
Title: "Halloween Party",
Category: "",
Description: "",
Order: "",
Country: "",
Year: "",
Month: "",
Favorite: false,
Private: false,
Ignore: false,
Watch: false,
FileCount: 0,
CreatedAt: "",
UpdatedAt: "",
};
const folder = new Folder(values);
const result = folder.baseName();
assert.equal(result, "10-Halloween");
const result2 = folder.baseName(8);
assert.equal(result2, "10-Hall…");
});
it("should return false", () => {
const values = {
Folder: true,
Path: "2011/10-Halloween",
UID: "dqbevau2zlhxrxww",
Title: "Halloween Party",
};
const folder = new Folder(values);
assert.equal(folder.isFile(), false);
});
it("should return entity name", () => {
const values = {
Folder: true,
Path: "2011/10-Halloween",
Root: "",
UID: "dqbevau2zlhxrxww",
Title: "Halloween Party",
};
const folder = new Folder(values);
assert.equal(folder.getEntityName(), "/2011/10-Halloween");
});
it("should return thumbnail url", () => {
const values = {
Folder: true,
Path: "2011/10-Halloween",
Root: "",
UID: "dqbevau2zlhxrxww",
Title: "Halloween Party",
};
const folder = new Folder(values);
assert.equal(folder.thumbnailUrl("tile_224"), "/api/v1/folders/t/dqbevau2zlhxrxww/public/tile_224");
});
it("should get date string", () => {
const values = {
Folder: true,
Path: "2011/10-Halloween",
Root: "",
UID: "dqbevau2zlhxrxww",
Title: "Halloween Party",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const folder = new Folder(values);
assert.equal(folder.getDateString().replaceAll("\u202f", " "), "Jul 8, 2012, 2:45 PM");
});
it("should toggle like", () => {
const values = {
Folder: true,
Path: "2011/10-Halloween",
Root: "",
UID: "dqbevau2zlhxrxww",
Title: "Halloween Party",
Favorite: true,
Private: true,
};
const folder = new Folder(values);
assert.equal(folder.Favorite, true);
folder.toggleLike();
assert.equal(folder.Favorite, false);
folder.toggleLike();
assert.equal(folder.Favorite, true);
});
it("should like folder", () => {
const values = {
Folder: true,
Path: "2011/10-Halloween",
Root: "",
UID: "dqbevau2zlhxrxww",
Title: "Halloween Party",
Favorite: false,
Private: true,
};
const folder = new Folder(values);
assert.equal(folder.Favorite, false);
folder.like();
assert.equal(folder.Favorite, true);
});
it("should unlike folder", () => {
const values = {
Folder: true,
Path: "2011/10-Halloween",
Root: "",
UID: "dqbevau2zlhxrxww",
Title: "Halloween Party",
Favorite: true,
Private: true,
};
const folder = new Folder(values);
assert.equal(folder.Favorite, true);
folder.unlike();
assert.equal(folder.Favorite, false);
});
it("should get collection resource", () => {
const result = Folder.getCollectionResource();
assert.equal(result, "folders");
});
it("should get model name", () => {
const result = Folder.getModelName();
assert.equal(result, "Folder");
});
it("should test find all", (done) => {
Folder.findAll("2011/10-Halloween")
.then((response) => {
assert.equal(response.status, 200);
assert.equal(response.count, 4);
assert.equal(response.folders, 3);
done();
})
.catch((error) => {
done(error);
});
});
it("should test find all uncached", (done) => {
Folder.findAllUncached("2011/10-Halloween")
.then((response) => {
assert.equal(response.status, 200);
assert.equal(response.count, 3);
assert.equal(response.folders, 2);
done();
})
.catch((error) => {
done(error);
});
});
it("should test find in originals", (done) => {
Folder.originals("2011/10-Halloween", { recursive: true })
.then((response) => {
assert.equal(response.status, 200);
assert.equal(response.count, 4);
assert.equal(response.folders, 3);
done();
})
.catch((error) => {
done(error);
});
});
it("should test search", (done) => {
Folder.search("2011/10-Halloween", { recursive: true, uncached: true })
.then((response) => {
assert.equal(response.status, 200);
assert.equal(response.count, 3);
assert.equal(response.folders, 2);
done();
})
.catch((error) => {
done(error);
});
});
});

View File

@@ -1,141 +0,0 @@
import "../fixtures";
import { Label, BatchSize } from "model/label";
let chai = require("chai/chai");
let assert = chai.assert;
describe("model/label", () => {
it("should get route view", () => {
const values = { ID: 5, UID: "ABC123", Name: "Black Cat", Slug: "black-cat" };
const label = new Label(values);
const result = label.route("test");
assert.equal(result.name, "test");
assert.equal(result.query.q, "label:black-cat");
});
it("should return batch size", () => {
assert.equal(Label.batchSize(), BatchSize);
Label.setBatchSize(30);
assert.equal(Label.batchSize(), 30);
Label.setBatchSize(BatchSize);
});
it("should return classes", () => {
const values = { ID: 5, UID: "ABC123", Name: "Black Cat", Slug: "black-cat", Favorite: true };
const label = new Label(values);
const result = label.classes(true);
assert.include(result, "is-label");
assert.include(result, "uid-ABC123");
assert.include(result, "is-selected");
assert.include(result, "is-favorite");
});
it("should get label entity name", () => {
const values = { ID: 5, UID: "ABC123", Name: "Black Cat", Slug: "black-cat" };
const label = new Label(values);
const result = label.getEntityName();
assert.equal(result, "black-cat");
});
it("should get label id", () => {
const values = { ID: 5, UID: "ABC123", Name: "Black Cat", Slug: "black-cat" };
const label = new Label(values);
const result = label.getId();
assert.equal(result, "ABC123");
});
it("should get label title", () => {
const values = { ID: 5, UID: "ABC123", Name: "Black Cat", Slug: "black-cat" };
const label = new Label(values);
const result = label.getTitle();
assert.equal(result, "Black Cat");
});
it("should get thumbnail url", () => {
const values = {
ID: 5,
UID: "ABC123",
Thumb: "c6b24d688564f7ddc7b245a414f003a8d8ff5a67",
Name: "Black Cat",
Slug: "black-cat",
};
const label = new Label(values);
const result = label.thumbnailUrl("xyz");
assert.equal(result, "/api/v1/t/c6b24d688564f7ddc7b245a414f003a8d8ff5a67/public/xyz");
const values2 = {
ID: 5,
UID: "ABC123",
Name: "Black Cat",
Slug: "black-cat",
};
const label2 = new Label(values2);
const result2 = label2.thumbnailUrl("xyz");
assert.equal(result2, "/api/v1/labels/ABC123/t/public/xyz");
const values3 = {
ID: 5,
Name: "Black Cat",
Slug: "black-cat",
};
const label3 = new Label(values3);
const result3 = label3.thumbnailUrl("xyz");
assert.equal(result3, "/api/v1/svg/label");
});
it("should get date string", () => {
const values = {
ID: 5,
UID: "ABC123",
Name: "Black Cat",
Slug: "black-cat",
CreatedAt: "2012-07-08T14:45:39Z",
};
const label = new Label(values);
const result = label.getDateString();
assert.equal(result.replaceAll("\u202f", " "), "Jul 8, 2012, 2:45 PM");
});
it("should get model name", () => {
const result = Label.getModelName();
assert.equal(result, "Label");
});
it("should get collection resource", () => {
const result = Label.getCollectionResource();
assert.equal(result, "labels");
});
it("should like label", () => {
const values = { ID: 5, UID: "ABC123", Name: "Black Cat", Slug: "black-cat", Favorite: false };
const label = new Label(values);
assert.equal(label.Favorite, false);
label.like();
assert.equal(label.Favorite, true);
});
it("should unlike label", () => {
const values = { ID: 5, UID: "ABC123", Name: "Black Cat", Slug: "black-cat", Favorite: true };
const label = new Label(values);
assert.equal(label.Favorite, true);
label.unlike();
assert.equal(label.Favorite, false);
});
it("should toggle like", () => {
const values = { ID: 5, UID: "ABC123", Name: "Black Cat", Slug: "black-cat", Favorite: true };
const label = new Label(values);
assert.equal(label.Favorite, true);
label.toggleLike();
assert.equal(label.Favorite, false);
label.toggleLike();
assert.equal(label.Favorite, true);
});
it("should get label defaults", () => {
const values = { ID: 5, UID: "ABC123" };
const label = new Label(values);
const result = label.getDefaults();
assert.equal(result.ID, 0);
});
});

View File

@@ -1,103 +0,0 @@
import "../fixtures";
import Link from "model/link";
let chai = require("chai/chai");
let assert = chai.assert;
describe("model/link", () => {
it("should get link defaults", () => {
const values = { UID: 5 };
const link = new Link(values);
const result = link.getDefaults();
assert.equal(result.UID, 0);
assert.equal(result.Perm, 0);
assert.equal(result.Comment, "");
assert.equal(result.ShareUID, "");
});
it("should get link url", () => {
const values = { UID: 5, Token: "1234hhtbbt", Slug: "friends", ShareUID: "family" };
const link = new Link(values);
const result = link.url();
assert.equal(result, "http://localhost:2342/s/1234hhtbbt/friends");
const values2 = { UID: 5, Token: "", ShareUID: "family" };
const link2 = new Link(values2);
const result2 = link2.url();
assert.equal(result2, "http://localhost:2342/s/…/family");
});
it("should get link caption", () => {
const values = { UID: 5, Token: "AcfgbTTh", Slug: "friends", ShareUID: "family" };
const link = new Link(values);
const result = link.caption();
assert.equal(result, "/s/acfgbtth");
});
it("should get link id", () => {
const values = { UID: 5 };
const link = new Link(values);
const result = link.getId();
assert.equal(result, 5);
const values2 = {};
const link2 = new Link(values2);
const result2 = link2.getId();
assert.equal(result2, false);
});
it("should test has id", () => {
const values = { UID: 5 };
const link = new Link(values);
const result = link.hasId();
assert.equal(result, true);
});
it("should get link slug", () => {
const values = { UID: 5, Token: "AcfgbTTh", Slug: "friends", ShareUID: "family" };
const link = new Link(values);
const result = link.getSlug();
assert.equal(result, "friends");
});
it("should test has slug", () => {
const values = { UID: 5, Token: "AcfgbTTh", Slug: "friends", ShareUID: "family" };
const link = new Link(values);
const result = link.hasSlug();
assert.equal(result, true);
const values2 = { UID: 5, Token: "AcfgbTTh", ShareUID: "family" };
const link2 = new Link(values2);
const result2 = link2.hasSlug();
assert.equal(result2, false);
});
it("should clone link", () => {
const values = { UID: 5, Token: "AcfgbTTh", Slug: "friends", ShareUID: "family" };
const link = new Link(values);
const result = link.clone();
assert.equal(result.Slug, "friends");
assert.equal(result.Token, "AcfgbTTh");
});
it("should test expire", () => {
const values = {
UID: 5,
Token: "AcfgbTTh",
Slug: "friends",
ShareUID: "family",
Expires: 80000,
ModifiedAt: "2012-07-08T14:45:39Z",
};
const link = new Link(values);
const result = link.expires();
assert.equal(result, "Jul 9, 2012");
});
it("should get collection resource", () => {
const result = Link.getCollectionResource();
assert.equal(result, "links");
});
it("should get model name", () => {
const result = Link.getModelName();
assert.equal(result, "Link");
});
});

View File

@@ -1,221 +0,0 @@
import "../fixtures";
import { Marker, BatchSize } from "model/marker";
let chai = require("chai/chai");
let assert = chai.assert;
describe("model/marker", () => {
it("should get marker defaults", () => {
const values = { FileUID: "fghjojp" };
const marker = new Marker(values);
const result = marker.getDefaults();
assert.equal(result.UID, "");
assert.equal(result.FileUID, "");
});
it("should get route view", () => {
const values = { UID: "ABC123ghytr", FileUID: "fhjouohnnmnd", Type: "face", Src: "image" };
const marker = new Marker(values);
const result = marker.route("test");
assert.equal(result.name, "test");
assert.equal(result.query.q, "marker:ABC123ghytr");
});
it("should return classes", () => {
const values = { UID: "ABC123ghytr", FileUID: "fhjouohnnmnd", Type: "face", Src: "image" };
const marker = new Marker(values);
const result = marker.classes(true);
assert.include(result, "is-marker");
assert.include(result, "uid-ABC123ghytr");
assert.include(result, "is-selected");
assert.notInclude(result, "is-review");
assert.notInclude(result, "is-invalid");
const result2 = marker.classes(false);
assert.include(result2, "is-marker");
assert.include(result2, "uid-ABC123ghytr");
assert.notInclude(result2, "is-selected");
assert.notInclude(result2, "is-review");
assert.notInclude(result2, "is-invalid");
const values2 = {
UID: "mBC123ghytr",
FileUID: "fhjouohnnmnd",
Type: "face",
Src: "image",
Invalid: true,
Review: true,
};
const marker2 = new Marker(values2);
const result3 = marker2.classes(true);
assert.include(result3, "is-marker");
assert.include(result3, "uid-mBC123ghytr");
assert.include(result3, "is-selected");
assert.include(result3, "is-review");
assert.include(result3, "is-invalid");
});
it("should get marker entity name", () => {
const values = {
UID: "ABC123ghytr",
FileUID: "fhjouohnnmnd",
Type: "face",
Src: "image",
Name: "test",
};
const marker = new Marker(values);
const result = marker.getEntityName();
assert.equal(result, "test");
});
it("should get marker title", () => {
const values = {
UID: "ABC123ghytr",
FileUID: "fhjouohnnmnd",
Type: "face",
Src: "image",
Name: "test",
};
const marker = new Marker(values);
const result = marker.getTitle();
assert.equal(result, "test");
});
it("should get thumbnail url", () => {
const values = { UID: "ABC123ghytr", FileUID: "fhjouohnnmnd", Type: "face", Src: "image" };
const marker = new Marker(values);
const result = marker.thumbnailUrl("xyz");
assert.equal(result, "/api/v1/svg/portrait");
const values2 = {
UID: "ABC123ghytr",
FileUID: "fhjouohnnmnd",
Type: "face",
Src: "image",
Thumb: "nicethumbuid",
};
const marker2 = new Marker(values2);
const result2 = marker2.thumbnailUrl();
assert.equal(result2, "/api/v1/t/nicethumbuid/public/tile_160");
});
it("should get date string", () => {
const values = {
UID: "ABC123ghytr",
FileUID: "fhjouohnnmnd",
Type: "face",
Src: "image",
CreatedAt: "2012-07-08T14:45:39Z",
};
const marker = new Marker(values);
const result = marker.getDateString();
assert.equal(result.replaceAll("\u202f", " "), "Jul 8, 2012, 2:45 PM");
});
it("should approve marker", () => {
const values = {
UID: "mBC123ghytr",
FileUID: "fhjouohnnmnd",
Type: "face",
Src: "image",
Invalid: true,
Review: true,
};
const marker = new Marker(values);
assert.equal(marker.Review, true);
assert.equal(marker.Invalid, true);
marker.approve();
assert.equal(marker.Review, false);
assert.equal(marker.Invalid, false);
});
it("should reject marker", () => {
const values = {
UID: "mCC123ghytr",
FileUID: "fhjouohnnmnd",
Type: "face",
Src: "image",
Invalid: false,
Review: true,
};
const marker = new Marker(values);
assert.equal(marker.Review, true);
assert.equal(marker.Invalid, false);
marker.reject();
assert.equal(marker.Review, false);
assert.equal(marker.Invalid, true);
});
it("should rename marker", (done) => {
const values = {
UID: "mDC123ghytr",
FileUID: "fhjouohnnmnd",
Type: "face",
Src: "image",
Subject: "skhljkpigh",
Name: "",
SubjSrc: "manual",
};
const marker = new Marker(values);
assert.equal(marker.Name, "");
marker.setName();
assert.equal(marker.Name, "");
const values2 = {
UID: "mDC123ghytr",
FileUID: "fhjouohnnmnd",
Type: "face",
Src: "image",
Subject: "skhljkpigh",
Name: "testname",
SubjSrc: "manual",
};
const marker2 = new Marker(values2);
assert.equal(marker2.Name, "testname");
marker2
.setName()
.then((response) => {
assert.equal(response.success, "ok");
done();
})
.catch((error) => {
done(error);
});
});
it("should clear subject", (done) => {
const values = {
UID: "mEC123ghytr",
FileUID: "fhjouohnnmnd",
Type: "face",
Src: "image",
Subject: "skhljkpigh",
Name: "testname",
SubjSrc: "manual",
};
const marker = new Marker(values);
marker
.clearSubject()
.then((response) => {
assert.equal(response.success, "ok");
done();
})
.catch((error) => {
done(error);
});
});
it("should return batch size", () => {
assert.equal(Marker.batchSize(), BatchSize);
Marker.setBatchSize(30);
assert.equal(Marker.batchSize(), 30);
Marker.setBatchSize(BatchSize);
});
it("should get collection resource", () => {
const result = Marker.getCollectionResource();
assert.equal(result, "markers");
});
it("should get model name", () => {
const result = Marker.getModelName();
assert.equal(result, "Marker");
});
});

File diff suppressed because it is too large Load Diff

View File

@@ -1,238 +0,0 @@
import "../fixtures";
import Rest from "model/rest";
import Album from "model/album";
import Label from "model/label";
import Link from "model/link";
let chai = require("chai/chai");
let assert = chai.assert;
describe("model/abstract", () => {
it("should set values", () => {
const values = { ID: 5, Name: "Black Cat", Slug: "black-cat" };
const label = new Label(values);
assert.equal(label.Name, "Black Cat");
assert.equal(label.Slug, "black-cat");
label.setValues();
assert.equal(label.Name, "Black Cat");
assert.equal(label.Slug, "black-cat");
const values2 = { ID: 6, Name: "White Cat", Slug: "white-cat" };
label.setValues(values2);
assert.equal(label.Name, "White Cat");
assert.equal(label.Slug, "white-cat");
});
it("should get values", () => {
const values = { ID: 5, Name: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values);
const result = album.getValues();
assert.equal(result.Name, "Christmas 2019");
assert.equal(result.UID, 66);
});
it("should get id", () => {
const values = { ID: 5, Name: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values);
const result = album.getId();
assert.equal(result, 66);
});
it("should test if id exists", () => {
const values = { ID: 5, Name: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values);
const result = album.hasId();
assert.equal(result, true);
});
it("should get model name", () => {
const result = Rest.getModelName();
assert.equal(result, "Item");
});
it("should update album", async () => {
const values = { ID: 5, Name: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values);
assert.equal(album.Description, undefined);
album.Name = "Christmas 2020";
await album.update();
assert.equal(album.Description, "Test description");
});
it("should save album", async () => {
const values = { UID: "abc", Name: "Christmas 2019", Slug: "christmas-2019" };
const album = new Album(values);
album.Name = "Christmas 2020";
assert.equal(album.Description, undefined);
await album.save();
assert.equal(album.Description, "Test description");
const values2 = { Name: "Christmas 2019", Slug: "christmas-2019" };
const album2 = new Album(values2);
album.Name = "Christmas 2020";
assert.equal(album2.Description, undefined);
await album2.save().then((response) => {
assert.equal(response.success, "ok");
});
assert.equal(album2.Description, undefined);
});
it("should remove album", async () => {
const values = { UID: "abc", Name: "Christmas 2019", Slug: "christmas-2019" };
const album = new Album(values);
assert.equal(album.Name, "Christmas 2019");
await album.remove();
});
it("should get edit form", async () => {
const values = { UID: "abc", Name: "Christmas 2019", Slug: "christmas-2019" };
const album = new Album(values);
const result = await album.getEditForm();
assert.equal(result.definition.foo, "edit");
});
it("should get create form", async () => {
const result = await Album.getCreateForm();
assert.equal(result.definition.foo, "bar");
});
it("should get search form", async () => {
const result = await Album.getSearchForm();
assert.equal(result.definition.foo, "bar");
});
it("should search label", async () => {
const result = await Album.search();
assert.equal(result.data.ID, 51);
assert.equal(result.data.Name, "tabby cat");
});
it("should get collection resource", () => {
assert.equal(Rest.getCollectionResource(), "");
});
it("should get slug", () => {
const values = { ID: 5, Name: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values);
const result = album.getSlug();
assert.equal(result, "christmas-2019");
});
it("should get slug", () => {
const values = { ID: 5, Name: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values);
const result = album.clone();
assert.equal(result.Slug, "christmas-2019");
assert.equal(result.Name, "Christmas 2019");
assert.equal(result.ID, 5);
});
it("should find album", async () => {
const values = { Name: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values);
return album
.find(5)
.then((response) => {
assert.equal(response.UID, "5");
return Promise.resolve();
})
.catch((error) => {
return Promise.reject(error);
});
});
it("should get entity name", () => {
const values = { ID: 5, Name: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values);
const result = album.getEntityName();
assert.equal(result, "christmas-2019");
});
it("should return model name", () => {
const values = { ID: 5, Name: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values);
const result = album.modelName();
assert.equal(result, "Album");
});
it("should return limit", () => {
const values = { ID: 5, Name: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values);
const result = Rest.limit();
assert.equal(result, 100000);
assert.equal(album.constructor.limit(), 100000);
});
it("should create link", async () => {
const values = { ID: 5, Name: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values);
album
.createLink("passwd", 8000)
.then((response) => {
assert.equal(response.Slug, "christmas-2019");
return Promise.resolve();
})
.catch((error) => {
return Promise.reject(error);
});
});
it("should update link", async () => {
const values = {
UID: 5,
Password: "passwd",
Slug: "friends",
Expires: 80000,
UpdatedAt: "2012-07-08T14:45:39Z",
Token: "abchhgftryue2345",
};
const link = new Link(values);
const values2 = { ID: 5, Name: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values2);
return album
.updateLink(link)
.then((response) => {
assert.equal(response.Slug, "friends");
return Promise.resolve();
})
.catch((error) => {
return Promise.reject(error);
});
});
it("should remove link", async () => {
const values = {
UID: 5,
Password: "passwd",
Slug: "friends",
Expires: 80000,
UpdatedAt: "2012-07-08T14:45:39Z",
};
const link = new Link(values);
const values2 = { ID: 5, Name: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values2);
return album
.removeLink(link)
.then((response) => {
assert.equal(response.Success, "ok");
return Promise.resolve();
})
.catch((error) => {
return Promise.reject(error);
});
});
it("should return links", async () => {
const values2 = { ID: 5, Name: "Christmas 2019", Slug: "christmas-2019", UID: 66 };
const album = new Album(values2);
return album
.links()
.then((response) => {
assert.equal(response.count, 2);
assert.equal(response.models.length, 2);
return Promise.resolve();
})
.catch((error) => {
return Promise.reject(error);
});
});
});

View File

@@ -1,75 +0,0 @@
import "../fixtures";
import Service from "model/service";
import Photo from "model/photo";
let chai = require("chai/chai");
let assert = chai.assert;
describe("model/service", () => {
it("should get service defaults", () => {
const values = { ID: 5 };
const service = new Service(values);
const result = service.getDefaults();
assert.equal(result.ID, 0);
assert.equal(result.AccShare, true);
assert.equal(result.AccName, "");
});
it("should get service entity name", () => {
const values = { ID: 5, AccName: "Test Name" };
const service = new Service(values);
const result = service.getEntityName();
assert.equal(result, "Test Name");
});
it("should get service id", () => {
const values = { ID: 5, AccName: "Test Name" };
const service = new Service(values);
const result = service.getId();
assert.equal(result, 5);
});
it("should get folders", (done) => {
const values = { ID: 123, AccName: "Test Name" };
const service = new Service(values);
service
.Folders()
.then((response) => {
assert.equal(response.foo, "folders");
done();
})
.catch((error) => {
done(error);
});
});
it("should get share photos", (done) => {
const values = { ID: 123, AccName: "Test Name" };
const service = new Service(values);
const values1 = { ID: 5, Title: "Crazy Cat", UID: 789 };
const photo = new Photo(values1);
const values2 = { ID: 6, Title: "Crazy Cat 2", UID: 783 };
const photo2 = new Photo(values2);
const Photos = [photo, photo2];
service
.Upload(Photos, "destination")
.then((response) => {
assert.equal(response.foo, "upload");
done();
})
.catch((error) => {
done(error);
});
});
it("should get collection resource", () => {
const result = Service.getCollectionResource();
assert.equal(result, "services");
});
it("should get model name", () => {
const result = Service.getModelName();
assert.equal(result, "Account");
});
});

View File

@@ -1,41 +0,0 @@
import "../fixtures";
import Settings from "model/settings";
let chai = require("chai/chai");
let assert = chai.assert;
describe("model/settings", () => {
it("should return if key was changed", () => {
const model = new Settings({ ui: { language: "de", scrollbar: false } });
assert.equal(model.changed("ui", "scrollbar"), false);
assert.equal(model.changed("ui", "language"), false);
});
it("should load settings", (done) => {
const model = new Settings({ ui: { language: "de", scrollbar: false } });
model
.load()
.then((response) => {
assert.equal(response["ui"]["scrollbar"], false);
assert.equal(response["ui"]["language"], "de");
done();
})
.catch((error) => {
done(error);
});
});
it("should save settings", (done) => {
const model = new Settings({ ui: { language: "de", scrollbar: false } });
model
.save()
.then((response) => {
assert.equal(response["ui"]["scrollbar"], false);
assert.equal(response["ui"]["language"], "de");
done();
})
.catch((error) => {
done(error);
});
});
});

View File

@@ -1,255 +0,0 @@
import "../fixtures";
import { Subject, BatchSize } from "model/subject";
let chai = require("chai/chai");
let assert = chai.assert;
describe("model/subject", () => {
it("should get face defaults", () => {
const values = {};
const subject = new Subject(values);
const result = subject.getDefaults();
assert.equal(result.UID, "");
assert.equal(result.Favorite, false);
});
it("should get route view", () => {
const values = { UID: "s123ghytrfggd", Type: "person", Src: "manual" };
const subject = new Subject(values);
const result = subject.route("test");
assert.equal(result.name, "test");
assert.equal(result.query.q, "subject:s123ghytrfggd");
const values2 = {
UID: "s123ghytrfggd",
Type: "person",
Src: "manual",
Name: "Jane Doe",
Slug: "jane-doe",
};
const subject2 = new Subject(values2);
const result2 = subject2.route("test");
assert.equal(result2.name, "test");
assert.equal(result2.query.q, "person:jane-doe");
});
it("should return classes", () => {
const values = {
UID: "s123ghytrfggd",
Type: "person",
Src: "manual",
Name: "Jane Doe",
Slug: "jane-doe",
Favorite: false,
Excluded: true,
Private: true,
Hidden: true,
};
const subject = new Subject(values);
const result = subject.classes(true);
assert.include(result, "is-subject");
assert.include(result, "uid-s123ghytrfggd");
assert.include(result, "is-selected");
assert.notInclude(result, "is-favorite");
assert.include(result, "is-private");
assert.include(result, "is-excluded");
assert.include(result, "is-hidden");
const values2 = {
UID: "s123ghytrfggd",
Type: "person",
Src: "manual",
Name: "Jane Doe",
Slug: "jane-doe",
Favorite: true,
Excluded: false,
Private: false,
};
const subject2 = new Subject(values2);
const result2 = subject2.classes(false);
assert.include(result2, "is-subject");
assert.include(result2, "uid-s123ghytrfggd");
assert.notInclude(result2, "is-selected");
assert.include(result2, "is-favorite");
assert.notInclude(result2, "is-private");
assert.notInclude(result2, "is-excluded");
});
it("should get subject entity name", () => {
const values = {
UID: "s123ghytrfggd",
Type: "person",
Src: "manual",
Name: "Jane Doe",
Slug: "jane-doe",
Favorite: false,
Excluded: true,
Private: true,
};
const subject = new Subject(values);
const result = subject.getEntityName();
assert.equal(result, "jane-doe");
});
it("should get subject title", () => {
const values = {
UID: "s123ghytrfggd",
Type: "person",
Src: "manual",
Name: "Jane Doe",
Slug: "jane-doe",
Favorite: false,
Excluded: true,
Private: true,
};
const subject = new Subject(values);
const result = subject.getTitle();
assert.equal(result, "Jane Doe");
});
it("should get thumbnail url", () => {
const values = {
UID: "s123ghytrfggd",
Type: "person",
Src: "manual",
Name: "Jane Doe",
Slug: "jane-doe",
Favorite: false,
Excluded: true,
Private: true,
Thumb: "nicethumb",
};
const subject = new Subject(values);
const result = subject.thumbnailUrl("xyz");
assert.equal(result, "/api/v1/t/nicethumb/public/xyz");
const result2 = subject.thumbnailUrl();
assert.equal(result2, "/api/v1/t/nicethumb/public/tile_160");
const values2 = {
UID: "s123ghytrfggd",
Type: "person",
Src: "manual",
Name: "Jane Doe",
Slug: "jane-doe",
Favorite: false,
Excluded: true,
Private: true,
};
const subject2 = new Subject(values2);
const result3 = subject2.thumbnailUrl("xyz");
assert.equal(result3, "/api/v1/svg/portrait");
});
it("should get date string", () => {
const values = {
UID: "s123ghytrfggd",
Type: "person",
Src: "manual",
Name: "Jane Doe",
Slug: "jane-doe",
Favorite: false,
Excluded: true,
Private: true,
Thumb: "nicethumb",
CreatedAt: "2012-07-08T14:45:39Z",
};
const subject = new Subject(values);
const result = subject.getDateString();
assert.equal(result.replaceAll("\u202f", " "), "Jul 8, 2012, 2:45 PM");
});
it("should like subject", () => {
const values = {
UID: "s123ghytrfggd",
Type: "person",
Src: "manual",
Name: "Jane Doe",
Slug: "jane-doe",
Favorite: false,
};
const subject = new Subject(values);
assert.equal(subject.Favorite, false);
subject.like();
assert.equal(subject.Favorite, true);
});
it("should unlike subject", () => {
const values = {
UID: "s123ghytrfggd",
Type: "person",
Src: "manual",
Name: "Jane Doe",
Slug: "jane-doe",
Favorite: true,
};
const subject = new Subject(values);
assert.equal(subject.Favorite, true);
subject.unlike();
assert.equal(subject.Favorite, false);
});
it("should toggle like", () => {
const values = {
UID: "s123ghytrfggd",
Type: "person",
Src: "manual",
Name: "Jane Doe",
Slug: "jane-doe",
Favorite: true,
};
const subject = new Subject(values);
assert.equal(subject.Favorite, true);
subject.toggleLike();
assert.equal(subject.Favorite, false);
subject.toggleLike();
assert.equal(subject.Favorite, true);
});
it("show and hide subject", () => {
const values = {
UID: "s123ghytrfggd",
Type: "person",
Src: "manual",
Name: "Jane Doe",
Slug: "jane-doe",
Hidden: true,
};
const subject = new Subject(values);
assert.equal(subject.Hidden, true);
subject.show();
assert.equal(subject.Hidden, false);
subject.hide();
assert.equal(subject.Hidden, true);
});
it("should toggle hidden", () => {
const values = {
UID: "s123ghytrfggd",
Type: "person",
Src: "manual",
Name: "Jane Doe",
Slug: "jane-doe",
Hidden: true,
};
const subject = new Subject(values);
assert.equal(subject.Hidden, true);
subject.toggleHidden();
assert.equal(subject.Hidden, false);
subject.toggleHidden();
assert.equal(subject.Hidden, true);
});
it("should return batch size", () => {
assert.equal(Subject.batchSize(), BatchSize);
Subject.setBatchSize(30);
assert.equal(Subject.batchSize(), 30);
Subject.setBatchSize(BatchSize);
});
it("should get collection resource", () => {
const result = Subject.getCollectionResource();
assert.equal(result, "subjects");
});
it("should get model name", () => {
const result = Subject.getModelName();
assert.equal(result, "Person");
});
});

View File

@@ -1,326 +0,0 @@
import "../fixtures";
import Thumb from "model/thumb";
import Photo from "model/photo";
import File from "model/file";
let chai = require("chai/chai");
let assert = chai.assert;
describe("model/thumb", () => {
it("should get thumb defaults", () => {
const values = {
UID: "55",
Title: "",
TakenAtLocal: "",
Caption: "",
Favorite: false,
Playable: false,
Width: 0,
Height: 0,
DownloadUrl: "",
};
const thumb = new Thumb(values);
const result = thumb.getDefaults();
assert.equal(result.UID, "");
});
it("should get id", () => {
const values = {
UID: "55",
};
const thumb = new Thumb(values);
assert.equal(thumb.getId(), "55");
});
it("should return hasId", () => {
const values = {
UID: "55",
};
const thumb = new Thumb(values);
assert.equal(thumb.hasId(), true);
const values2 = {
Title: "",
};
const thumb2 = new Thumb(values2);
assert.equal(thumb2.hasId(), false);
});
it("should toggle like", () => {
const values = {
UID: "55",
Title: "",
TakenAtLocal: "",
Caption: "",
Favorite: true,
Playable: false,
Width: 0,
Height: 0,
DownloadUrl: "",
};
const thumb = new Thumb(values);
assert.equal(thumb.Favorite, true);
thumb.toggleLike();
assert.equal(thumb.Favorite, false);
thumb.toggleLike();
assert.equal(thumb.Favorite, true);
});
it("should return thumb not found", () => {
const result = Thumb.notFound();
assert.equal(result.UID, "");
assert.equal(result.Favorite, false);
});
it("should test from file", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Name: "1/2/IMG123.jpg",
Hash: "abc123",
Width: 500,
Height: 900,
};
const file = new File(values);
const values2 = {
UID: "5",
Title: "Crazy Cat",
TakenAt: "2012-07-08T14:45:39Z",
TakenAtLocal: "2012-07-08T14:45:39Z",
Caption: "Nice description",
Favorite: true,
};
const photo = new Photo(values2);
const result = Thumb.fromFile(photo, file);
assert.equal(result.UID, "5");
assert.equal(result.Caption, "Nice description");
assert.equal(result.Width, 500);
const result2 = Thumb.fromFile();
assert.equal(result2.UID, "");
});
it("should test from files", () => {
const values2 = {
UID: "5",
Title: "Crazy Cat",
TakenAt: "2012-07-08T14:45:39Z",
TakenAtLocal: "2012-07-08T14:45:39Z",
Caption: "Nice description",
Favorite: true,
};
const photo = new Photo(values2);
const values3 = {
UID: "5",
Title: "Crazy Cat",
TakenAt: "2012-07-08T14:45:39Z",
TakenAtLocal: "2012-07-08T14:45:39Z",
Caption: "Nice description",
Favorite: true,
};
const photo2 = new Photo(values3);
const Photos = [photo, photo2];
const result = Thumb.fromFiles(Photos);
assert.equal(result.length, 0);
const values4 = {
ID: 8,
UID: "ABC123",
Caption: "Nice description 2",
Hash: "abc345",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: true,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt53",
},
],
};
const photo3 = new Photo(values4);
const Photos2 = [photo, photo2, photo3];
const result2 = Thumb.fromFiles(Photos2);
assert.equal(result2[0].UID, "ABC123");
assert.equal(result2[0].Caption, "Nice description 2");
assert.equal(result2[0].Width, 500);
assert.equal(result2.length, 1);
const values5 = {
ID: 8,
UID: "ABC123",
Caption: "Nice description 2",
Hash: "abc345",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: true,
FileType: "mov",
Width: 500,
Height: 600,
Hash: "1xxbgdt53",
},
],
};
const photo4 = new Photo(values5);
const Photos3 = [photo3, photo2, photo4];
const result3 = Thumb.fromFiles(Photos3);
assert.equal(result3.length, 1);
assert.equal(result3[0].UID, "ABC123");
assert.equal(result3[0].Caption, "Nice description 2");
assert.equal(result3[0].Width, 500);
});
it("should test from files", () => {
const Photos = [];
const result = Thumb.fromFiles(Photos);
assert.equal(result, "");
});
it("should test from photo", () => {
const values = {
ID: 8,
UID: "ABC123",
Caption: "Nice description 3",
Hash: "345ggh",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: true,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt53",
},
],
};
const photo = new Photo(values);
const result = Thumb.fromPhoto(photo);
assert.equal(result.UID, "ABC123");
assert.equal(result.Caption, "Nice description 3");
assert.equal(result.Width, 500);
const values3 = {
ID: 8,
UID: "ABC124",
Caption: "Nice description 3",
};
const photo3 = new Photo(values3);
const result2 = Thumb.fromPhoto(photo3);
assert.equal(result2.UID, "");
const values2 = {
ID: 8,
UID: "ABC123",
Title: "Crazy Cat",
TakenAt: "2012-07-08T14:45:39Z",
TakenAtLocal: "2012-07-08T14:45:39Z",
Caption: "Nice description",
Favorite: true,
Hash: "xdf45m",
};
const photo2 = new Photo(values2);
const result3 = Thumb.fromPhoto(photo2);
assert.equal(result3.UID, "ABC123");
assert.equal(result3.Title, "Crazy Cat");
assert.equal(result3.Caption, "Nice description");
});
it("should test from photos", () => {
const values = {
ID: 8,
UID: "ABC123",
Caption: "Nice description 3",
Hash: "345ggh",
Files: [
{
UID: "123fgb",
Name: "1980/01/superCuteKitten.jpg",
Primary: true,
FileType: "jpg",
Width: 500,
Height: 600,
Hash: "1xxbgdt53",
},
],
};
const photo = new Photo(values);
const Photos = [photo];
const result = Thumb.fromPhotos(Photos);
assert.equal(result[0].UID, "ABC123");
assert.equal(result[0].Caption, "Nice description 3");
assert.equal(result[0].Width, 500);
});
it("should return download url", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Name: "1/2/IMG123.jpg",
};
const file = new File(values);
assert.equal(Thumb.downloadUrl(file), "/api/v1/dl/54ghtfd?t=2lbh9x09");
const values2 = {
InstanceID: 5,
UID: "ABC123",
FileType: "jpg",
Name: "1/2/IMG123.jpg",
};
const file2 = new File(values2);
assert.equal(Thumb.downloadUrl(file2), "");
});
it("should return thumbnail url", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Name: "1/2/IMG123.jpg",
};
const file = new File(values);
assert.equal(Thumb.thumbnailUrl(file, "abc"), "/api/v1/t/54ghtfd/public/abc");
const values2 = {
InstanceID: 5,
UID: "ABC123",
Name: "1/2/IMG123.jpg",
};
const file2 = new File(values2);
assert.equal(Thumb.thumbnailUrl(file2, "bcd"), "/static/img/404.jpg");
});
it("should calculate size", () => {
const values = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Width: 900,
Height: 850,
Name: "1/2/IMG123.jpg",
};
const file = new File(values);
const result = Thumb.calculateSize(file, 600, 800); //max 0,75
assert.equal(result.width, 600);
assert.equal(result.height, 567);
const values3 = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
Width: 750,
Height: 850,
Name: "1/2/IMG123.jpg",
};
const file3 = new File(values3);
const result2 = Thumb.calculateSize(file3, 900, 450);
assert.equal(result2.width, 398);
assert.equal(result2.height, 450);
const result4 = Thumb.calculateSize(file3, 900, 950);
assert.equal(result4.width, 750);
assert.equal(result4.height, 850);
});
});

View File

@@ -1,325 +0,0 @@
import "../fixtures";
import User from "model/user";
import File from "model/file";
import Config from "common/config";
import StorageShim from "node-storage-shim";
const defaultConfig = new Config(new StorageShim(), window.__CONFIG__);
let chai = require("chai/chai");
let assert = chai.assert;
describe("model/user", () => {
it("should get handle", () => {
const values = {
ID: 5,
Name: "max",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
};
const user = new User(values);
const result = user.getHandle();
assert.equal(result, "max");
const values2 = {
ID: 6,
Name: "",
DisplayName: "",
Email: "test@test.com",
Role: "admin",
};
const user2 = new User(values2);
const result2 = user2.getHandle();
assert.equal(result2, "");
});
it("should get default base path", () => {
const values = {
ID: 5,
Name: "max",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
};
const user = new User(values);
const result = user.defaultBasePath();
assert.equal(result, "users/max");
const values2 = {
ID: 6,
Name: "",
DisplayName: "",
Email: "test@test.com",
Role: "admin",
};
const user2 = new User(values2);
const result2 = user2.defaultBasePath();
assert.equal(result2, "");
});
it("should get display name", () => {
const values = {
ID: 5,
Name: "max",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
};
const user = new User(values);
const result = user.getDisplayName();
assert.equal(result, "Max Last");
const values2 = {
ID: 6,
Name: "",
DisplayName: "",
Email: "test@test.com",
Role: "admin",
};
const user2 = new User(values2);
const result2 = user2.getDisplayName();
assert.equal(result2, "Unknown");
const values3 = {
ID: 7,
Name: "",
DisplayName: "",
Email: "test@test.com",
Role: "admin",
Details: {
NickName: "maxi",
GivenName: "Maximilian",
},
};
const user3 = new User(values3);
const result3 = user3.getDisplayName();
assert.equal(result3, "maxi");
const values4 = {
ID: 8,
Name: "",
DisplayName: "",
Email: "test@test.com",
Role: "admin",
Details: {
NickName: "",
GivenName: "Maximilian",
},
};
const user4 = new User(values4);
const result4 = user4.getDisplayName();
assert.equal(result4, "Maximilian");
});
it("should get account info", () => {
const values = {
ID: 5,
Name: "max",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
};
const user = new User(values);
const result = user.getAccountInfo();
assert.equal(result, "max");
const values2 = {
ID: 6,
Name: "",
DisplayName: "",
Email: "test@test.com",
Role: "admin",
};
const user2 = new User(values2);
const result2 = user2.getAccountInfo();
assert.equal(result2, "test@test.com");
const values3 = {
ID: 7,
Name: "",
DisplayName: "",
Email: "",
Role: "admin",
};
const user3 = new User(values3);
const result3 = user3.getAccountInfo();
assert.equal(result3, "Admin");
const values4 = {
ID: 8,
Name: "",
DisplayName: "",
Email: "",
Role: "",
};
const user4 = new User(values4);
const result4 = user4.getAccountInfo();
assert.equal(result4, "Account");
const values5 = {
ID: 9,
Name: "",
DisplayName: "",
Email: "",
Role: "admin",
Details: {
JobTitle: "Developer",
},
};
const user5 = new User(values5);
const result5 = user5.getAccountInfo();
assert.equal(result5, "Developer");
});
it("should get entity name", () => {
const values = {
ID: 5,
Name: "max",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
};
const user = new User(values);
const result = user.getEntityName();
assert.equal(result, "Max Last");
});
it("should get id", () => {
const values = {
ID: 5,
Name: "max",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
};
const user = new User(values);
const result = user.getId();
assert.equal(result, 5);
});
it("should get model name", () => {
const result = User.getModelName();
assert.equal(result, "User");
});
it("should get collection resource", () => {
const result = User.getCollectionResource();
assert.equal(result, "users");
});
it("should get register form", async () => {
const values = { ID: 52, Name: "max", DisplayName: "Max Last" };
const user = new User(values);
const result = await user.getRegisterForm();
assert.equal(result.definition.foo, "register");
});
it("should get avatar url", async () => {
const values = { ID: 52, Name: "max", DisplayName: "Max Last" };
const user = new User(values);
const result = await user.getAvatarURL();
assert.equal(result, "/static/img/avatar/tile_500.jpg");
const values2 = {
ID: 53,
Name: "max",
DisplayName: "Max Last",
Thumb: "91e6c374afb78b28a52d7b4fd4fd2ea861b87123",
};
const user2 = new User(values2);
const result2 = await user2.getAvatarURL("tile_500", defaultConfig);
assert.equal(result2, "/api/v1/t/91e6c374afb78b28a52d7b4fd4fd2ea861b87123/public/tile_500");
});
it("should upload avatar", async () => {
const values = { ID: 52, Name: "max", DisplayName: "Max Last" };
const user = new User(values);
const values2 = {
InstanceID: 5,
UID: "ABC123",
Hash: "54ghtfd",
FileType: "jpg",
MediaType: "image",
Name: "1/2/IMG123.jpg",
CreatedAt: "2012-07-08T14:45:39Z",
UpdatedAt: "2012-07-08T14:45:39Z",
};
const file = new File(values2);
const Files = [file];
return user
.uploadAvatar(Files)
.then((response) => {
assert.equal("abc", response.Thumb);
assert.equal("manual", response.ThumbSrc);
return Promise.resolve();
})
.catch((error) => {
return Promise.reject(error);
});
});
it("should get profile form", async () => {
const values = { ID: 53, Name: "max", DisplayName: "Max Last" };
const user = new User(values);
const result = await user.getProfileForm();
assert.equal(result.definition.foo, "profile");
});
it("should return whether user is remote", async () => {
const values = { ID: 52, Name: "max", DisplayName: "Max Last", AuthProvider: "local" };
const user = new User(values);
const result = await user.isRemote();
assert.equal(result, false);
const values2 = { ID: 51, Name: "max", DisplayName: "Max Last", AuthProvider: "ldap" };
const user2 = new User(values2);
const result2 = await user2.isRemote();
assert.equal(result2, true);
});
it("should return auth info", async () => {
const values = { ID: 50, Name: "max", DisplayName: "Max Last", AuthProvider: "oidc" };
const user = new User(values);
const result = await user.authInfo();
assert.equal(result, "OIDC");
const values2 = { ID: 52, Name: "max", DisplayName: "Max Last", AuthProvider: "oidc", AuthMethod: "session" };
const user2 = new User(values2);
const result2 = await user2.authInfo();
assert.equal(result2, "OIDC (Session)");
});
it("should get change password", async () => {
const values = {
ID: 54,
Name: "max",
DisplayName: "Max Last",
Email: "test@test.com",
Role: "admin",
};
const user = new User(values);
const result = await user.changePassword("old", "new");
assert.equal(result.new_password, "new");
});
});

View File

@@ -1,252 +0,0 @@
import "../fixtures";
import * as options from "../../../src/options/options";
import {
AccountTypes,
Colors,
DefaultLocale,
Expires,
FallbackLocale,
FeedbackCategories,
FindLanguage,
FindLocale,
Gender,
Intervals,
ItemsPerPage,
MapsAnimate,
MapsStyle,
Orientations,
PhotoTypes,
RetryLimits,
SetDefaultLocale,
StartPages,
ThumbFilters,
Thumbs,
ThumbSizes,
Timeouts,
} from "../../../src/options/options";
let chai = require("chai/chai");
let assert = chai.assert;
describe("options/options", () => {
it("should get timezones", () => {
const timezones = options.TimeZones();
assert.equal(timezones[0].ID, "Local");
assert.equal(timezones[0].Name, "Local");
assert.equal(timezones[1].ID, "UTC");
assert.equal(timezones[1].Name, "UTC");
});
it("should get days", () => {
const Days = options.Days();
assert.equal(Days[0].text, "01");
assert.equal(Days[30].text, "31");
});
it("should get years", () => {
const Years = options.Years();
const currentYear = new Date().getUTCFullYear();
assert.equal(Years[0].text, currentYear);
});
it("should get indexed years", () => {
const IndexedYears = options.IndexedYears();
assert.equal(IndexedYears[0].text, "2021");
});
it("should get months", () => {
const Months = options.Months();
assert.equal(Months[5].text, "June");
});
it("should get short months", () => {
const MonthsShort = options.MonthsShort();
assert.equal(MonthsShort[5].text, "06");
});
it("should get languages", () => {
const Languages = options.Languages();
assert.equal(Languages[0].value, "en");
});
it("should set default locale", () => {
assert.equal(DefaultLocale, "en");
SetDefaultLocale("de");
assert.equal(DefaultLocale, "de");
SetDefaultLocale("en");
});
it("should return default when no locale is provided", () => {
assert.equal(FindLanguage("").value, "en");
});
it("should return default locale is smaller than 2", () => {
assert.equal(FindLanguage("d").value, "en");
});
it("should return default locale", () => {
assert.equal(FindLanguage("xx").value, "en");
});
it("should return correct locale", () => {
assert.equal(FindLanguage("de").value, "de");
assert.equal(FindLanguage("de").text, "Deutsch");
assert.equal(FindLanguage("de_AT").value, "de");
assert.equal(FindLanguage("de_AT").text, "Deutsch");
assert.equal(FindLanguage("zh-tw").value, "zh_TW");
assert.equal(FindLanguage("zh-tw").text, "繁體中文");
assert.equal(FindLanguage("zh+tw").value, "zh_TW");
assert.equal(FindLanguage("zh+tw").text, "繁體中文");
assert.equal(FindLanguage("zh_AT").value, "zh");
assert.equal(FindLanguage("zh_AT").text, "简体中文");
assert.equal(FindLanguage("ZH_TW").value, "zh_TW");
assert.equal(FindLanguage("ZH_TW").text, "繁體中文");
assert.equal(FindLanguage("zH-tW").value, "zh_TW");
assert.equal(FindLanguage("zH-tW").text, "繁體中文");
});
it("should return default locale", () => {
assert.equal(FindLocale("xx"), "en");
assert.equal(FindLocale(""), "en");
});
it("should return fallback locale", () => {
assert.equal(FallbackLocale(), "en");
});
it("should return items per page", () => {
assert.equal(ItemsPerPage()[0].value, 10);
});
it("should return start page options", () => {
let features = {
account: true,
albums: true,
archive: true,
delete: true,
download: true,
edit: true,
estimates: true,
favorites: true,
files: true,
folders: true,
import: true,
labels: true,
library: true,
logs: true,
calendar: true,
moments: true,
people: true,
places: true,
private: true,
ratings: true,
reactions: true,
review: true,
search: true,
services: true,
settings: true,
share: true,
upload: true,
videos: true,
};
assert.equal(StartPages(features).length, 12);
assert.equal(StartPages(features)[5].value, "people");
assert.equal(StartPages(features)[5].props.disabled, false);
features = {
account: true,
albums: true,
archive: true,
delete: true,
download: true,
edit: true,
estimates: true,
favorites: true,
files: true,
folders: true,
import: true,
labels: true,
library: true,
logs: true,
calendar: false,
moments: true,
people: false,
places: true,
private: true,
ratings: true,
reactions: true,
review: true,
search: true,
services: true,
settings: true,
share: true,
upload: true,
videos: true,
};
assert.equal(StartPages(features).length, 12);
assert.equal(StartPages(features)[5].value, "people");
assert.equal(StartPages(features)[5].props.disabled, true);
});
it("should return animation options", () => {
assert.equal(MapsAnimate()[1].value, 2500);
});
it("should return photo types", () => {
assert.equal(PhotoTypes()[0].value, "image");
assert.equal(PhotoTypes()[1].value, "raw");
});
it("should return map styles", () => {
let styles = MapsStyle(true);
assert.include(styles[styles.length - 1].value, "low-resolution");
styles = MapsStyle(false);
assert.notInclude(styles[styles.length - 1].value, "low-resolution");
});
it("should return timeouts", () => {
assert.equal(Timeouts()[1].value, "high");
});
it("should return retry limits", () => {
assert.equal(RetryLimits()[1].value, 1);
});
it("should return intervals", () => {
assert.equal(Intervals()[0].text, "Never");
assert.equal(Intervals()[1].text, "1 hour");
});
it("should return expiry options", () => {
assert.equal(Expires()[0].text, "Never");
assert.equal(Expires()[1].text, "After 1 day");
});
it("should return colors", () => {
assert.equal(Colors()[0].Slug, "purple");
});
it("should return feedback categories", () => {
assert.equal(FeedbackCategories()[0].value, "feedback");
});
it("should return thumb sizes", () => {
assert.equal(ThumbSizes()[1].value, "fit_720");
});
it("should return thumb filters", () => {
assert.equal(ThumbFilters()[0].value, "blackman");
});
it("should return gender", () => {
assert.equal(Gender()[2].value, "other");
});
it("should return orientations", () => {
assert.equal(Orientations()[1].text, "90°");
});
it("should return service account type options", () => {
assert.equal(AccountTypes()[0].value, "webdav");
assert.equal(AccountTypes().length, 1);
});
});

View File

@@ -80,7 +80,7 @@ describe("common/util", () => {
23,
"Apple",
"iPhone 15 Pro",
false
false,
);
expect(iPhone15Pro).toBe("iPhone 15 Pro");
@@ -89,11 +89,17 @@ describe("common/util", () => {
23,
"Apple",
"iPhone 15 Pro",
true
true,
);
expect(iPhone15ProLong).toBe("Apple iPhone 15 Pro");
const iPhone14 = $util.formatCamera({ Make: "Apple", Model: "iPhone 14" }, 22, "Apple", "iPhone 14", false);
const iPhone14 = $util.formatCamera(
{ Make: "Apple", Model: "iPhone 14" },
22,
"Apple",
"iPhone 14",
false,
);
expect(iPhone14).toBe("iPhone 14");
const iPhone13 = $util.formatCamera(null, 21, "Apple", "iPhone 13", false);
@@ -142,7 +148,7 @@ describe("common/util", () => {
expect($util.thumb(thumbs, 1300, 900).w).toBe(1800);
expect($util.thumb(thumbs, 1300, 900).h).toBe(1200);
expect($util.thumb(thumbs, 1300, 900).src).toBe(
"/api/v1/t/bfdcf45e58b1978af66bbf6212c195851dc65814/174usyd0/fit_1920"
"/api/v1/t/bfdcf45e58b1978af66bbf6212c195851dc65814/174usyd0/fit_1920",
);
expect($util.thumb(thumbs, 1400, 1200).size).toBe("fit_1920");
expect($util.thumb(thumbs, 100000, 120000).size).toBe("fit_7680");
@@ -191,17 +197,19 @@ describe("common/util", () => {
expect(result).toBe("teststring");
});
it("should truncate xxx", () => {
const result = $util.truncate("teststring for mocha", 5, "ng");
const result = $util.truncate("teststring for vitest", 5, "ng");
expect(result).toBe("tesng");
});
it.skip("should encode html", () => {
it("should encode html", () => {
const result = $util.encodeHTML("Micha & Theresa > < 'Lilly'");
expect(result).toBe("Micha & Theresa > < 'Lilly'");
expect(result).toBe("Micha &amp; Theresa &gt; &lt; &apos;Lilly&apos;");
});
it.skip("should encode link", () => {
const result = $util.encodeHTML("Try this: https://photoswipe.com/options/?foo=bar&bar=baz. It's a link!");
const result = $util.encodeHTML(
"Try this: https://photoswipe.com/options/?foo=bar&bar=baz. It's a link!",
);
expect(result).toBe(
`Try this: <a href="https://photoswipe.com/options/" target="_blank">https://photoswipe.com/options/</a> It's a link!`
`Try this: <a href="https://photoswipe.com/options/" target="_blank">https://photoswipe.com/options/</a> It&apos;s a link!`,
);
});
it("should generate tokens reliably", () => {

View File

@@ -1,5 +1,6 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { mount } from "@vue/test-utils";
import { nextTick } from "vue";
import PLoadingBar from "component/loading-bar.vue";
// Mock $event subscription
@@ -23,7 +24,6 @@ describe("PLoadingBar component", () => {
beforeEach(() => {
vi.clearAllMocks();
vi.useFakeTimers();
wrapper = mount(PLoadingBar, {
@@ -42,64 +42,120 @@ describe("PLoadingBar component", () => {
afterEach(() => {
vi.useRealTimers();
if (wrapper) {
wrapper.unmount();
}
});
it("should render correctly", () => {
expect(wrapper.vm).toBeTruthy();
expect(wrapper.find("#p-loading-bar").exists()).toBe(true);
expect(wrapper.find(".top-progress").exists()).toBe(false); // Initially not visible
describe("Component Initialization", () => {
it("should render container element", () => {
const container = wrapper.find("#p-loading-bar");
expect(container.exists()).toBe(true);
});
// Check computed properties
expect(wrapper.vm.progressColor).toBe("#29d"); // Default color
expect(wrapper.vm.isStarted).toBe(false);
it("should not show progress bar initially", () => {
const progressBar = wrapper.find(".top-progress");
expect(progressBar.exists()).toBe(false);
});
it("should subscribe to AJAX events on mount", () => {
expect(mockSubscribe).toHaveBeenCalledTimes(2);
expect(mockSubscribe.mock.calls[0][0]).toBe("ajax.start");
expect(mockSubscribe.mock.calls[1][0]).toBe("ajax.end");
});
});
it("should subscribe to ajax events on mount", () => {
expect(mockSubscribe).toHaveBeenCalledTimes(2);
expect(mockSubscribe.mock.calls[0][0]).toBe("ajax.start");
expect(mockSubscribe.mock.calls[1][0]).toBe("ajax.end");
describe("Progress Bar Visibility", () => {
it("should show progress bar when started", async () => {
// Start the loading bar
wrapper.vm.start();
await nextTick();
const progressBar = wrapper.find(".top-progress");
expect(progressBar.exists()).toBe(true);
});
it("should hide progress bar when completed", async () => {
// Start and complete the loading bar
wrapper.vm.start();
await nextTick();
wrapper.vm.done();
await nextTick();
// Fast forward through completion animation
vi.advanceTimersByTime(1000);
await nextTick();
const progressBar = wrapper.find(".top-progress");
expect(progressBar.exists()).toBe(false);
});
});
it("should start the loading bar", async () => {
wrapper.vm.start();
describe("Progress Bar Appearance", () => {
beforeEach(async () => {
wrapper.vm.start();
await nextTick();
});
await wrapper.vm.$nextTick();
expect(wrapper.vm.visible).toBe(true);
it("should display with default color", async () => {
const progressBar = wrapper.find(".top-progress");
const barStyle = progressBar.attributes("style");
// After transition, the bar should be displayed
wrapper.vm.afterEnter();
expect(wrapper.vm.status).not.toBeNull();
expect(barStyle).toContain("background-color: rgb(34, 153, 221)"); // #29d
});
it("should display with error color when failed", async () => {
wrapper.vm.fail();
await nextTick();
const progressBar = wrapper.find(".top-progress");
const barStyle = progressBar.attributes("style");
expect(barStyle).toContain("background-color: rgb(244, 67, 54)"); // #f44336
});
it("should have peg element for styling", () => {
const peg = wrapper.find(".peg");
expect(peg.exists()).toBe(true);
});
});
it("should make progress visible when started", async () => {
expect(wrapper.vm.visible).toBe(false);
describe("Progress Bar Behavior", () => {
it("should show progress bar when started", async () => {
wrapper.vm.start();
await nextTick();
// Start the bar
wrapper.vm.start();
await wrapper.vm.$nextTick();
const progressBar = wrapper.find(".top-progress");
expect(progressBar.exists()).toBe(true);
expect(progressBar.attributes("style")).toContain("width:");
});
// Should be visible now
expect(wrapper.vm.visible).toBe(true);
});
it("should pause progress when paused", async () => {
wrapper.vm.start();
wrapper.vm.pause();
await nextTick();
it("should handle error state", async () => {
wrapper.vm.fail();
await wrapper.vm.$nextTick();
// When paused, progress bar should still exist but not advance
const progressBar = wrapper.find(".top-progress");
expect(progressBar.exists()).toBe(true);
});
expect(wrapper.vm.error).toBe(true);
expect(wrapper.vm.progressColor).toBe("#f44336"); // Error color
});
it("should complete progress when done is called", async () => {
wrapper.vm.start();
await nextTick();
it("should pause the loading bar", () => {
wrapper.vm.start();
wrapper.vm.pause();
const progressBar = wrapper.find(".top-progress");
expect(progressBar.exists()).toBe(true);
expect(wrapper.vm.isPaused).toBe(true);
});
wrapper.vm.done();
it("should initialize progress to zero", () => {
expect(wrapper.vm.progress).toBe(0);
// Allow time for completion animation
vi.advanceTimersByTime(1000);
await nextTick();
expect(wrapper.vm.getProgress()).toBe(0);
// Progress bar should disappear after completion
expect(wrapper.find(".top-progress").exists()).toBe(false);
});
});
});

View File

@@ -0,0 +1,246 @@
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
import { mount } from "@vue/test-utils";
import { nextTick } from "vue";
import PLocationInput from "component/location/input.vue";
describe("PLocationInput", () => {
let wrapper;
const defaultProps = {
latlng: [null, null],
disabled: false,
hideDetails: true,
label: "Location",
placeholder: "37.75267, -122.543",
density: "comfortable",
validateOn: "input",
showMapButton: false,
icon: "mdi-map-marker",
mapButtonTitle: "Open Map",
mapButtonDisabled: false,
enableUndo: false,
autoApply: true,
debounceDelay: 1000,
};
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
if (wrapper) {
wrapper.unmount();
}
vi.useRealTimers();
vi.clearAllTimers();
});
const createWrapper = (props = {}) => {
return mount(PLocationInput, {
props: { ...defaultProps, ...props },
});
};
describe("Component Rendering", () => {
it("should render input field with correct placeholder", () => {
const placeholder = "Custom placeholder";
wrapper = createWrapper({ placeholder });
const input = wrapper.find("input");
expect(input.exists()).toBe(true);
expect(input.attributes("placeholder")).toBe(placeholder);
});
it("should disable input when disabled prop is true", () => {
wrapper = createWrapper({ disabled: true });
const input = wrapper.find("input");
expect(input.attributes("disabled")).toBeDefined();
});
it("should show map button when showMapButton is true", () => {
wrapper = createWrapper({ showMapButton: true });
const mapButton = wrapper.find(".action-map");
expect(mapButton.exists()).toBe(true);
});
it("should display existing coordinates in input field", async () => {
wrapper = createWrapper({ latlng: [37.7749, -122.4194] });
await nextTick();
const input = wrapper.find("input");
expect(input.element.value).toBe("37.7749, -122.4194");
});
});
describe("User Input and Validation", () => {
beforeEach(() => {
wrapper = createWrapper();
});
it("should emit coordinates when valid input is entered and Enter is pressed", async () => {
const input = wrapper.find("input");
await input.setValue("37.7749, -122.4194");
await input.trigger("keydown.enter");
expect(wrapper.emitted("update:latlng")).toEqual([[[37.7749, -122.4194]]]);
expect(wrapper.emitted("changed")).toEqual([[{ lat: 37.7749, lng: -122.4194 }]]);
});
it("should not emit coordinates for invalid input", async () => {
const input = wrapper.find("input");
await input.setValue("invalid coordinates");
await input.trigger("keydown.enter");
expect(wrapper.emitted("update:latlng")).toBeFalsy();
expect(wrapper.emitted("changed")).toBeFalsy();
});
it("should handle various valid coordinate formats", async () => {
const input = wrapper.find("input");
// Test with spaces around comma
await input.setValue("90, 180");
await input.trigger("keydown.enter");
expect(wrapper.emitted("update:latlng")[0]).toEqual([[90, 180]]);
});
});
describe("Button Interactions", () => {
it("should emit open-map event when map button is clicked", async () => {
wrapper = createWrapper({ showMapButton: true });
const mapButton = wrapper.find(".action-map");
await mapButton.trigger("click");
expect(wrapper.emitted("open-map")).toBeTruthy();
});
it("should clear coordinates when clear button is clicked", async () => {
wrapper = createWrapper({ latlng: [37.7749, -122.4194] });
// Wait for component to initialize and coordinateInput to be set
await nextTick();
const clearButton = wrapper.find(".action-clear");
expect(clearButton.exists()).toBe(true);
await clearButton.trigger("click");
expect(wrapper.emitted("update:latlng")).toEqual([[[0, 0]]]);
expect(wrapper.emitted("changed")).toEqual([[{ lat: 0, lng: 0 }]]);
expect(wrapper.emitted("cleared")).toBeTruthy();
});
it("should show and work with undo button when enabled", async () => {
wrapper = createWrapper({ enableUndo: true, latlng: [37.7749, -122.4194] });
// Wait for component to initialize and coordinateInput to be set
await nextTick();
// Clear coordinates first
const clearButton = wrapper.find(".action-clear");
expect(clearButton.exists()).toBe(true);
await clearButton.trigger("click");
await nextTick();
// Undo button should appear
const undoButton = wrapper.find(".action-undo");
expect(undoButton.exists()).toBe(true);
// Click undo to restore coordinates
await undoButton.trigger("click");
const latlngEmits = wrapper.emitted("update:latlng");
// Last emit should restore original coordinates
expect(latlngEmits[latlngEmits.length - 1]).toEqual([[37.7749, -122.4194]]);
});
});
describe("Auto Apply Feature", () => {
it("should auto apply valid coordinates after debounce delay", async () => {
wrapper = createWrapper({ autoApply: true, debounceDelay: 500 });
const input = wrapper.find("input");
await input.setValue("37.7749, -122.4194");
// Should not emit immediately
expect(wrapper.emitted("update:latlng")).toBeFalsy();
// Fast forward timer
vi.advanceTimersByTime(500);
await nextTick();
expect(wrapper.emitted("update:latlng")).toEqual([[[37.7749, -122.4194]]]);
});
it("should not auto apply when autoApply is disabled", async () => {
wrapper = createWrapper({ autoApply: false });
const input = wrapper.find("input");
await input.setValue("37.7749, -122.4194");
vi.advanceTimersByTime(1000);
await nextTick();
expect(wrapper.emitted("update:latlng")).toBeFalsy();
});
});
describe("Paste Functionality", () => {
beforeEach(() => {
wrapper = createWrapper();
});
it("should handle paste with valid coordinates", async () => {
const input = wrapper.find("input");
const pasteEvent = new Event("paste");
pasteEvent.clipboardData = {
getData: vi.fn().mockReturnValue("40.7128, -74.0060"),
};
await input.trigger("paste", { clipboardData: pasteEvent.clipboardData });
expect(wrapper.emitted("update:latlng")).toEqual([[[40.7128, -74.006]]]);
expect(wrapper.emitted("changed")).toEqual([[{ lat: 40.7128, lng: -74.006 }]]);
});
it("should handle paste with space-separated coordinates", async () => {
const input = wrapper.find("input");
const pasteEvent = new Event("paste");
pasteEvent.clipboardData = {
getData: vi.fn().mockReturnValue("40.7128 -74.0060"),
};
await input.trigger("paste", { clipboardData: pasteEvent.clipboardData });
expect(wrapper.emitted("update:latlng")).toEqual([[[40.7128, -74.006]]]);
});
});
describe("Props Updates", () => {
it("should update input field when lat/lng props change", async () => {
wrapper = createWrapper();
await wrapper.setProps({ latlng: [40.7128, -74.006] });
const input = wrapper.find("input");
expect(input.element.value).toBe("40.7128, -74.006");
});
it("should clear input field when coordinates are invalid", async () => {
wrapper = createWrapper({ latlng: [0, 0] });
await nextTick();
const input = wrapper.find("input");
expect(input.element.value).toBe("");
});
});
});

View File

@@ -80,7 +80,7 @@ describe("PSidebarInfo component", () => {
expect(mockModel.getLatLng).toHaveBeenCalled();
});
it.skip("should emit close event when close button is clicked", async () => {
it("should emit close event when close button is clicked", async () => {
// Try finding close button by various selectors
const closeButtonSelectors = [".close-button", "button[aria-label='Close']", "button[title='Close']"];

View File

@@ -67,21 +67,24 @@ describe("options/options", () => {
});
it("should set default locale", () => {
expect(DefaultLocale).toBe("en");
// Assuming DefaultLocale is exported and mutable for testing purposes
// Initial state check might depend on test execution order, so we control it here.
SetDefaultLocale("en"); // Ensure starting state
expect(options.DefaultLocale).toBe("en");
SetDefaultLocale("de");
expect(DefaultLocale).toBe("de");
SetDefaultLocale("en");
expect(options.DefaultLocale).toBe("de");
SetDefaultLocale("en"); // Reset for other tests
});
it("should return default when no locale is provided", () => {
expect(FindLanguage("").value).toBe("en");
});
it("should return default locale is smaller than 2", () => {
it("should return default if locale is smaller than 2", () => {
expect(FindLanguage("d").value).toBe("en");
});
it("should return default locale", () => {
it("should return default for unknown locale", () => {
expect(FindLanguage("xx").value).toBe("en");
});
@@ -150,34 +153,9 @@ describe("options/options", () => {
expect(StartPages(features)[5].value).toBe("people");
expect(StartPages(features)[5].props.disabled).toBe(false);
features = {
account: true,
albums: true,
archive: true,
delete: true,
download: true,
edit: true,
estimates: true,
favorites: true,
files: true,
folders: true,
import: true,
labels: true,
library: true,
logs: true,
...features, // copy previous settings
calendar: false,
moments: true,
people: false,
places: true,
private: true,
ratings: true,
reactions: true,
review: true,
search: true,
services: true,
settings: true,
share: true,
upload: true,
videos: true,
};
expect(StartPages(features).length).toBe(12);
expect(StartPages(features)[5].value).toBe("people");

View File

@@ -1,8 +1,11 @@
import { afterEach, vi } from "vitest";
import "@testing-library/jest-dom";
import "./vue-setup";
import { config } from "@vue/test-utils";
import { createVuetify } from "vuetify";
import * as components from "vuetify/components";
import * as directives from "vuetify/directives";
import "vuetify/styles";
// Import and set up global config
import clientConfig from "./config";
import { $config } from "app/session";
@@ -11,7 +14,54 @@ $config.setValues(clientConfig);
// Make config available in browser environment
window.__CONFIG__ = clientConfig;
console.log("Running tests in real browser environment");
// Create a proper Vuetify instance with all components and styles
const vuetify = createVuetify({
components,
directives,
theme: {
defaultTheme: "light",
},
});
// Configure Vue Test Utils global configuration
config.global.mocks = {
$gettext: (text) => text,
$isRtl: false,
$config: {
feature: (_name) => true,
},
};
config.global.plugins = [vuetify];
config.global.stubs = {
transition: false,
};
config.global.directives = {
tooltip: {
mounted(el, binding) {
el.setAttribute("data-tooltip", binding.value);
},
},
};
const originalMount = config.global.mount;
config.global.mount = function (component, options = {}) {
options.global = options.global || {};
options.global.config = options.global.config || {};
options.global.config.globalProperties = options.global.config.globalProperties || {};
options.global.config.globalProperties.$emit = vi.fn();
// Add vuetify to all mount calls
if (!options.global.plugins) {
options.global.plugins = [vuetify];
} else if (Array.isArray(options.global.plugins)) {
options.global.plugins.push(vuetify);
}
return originalMount(component, options);
};
// Clean up after each test
afterEach(() => {
@@ -20,3 +70,7 @@ afterEach(() => {
// Export shared configuration
export { clientConfig };
export default {
vuetify,
};

View File

@@ -1,63 +0,0 @@
import { config } from "@vue/test-utils";
import { vi } from "vitest";
import { createVuetify } from "vuetify";
import * as components from "vuetify/components";
import * as directives from "vuetify/directives";
import "vuetify/styles";
import { Settings } from "luxon";
// Setup timezone to match test expectations (UTC+2/CEST)
Settings.defaultZoneName = "Europe/Berlin";
// Create a proper Vuetify instance with all components and styles
const vuetify = createVuetify({
components,
directives,
theme: {
defaultTheme: "light",
},
});
// Configure Vue Test Utils global configuration
config.global.mocks = {
$gettext: (text) => text,
$isRtl: false,
$config: {
feature: (_name) => true,
},
};
config.global.plugins = [vuetify];
config.global.stubs = {
transition: false,
};
config.global.directives = {
tooltip: {
mounted(el, binding) {
el.setAttribute("data-tooltip", binding.value);
},
},
};
const originalMount = config.global.mount;
config.global.mount = function (component, options = {}) {
options.global = options.global || {};
options.global.config = options.global.config || {};
options.global.config.globalProperties = options.global.config.globalProperties || {};
options.global.config.globalProperties.$emit = vi.fn();
// Add vuetify to all mount calls
if (!options.global.plugins) {
options.global.plugins = [vuetify];
} else if (Array.isArray(options.global.plugins)) {
options.global.plugins.push(vuetify);
}
return originalMount(component, options);
};
export default {
vuetify,
};