2024-06-07 23:33:45 +01:00
|
|
|
import {expect, describe, it, beforeAll} from "vitest";
|
2024-05-06 16:30:23 +01:00
|
|
|
import { randomString, padInt } from "./utils";
|
2024-03-31 00:47:47 +00:00
|
|
|
|
|
|
|
import Phaser from "phaser";
|
|
|
|
|
|
|
|
describe("utils", () => {
|
2024-06-07 23:33:45 +01:00
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
new Phaser.Game({
|
|
|
|
type: Phaser.HEADLESS,
|
|
|
|
});
|
|
|
|
});
|
2024-03-31 00:47:47 +00:00
|
|
|
describe("randomString", () => {
|
|
|
|
it("should return a string of the specified length", () => {
|
|
|
|
const str = randomString(10);
|
|
|
|
expect(str.length).toBe(10);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should work with seed", () => {
|
|
|
|
const state = Phaser.Math.RND.state();
|
|
|
|
const str1 = randomString(10, true);
|
|
|
|
Phaser.Math.RND.state(state);
|
|
|
|
const str2 = randomString(10, true);
|
|
|
|
|
|
|
|
expect(str1).toBe(str2);
|
|
|
|
});
|
|
|
|
});
|
2024-05-06 16:30:23 +01:00
|
|
|
|
|
|
|
describe("padInt", () => {
|
|
|
|
it("should return a string", () => {
|
|
|
|
const result = padInt(1, 10);
|
2024-05-23 16:03:10 +01:00
|
|
|
expect(typeof result).toBe("string");
|
2024-05-06 16:30:23 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should return a padded result with default padWith", () => {
|
|
|
|
const result = padInt(1, 3);
|
2024-05-23 16:03:10 +01:00
|
|
|
expect(result).toBe("001");
|
2024-05-06 16:30:23 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should return a padded result using a custom padWith", () => {
|
2024-05-23 16:03:10 +01:00
|
|
|
const result = padInt(1, 10, "yes");
|
|
|
|
expect(result).toBe("yesyesyes1");
|
2024-05-06 16:30:23 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should return inputted value when zero length is entered", () => {
|
|
|
|
const result = padInt(1, 0);
|
2024-05-23 16:03:10 +01:00
|
|
|
expect(result).toBe("1");
|
|
|
|
});
|
2024-05-06 16:30:23 +01:00
|
|
|
});
|
2024-03-31 00:47:47 +00:00
|
|
|
});
|