photoprism/frontend/tests/unit/model/label_test.js

130 lines
11 KiB
JavaScript
Raw Normal View History

2019-07-28 17:51:27 +02:00
import Label from "model/label";
2019-07-28 18:40:33 +02:00
import MockAdapter from "axios-mock-adapter";
import Api from "common/api";
2021-07-05 16:41:43 +02:00
import { Settings } from "luxon";
2021-07-05 16:41:43 +02:00
Settings.defaultLocale = "en";
Settings.defaultZoneName = "UTC";
window.__CONFIG__ = {
name: "PhotoPrism",
version: "201213-283748ca-Linux-x86_64-DEBUG",
copyright: "(c) 2018-2021 Michael Mayer \u003chello@photoprism.org\u003e",
flags: "public debug experimental settings",
apiUri: "/api/v1",
staticUri: "/static",
contentUri: "/api/v1",
"siteUrl":"http://localhost:2342/","sitePreview":"http://localhost:2342/static/img/preview.jpg","siteTitle":"PhotoPrism","siteCaption":"Browse Your Life","siteDescription":"Open-Source Photo Management","siteAuthor":"@photoprism_app","debug":true,"readonly":false,"uploadNSFW":false,"public":true,"experimental":true,"disableSettings":false,"albumCategories":null,"albums":[],"cameras":[{"ID":6,"Slug":"apple-iphone-5s","Name":"Apple iPhone 5s","Make":"Apple","Model":"iPhone 5s"},{"ID":7,"Slug":"apple-iphone-6","Name":"Apple iPhone 6","Make":"Apple","Model":"iPhone 6"},{"ID":8,"Slug":"apple-iphone-se","Name":"Apple iPhone SE","Make":"Apple","Model":"iPhone SE"},{"ID":2,"Slug":"canon-eos-5d","Name":"Canon EOS 5D","Make":"Canon","Model":"EOS 5D"},{"ID":4,"Slug":"canon-eos-6d","Name":"Canon EOS 6D","Make":"Canon","Model":"EOS 6D"},{"ID":5,"Slug":"canon-eos-7d","Name":"Canon EOS 7D","Make":"Canon","Model":"EOS 7D"},{"ID":9,"Slug":"huawei-p30","Name":"HUAWEI P30","Make":"HUAWEI","Model":"P30"},{"ID":3,"Slug":"olympus-c2500l","Name":"Olympus C2500L","Make":"Olympus","Model":"C2500L"},{"ID":1,"Slug":"zz","Name":"Unknown","Make":"","Model":"Unknown"}],"lenses":[{"ID":2,"Slug":"24-0-105-0-mm","Name":"24.0 - 105.0 mm","Make":"","Model":"24.0 - 105.0 mm","Type":""},{"ID":7,"Slug":"apple-iphone-5s-back-camera-4-12mm-f-2-2","Name":"Apple iPhone 5s back camera 4.12mm f/2.2","Make":"Apple","Model":"iPhone 5s back camera 4.12mm f/2.2","Type":""},{"ID":9,"Slug":"apple-iphone-6-back-camera-4-15mm-f-2-2","Name":"Apple iPhone 6 back camera 4.15mm f/2.2","Make":"Apple","Model":"iPhone 6 back camera 4.15mm f/2.2","Type":""},{"ID":10,"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":6,"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":4,"Slug":"ef24-105mm-f-4l-is-usm","Name":"EF24-105mm f/4L IS USM","Make":"","Model":"EF24-105mm f/4L IS USM","Type":""},{"ID":8,"Slug":"ef35mm-f-2-is-usm","Name":"EF35mm f/2 IS USM","Make":"","Model":"EF35mm f/2 IS USM","Type":""},{"ID":5,"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":"at","Slug":"austria","Name":"Austria"},{"ID":"bw","Slug":"botswana","Name":"Botswana"},{"ID":"ca","Slug":"canada","Name":"Canada"},{"ID":"cu","Slug":"cuba","Name":"Cuba"},{"ID":"fr","Slug":"france","Name":"France"},{"ID":"de","Slug":"germany","Name":"Germany"},{"ID":"gr","Slug":"greece","Name":"Greece"},{"ID":"it","Slug":"italy","Name":"Italy"},{"ID":"za","Slug":"south-africa","Name":"South Africa"},{"ID":"ch","Slug":"switzerland","Name":"Switzerland"},{"ID":"gb","Slug":"united-kingdom","Name":"United Kingdom"},{"ID":"us","Slug":"usa","Name":"USA"},{"ID":"zz","Slug":"zz","Name":"Unknown"}],"thumbs":[{"size":"fit_720","use":"Mobile, TV","w":720,"h":720},{"size":"fit_1280","use":"Mobile, HD Ready TV","w":1280,"h":1024},{"size":"fit_1920","use":"Mobile, Full HD TV","w":1920,"h":1200},{"size":"fit_2048","use":"Tablets, Cinema 2K","w":2048,"h":2048},{"size":"fit_2560","use":"Quad HD, Retina Display","w":2560,"h":1600},{"size":"fit_4096","use":"Ultra HD, Retina 4K","w":4096,"h":4096},{"size":"fit_7680","use":"8K Ultra HD 2, Retina 6K","w":7680,"h":4320}],"status":"unregistered","mapKey":"jOTd5JGKYQV1fiAW4UZO","downloadToken":"2lbh9x09","previewToken":"public","jsHash":"6d752756","cssHash":"c5bb9de2","settings":{"ui":{"scrollbar":true,"theme":"default","language":"en"},"templates":{"default":"index.tmpl"},"maps":{"animate":0,"style":"streets"},"features":{"upload":true,"download":true,"private":true,"review":true,"files":true,"moments":true,"labels":true,"places":true,"edit":true,"archive":true,"delete":false,"share":true,"library":true,"
2020-07-02 10:03:00 +02:00
let chai = require("chai/chai");
2019-08-13 08:09:38 +02:00
let assert = chai.assert;
2019-07-28 17:51:27 +02:00
2019-07-28 18:40:33 +02:00
const mock = new MockAdapter(Api);
mock
.onPost().reply(200)
.onDelete().reply(200);
2019-07-28 18:40:33 +02:00
describe("model/label", () => {
2021-03-11 15:18:05 +01:00
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");
console.log(result)
assert.equal(result.name, "test");
assert.equal(result.query.q, "label:black-cat");
});
it("should return batch size", () => {
assert.equal(Label.batchSize(), 24);
});
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");
});
2019-07-28 17:51:27 +02:00
it("should get label entity name", () => {
const values = {ID: 5, UID: "ABC123", Name: "Black Cat", Slug: "black-cat"};
2019-07-28 17:51:27 +02:00
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"};
2019-07-28 17:51:27 +02:00
const label = new Label(values);
const result = label.getId();
assert.equal(result, "ABC123");
2019-07-28 17:51:27 +02:00
});
it("should get label title", () => {
const values = {ID: 5, UID: "ABC123", Name: "Black Cat", Slug: "black-cat"};
2019-07-28 17:51:27 +02:00
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", Name: "Black Cat", Slug: "black-cat"};
2019-07-28 17:51:27 +02:00
const label = new Label(values);
const result = label.thumbnailUrl("xyz");
assert.equal(result, "/api/v1/labels/ABC123/t/public/xyz");
2019-07-28 17:51:27 +02:00
});
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, "Jul 8, 2012, 2:45 PM");
});
2019-07-28 18:40:33 +02:00
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");
});
2019-08-09 13:43:47 +02:00
it("should like label", () => {
const values = {ID: 5, UID: "ABC123", Name: "Black Cat", Slug: "black-cat", Favorite: false};
2019-08-09 13:43:47 +02:00
const label = new Label(values);
assert.equal(label.Favorite, false);
2019-08-09 13:43:47 +02:00
label.like();
assert.equal(label.Favorite, true);
2019-08-09 13:43:47 +02:00
});
it("should unlike label", () => {
const values = {ID: 5, UID: "ABC123",Name: "Black Cat", Slug: "black-cat", Favorite: true};
2019-08-09 13:43:47 +02:00
const label = new Label(values);
assert.equal(label.Favorite, true);
2019-08-09 13:43:47 +02:00
label.unlike();
assert.equal(label.Favorite, false);
2019-08-09 13:43:47 +02:00
});
it("should toggle like", () => {
const values = {ID: 5, UID: "ABC123", Name: "Black Cat", Slug: "black-cat", Favorite: true};
2019-08-09 13:43:47 +02:00
const label = new Label(values);
assert.equal(label.Favorite, true);
2019-08-09 13:43:47 +02:00
label.toggleLike();
assert.equal(label.Favorite, false);
2019-08-09 13:43:47 +02:00
label.toggleLike();
assert.equal(label.Favorite, true);
2019-08-09 13:43:47 +02:00
});
2020-06-30 16:53:12 +02:00
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);
});
});