@@ -10,7 +10,11 @@ import { createAxiosError, createMockLogger } from "../../../mocks/testHelpers";
1010
1111import type { Task } from "coder/site/src/api/typesGenerated" ;
1212
13- type TasksPanelClientMethods =
13+ import type { CoderApi } from "@/api/coderApi" ;
14+
15+ /** Subset of CoderApi used by TasksPanel */
16+ type TasksPanelClient = Pick <
17+ CoderApi ,
1418 | "getTasks"
1519 | "getTask"
1620 | "getTaskLogs"
@@ -20,9 +24,10 @@ type TasksPanelClientMethods =
2024 | "getTemplateVersionPresets"
2125 | "startWorkspace"
2226 | "stopWorkspace"
23- | "getHost" ;
27+ | "getHost"
28+ > ;
2429
25- type MockClient = Record < TasksPanelClientMethods , ReturnType < typeof vi . fn > > ;
30+ type MockClient = { [ K in keyof TasksPanelClient ] : ReturnType < typeof vi . fn > } ;
2631
2732function createClient ( baseUrl = "https://coder.example.com" ) : MockClient {
2833 return {
@@ -59,17 +64,20 @@ function createHarness(): Harness {
5964 const client = createClient ( ) ;
6065 const panel = new TasksPanel (
6166 vscode . Uri . file ( "/test/extension" ) ,
62- client as unknown as ConstructorParameters < typeof TasksPanel > [ 1 ] ,
67+ // Cast needed: mock only implements the subset of CoderApi methods used by TasksPanel
68+ client as unknown as CoderApi ,
6369 createMockLogger ( ) ,
6470 ) ;
6571
6672 const posted : unknown [ ] = [ ] ;
6773 let handler : ( ( msg : unknown ) => void ) | null = null ;
6874
69- const webview = {
75+ const webview : vscode . WebviewView = {
76+ viewType : "coder.tasksPanel" ,
7077 webview : {
7178 options : { enableScripts : false , localResourceRoots : [ ] } ,
7279 html : "" ,
80+ cspSource : "" ,
7381 postMessage : vi . fn ( ( msg : unknown ) => {
7482 posted . push ( msg ) ;
7583 return Promise . resolve ( true ) ;
@@ -81,12 +89,13 @@ function createHarness(): Harness {
8189 asWebviewUri : vi . fn ( ( uri : vscode . Uri ) => uri ) ,
8290 } ,
8391 visible : true ,
92+ show : vi . fn ( ) ,
8493 onDidChangeVisibility : vi . fn ( ( ) => ( { dispose : vi . fn ( ) } ) ) ,
8594 onDidDispose : vi . fn ( ( ) => ( { dispose : vi . fn ( ) } ) ) ,
8695 } ;
8796
8897 panel . resolveWebviewView (
89- webview as unknown as vscode . WebviewView ,
98+ webview ,
9099 { } as vscode . WebviewViewResolveContext ,
91100 { } as vscode . CancellationToken ,
92101 ) ;
@@ -460,18 +469,16 @@ describe("TasksPanel", () => {
460469 } ) ;
461470
462471 describe ( "public methods" , ( ) => {
463- interface PublicMethodTestCase {
464- method : string ;
465- expectedType : string ;
466- }
467- it . each < PublicMethodTestCase > ( [
468- { method : "showCreateForm" , expectedType : "showCreateForm" } ,
469- { method : "refresh" , expectedType : "refresh" } ,
470- ] ) ( "$method sends notification" , ( { method, expectedType } ) => {
472+ it ( "showCreateForm sends notification" , ( ) => {
471473 const h = createHarness ( ) ;
472- ( h . panel as unknown as Record < string , ( ) => void > ) [ method ] ( ) ;
474+ h . panel . showCreateForm ( ) ;
475+ expect ( h . messages ( ) ) . toContainEqual ( { type : "showCreateForm" } ) ;
476+ } ) ;
473477
474- expect ( h . messages ( ) ) . toContainEqual ( { type : expectedType } ) ;
478+ it ( "refresh sends notification" , ( ) => {
479+ const h = createHarness ( ) ;
480+ h . panel . refresh ( ) ;
481+ expect ( h . messages ( ) ) . toContainEqual ( { type : "refresh" } ) ;
475482 } ) ;
476483 } ) ;
477484
0 commit comments