|
1 | 1 | import { expect, test } from "@playwright/experimental-ct-svelte";
|
2 | 2 | import Highlight from "./Highlight.test.svelte";
|
3 | 3 | import HighlightAuto from "./HighlightAuto.test.svelte";
|
| 4 | +import LineNumbersCustomStartingLine from "./LineNumbers.customStartingLine.test.svelte"; |
| 5 | +import LineNumbersHideBorder from "./LineNumbers.hideBorder.test.svelte"; |
4 | 6 | import LineNumbers from "./LineNumbers.test.svelte";
|
| 7 | +import LineNumbersWrapLines from "./LineNumbers.wrapLines.test.svelte"; |
5 | 8 | import SvelteHighlight from "./SvelteHighlight.test.svelte";
|
| 9 | + |
6 | 10 | test.use({ viewport: { width: 1200, height: 600 } });
|
7 | 11 |
|
8 | 12 | test("Highlight", async ({ mount, page }) => {
|
@@ -32,10 +36,61 @@ test("SvelteHighlight", async ({ mount, page }) => {
|
32 | 36 | await expect(page.locator(".hljs-attr")).toHaveText("on:click");
|
33 | 37 | });
|
34 | 38 |
|
35 |
| -test("LineNumbers", async ({ mount, page }) => { |
| 39 | +test("LineNumbers - basic functionality", async ({ mount, page }) => { |
36 | 40 | await mount(LineNumbers);
|
37 | 41 | await expect(page.getByText("1")).toBeVisible();
|
38 | 42 |
|
39 | 43 | await expect(page.locator(".hljs-keyword")).toHaveText("const");
|
40 | 44 | await expect(page.locator(".hljs-title")).toHaveText("add");
|
| 45 | + |
| 46 | + const lineNumbersColumn = page.locator("td.hljs").first(); |
| 47 | + await expect(lineNumbersColumn).toHaveCSS("position", "sticky"); |
| 48 | + await expect(lineNumbersColumn).not.toHaveClass(/hideBorder/); |
| 49 | +}); |
| 50 | + |
| 51 | +test("LineNumbers - hide border", async ({ mount, page }) => { |
| 52 | + await mount(LineNumbersHideBorder); |
| 53 | + |
| 54 | + const lineNumbersColumn = page.locator("td.hljs").first(); |
| 55 | + await expect(lineNumbersColumn).toHaveClass(/hideBorder/); |
| 56 | +}); |
| 57 | + |
| 58 | +test("LineNumbers - wrap lines", async ({ mount, page }) => { |
| 59 | + await mount(LineNumbersWrapLines); |
| 60 | + |
| 61 | + const preElement = page.locator("pre.wrapLines"); |
| 62 | + await expect(preElement).toBeVisible(); |
| 63 | +}); |
| 64 | + |
| 65 | +test("LineNumbers - custom starting number", async ({ mount, page }) => { |
| 66 | + await mount(LineNumbersCustomStartingLine); |
| 67 | + |
| 68 | + await expect(page.getByText("100")).toBeVisible(); |
| 69 | +}); |
| 70 | + |
| 71 | +test("Language tag styling", async ({ mount, page }) => { |
| 72 | + await mount(Highlight, { |
| 73 | + props: { |
| 74 | + langtag: true, |
| 75 | + code: "const x = 1;", |
| 76 | + language: { name: "javascript", register: () => {} }, |
| 77 | + style: "--langtag-background: red; --langtag-color: white;", |
| 78 | + }, |
| 79 | + }); |
| 80 | + |
| 81 | + const langTag = page.locator("[data-language]"); |
| 82 | + await expect(langTag).toBeVisible(); |
| 83 | + // Could add more specific style checks if needed |
| 84 | +}); |
| 85 | + |
| 86 | +test("Auto-highlighting detects language", async ({ mount, page }) => { |
| 87 | + await mount(HighlightAuto, { |
| 88 | + props: { |
| 89 | + code: "body { color: red; }", |
| 90 | + }, |
| 91 | + }); |
| 92 | + |
| 93 | + // Should detect CSS and apply appropriate highlighting |
| 94 | + await expect(page.locator(".hljs-selector-tag")).toBeVisible(); |
| 95 | + await expect(page.locator("pre")).toHaveAttribute("data-language", "css"); |
41 | 96 | });
|
0 commit comments