Skip to content

Commit a1613e9

Browse files
committed
test(useChat): 优化中断会话提示相关单元测试
- 在消息断言中添加id字段类型匹配 - 移除 localStorage 清理操作以简化测试 - 调整 SESSION_STATUS 和 LOAD_SESSION 中断状态测试逻辑,删除对 localStorage 状态的依赖 - 删除无效的本地存储相关测试用例,确保中断状态总是显示提示 - 更新 dismissContinuePrompt 测试,改为只验证动作派发,不依赖 localStorage - 统一保证中断时提示始终显示,且消除提示操作后的状态正确性验证
1 parent 42ba20b commit a1613e9

1 file changed

Lines changed: 13 additions & 57 deletions

File tree

packages/vscode-ide-companion/src/webview/context/ChatProvider.test.tsx

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ describe("appReducer - USER_MESSAGE", () => {
332332

333333
expect(result.current.state.messages).toHaveLength(1);
334334
expect(result.current.state.messages[0]).toEqual({
335+
id: expect.any(String),
335336
role: "user",
336337
content: "Hello world",
337338
meta: { timestamp: 123 },
@@ -769,7 +770,6 @@ describe("appReducer - Continue prompt", () => {
769770
beforeEach(() => {
770771
clearMessageHandlers();
771772
vi.clearAllMocks();
772-
localStorage.clear();
773773
});
774774

775775
it("showContinuePrompt defaults to false", () => {
@@ -804,14 +804,11 @@ describe("appReducer - Continue prompt", () => {
804804
expect(result.current.state.showContinuePrompt).toBe(false);
805805
});
806806

807-
it("SESSION_STATUS interrupted sets showContinuePrompt true without localStorage key", () => {
807+
it("SESSION_STATUS interrupted sets showContinuePrompt true", () => {
808808
const { result } = renderHook(() => useChat(), {
809809
wrapper: createWrapper(),
810810
});
811811

812-
// Ensure no localStorage entry
813-
localStorage.removeItem("deepcode:continuePromptDismissed:s1");
814-
815812
act(() => {
816813
result.current.dispatch({
817814
type: "SESSION_STATUS",
@@ -825,26 +822,6 @@ describe("appReducer - Continue prompt", () => {
825822
expect(result.current.state.loading).toBe(false);
826823
});
827824

828-
it("SESSION_STATUS interrupted does not show prompt when dismissed in localStorage", () => {
829-
const { result } = renderHook(() => useChat(), {
830-
wrapper: createWrapper(),
831-
});
832-
833-
// Simulate that user previously dismissed
834-
localStorage.setItem("deepcode:continuePromptDismissed:s1", "1");
835-
836-
act(() => {
837-
result.current.dispatch({
838-
type: "SESSION_STATUS",
839-
status: "interrupted",
840-
sessionId: "s1",
841-
});
842-
});
843-
844-
expect(result.current.state.activeSessionStatus).toBe("interrupted");
845-
expect(result.current.state.showContinuePrompt).toBe(false);
846-
});
847-
848825
it("SESSION_STATUS with non-interrupted status sets showContinuePrompt false", () => {
849826
const { result } = renderHook(() => useChat(), {
850827
wrapper: createWrapper(),
@@ -873,13 +850,11 @@ describe("appReducer - Continue prompt", () => {
873850
expect(result.current.state.showContinuePrompt).toBe(false);
874851
});
875852

876-
it("LOAD_SESSION with interrupted status shows prompt without localStorage", () => {
853+
it("LOAD_SESSION with interrupted status shows prompt", () => {
877854
const { result } = renderHook(() => useChat(), {
878855
wrapper: createWrapper(),
879856
});
880857

881-
localStorage.removeItem("deepcode:continuePromptDismissed:s1");
882-
883858
act(() => {
884859
result.current.dispatch({
885860
type: "LOAD_SESSION",
@@ -894,27 +869,6 @@ describe("appReducer - Continue prompt", () => {
894869
expect(result.current.state.showContinuePrompt).toBe(true);
895870
});
896871

897-
it("LOAD_SESSION with interrupted status does not show prompt when dismissed", () => {
898-
const { result } = renderHook(() => useChat(), {
899-
wrapper: createWrapper(),
900-
});
901-
902-
localStorage.setItem("deepcode:continuePromptDismissed:s1", "1");
903-
904-
act(() => {
905-
result.current.dispatch({
906-
type: "LOAD_SESSION",
907-
sessionId: "s1",
908-
status: "interrupted",
909-
messages: [],
910-
sessions: [],
911-
});
912-
});
913-
914-
expect(result.current.state.activeSessionStatus).toBe("interrupted");
915-
expect(result.current.state.showContinuePrompt).toBe(false);
916-
});
917-
918872
it("LOAD_SESSION with non-interrupted status does not show prompt", () => {
919873
const { result } = renderHook(() => useChat(), {
920874
wrapper: createWrapper(),
@@ -933,7 +887,7 @@ describe("appReducer - Continue prompt", () => {
933887
expect(result.current.state.showContinuePrompt).toBe(false);
934888
});
935889

936-
it("dismissContinuePrompt action persists to localStorage and dispatches", () => {
890+
it("dismissContinuePrompt action dispatches DISMISS_CONTINUE_PROMPT", () => {
937891
const { result } = renderHook(() => useChat(), {
938892
wrapper: createWrapper(),
939893
});
@@ -957,18 +911,14 @@ describe("appReducer - Continue prompt", () => {
957911
});
958912

959913
expect(result.current.state.showContinuePrompt).toBe(false);
960-
expect(localStorage.getItem("deepcode:continuePromptDismissed:s1")).toBe("1");
961914
});
962915

963-
it("different sessions have independent dismiss state", () => {
916+
it("SESSION_STATUS interrupted always shows prompt when interrupted", () => {
964917
const { result } = renderHook(() => useChat(), {
965918
wrapper: createWrapper(),
966919
});
967920

968-
// Dismiss session 1
969-
localStorage.setItem("deepcode:continuePromptDismissed:s1", "1");
970-
971-
// Session 1 should not show prompt
921+
// Dismiss once
972922
act(() => {
973923
result.current.dispatch({
974924
type: "SESSION_STATUS",
@@ -977,9 +927,15 @@ describe("appReducer - Continue prompt", () => {
977927
});
978928
});
979929

930+
expect(result.current.state.showContinuePrompt).toBe(true);
931+
932+
act(() => {
933+
result.current.actions.dismissContinuePrompt();
934+
});
935+
980936
expect(result.current.state.showContinuePrompt).toBe(false);
981937

982-
// Session 2 should show prompt (not dismissed)
938+
// Next interruption should always show the prompt (no localStorage persistence)
983939
act(() => {
984940
result.current.dispatch({
985941
type: "SESSION_STATUS",

0 commit comments

Comments
 (0)