| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- import { describe, expect, it } from "vitest";
- import { shouldRefreshLiveGitData } from "../src/hooks/useGitRepository.js";
- describe("shouldRefreshLiveGitData", () => {
- it("refreshes on initial load and workspace changes", () => {
- expect(
- shouldRefreshLiveGitData(null, {
- workspacePath: "/repo-a",
- workspaceKey: "/repo-a",
- includeExtendedData: false,
- refreshToken: 0,
- workspaceRpcEnabled: true,
- }),
- ).toBe(true);
- expect(
- shouldRefreshLiveGitData(
- {
- workspacePath: "/repo-a",
- workspaceKey: "/repo-a",
- includeExtendedData: false,
- refreshToken: 0,
- workspaceRpcEnabled: true,
- },
- {
- workspacePath: "/repo-b",
- workspaceKey: "/repo-b",
- includeExtendedData: false,
- refreshToken: 0,
- workspaceRpcEnabled: true,
- },
- ),
- ).toBe(true);
- });
- it("refreshes when the pane opens or user triggers an explicit refresh", () => {
- expect(
- shouldRefreshLiveGitData(
- {
- workspacePath: "/repo-a",
- workspaceKey: "/repo-a",
- includeExtendedData: false,
- refreshToken: 0,
- workspaceRpcEnabled: true,
- },
- {
- workspacePath: "/repo-a",
- workspaceKey: "/repo-a",
- includeExtendedData: true,
- refreshToken: 0,
- workspaceRpcEnabled: true,
- },
- ),
- ).toBe(true);
- expect(
- shouldRefreshLiveGitData(
- {
- workspacePath: "/repo-a",
- workspaceKey: "/repo-a",
- includeExtendedData: true,
- refreshToken: 0,
- workspaceRpcEnabled: true,
- },
- {
- workspacePath: "/repo-a",
- workspaceKey: "/repo-a",
- includeExtendedData: true,
- refreshToken: 1,
- workspaceRpcEnabled: true,
- },
- ),
- ).toBe(true);
- });
- it("refreshes when workspace identity changes even if the remote path is the same", () => {
- expect(
- shouldRefreshLiveGitData(
- {
- workspacePath: "/root",
- workspaceKey: "remote:ssh:root@server-a:/root",
- includeExtendedData: false,
- refreshToken: 0,
- workspaceRpcEnabled: true,
- },
- {
- workspacePath: "/root",
- workspaceKey: "remote:ssh:root@server-b:/root",
- includeExtendedData: false,
- refreshToken: 0,
- workspaceRpcEnabled: true,
- },
- ),
- ).toBe(true);
- });
- it("does not refresh when only the pane closes or task-local data changes", () => {
- expect(
- shouldRefreshLiveGitData(
- {
- workspacePath: "/repo-a",
- workspaceKey: "/repo-a",
- includeExtendedData: true,
- refreshToken: 1,
- workspaceRpcEnabled: true,
- },
- {
- workspacePath: "/repo-a",
- workspaceKey: "/repo-a",
- includeExtendedData: false,
- refreshToken: 1,
- workspaceRpcEnabled: true,
- },
- ),
- ).toBe(false);
- expect(
- shouldRefreshLiveGitData(
- {
- workspacePath: "/repo-a",
- workspaceKey: "/repo-a",
- includeExtendedData: false,
- refreshToken: 1,
- workspaceRpcEnabled: true,
- },
- {
- workspacePath: "/repo-a",
- workspaceKey: "/repo-a",
- includeExtendedData: false,
- refreshToken: 1,
- workspaceRpcEnabled: true,
- },
- ),
- ).toBe(false);
- });
- it("does not refresh disconnected remote placeholders until workspace RPC is available", () => {
- expect(
- shouldRefreshLiveGitData(null, {
- workspacePath: "/root",
- workspaceKey: "remote:ssh:root@server:/root",
- includeExtendedData: false,
- refreshToken: 0,
- workspaceRpcEnabled: false,
- }),
- ).toBe(false);
- expect(
- shouldRefreshLiveGitData(
- {
- workspacePath: "/root",
- workspaceKey: "remote:ssh:root@server:/root",
- includeExtendedData: false,
- refreshToken: 0,
- workspaceRpcEnabled: false,
- },
- {
- workspacePath: "/root",
- workspaceKey: "remote:ssh:root@server:/root",
- includeExtendedData: false,
- refreshToken: 0,
- workspaceRpcEnabled: true,
- },
- ),
- ).toBe(true);
- });
- });
|