aboutsummaryrefslogtreecommitdiff
path: root/webAO/__tests__
diff options
context:
space:
mode:
authorstonedDiscord <Tukz@gmx.de>2026-01-01 16:56:51 +0100
committerGitHub <noreply@github.com>2026-01-01 16:56:51 +0100
commit33744e44ceaf3825da451ba38281fd84b255de80 (patch)
treee6c080d7e8e6f56652c2269a380eff40b899a065 /webAO/__tests__
parente07fe372bc20d16eb590b68ed256007312b3801a (diff)
parent01ecb948edb015613e05bc2b6da4021137957745 (diff)
Merge pull request #286 from AttorneyOnline/bnnuy
Bnnuy
Diffstat (limited to 'webAO/__tests__')
-rw-r--r--webAO/__tests__/aoml.test.ts67
-rw-r--r--webAO/__tests__/isLowMemory.test.ts22
-rw-r--r--webAO/__tests__/setEmote.test.js140
3 files changed, 44 insertions, 185 deletions
diff --git a/webAO/__tests__/aoml.test.ts b/webAO/__tests__/aoml.test.ts
index b799da6..d612945 100644
--- a/webAO/__tests__/aoml.test.ts
+++ b/webAO/__tests__/aoml.test.ts
@@ -1,8 +1,4 @@
-import request from "../services/request";
-import mlConfig from "../utils/aoml";
-
-jest.mock("../services/request");
-const networkRequest = `
+const configIni = `
c0 = 247, 247, 247
c0_name = White
c0_talking = 1
@@ -36,73 +32,56 @@ c6_remove = 0
c6_talking = 0
`;
-const mockRequest = request as jest.MockedFunction<typeof request>;
-mockRequest.mockReturnValue(Promise.resolve(networkRequest));
-
-describe("mlConfig", () => {
- beforeEach(() => {
- // Clear all instances and calls to constructor and all methods:
- mockRequest.mockClear();
- });
+import mlConfig from "../utils/aoml";
- it("Should make a network request", () => {
- mlConfig("localhost");
- expect(mockRequest).toHaveBeenCalledTimes(1);
- });
-});
describe("applyMarkdown", () => {
- const config = mlConfig("localhost");
-
- beforeEach(() => {
- // Clear all instances and calls to constructor and all methods:
- mockRequest.mockClear();
- });
+ const config = mlConfig(configIni);
- it("Should create an array of spans containing letters", async () => {
+ it("Should create an array of spans containing letters", () => {
const word = `hello`;
- const actual = await config.applyMarkdown(`hello`, `blue`);
+ const actual = config.applyMarkdown(`hello`, `blue`);
let index = 0;
for (const element of actual) {
expect(element.innerHTML).toBe(word[index]);
index++;
}
});
- it("Should add colors based on settings", async () => {
- const config = mlConfig("localhost");
- const actual = await config.applyMarkdown(`(heya)`, `blue`);
+ it("Should add colors based on settings", () => {
+ const config = mlConfig(configIni);
+ const actual = config.applyMarkdown(`(heya)`, `blue`);
expect(actual[0].getAttribute("style")).toBe("color: rgb(107, 198, 247);");
});
- it("Should keep a letter if remove = 0", async () => {
- const config = mlConfig("localhost");
+ it("Should keep a letter if remove = 0", () => {
+ const config = mlConfig(configIni);
- const actual = await config.applyMarkdown(`(What())Hey!`, `white`);
+ const actual = config.applyMarkdown(`(What())Hey!`, `white`);
const expected = `(`;
expect(actual[5].innerHTML).toBe(expected);
});
- it("Should remove a letter if remove = 1", async () => {
- const config = mlConfig("localhost");
+ it("Should remove a letter if remove = 1", () => {
+ const config = mlConfig(configIni);
- const actual = await config.applyMarkdown(`~What~()Hey!`, `white`);
+ const actual = config.applyMarkdown(`~What~()Hey!`, `white`);
const expected = ``;
expect(actual[0].innerHTML).toBe(expected);
});
- it("Should remove a letter if remove = 1", async () => {
- const config = mlConfig("localhost");
+ it("Should remove a letter if remove = 1", () => {
+ const config = mlConfig(configIni);
- const actual = await config.applyMarkdown(`~What~()Hey!`, `white`);
+ const actual = config.applyMarkdown(`~What~()Hey!`, `white`);
const expected = ``;
expect(actual[0].innerHTML).toBe(expected);
});
- it("Should keep a closing letter if remove = 0", async () => {
- const config = mlConfig("localhost");
+ it("Should keep a closing letter if remove = 0", () => {
+ const config = mlConfig(configIni);
- const actual = await config.applyMarkdown(`~NO[]~!`, `white`);
+ const actual = config.applyMarkdown(`~NO[]~!`, `white`);
const expected = ``;
expect(actual[4].innerHTML).toBe(expected);
});
- it("Should remove a closing letter if remove = 1", async () => {
- const config = mlConfig("localhost");
- const actual = await config.applyMarkdown(`~NO||~!`, `white`);
+ it("Should remove a closing letter if remove = 1", () => {
+ const config = mlConfig(configIni);
+ const actual = config.applyMarkdown(`~NO||~!`, `white`);
const expected = ``;
expect(actual[5].innerHTML).toBe(expected);
});
diff --git a/webAO/__tests__/isLowMemory.test.ts b/webAO/__tests__/isLowMemory.test.ts
index 6428e17..870b40e 100644
--- a/webAO/__tests__/isLowMemory.test.ts
+++ b/webAO/__tests__/isLowMemory.test.ts
@@ -1,11 +1,31 @@
import { isLowMemory } from '../client/isLowMemory';
import { setOldLoading } from '../client';
+import { AO_HOST, setAOhost } from '../client/aoHost';
-// Mock the setOldLoading function
+// Mock the setOldLoading function and prevent any network requests
jest.mock('../client', () => ({
setOldLoading: jest.fn(),
}));
+// Mock any potential network requests
+jest.mock('../services/request', () => ({
+ __esModule: true,
+ default: jest.fn().mockResolvedValue(''),
+ request: jest.fn().mockResolvedValue(''),
+ requestBuffer: jest.fn().mockResolvedValue(new ArrayBuffer(0)),
+}));
+
+// Mock the fileExists function to prevent network requests
+jest.mock('../utils/fileExists', () => ({
+ __esModule: true,
+ default: jest.fn().mockResolvedValue(false),
+}));
+
+// Set AO_HOST to a valid URL before tests run
+beforeAll(() => {
+ setAOhost('https://example.com/');
+});
+
describe('isLowMemory', () => {
beforeEach(() => {
// Reset mock before each test to ensure isolation
diff --git a/webAO/__tests__/setEmote.test.js b/webAO/__tests__/setEmote.test.js
deleted file mode 100644
index 3a4a521..0000000
--- a/webAO/__tests__/setEmote.test.js
+++ /dev/null
@@ -1,140 +0,0 @@
-import setEmote from "../client/setEmote.ts";
-import Client from "../client.ts";
-import fileExists from "../utils/fileExists.ts";
-import transparentPng from "../constants/transparentPng.js";
-
-jest.mock("../viewport/utils/createMusic");
-jest.mock("../utils/fileExists");
-jest.mock("../viewport/utils/createSfxAudio");
-jest.mock("../viewport/utils/createShoutAudio");
-jest.mock("../viewport/utils/createTestimonyAudio");
-describe("setEmote", () => {
- const AO_HOST = "";
-
- const client = new Client("127.0.0.1");
- const firstExtension = ".gif";
-
- test("Should have a client_def_char_img with a valid source", async () => {
- fileExists.mockReturnValue(true);
- document.body.innerHTML = `
- <img id="client_def_char_img" />
- `;
- await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 0, "def");
- const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`;
- expect(document.getElementById("client_def_char_img").src).toEqual(
- expected,
- );
- });
- test("Should have a client_pro_char_img to have a valid src", async () => {
- document.body.innerHTML = `
- <img id="client_pro_char_img" />
-
- `;
- await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 0, "pro");
- const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`;
- expect(document.getElementById("client_pro_char_img").src).toEqual(
- expected,
- );
- });
- test("Should have a client_wit_char_img", async () => {
- document.body.innerHTML = `
- <img id="client_wit_char_img" />
- `;
- await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 0, "wit");
- const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`;
-
- expect(document.getElementById("client_wit_char_img").src).toEqual(
- expected,
- );
- });
- test("Should have a client_def_pair_img", async () => {
- document.body.innerHTML = `
-<img id="client_def_pair_img" />
-
-`;
- await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 1, "def");
- const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`;
-
- expect(document.getElementById("client_def_pair_img").src).toEqual(
- expected,
- );
- });
- test("Should have a client_pro_pair_img", async () => {
- document.body.innerHTML = `
-<img id="client_pro_pair_img" />
-
-`;
- await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 1, "pro");
- const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`;
-
- expect(document.getElementById("client_pro_pair_img").src).toEqual(
- expected,
- );
- });
- test("Should have a client_wit_pair_img", async () => {
- document.body.innerHTML = `
-<img id="client_wit_pair_img" />
-
-`;
- await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 1, "wit");
- const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`;
-
- expect(document.getElementById("client_wit_pair_img").src).toEqual(
- expected,
- );
- });
- test("Should have a client_char_img", async () => {
- document.body.innerHTML = `
- <img id="client_char_img" />
-
- `;
- await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 0, "notvalid");
- const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`;
-
- expect(document.getElementById("client_char_img").src).toEqual(expected);
- });
- test("Should have a client_pair_img", async () => {
- document.body.innerHTML = `
- <img id="client_pair_img" />
- `;
- await setEmote(AO_HOST, client, "salanto", "coding", "(a)", 1, "notvalid");
- const expected = `http://localhost/characters/salanto/(a)coding${firstExtension}`;
-
- expect(document.getElementById("client_pair_img").src).toEqual(expected);
- });
- test("Should handle .png urls differently", async () => {
- fileExists.mockReturnValueOnce(false);
- document.body.innerHTML = `
- <img id="client_pair_img" />
- `;
- await setEmote(
- AO_HOST,
- client,
- "salanto",
- "coding",
- "prefixNotValid",
- 1,
- "notvalid",
- );
- const expected = "http://localhost/characters/salanto/coding.png";
-
- expect(document.getElementById("client_pair_img").src).toEqual(expected);
- });
- test("Should replace character if new character responds", async () => {
- fileExists.mockReturnValue(false);
- document.body.innerHTML = `
- <img id="client_pair_img" />
- `;
- await setEmote(
- AO_HOST,
- client,
- "salanto",
- "coding",
- "prefixNotValid",
- 1,
- "notvalid",
- );
- const expected = transparentPng;
- expect(document.getElementById("client_pair_img").src).toEqual(expected);
- });
-});