photoprism/frontend/tests/unit/common/util_test.js
Michael Mayer 26560e8d71 Frontend: Upgrade Webpack from v4 to v5
Most frontend packages have been upgraded as part of this commit.
JS unit tests have been refactored alongside.
2021-07-12 19:25:37 +02:00

57 lines
1.7 KiB
JavaScript

import "../fixtures";
import Util from "common/util";
let chai = require("chai/chai");
let assert = chai.assert;
describe("common/util", () => {
it("should return duration 3ns", () => {
const duration = Util.duration(-3);
assert.equal(duration, "3ns");
});
it("should return duration 0s", () => {
const duration = Util.duration(0);
assert.equal(duration, "0s");
});
it("should return duration 2µs", () => {
const duration = Util.duration(2000);
assert.equal(duration, "2µs");
});
it("should return duration 4ms", () => {
const duration = Util.duration(4000000);
assert.equal(duration, "4ms");
});
it("should return duration 6s", () => {
const duration = Util.duration(6000000000);
assert.equal(duration, "00:00:06");
});
it("should return duration 10min", () => {
const duration = Util.duration(600000000000);
assert.equal(duration, "00:10:00");
});
it("should convert -1 to roman", () => {
const roman = Util.arabicToRoman(-1);
assert.equal(roman, "");
});
it("should convert 2500 to roman", () => {
const roman = Util.arabicToRoman(2500);
assert.equal(roman, "MMD");
});
it("should convert 112 to roman", () => {
const roman = Util.arabicToRoman(112);
assert.equal(roman, "CXII");
});
it("should convert 9 to roman", () => {
const roman = Util.arabicToRoman(9);
assert.equal(roman, "IX");
});
it("should truncate xxx", () => {
const result = Util.truncate("teststring");
assert.equal(result, "teststring");
});
it("should truncate xxx", () => {
const result = Util.truncate("teststring for mocha", 5, "ng");
assert.equal(result, "tesng");
});
});