-
-
Notifications
You must be signed in to change notification settings - Fork 177
fix(editor): stop editor shortcuts reaching the timeline under a modal #425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/components/ai-edition/LeftPanel.providerRefresh.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // @vitest-environment jsdom | ||
| // Issue #420: the provider dialog's open state moved out of `ChatStripPanel` and into | ||
| // EditorDialogsContext, and the `onClose` that used to re-read the LLM snapshot went with it. | ||
| // Connecting a provider in that dialog is what enables the composer here and what fills the | ||
| // model pill, so the panel now refreshes whenever the dialog is NOT open — on mount, and again | ||
| // on every close. | ||
| // | ||
| // That re-read is the one behaviour the lift had to re-establish by hand rather than move, and | ||
| // it cannot be seen from the dialog's own tests (they never mount this panel), so it is pinned | ||
| // here: refreshed once on mount, not again when the dialog opens, once more when it closes. | ||
|
|
||
| import "@testing-library/jest-dom"; | ||
| import { act, cleanup, render } from "@testing-library/react"; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| const llmGetSnapshot = vi.fn(() => | ||
| Promise.resolve({ | ||
| config: null, | ||
| connectedProviders: [], | ||
| availableProviders: [], | ||
| credentialSummary: [], | ||
| }), | ||
| ); | ||
|
|
||
| vi.mock("@/native/client", () => ({ | ||
| nativeBridgeClient: { | ||
| aiEdition: { | ||
| llmGetSnapshot: () => llmGetSnapshot(), | ||
| chatListSessions: () => Promise.resolve([]), | ||
| chatBudget: () => Promise.resolve(null), | ||
| llmListProviderModels: () => Promise.resolve({ models: [] }), | ||
| }, | ||
| }, | ||
| })); | ||
|
|
||
| // The panel's copy is not what is under test, and an echoing translator keeps this file off | ||
| // the critical path of a copy edit. | ||
| vi.mock("@/contexts/I18nContext", () => ({ | ||
| useI18n: () => ({ | ||
| locale: "en", | ||
| setLocale: () => { | ||
| /* fixed locale */ | ||
| }, | ||
| }), | ||
| useScopedT: () => (key: string) => key, | ||
| })); | ||
|
|
||
| import { EditorDialogsProvider, useEditorDialogActions } from "@/contexts/EditorDialogsContext"; | ||
| import { LeftPanel } from "./LeftPanel"; | ||
|
|
||
| let dialogActions: ReturnType<typeof useEditorDialogActions> | null = null; | ||
|
|
||
| /** Hands the test the context's openers, which the app menu and the panel's own gear share. */ | ||
| function CaptureDialogActions() { | ||
| dialogActions = useEditorDialogActions(); | ||
| return null; | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| llmGetSnapshot.mockClear(); | ||
| dialogActions = null; | ||
| // The panel subscribes to streamed chat events on mount; there is no preload in jsdom. | ||
| (window as unknown as { electronAPI?: unknown }).electronAPI = { | ||
| onAiEditionChatEvent: () => () => { | ||
| /* unsubscribe */ | ||
| }, | ||
| }; | ||
| // jsdom implements no scrolling at all, and the transcript pins itself to the bottom on | ||
| // every render. | ||
| Element.prototype.scrollTo = () => { | ||
| /* no scrolling in jsdom */ | ||
| }; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| cleanup(); | ||
| (window as unknown as { electronAPI?: unknown }).electronAPI = undefined; | ||
| }); | ||
|
|
||
| describe("ChatStripPanel, against the lifted provider dialog", () => { | ||
| it("re-reads the LLM snapshot when the dialog closes, and not when it opens", async () => { | ||
| render( | ||
| <EditorDialogsProvider> | ||
| <CaptureDialogActions /> | ||
| <LeftPanel active="chat" /> | ||
| </EditorDialogsProvider>, | ||
| ); | ||
| // Mount: the dialog is closed, so the same effect that watches for a close seeds the | ||
| // composer's view of the provider config. | ||
| await act(async () => { | ||
| await Promise.resolve(); | ||
| }); | ||
| expect(llmGetSnapshot).toHaveBeenCalledTimes(1); | ||
|
|
||
| // Opening it must not refresh — nothing has been connected yet, and the old code's | ||
| // `onClose` did not fire here either. | ||
| await act(async () => { | ||
| dialogActions?.openDialog("providers"); | ||
| }); | ||
| expect(llmGetSnapshot).toHaveBeenCalledTimes(1); | ||
|
|
||
| // Closing is the event that used to be `onClose` -> `refreshLlm()`. | ||
| await act(async () => { | ||
| dialogActions?.closeDialog(); | ||
| }); | ||
| expect(llmGetSnapshot).toHaveBeenCalledTimes(2); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.