photoprism/frontend/tests/unit/model/label_test.js
Michael Mayer 26560e8d71 Frontend: Upgrade Webpack from v4 to v5
Most frontend packages have been upgraded as part of this commit.
JS unit tests have been refactored alongside.
2021-07-12 19:25:37 +02:00

113 lines
3.5 KiB
JavaScript

import "../fixtures";
import Label 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(), 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");
});
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", Name: "Black Cat", Slug: "black-cat" };
const label = new Label(values);
const result = label.thumbnailUrl("xyz");
assert.equal(result, "/api/v1/labels/ABC123/t/public/xyz");
});
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");
});
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);
});
});