61 lines
1.1 KiB
JavaScript
61 lines
1.1 KiB
JavaScript
|
|
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__
|