diff --git a/client/specs/extension.spec.ts b/client/specs/extension.spec.ts index 0a3c8aa4..ccecce9f 100644 --- a/client/specs/extension.spec.ts +++ b/client/specs/extension.spec.ts @@ -2,14 +2,13 @@ import { join } from 'path' import { expect } from '@jest/globals' import mockfs from 'mock-fs' -import { activate, deactivate, forwardOnDidChangeWorkspaceFolders, setLanguageServerLauncher, setResourceRootDir } from '../src/extension' +import { activate, deactivate, forwardOnDidChangeWorkspaceFolders, getTocTree, setLanguageServerLauncher, setResourceRootDir } from '../src/extension' import { type Extension, type ExtensionContext, type WebviewPanel } from 'vscode' import * as vscode from 'vscode' import * as utils from '../src/utils' // Used for dependency mocking in tests import Sinon from 'sinon' import { type LanguageClient } from 'vscode-languageclient/node' import { OpenstaxCommand } from '../src/extension-types' -import { type TocEditorPanel } from '../src/panel-toc-editor' import { type BooksAndOrphans, ExtensionServerNotification } from '../../common/src/requests' import { type PanelManager } from '../src/panel' import { type CnxmlPreviewPanel } from '../src/panel-cnxml-preview' @@ -53,20 +52,19 @@ describe('Extension', () => { it('Starts up', async function () { await expect(activate(extensionContext)).resolves.toBeTruthy() }) - it('updates the TocPanel when the language server sends a BookTocs Notification', async () => { + it('updates the TreeView when the language server sends a BookTocs Notification', async () => { setResourceRootDir(join(__dirname, '..', 'static')) - const extensions = await activate(extensionContext) - const pm = extensions[OpenstaxCommand.SHOW_TOC_EDITOR] - expect(pm.panel()).toBeNull() + await activate(extensionContext) expect(onNotificationStub.firstCall.args[0]).toBe(ExtensionServerNotification.BookTocs) const cb = onNotificationStub.firstCall.args[1] const params: BooksAndOrphans = { books: [], orphans: [] } cb(params) - const panel = pm.newPanel() as TocEditorPanel - const updateStub = sinon.stub(panel, 'update') + const { tocTreesProvider } = getTocTree() + if (tocTreesProvider == null) throw new Error('tocTreesProvider was not set yet') + const updateStub = sinon.stub(tocTreesProvider, 'update') cb(params) expect(updateStub.callCount).toBe(1) diff --git a/client/src/extension.ts b/client/src/extension.ts index 26a80324..a0f41500 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -34,6 +34,11 @@ export function setLanguageServerLauncher(l: typeof languageServerLauncher) { export const forwardOnDidChangeWorkspaceFolders = (clientInner: LanguageClient) => async (event: vscode.WorkspaceFoldersChangeEvent) => { await clientInner.sendRequest('onDidChangeWorkspaceFolders', event) } +export const getTocTree = (): { + tocTreesView: vscode.TreeView | undefined | null + tocTreesProvider: TocsTreeProvider | undefined | null + tocEventHandler: TocsEventHandler | undefined | null +} => ({ tocTreesView, tocTreesProvider, tocEventHandler }) type ExtensionExports = { [key in OpenstaxCommand]: PanelManager> } export async function activate(context: vscode.ExtensionContext): Promise { diff --git a/client/src/panel.ts b/client/src/panel.ts index 9172984d..fd06af18 100644 --- a/client/src/panel.ts +++ b/client/src/panel.ts @@ -80,7 +80,7 @@ export abstract class Panel implements DisposableS this.panel.onDidDispose(() => { this.dispose() }) this.registerDisposable(this.panel.webview.onDidReceiveMessage((message) => { - /* istanbul ignore if */ + /* istanbul ignore next */ if (message.type === PanelStateMessageType.Request) { void ensureCatchPromise(this.sendState()) } else {