Skip to content

Commit 04fc4e4

Browse files
committed
making a mess
1 parent 7ff80d1 commit 04fc4e4

File tree

8 files changed

+204
-5
lines changed

8 files changed

+204
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
test-results
12
.DS_Store
23
node_modules
34
/build

bun.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"devDependencies": {
1717
"@iconify-json/tabler": "^1.2.19",
18+
"@playwright/test": "^1.49.1",
1819
"@sveltejs/adapter-auto": "^6.0.1",
1920
"@sveltejs/kit": "^2.22.2",
2021
"@sveltejs/vite-plugin-svelte": "^5.1.0",
@@ -137,6 +138,8 @@
137138

138139
"@jridgewell/trace-mapping": ["@jridgewell/[email protected]", "", { "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ=="],
139140

141+
"@playwright/test": ["@playwright/[email protected]", "", { "dependencies": { "playwright": "1.53.1" }, "bin": { "playwright": "cli.js" } }, "sha512-Z4c23LHV0muZ8hfv4jw6HngPJkbbtZxTkxPNIg7cJcTc9C28N/p2q7g3JZS2SiKBBHJ3uM1dgDye66bB7LEk5w=="],
142+
140143
"@polka/url": ["@polka/[email protected]", "", {}, "sha512-8LduaNlMZGwdZ6qWrKlfa+2M4gahzFkprZiAt2TF8uS0qQgBizKXpXURqvTJ4WtmupWxaLqjRb2UCTe72mu+Aw=="],
141144

142145
"@popperjs/core": ["@popperjs/[email protected]", "", {}, "sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A=="],
@@ -519,6 +522,10 @@
519522

520523
"pkg-types": ["[email protected]", "", { "dependencies": { "confbox": "^0.1.8", "mlly": "^1.7.4", "pathe": "^2.0.1" } }, "sha512-/Jm5M4RvtBFVkKWRu2BLUTNP8/M2a+UwuAX+ae4770q1qVGtfjG+WTCupoZixokjmHiry8uI+dlY8KXYV5HVVQ=="],
521524

525+
"playwright": ["[email protected]", "", { "dependencies": { "playwright-core": "1.53.1" }, "optionalDependencies": { "fsevents": "2.3.2" }, "bin": { "playwright": "cli.js" } }, "sha512-LJ13YLr/ocweuwxyGf1XNFWIU4M2zUSo149Qbp+A4cpwDjsxRPj7k6H25LBrEHiEwxvRbD8HdwvQmRMSvquhYw=="],
526+
527+
"playwright-core": ["[email protected]", "", { "bin": { "playwright-core": "cli.js" } }, "sha512-Z46Oq7tLAyT0lGoFx4DOuB1IA9D1TPj0QkYxpPVUnGDqHHvDpCftu1J2hM2PiWsNMoZh8+LQaarAWcDfPBc6zg=="],
528+
522529
"postcss": ["[email protected]", "", { "dependencies": { "nanoid": "^3.3.8", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" } }, "sha512-dle9A3yYxlBSrt8Fu+IpjGT8SY8hN0mlaA6GY8t0P5PjIOZemULz/E2Bnm/2dcUOena75OTNkHI76uZBNUUq3A=="],
523530

524531
"prettier": ["[email protected]", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-5xGWRa90Sp2+x1dQtNpIpeOQpTDBs9cZDmA/qs2vDNN2i18PdapqY7CmBeyLlMuGqXJRIOPaCaVZTLNQRWUH/A=="],
@@ -731,6 +738,8 @@
731738

732739
"mlly/acorn": ["[email protected]", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA=="],
733740

741+
"playwright/fsevents": ["[email protected]", "", { "os": "darwin" }, "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA=="],
742+
734743
"pretty-format/ansi-styles": ["[email protected]", "", {}, "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA=="],
735744

736745
"strip-literal/js-tokens": ["[email protected]", "", {}, "sha512-mxa9E9ITFOt0ban3j6L5MpjwegGz6lBQmM1IJkWeBZGcMxto50+eWdjC/52xDbS2vy0k7vIMK0Fe2wfL9OQSpQ=="],

e2e/demo.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
test.beforeEach(async ({ page }) => {
4+
await page.goto("/")
5+
})
6+
7+
test("home page loads", async ({ page }) => {
8+
const resp = await page.goto("/")
9+
expect(resp).toBeDefined()
10+
expect(resp?.ok()).toBe(true);
11+
});
12+
13+
test("blank text updates with formatted output", async ({ page }) => {
14+
await page.getByLabel("Keybinds").waitFor()
15+
const textbox = page.getByRole('textbox').nth(1)
16+
await textbox.click();
17+
await textbox.fill("lorem ipsum")
18+
const output = page.locator("#outputbox").first();
19+
await expect(output).toHaveText(`"lorem ipsum"`);
20+
})
21+
22+
test("does the bold button work", async ({ page }) => {
23+
const textbox = page.getByRole('textbox').nth(1)
24+
await textbox.click();
25+
await textbox.fill("lorem ipsum")
26+
await textbox.selectText()
27+
let button = page.getByRole("button", { name: "Bold " })
28+
await button.click();
29+
await expect(await textbox.locator("p>strong").count()).toBeGreaterThan(0)
30+
await expect(textbox.locator("p>strong").first()).toHaveCSS("font-family", "MinecraftBold")
31+
})
32+
33+
test("does the italic button work", async ({ page }) => {
34+
const textbox = page.getByRole("textbox").nth(1);
35+
await textbox.click();
36+
await textbox.fill("lorem ipsum");
37+
await textbox.selectText();
38+
let button = page.getByRole("button", { name: "Italic " });
39+
await button.click();
40+
await expect(await textbox.locator("p>em").count()).toBeGreaterThan(0);
41+
await expect(textbox.locator("p>em").first()).toHaveCSS(
42+
"font-style",
43+
"italic",
44+
);
45+
})

package-lock.json

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
1111
"format": "prettier . --write . --cache",
1212
"test:unit": "vitest",
13-
"test": "npm run test:unit -- --run"
13+
"test": "npm run test:unit -- --run && npm run test:e2e",
14+
"test:e2e": "playwright test"
1415
},
1516
"devDependencies": {
1617
"@iconify-json/tabler": "^1.2.19",
18+
"@playwright/test": "^1.49.1",
1719
"@sveltejs/adapter-auto": "^6.0.1",
1820
"@sveltejs/kit": "^2.22.2",
1921
"@sveltejs/vite-plugin-svelte": "^5.1.0",

playwright.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from "@playwright/test";
2+
3+
export default defineConfig({
4+
webServer: {
5+
command: "npm run build && npm run preview",
6+
port: 4173,
7+
},
8+
testDir: "e2e",
9+
});

src/routes/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@
556556
<IconCopy />
557557
{/if}</button>
558558
<p>
559-
<code class="inline break-all"
559+
<code id="outputbox" class="inline break-all"
560560
>{editor
561561
? convert(tiptapJSON!, "standard", outputVersion, shouldOptimise)
562562
: "Loading..."}

src/tests/translating_mc_json.spec.ts

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { translate } from "$lib/text/nbt_or_json";
1+
import { addTypeSpecificValues, translate } from "$lib/text/nbt_or_json";
2+
import type { MinecraftText, TranslateOptions } from "$lib/types";
3+
import type { JSONContent } from "@tiptap/core";
24
import { describe, expect, it } from "vitest";
35
import { readTestDataFile, readTestJSONFile } from "./test_utils";
4-
import type { TranslateOptions } from "$lib/types";
5-
import type { JSONContent } from "@tiptap/core";
66

77
describe("translate", () => {
88
it("should return a basic string", () => {
@@ -193,3 +193,72 @@ describe("translate", () => {
193193
expect(result).toBe("[]");
194194
});
195195
});
196+
197+
describe("adding type props", () => {
198+
it("should add text property for type 'text'", () => {
199+
const current: MinecraftText = {};
200+
const c: JSONContent = { type: "text", text: "hello" };
201+
const result = addTypeSpecificValues(current, c, false);
202+
expect(result.text).toBe("hello");
203+
});
204+
205+
it("should add score property for type 'score'", () => {
206+
const current: MinecraftText = {};
207+
const c: JSONContent = {
208+
type: "score",
209+
attrs: { name: "player", objective: "obj" },
210+
};
211+
const result = addTypeSpecificValues(current, c, false);
212+
expect(result.score).toEqual({ name: "player", objective: "obj" });
213+
});
214+
215+
it("should add translate, with, and fallback for type 'translate'", () => {
216+
const current: MinecraftText = {};
217+
const c: JSONContent = {
218+
type: "translate",
219+
attrs: {
220+
key: "translation.key",
221+
params: ["param1", "param2"],
222+
fallback: "fallback text",
223+
},
224+
};
225+
const result = addTypeSpecificValues(current, c, false);
226+
expect(result.translate).toBe("translation.key");
227+
expect(result.with).toEqual(["param1", "param2"]);
228+
expect(result.fallback).toBe("fallback text");
229+
});
230+
231+
it("should add nbt, storage, block, entity, interpret for nbt types", () => {
232+
const current: MinecraftText = {};
233+
const c: JSONContent = {
234+
type: "storage_nbt",
235+
attrs: {
236+
nbt: "someNbt",
237+
storage: "someStorage",
238+
block: "someBlock",
239+
entity: "someEntity",
240+
interpret: true,
241+
},
242+
};
243+
const result = addTypeSpecificValues(current, c, false);
244+
expect(result.nbt).toBe("someNbt");
245+
expect(result.storage).toBe("someStorage");
246+
expect(result.block).toBe("someBlock");
247+
expect(result.entity).toBe("someEntity");
248+
expect(result.interpret).toBe(true);
249+
});
250+
251+
it("should add keybind property for type 'keybind'", () => {
252+
const current: MinecraftText = {};
253+
const c: JSONContent = { type: "keybind", attrs: { key: "key.jump" } };
254+
const result = addTypeSpecificValues(current, c, false);
255+
expect(result.keybind).toBe("key.jump");
256+
});
257+
258+
it("should add selector property for type 'selector'", () => {
259+
const current: MinecraftText = {};
260+
const c: JSONContent = { type: "selector", attrs: { selector: "@a" } };
261+
const result = addTypeSpecificValues(current, c, false);
262+
expect(result.selector).toBe("@a");
263+
});
264+
});

0 commit comments

Comments
 (0)