summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/context/terminal.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/app/src/context/terminal.test.ts')
-rw-r--r--packages/app/src/context/terminal.test.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/packages/app/src/context/terminal.test.ts b/packages/app/src/context/terminal.test.ts
index a250de57c..6e07e0312 100644
--- a/packages/app/src/context/terminal.test.ts
+++ b/packages/app/src/context/terminal.test.ts
@@ -2,6 +2,7 @@ import { beforeAll, describe, expect, mock, test } from "bun:test"
let getWorkspaceTerminalCacheKey: (dir: string) => string
let getLegacyTerminalStorageKeys: (dir: string, legacySessionID?: string) => string[]
+let migrateTerminalState: (value: unknown) => unknown
beforeAll(async () => {
mock.module("@solidjs/router", () => ({
@@ -17,6 +18,7 @@ beforeAll(async () => {
const mod = await import("./terminal")
getWorkspaceTerminalCacheKey = mod.getWorkspaceTerminalCacheKey
getLegacyTerminalStorageKeys = mod.getLegacyTerminalStorageKeys
+ migrateTerminalState = mod.migrateTerminalState
})
describe("getWorkspaceTerminalCacheKey", () => {
@@ -37,3 +39,44 @@ describe("getLegacyTerminalStorageKeys", () => {
])
})
})
+
+describe("migrateTerminalState", () => {
+ test("drops invalid terminals and restores a valid active terminal", () => {
+ expect(
+ migrateTerminalState({
+ active: "missing",
+ all: [
+ null,
+ { id: "one", title: "Terminal 2" },
+ { id: "one", title: "duplicate", titleNumber: 9 },
+ { id: "two", title: "logs", titleNumber: 4, rows: 24, cols: 80 },
+ { title: "no-id" },
+ ],
+ }),
+ ).toEqual({
+ active: "one",
+ all: [
+ { id: "one", title: "Terminal 2", titleNumber: 2 },
+ { id: "two", title: "logs", titleNumber: 4, rows: 24, cols: 80 },
+ ],
+ })
+ })
+
+ test("keeps a valid active id", () => {
+ expect(
+ migrateTerminalState({
+ active: "two",
+ all: [
+ { id: "one", title: "Terminal 1" },
+ { id: "two", title: "shell", titleNumber: 7 },
+ ],
+ }),
+ ).toEqual({
+ active: "two",
+ all: [
+ { id: "one", title: "Terminal 1", titleNumber: 1 },
+ { id: "two", title: "shell", titleNumber: 7 },
+ ],
+ })
+ })
+})