Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: James Long <longster@gmail.com> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com> Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: Simon Klee <hello@simonklee.dk> Co-authored-by: Jay <air@live.ca> Co-authored-by: David Hill <1879069+iamdavidhill@users.noreply.github.com> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: James Long <jlongster@users.noreply.github.com> Co-authored-by: 冯基魁 <56265583+fengjikui@users.noreply.github.com> Co-authored-by: Aiden Cline <rekram1-node@users.noreply.github.com>
82 lines
2.8 KiB
TypeScript
82 lines
2.8 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import {
|
|
SESSION_OPEN_FILE_TAB,
|
|
closeSessionTab,
|
|
openSessionTab,
|
|
previewSessionTab,
|
|
type SessionTabState,
|
|
} from "./layout-tabs"
|
|
|
|
const state = (all: string[], active?: string, preview?: string): SessionTabState => ({
|
|
tabs: { all, active },
|
|
preview,
|
|
})
|
|
|
|
describe("previewSessionTab", () => {
|
|
test("appends the Open File placeholder", () => {
|
|
expect(previewSessionTab(state(["file://a.ts"], "file://a.ts"), SESSION_OPEN_FILE_TAB)).toEqual(
|
|
state(["file://a.ts", SESSION_OPEN_FILE_TAB], SESSION_OPEN_FILE_TAB, SESSION_OPEN_FILE_TAB),
|
|
)
|
|
})
|
|
|
|
test("replaces the current preview in place", () => {
|
|
expect(
|
|
previewSessionTab(
|
|
state(["context", SESSION_OPEN_FILE_TAB, "file://b.ts"], SESSION_OPEN_FILE_TAB, SESSION_OPEN_FILE_TAB),
|
|
"file://a.ts",
|
|
),
|
|
).toEqual(state(["context", "file://a.ts", "file://b.ts"], "file://a.ts", "file://a.ts"))
|
|
})
|
|
|
|
test("activates a durable tab without duplicating it", () => {
|
|
expect(
|
|
previewSessionTab(
|
|
state(["file://a.ts", SESSION_OPEN_FILE_TAB, "file://b.ts"], SESSION_OPEN_FILE_TAB, SESSION_OPEN_FILE_TAB),
|
|
"file://b.ts",
|
|
),
|
|
).toEqual(state(["file://a.ts", "file://b.ts"], "file://b.ts"))
|
|
})
|
|
|
|
test("replaces a restored Open File placeholder", () => {
|
|
expect(
|
|
previewSessionTab(state(["file://a.ts", SESSION_OPEN_FILE_TAB], SESSION_OPEN_FILE_TAB), "file://b.ts"),
|
|
).toEqual(state(["file://a.ts", "file://b.ts"], "file://b.ts", "file://b.ts"))
|
|
})
|
|
})
|
|
|
|
describe("openSessionTab", () => {
|
|
test("pins the current preview", () => {
|
|
expect(openSessionTab(state(["file://a.ts"], "file://a.ts", "file://a.ts"), "file://a.ts")).toEqual(
|
|
state(["file://a.ts"], "file://a.ts"),
|
|
)
|
|
})
|
|
|
|
test("replaces a preview with a directly opened file", () => {
|
|
expect(openSessionTab(state(["file://a.ts"], "file://a.ts", "file://a.ts"), "file://b.ts")).toEqual(
|
|
state(["file://b.ts"], "file://b.ts"),
|
|
)
|
|
})
|
|
|
|
test("keeps the preview when switching to Review", () => {
|
|
expect(openSessionTab(state(["file://a.ts"], "file://a.ts", "file://a.ts"), "review")).toEqual(
|
|
state(["file://a.ts"], "review", "file://a.ts"),
|
|
)
|
|
})
|
|
|
|
test("replaces a restored Open File placeholder with a direct open", () => {
|
|
expect(openSessionTab(state(["file://a.ts", SESSION_OPEN_FILE_TAB], SESSION_OPEN_FILE_TAB), "file://b.ts")).toEqual(
|
|
state(["file://a.ts", "file://b.ts"], "file://b.ts"),
|
|
)
|
|
})
|
|
})
|
|
|
|
describe("closeSessionTab", () => {
|
|
test("clears preview metadata and selects the left neighbor", () => {
|
|
expect(
|
|
closeSessionTab(
|
|
state(["file://a.ts", "file://b.ts", "file://c.ts"], "file://b.ts", "file://b.ts"),
|
|
"file://b.ts",
|
|
),
|
|
).toEqual(state(["file://a.ts", "file://c.ts"], "file://a.ts"))
|
|
})
|
|
})
|