Frontend: Add unit tests

This commit is contained in:
theresa 2021-10-06 16:42:53 +02:00
parent 1d4455bb64
commit 0bf22f8543
7 changed files with 130 additions and 9 deletions

View file

@ -128,15 +128,9 @@ describe("common/config", () => {
});
assert.equal(config.values.people[0].Name, "New Name");
config.onPeople(".deleted", {
entities: [
{
UID: "abc123",
Name: "New Name",
Keywords: ["New", "Name"],
},
],
entities: ["abc123"],
});
assert.equal(config.values.people[0].Name, "New Name");
assert.empty(config.values.people);
});
it("should return if language is rtl", () => {

View file

@ -53,4 +53,8 @@ describe("common/util", () => {
const result = Util.truncate("teststring for mocha", 5, "ng");
assert.equal(result, "tesng");
});
it("should encode html", () => {
const result = Util.encodeHTML("Micha & Theresa > < 'Lilly'");
assert.equal(result, "Micha &amp; Theresa &gt; &lt; &#x27;Lilly&#x27;");
});
});

View file

@ -333,6 +333,8 @@ Mock.onPost("api/v1/subjects/s123ghytrfggd/like").reply(200, { status: "ok" }, m
Mock.onDelete("api/v1/subjects/s123ghytrfggd/like").reply(200, { status: "ok" }, mockHeaders);
Mock.onGet("api/v1/config/options").reply(200, { success: "ok" }, mockHeaders);
Mock.onPost("api/v1/config/options").reply(200, { success: "ok" }, mockHeaders);
Mock.onPost("api/v1/albums").reply(200, { success: "ok" }, mockHeaders);
//Mock.onPost().reply(200);
//Mock.onDelete().reply(200);

View file

@ -72,7 +72,11 @@ describe("model/face", () => {
assert.equal(result, "/api/v1/t/7ca759a2b788cc5bcc08dbbce9854ff94a2f94d1/public/xyz");
const values2 = { ID: "f123ghytrfggd", Samples: 5, Thumb: "7ca759a2b788cc5bcc08dbbce9854ff94a2f94d1" };
const values2 = {
ID: "f123ghytrfggd",
Samples: 5,
Thumb: "7ca759a2b788cc5bcc08dbbce9854ff94a2f94d1",
};
const face2 = new Face(values2);
const result2 = face2.thumbnailUrl();
@ -105,6 +109,21 @@ describe("model/face", () => {
assert.equal(face.Hidden, true);
});
it("should toggle hidden", () => {
const values = {
ID: "f123ghytrfggd",
Samples: 5,
CreatedAt: "2012-07-08T14:45:39Z",
Hidden: true,
};
const face = new Face(values);
assert.equal(face.Hidden, true);
face.toggleHidden();
assert.equal(face.Hidden, false);
face.toggleHidden();
assert.equal(face.Hidden, true);
});
it("should return batch size", () => {
assert.equal(Face.batchSize(), 24);
});

View file

@ -1386,6 +1386,7 @@ describe("model/photo", () => {
],
};
const photo = new Photo(values);
photo.Title = "New Title";
photo
.update()
.then((response) => {
@ -1395,5 +1396,63 @@ describe("model/photo", () => {
.catch((error) => {
done(error);
});
assert.equal(photo.Title, "New Title");
});
it("should test get Markers", () => {
const values = {
ID: 10,
UID: "pqbemz8276mhtobh",
Lat: 1.1,
Lng: 3.3,
CameraID: 123,
Title: "Test Titel",
Description: "Super nice video",
Files: [
{
UID: "fqbfk181n4ca5sud",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
Type: "mp4",
Hash: "1xxbgdt55",
},
],
};
const photo = new Photo(values);
const result = photo.getMarkers(true);
assert.empty(result);
const values2 = {
ID: 10,
UID: "pqbemz8276mhtobh",
Lat: 1.1,
Lng: 3.3,
CameraID: 123,
Title: "Test Titel",
Description: "Super nice video",
Files: [
{
UID: "fqbfk181n4ca5sud",
Name: "1980/01/superCuteKitten.mp4",
Primary: true,
Type: "mp4",
Hash: "1xxbgdt55",
Markers: [
{
UID: "aaa123",
Invalid: false,
},
{
UID: "bbb123",
Invalid: true,
},
],
},
],
};
const photo2 = new Photo(values2);
const result2 = photo2.getMarkers(true);
assert.equal(result2.length, 1);
const result3 = photo2.getMarkers(false);
assert.equal(result3.length, 2);
});
});

View file

@ -65,6 +65,15 @@ describe("model/abstract", () => {
assert.equal(album.Description, undefined);
await album.save();
assert.equal(album.Description, "Test description");
const values2 = { Name: "Christmas 2019", Slug: "christmas-2019" };
const album2 = new Album(values2);
album.Name = "Christmas 2020";
assert.equal(album2.Description, undefined);
await album2.save().then((response) => {
assert.equal(response.success, "ok");
});
assert.equal(album2.Description, undefined);
});
it("should remove album", async () => {

View file

@ -200,6 +200,40 @@ describe("model/subject", () => {
assert.equal(subject.Favorite, true);
});
it("show and hide subject", () => {
const values = {
UID: "s123ghytrfggd",
Type: "person",
Src: "manual",
Name: "Jane Doe",
Slug: "jane-doe",
Hidden: true,
};
const subject = new Subject(values);
assert.equal(subject.Hidden, true);
subject.show();
assert.equal(subject.Hidden, false);
subject.hide();
assert.equal(subject.Hidden, true);
});
it("should toggle hidden", () => {
const values = {
UID: "s123ghytrfggd",
Type: "person",
Src: "manual",
Name: "Jane Doe",
Slug: "jane-doe",
Hidden: true,
};
const subject = new Subject(values);
assert.equal(subject.Hidden, true);
subject.toggleHidden();
assert.equal(subject.Hidden, false);
subject.toggleHidden();
assert.equal(subject.Hidden, true);
});
it("should return batch size", () => {
assert.equal(Subject.batchSize(), 60);
});