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

125 lines
4.6 KiB
JavaScript
Raw Normal View History

2019-07-28 16:46:24 +00:00
import Album from "model/album";
import MockAdapter from "axios-mock-adapter";
import Api from "common/api";
import {Settings} from "luxon";
Settings.defaultLocale = "en"
Settings.defaultZoneName = "UTC"
2020-07-02 08:03:00 +00:00
let chai = require("chai/chai");
2019-08-13 06:09:10 +00:00
let assert = chai.assert;
2019-07-28 16:46:24 +00:00
const mock = new MockAdapter(Api);
mock
.onPost().reply(200)
.onDelete().reply(200);
2019-07-28 16:46:24 +00:00
2019-08-09 11:43:29 +00:00
describe("model/album", () => {
2019-07-28 16:46:24 +00:00
it("should get album entity name", () => {
const values = {id: 5, Title: "Christmas 2019", Slug: "christmas-2019"};
2019-07-28 16:46:24 +00:00
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};
2019-07-28 16:46:24 +00:00
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"};
2019-07-28 16:46:24 +00:00
const album = new Album(values);
const result = album.getTitle();
assert.equal(result, "Christmas 2019");
});
it("should get thumbnail url", () => {
const values = {id: 5, Title: "Christmas 2019", Slug: "christmas-2019", UID: 66};
2019-07-28 16:46:24 +00:00
const album = new Album(values);
const result = album.thumbnailUrl("xyz");
assert.equal(result, "/api/v1/albums/66/t/public/xyz");
2019-07-28 16:46:24 +00:00
});
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, "Jul 8, 2012, 2:45 PM");
});
2020-10-19 09:36:07 +00:00
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");
});
2020-10-19 09:36:07 +00:00
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 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"));
2020-10-19 09:36:07 +00:00
});
2019-07-28 16:46:24 +00:00
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");
});
2019-08-09 11:31:56 +00:00
it("should like album", () => {
const values = {id: 5, Title: "Christmas 2019", Slug: "christmas-2019", Favorite: false};
2019-08-09 11:31:56 +00:00
const album = new Album(values);
assert.equal(album.Favorite, false);
2019-08-09 11:31:56 +00:00
album.like();
assert.equal(album.Favorite, true);
2019-08-09 11:31:56 +00:00
});
it("should unlike album", () => {
const values = {id: 5, Title: "Christmas 2019", Slug: "christmas-2019", Favorite: true};
2019-08-09 11:31:56 +00:00
const album = new Album(values);
assert.equal(album.Favorite, true);
2019-08-09 11:31:56 +00:00
album.unlike();
assert.equal(album.Favorite, false);
2019-08-09 11:31:56 +00:00
});
it("should toggle like", () => {
const values = {id: 5, Title: "Christmas 2019", Slug: "christmas-2019", Favorite: true};
2019-08-09 11:31:56 +00:00
const album = new Album(values);
assert.equal(album.Favorite, true);
2019-08-09 11:31:56 +00:00
album.toggleLike();
assert.equal(album.Favorite, false);
2019-08-09 11:31:56 +00:00
album.toggleLike();
assert.equal(album.Favorite, true);
2019-08-09 11:31:56 +00:00
});
});