Added StringHelpers, UniqIdGenerators and UrlParser test
UniqIdGenerators skips window.crypt test URL tests need to be more in detail
This commit is contained in:
60
tests/StringHelpers.test.js
Normal file
60
tests/StringHelpers.test.js
Normal file
@@ -0,0 +1,60 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
import {
|
||||
formatString,
|
||||
numberWithCommas,
|
||||
convertLBtoBR
|
||||
} from '../src/utils/StringHelpers.mjs';
|
||||
|
||||
describe("formatString", () => {
|
||||
it('Should replace {n} entries in strings', () => {
|
||||
expect(
|
||||
formatString("{0} is cool, {1} is not", "Alpha", "Beta")
|
||||
).toBe("Alpha is cool, Beta is not");
|
||||
expect(
|
||||
formatString("{0} is cool, {1} is not", "Alpha")
|
||||
).toBe("Alpha is cool, {1} is not");
|
||||
});
|
||||
});
|
||||
|
||||
describe("numberWithCommas", () => {
|
||||
it('Should format a number into a decimal formatted', () => {
|
||||
let numbers_list = [
|
||||
{
|
||||
"in": 123,
|
||||
"out": "123",
|
||||
},
|
||||
{
|
||||
"in": 1234,
|
||||
"out": "1,234"
|
||||
},
|
||||
{
|
||||
"in": 12345,
|
||||
"out": "12,345"
|
||||
},
|
||||
{
|
||||
"in": 123456,
|
||||
"out": "123,456"
|
||||
},
|
||||
{
|
||||
"in": 1234567,
|
||||
"out": "1,234,567"
|
||||
},
|
||||
{
|
||||
"in": 1234567890,
|
||||
"out": "1,234,567,890"
|
||||
},
|
||||
];
|
||||
for (let number of numbers_list) {
|
||||
expect(numberWithCommas(number.in)).toBe(number.out);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("convertLBtoBR", () => {
|
||||
it('Should convert LF/CR to <br>', () => {
|
||||
expect(convertLBtoBR("AB\nCD")).toBe("AB<br>CD");
|
||||
});
|
||||
});
|
||||
|
||||
// __END__
|
||||
29
tests/UniqIdGenerators.test.js
Normal file
29
tests/UniqIdGenerators.test.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
import {
|
||||
// generateId,
|
||||
randomIdF,
|
||||
} from '../src/utils/UniqIdGenerators.mjs';
|
||||
|
||||
// window. is not defined in headless mode
|
||||
// TODO: fix
|
||||
/* describe("generateId", () => {
|
||||
it('Should create a random id in defined length', () => {
|
||||
let len_list = [
|
||||
1, 12, 24, 32, 64
|
||||
];
|
||||
for (let len of len_list) {
|
||||
expect(generateId(len)).lengthOf(len);
|
||||
}
|
||||
});
|
||||
}); */
|
||||
|
||||
describe("randomIdF", () => {
|
||||
it('Should create a 10 character long random id', () => {
|
||||
let rand_id = randomIdF();
|
||||
expect(rand_id).lengthOf(11);
|
||||
expect(rand_id).match(/^[a-z0-9]{11}$/);
|
||||
});
|
||||
});
|
||||
|
||||
// __END__
|
||||
22
tests/UrlParser.test.js
Normal file
22
tests/UrlParser.test.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
|
||||
import {
|
||||
parseQueryString,
|
||||
getQueryStringParam,
|
||||
} from '../src/utils/UrlParser.mjs';
|
||||
|
||||
describe("parseQueryString", () => {
|
||||
it('Should parse query string for key', () => {
|
||||
let kv = parseQueryString("http://foor.org?key=value");
|
||||
expect(kv).toEqual({"http://foor.org?key": "value"});
|
||||
});
|
||||
});
|
||||
|
||||
describe("getQueryStringParam", () => {
|
||||
it('Should parse query string for key', () => {
|
||||
let kv = getQueryStringParam("key", "http://foor.org?key=value");
|
||||
expect(kv).toEqual("value");
|
||||
});
|
||||
});
|
||||
|
||||
// __END__
|
||||
Reference in New Issue
Block a user