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";
|
2019-08-09 16:02:21 +02:00
|
|
|
import Api from "common/api";
|
|
|
|
|
2019-08-13 08:09:38 +02:00
|
|
|
let chai = require('../../../node_modules/chai/chai');
|
|
|
|
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);
|
|
|
|
|
2019-08-09 16:02:21 +02:00
|
|
|
mock
|
|
|
|
.onPost().reply(200)
|
|
|
|
.onDelete().reply(200);
|
2019-07-28 18:40:33 +02:00
|
|
|
|
|
|
|
describe("model/label", () => {
|
2019-07-28 17:51:27 +02:00
|
|
|
it("should get label entity name", () => {
|
2020-05-23 20:58:58 +02:00
|
|
|
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", () => {
|
2020-05-23 20:58:58 +02:00
|
|
|
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();
|
2019-12-16 23:33:52 +01:00
|
|
|
assert.equal(result, "ABC123");
|
2019-07-28 17:51:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should get label title", () => {
|
2020-05-23 20:58:58 +02:00
|
|
|
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", () => {
|
2020-05-23 20:58:58 +02:00
|
|
|
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);
|
2020-05-21 13:26:28 +02:00
|
|
|
const result = label.thumbnailUrl("xyz");
|
2019-12-16 23:33:52 +01:00
|
|
|
assert.equal(result, "/api/v1/labels/ABC123/thumbnail/xyz");
|
2019-07-28 17:51:27 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should get thumbnail src set", () => {
|
2020-05-23 20:58:58 +02:00
|
|
|
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);
|
2020-05-21 13:26:28 +02:00
|
|
|
const result = label.thumbnailSrcset("");
|
2019-12-16 23:33:52 +01:00
|
|
|
assert.equal(result, "/api/v1/labels/ABC123/thumbnail/fit_720 720w, /api/v1/labels/ABC123/thumbnail/fit_1280 1280w, /api/v1/labels/ABC123/thumbnail/fit_1920 1920w, /api/v1/labels/ABC123/thumbnail/fit_2560 2560w, /api/v1/labels/ABC123/thumbnail/fit_3840 3840w");
|
2019-07-28 17:51:27 +02:00
|
|
|
});
|
|
|
|
|
2019-07-28 18:40:33 +02:00
|
|
|
it("should get thumbnail sizes", () => {
|
2020-05-23 20:58:58 +02:00
|
|
|
const values = {ID: 5, UID: "ABC123", Name: "Black Cat", Slug: "black-cat"};
|
2019-07-28 18:40:33 +02:00
|
|
|
const label = new Label(values);
|
2020-05-21 13:26:28 +02:00
|
|
|
const result = label.thumbnailSizes();
|
2019-07-28 18:40:33 +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:34:08 +02:00
|
|
|
it("should get date string", () => {
|
2020-05-23 20:58:58 +02:00
|
|
|
const values = {ID: 5, UID: "ABC123", Name: "Black Cat", Slug: "black-cat", CreatedAt: "2012-07-08T14:45:39Z"};
|
2019-08-09 10:34:08 +02:00
|
|
|
const label = new Label(values);
|
|
|
|
const result = label.getDateString();
|
2019-09-19 23:23:39 +02:00
|
|
|
assert.equal(result, "Jul 8, 2012, 2:45 PM");
|
2019-08-09 10:34:08 +02:00
|
|
|
});
|
|
|
|
|
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", () => {
|
2020-05-23 20:58:58 +02:00
|
|
|
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);
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.equal(label.Favorite, false);
|
2019-08-09 13:43:47 +02:00
|
|
|
label.like();
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.equal(label.Favorite, true);
|
2019-08-09 13:43:47 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should unlike label", () => {
|
2020-05-23 20:58:58 +02:00
|
|
|
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);
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.equal(label.Favorite, true);
|
2019-08-09 13:43:47 +02:00
|
|
|
label.unlike();
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.equal(label.Favorite, false);
|
2019-08-09 13:43:47 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should toggle like", () => {
|
2020-05-23 20:58:58 +02:00
|
|
|
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);
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.equal(label.Favorite, true);
|
2019-08-09 13:43:47 +02:00
|
|
|
label.toggleLike();
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.equal(label.Favorite, false);
|
2019-08-09 13:43:47 +02:00
|
|
|
label.toggleLike();
|
2020-05-23 20:58:58 +02:00
|
|
|
assert.equal(label.Favorite, true);
|
2019-08-09 13:43:47 +02:00
|
|
|
});
|
2019-09-19 23:23:39 +02:00
|
|
|
});
|