2019-07-28 18:46:24 +02:00
|
|
|
import Album from "model/album";
|
|
|
|
import MockAdapter from "axios-mock-adapter";
|
2019-08-09 16:02:00 +02:00
|
|
|
import Api from "common/api";
|
|
|
|
|
2020-07-02 10:03:00 +02:00
|
|
|
let chai = require("chai/chai");
|
2019-08-13 08:09:10 +02:00
|
|
|
let assert = chai.assert;
|
2019-07-28 18:46:24 +02:00
|
|
|
|
|
|
|
const mock = new MockAdapter(Api);
|
|
|
|
|
2019-08-09 16:02:00 +02:00
|
|
|
mock
|
|
|
|
.onPost().reply(200)
|
|
|
|
.onDelete().reply(200);
|
2019-07-28 18:46:24 +02:00
|
|
|
|
2019-08-09 13:43:29 +02:00
|
|
|
describe("model/album", () => {
|
2019-07-28 18:46:24 +02:00
|
|
|
it("should get album entity name", () => {
|
2020-05-26 09:02:19 +02:00
|
|
|
const values = {id: 5, Title: "Christmas 2019", Slug: "christmas-2019"};
|
2019-07-28 18:46:24 +02:00
|
|
|
const album = new Album(values);
|
|
|
|
const result = album.getEntityName();
|
|
|
|
assert.equal(result, "christmas-2019");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should get album id", () => {
|
2020-05-26 09:02:19 +02:00
|
|
|
const values = {id: 5, Title: "Christmas 2019", Slug: "christmas-2019", UID: 66};
|
2019-07-28 18:46:24 +02:00
|
|
|
const album = new Album(values);
|
|
|
|
const result = album.getId();
|
|
|
|
assert.equal(result, "66");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should get album title", () => {
|
2020-05-26 09:02:19 +02:00
|
|
|
const values = {id: 5, Title: "Christmas 2019", Slug: "christmas-2019"};
|
2019-07-28 18:46:24 +02:00
|
|
|
const album = new Album(values);
|
|
|
|
const result = album.getTitle();
|
|
|
|
assert.equal(result, "Christmas 2019");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should get thumbnail url", () => {
|
2020-05-26 09:02:19 +02:00
|
|
|
const values = {id: 5, Title: "Christmas 2019", Slug: "christmas-2019", UID: 66};
|
2019-07-28 18:46:24 +02:00
|
|
|
const album = new Album(values);
|
2020-05-21 13:26:28 +02:00
|
|
|
const result = album.thumbnailUrl("xyz");
|
2020-05-27 19:38:40 +02:00
|
|
|
assert.equal(result, "/api/v1/albums/66/t/static/xyz");
|
2019-07-28 18:46:24 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should get thumbnail src set", () => {
|
2020-05-26 09:02:19 +02:00
|
|
|
const values = {id: 5, Title: "Christmas 2019", Slug: "christmas-2019", UID: 66};
|
2019-07-28 18:46:24 +02:00
|
|
|
const album = new Album(values);
|
2020-05-21 13:26:28 +02:00
|
|
|
const result = album.thumbnailSrcset("");
|
2020-05-27 19:38:40 +02:00
|
|
|
assert.equal(result, "/api/v1/albums/66/t/static/fit_720 720w, /api/v1/albums/66/t/static/fit_1280 1280w, /api/v1/albums/66/t/static/fit_1920 1920w, /api/v1/albums/66/t/static/fit_2560 2560w, /api/v1/albums/66/t/static/fit_3840 3840w");
|
2019-07-28 18:46:24 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should get thumbnail sizes", () => {
|
2020-05-26 09:02:19 +02:00
|
|
|
const values = {id: 5, Title: "Christmas 2019", Slug: "christmas-2019", CreatedAt: "2012-07-08T14:45:39Z"};
|
2019-07-28 18:46:24 +02:00
|
|
|
const album = new Album(values);
|
2020-05-21 13:26:28 +02:00
|
|
|
const result = album.thumbnailSizes();
|
2019-07-28 18:46:24 +02:00
|
|
|
assert.equal(result, "(min-width: 2560px) 3840px, (min-width: 1920px) 2560px, (min-width: 1280px) 1920px, (min-width: 720px) 1280px, 720px");
|
|
|
|
});
|
|
|
|
|
2019-08-09 10:33:49 +02:00
|
|
|
it("should get date string", () => {
|
2020-05-26 09:02:19 +02:00
|
|
|
const values = {ID: 5, Title: "Christmas 2019", Slug: "christmas-2019", CreatedAt: "2012-07-08T14:45:39Z"};
|
2019-08-09 10:33:49 +02:00
|
|
|
const album = new Album(values);
|
|
|
|
const result = album.getDateString();
|
2019-09-19 23:23:39 +02:00
|
|
|
assert.equal(result, "Jul 8, 2012, 2:45 PM");
|
2019-08-09 10:33:49 +02:00
|
|
|
});
|
|
|
|
|
2019-07-28 18:46:24 +02: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 13:31:56 +02:00
|
|
|
it("should like album", () => {
|
2020-05-26 09:02:19 +02:00
|
|
|
const values = {id: 5, Title: "Christmas 2019", Slug: "christmas-2019", Favorite: false};
|
2019-08-09 13:31:56 +02:00
|
|
|
const album = new Album(values);
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.equal(album.Favorite, false);
|
2019-08-09 13:31:56 +02:00
|
|
|
album.like();
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.equal(album.Favorite, true);
|
2019-08-09 13:31:56 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should unlike album", () => {
|
2020-05-26 09:02:19 +02:00
|
|
|
const values = {id: 5, Title: "Christmas 2019", Slug: "christmas-2019", Favorite: true};
|
2019-08-09 13:31:56 +02:00
|
|
|
const album = new Album(values);
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.equal(album.Favorite, true);
|
2019-08-09 13:31:56 +02:00
|
|
|
album.unlike();
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.equal(album.Favorite, false);
|
2019-08-09 13:31:56 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should toggle like", () => {
|
2020-05-26 09:02:19 +02:00
|
|
|
const values = {id: 5, Title: "Christmas 2019", Slug: "christmas-2019", Favorite: true};
|
2019-08-09 13:31:56 +02:00
|
|
|
const album = new Album(values);
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.equal(album.Favorite, true);
|
2019-08-09 13:31:56 +02:00
|
|
|
album.toggleLike();
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.equal(album.Favorite, false);
|
2019-08-09 13:31:56 +02:00
|
|
|
album.toggleLike();
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.equal(album.Favorite, true);
|
2019-08-09 13:31:56 +02:00
|
|
|
});
|
2019-09-19 23:23:39 +02:00
|
|
|
});
|