aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils/__tests__
diff options
context:
space:
mode:
authorstonedDiscord <stonedDiscord@users.noreply.github.com>2024-11-20 13:31:50 +0000
committerGitHub Action <actions@github.com>2024-11-20 13:31:50 +0000
commit6684f3fce6e90fd0574d7bab63b629554ab03ef6 (patch)
treeb2a62247d17e23a77af57aea355ba621666817c2 /webAO/utils/__tests__
parent95a2d1361d84c61b454ebe506e6963b93f6d8dee (diff)
Prettified Code!
Diffstat (limited to 'webAO/utils/__tests__')
-rw-r--r--webAO/utils/__tests__/aoml.test.ts152
-rw-r--r--webAO/utils/__tests__/paths.test.ts22
-rw-r--r--webAO/utils/__tests__/tryUrls.test.ts51
3 files changed, 108 insertions, 117 deletions
diff --git a/webAO/utils/__tests__/aoml.test.ts b/webAO/utils/__tests__/aoml.test.ts
index 78355ed..b5cd9b1 100644
--- a/webAO/utils/__tests__/aoml.test.ts
+++ b/webAO/utils/__tests__/aoml.test.ts
@@ -1,7 +1,7 @@
-import request from '../../services/request'
-import mlConfig from '../aoml';
+import request from "../../services/request";
+import mlConfig from "../aoml";
-jest.mock('../../services/request')
+jest.mock("../../services/request");
const networkRequest = `
c0 = 247, 247, 247
c0_name = White
@@ -34,80 +34,76 @@ c6_start = |
c6_end = |
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();
-
- });
-
- 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();
-
- });
-
- it('Should create an array of spans containing letters', async () => {
- const word = `hello`
- const actual = await 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`)
- expect(actual[0].getAttribute('style')).toBe('color: rgb(107, 198, 247);')
- })
- it('Should keep a letter if remove = 0', async () => {
- const config = mlConfig('localhost')
-
- const actual = await 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')
-
- const actual = await 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')
-
- const actual = await 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')
-
- const actual = await 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`)
- const expected = ``
- expect(actual[5].innerHTML).toBe(expected)
- })
-
-})
-
+mockRequest.mockReturnValue(Promise.resolve(networkRequest));
+
+describe("mlConfig", () => {
+ beforeEach(() => {
+ // Clear all instances and calls to constructor and all methods:
+ mockRequest.mockClear();
+ });
+
+ 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();
+ });
+
+ it("Should create an array of spans containing letters", async () => {
+ const word = `hello`;
+ const actual = await 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`);
+ expect(actual[0].getAttribute("style")).toBe("color: rgb(107, 198, 247);");
+ });
+ it("Should keep a letter if remove = 0", async () => {
+ const config = mlConfig("localhost");
+
+ const actual = await 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");
+
+ const actual = await 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");
+
+ const actual = await 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");
+
+ const actual = await 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`);
+ const expected = ``;
+ expect(actual[5].innerHTML).toBe(expected);
+ });
+});
diff --git a/webAO/utils/__tests__/paths.test.ts b/webAO/utils/__tests__/paths.test.ts
index 4f41d09..fe7b1bf 100644
--- a/webAO/utils/__tests__/paths.test.ts
+++ b/webAO/utils/__tests__/paths.test.ts
@@ -1,13 +1,11 @@
-import {getFilenameFromPath} from '../paths'
-jest.mock('../fileExists')
+import { getFilenameFromPath } from "../paths";
+jest.mock("../fileExists");
-describe('getFilenameFromPath', () => {
- const EXAMPLE_PATH = "localhost/stoneddiscord/assets.png"
- it('Should get the last value from a path', async () => {
- const actual = getFilenameFromPath(EXAMPLE_PATH);
- const expected = 'assets.png';
- expect(actual).toBe(expected);
- });
-})
-
-
+describe("getFilenameFromPath", () => {
+ const EXAMPLE_PATH = "localhost/stoneddiscord/assets.png";
+ it("Should get the last value from a path", async () => {
+ const actual = getFilenameFromPath(EXAMPLE_PATH);
+ const expected = "assets.png";
+ expect(actual).toBe(expected);
+ });
+});
diff --git a/webAO/utils/__tests__/tryUrls.test.ts b/webAO/utils/__tests__/tryUrls.test.ts
index ebc2f6b..f85392c 100644
--- a/webAO/utils/__tests__/tryUrls.test.ts
+++ b/webAO/utils/__tests__/tryUrls.test.ts
@@ -1,31 +1,28 @@
-import fileExists from '../fileExists'
-import tryUrls from '../tryUrls';
-import transparentPng from '../../constants/transparentPng'
-jest.mock('../fileExists')
+import fileExists from "../fileExists";
+import tryUrls from "../tryUrls";
+import transparentPng from "../../constants/transparentPng";
+jest.mock("../fileExists");
const mockFileExists = fileExists as jest.MockedFunction<typeof fileExists>;
-describe('tryUrls', () => {
- it('Should try multiple file extensions', async () => {
- const url = "localhost/stoneddiscord/assets"
- mockFileExists
- .mockReturnValueOnce(Promise.resolve(false))
- .mockReturnValueOnce(Promise.resolve(false))
- .mockReturnValueOnce(Promise.resolve(false))
- .mockReturnValueOnce(Promise.resolve(true))
- const actual = await tryUrls(url)
- const expected = 'localhost/stoneddiscord/assets.apng'
- expect(actual).toBe(expected);
- });
-
- it('Should return a transparent png if it cant find any assets', async () => {
- const url = "localhost/stoneddiscord/assets"
- mockFileExists
- .mockReturnValue(Promise.resolve(false))
- const actual = await tryUrls(url)
- const expected = transparentPng
- expect(actual).toBe(expected);
- });
-})
-
+describe("tryUrls", () => {
+ it("Should try multiple file extensions", async () => {
+ const url = "localhost/stoneddiscord/assets";
+ mockFileExists
+ .mockReturnValueOnce(Promise.resolve(false))
+ .mockReturnValueOnce(Promise.resolve(false))
+ .mockReturnValueOnce(Promise.resolve(false))
+ .mockReturnValueOnce(Promise.resolve(true));
+ const actual = await tryUrls(url);
+ const expected = "localhost/stoneddiscord/assets.apng";
+ expect(actual).toBe(expected);
+ });
+ it("Should return a transparent png if it cant find any assets", async () => {
+ const url = "localhost/stoneddiscord/assets";
+ mockFileExists.mockReturnValue(Promise.resolve(false));
+ const actual = await tryUrls(url);
+ const expected = transparentPng;
+ expect(actual).toBe(expected);
+ });
+});