summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/pages/session/use-session-commands.test.ts
blob: ada1871e1c045e487de5d7fc58714b66730181d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { describe, expect, test } from "bun:test"
import { canAddSelectionContext } from "./session-command-helpers"

describe("canAddSelectionContext", () => {
  test("returns false without active tab", () => {
    expect(
      canAddSelectionContext({
        active: undefined,
        pathFromTab: () => "src/a.ts",
        selectedLines: () => ({ start: 1, end: 1 }),
      }),
    ).toBe(false)
  })

  test("returns false when active tab is not a file", () => {
    expect(
      canAddSelectionContext({
        active: "context",
        pathFromTab: () => undefined,
        selectedLines: () => ({ start: 1, end: 1 }),
      }),
    ).toBe(false)
  })

  test("returns false without selected lines", () => {
    expect(
      canAddSelectionContext({
        active: "file://src/a.ts",
        pathFromTab: () => "src/a.ts",
        selectedLines: () => null,
      }),
    ).toBe(false)
  })

  test("returns true when file and selection exist", () => {
    expect(
      canAddSelectionContext({
        active: "file://src/a.ts",
        pathFromTab: () => "src/a.ts",
        selectedLines: () => ({ start: 1, end: 2 }),
      }),
    ).toBe(true)
  })
})