blob: 6dc2745d18d070c0e4f75fcd4924b229775d449e [file] [log] [blame]
banksean2be768e2025-07-18 16:41:39 +00001import { test, expect } from "@sand4rt/experimental-ct-web";
2import { SketchDiffRangePicker } from "./sketch-diff-range-picker";
3import { GitDataService } from "./git-data-service";
4import { GitLogEntry } from "../types";
5
6// Mock GitDataService
7class MockGitDataService {
8 async getBaseCommitRef(): Promise<string> {
9 return "sketch-base";
10 }
11
12 async getCommitHistory(): Promise<GitLogEntry[]> {
13 return [
14 {
15 hash: "abc123456",
16 subject: "Test commit",
17 refs: ["refs/heads/main"],
18 },
19 ];
20 }
21}
22
23test("initializes with empty commits array", async ({ mount }) => {
24 const component = await mount(SketchDiffRangePicker, {});
25
26 // Check initial state
27 const commits = await component.evaluate(
28 (el: SketchDiffRangePicker) => el.commits,
29 );
30 expect(commits).toEqual([]);
31});
32
33test("renders without errors", async ({ mount }) => {
34 const mockGitService = new MockGitDataService() as unknown as GitDataService;
35 const component = await mount(SketchDiffRangePicker, {
36 props: {
37 gitService: mockGitService,
38 },
39 });
40
41 // Check that the component was created successfully
42 const tagName = await component.evaluate(
43 (el: SketchDiffRangePicker) => el.tagName,
44 );
45 expect(tagName.toLowerCase()).toBe("sketch-diff-range-picker");
46});
47
48test("extends SketchTailwindElement (no shadow DOM)", async ({ mount }) => {
49 const component = await mount(SketchDiffRangePicker, {});
50
51 // Test that it uses the correct base class by checking if createRenderRoot returns the element itself
52 // This is the key difference between SketchTailwindElement and LitElement
53 const renderRoot = await component.evaluate((el: SketchDiffRangePicker) => {
54 return el.createRenderRoot() === el;
55 });
56 expect(renderRoot).toBe(true);
57});