Frontend: Add unit tests

This commit is contained in:
Theresa Gresch 2020-10-19 11:36:07 +02:00
parent 1aaec319b1
commit bb30a841c4
3 changed files with 131 additions and 1 deletions

View file

@ -51,13 +51,41 @@ describe("model/album", () => {
assert.equal(result, "Jul 8, 2012, 2:45 PM");
});
it("should get album date string", () => {
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");
});
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, "2020");
});
it("should get model name", () => {
const result = Album.getModelName();
assert.equal(result, "Album");

View file

@ -34,6 +34,7 @@ mock
Type: "mp4",
Hash: "1xxbgdt55"}]})
.onDelete("api/v1/photos/abc123/unlike").reply(200)
.onDelete("api/v1/photos/pqbemz8276mhtobh/files/fqbfk181n4ca5sud").reply(200, {"success": "successfully deleted"})
.onPost("api/v1/photos/pqbemz8276mhtobh/files/fqbfk181n4ca5sud/unstack").reply(200, {"success": "ok"})
.onPost("api/v1/photos/pqbemz8276mhtobh/label", {Name: "Cat", Priority: 10}).reply(200, {"success": "ok"})
.onPut("api/v1/photos/pqbemz8276mhtobh/label/12345", {Uncertainty: 0}).reply(200, {"success": "ok"})
@ -119,6 +120,53 @@ describe("model/photo", () => {
assert.equal(result.height, 160);
});
it("should get local day string", () => {
const values = {ID: 5, Title: "Crazy Cat", TakenAt: "2012-07-08T14:45:39Z", TimeZone: "UTC"};
const photo = new Photo(values);
const result = photo.localDayString();
assert.equal(result, "01");
const values2 = {ID: 5, Title: "Crazy Cat", TakenAtLocal: "2012-07-08T14:45:39Z", TakenAt: "2012-07-08T14:45:39Z", TimeZone: "UTC", Day: 8};
const photo2 = new Photo(values2);
const result2 = photo2.localDayString();
assert.equal(result2, "08");
});
it("should get local month string", () => {
const values = {ID: 5, Title: "Crazy Cat", TakenAt: "2012-07-08T14:45:39Z", TimeZone: "UTC"};
const photo = new Photo(values);
const result = photo.localMonthString();
assert.equal(result, "09");
const values2 = {ID: 5, Title: "Crazy Cat", TakenAtLocal: "2012-07-08T14:45:39Z", TakenAt: "2012-07-08T14:45:39Z", TimeZone: "UTC", Month: 8};
const photo2 = new Photo(values2);
const result2 = photo2.localMonthString();
assert.equal(result2, "08");
});
it("should get local year string", () => {
const values = {ID: 5, Title: "Crazy Cat", TakenAt: "2012-07-08T14:45:39Z", TimeZone: "UTC"};
const photo = new Photo(values);
const result = photo.localYearString();
assert.equal(result, "2020");
const values2 = {ID: 5, Title: "Crazy Cat", TakenAtLocal: "2012-07-08T14:45:39Z", TakenAt: "2012-07-08T14:45:39Z", TimeZone: "UTC", Year: 2010};
const photo2 = new Photo(values2);
const result2 = photo2.localYearString();
assert.equal(result2, "2010");
});
it("should get local date string", () => {
const values = {ID: 5, Title: "Crazy Cat", TakenAtLocal: "2012-07-08T14:45:39Z", TakenAt: "2012-07-08T14:45:39Z", TimeZone: "UTC"};
const photo = new Photo(values);
const result = photo.localDateString();
assert.equal(result, "2012-07-08T14:45:39");
});
it("should get local date", () => {
const values = {ID: 5, Title: "Crazy Cat", TakenAt: "2012-07-08T14:45:39Z", TimeZone: "Indian/Reunion"};
const photo = new Photo(values);
const result = photo.localDate();
assert.equal(String(result), "2012-07-08T14:45:39.000Z");
});
it("should get date string", () => {
const values = {ID: 5, Title: "Crazy Cat", TakenAtLocal: "2012-07-08T14:45:39Z", TakenAt: "2012-07-08T14:45:39Z", TimeZone: "UTC"};
const photo = new Photo(values);
@ -132,6 +180,14 @@ describe("model/photo", () => {
const photo3 = new Photo(values3);
const result3 = photo3.getDateString();
assert.equal(result3, "Sunday, July 8, 2012");
const values4 = {ID: 5, Title: "Crazy Cat", TakenAtLocal: "2012-07-08T14:45:39Z", TakenAt: "2012-07-08T14:45:39Z", Month: -1};
const photo4 = new Photo(values4);
const result4 = photo4.getDateString();
assert.equal(result4, "2012");
const values5 = {ID: 5, Title: "Crazy Cat", TakenAtLocal: "2012-07-08T14:45:39Z", TakenAt: "2012-07-08T14:45:39Z", Day: -1};
const photo5 = new Photo(values5);
const result5 = photo5.getDateString();
assert.equal(result5, "July 2012");
});
it("should get short date string", () => {
@ -147,6 +203,14 @@ describe("model/photo", () => {
const photo3 = new Photo(values3);
const result3 = photo3.shortDateString();
assert.equal(result3, "Jul 8, 2012");
const values4 = {ID: 5, Title: "Crazy Cat", TakenAtLocal: "2012-07-08T14:45:39Z", TakenAt: "2012-07-08T14:45:39Z", Month: -1};
const photo4 = new Photo(values4);
const result4 = photo4.shortDateString();
assert.equal(result4, "2012");
const values5 = {ID: 5, Title: "Crazy Cat", TakenAtLocal: "2012-07-08T14:45:39Z", TakenAt: "2012-07-08T14:45:39Z", Day: -1};
const photo5 = new Photo(values5);
const result5 = photo5.shortDateString();
assert.equal(result5, "July 2012");
});
it("should test whether photo has location", () => {
@ -633,6 +697,35 @@ describe("model/photo", () => {
);
});
it("should delete file", (done) => {
const values = {
ID: 10,
UID: "pqbemz8276mhtobh",
Files: [{
UID: "fqbfk181n4ca5sud",
Name: "1980/01/superCuteKitten.mp4",
Primary: false,
Type: "mp4",
Hash: "1xxbgdt55"},
{
UID: "fqbfk181n4ca5abc",
Name: "1980/01/superCuteKitten.mp4",
Primary: true,
Type: "mp4",
Hash: "1xxbgdt89"}]};
const photo = new Photo(values);
photo.deleteFile("fqbfk181n4ca5sud").then(
(response) => {
assert.equal(response.success, "successfully deleted");
done();
}
).catch(
(error) => {
done(error);
}
);
});
it("should add label", (done) => {
const values = {
ID: 10,

View file

@ -133,6 +133,12 @@ describe("model/thumb", () => {
});
it("should test from files", () => {
const Photos = [];
const result = Thumb.fromFiles(Photos);
assert.equal(result, "");
});
it("should test from photo", () => {
const values = {
ID: 8,
@ -260,6 +266,9 @@ describe("model/thumb", () => {
const result2 = Thumb.calculateSize(file3, 900, 450);
assert.equal(result2.width, 397);
assert.equal(result2.height, 450);
const result4 = Thumb.calculateSize(file3, 900, 950);
assert.equal(result4.width, 750);
assert.equal(result4.height, 850);
});
});