Skip to content

Commit 6b6a328

Browse files
committed
Add tests for the new webview message handler
1 parent 54c2e6e commit 6b6a328

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

extension/src/test/suite/experiments/index.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,30 @@ suite('Experiments Test Suite', () => {
344344
return { experiments, experimentsModel, mockExecuteCommand }
345345
}
346346

347+
it('should be able to handle a message to hide a table column', async () => {
348+
const { experiments, columnsModel } = buildExperiments(disposable)
349+
350+
const mockToggleStatus = stub(columnsModel, 'toggleStatus')
351+
const mockSendTelemetryEvent = stub(Telemetry, 'sendTelemetryEvent')
352+
const webview = await experiments.showWebview()
353+
const mockMessageReceived = getMessageReceivedEmitter(webview)
354+
const mockColumnId = 'mock-column-id'
355+
356+
mockMessageReceived.fire({
357+
payload: mockColumnId,
358+
type: MessageFromWebviewType.HIDE_EXPERIMENTS_TABLE_COLUMN
359+
})
360+
361+
expect(mockToggleStatus).to.be.calledOnce
362+
expect(mockToggleStatus).to.be.calledWithExactly(mockColumnId)
363+
364+
expect(mockSendTelemetryEvent).to.be.calledWithExactly(
365+
EventName.VIEWS_EXPERIMENTS_TABLE_HIDE_COLUMN,
366+
{ path: mockColumnId },
367+
undefined
368+
)
369+
})
370+
347371
it('should be able to handle a message to apply an experiment to workspace', async () => {
348372
const { experiments, mockExecuteCommand } =
349373
setupExperimentsAndMockCommands()

extension/src/test/suite/experiments/util.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { CheckpointsModel } from '../../../experiments/checkpoints/model'
1919
import { FileSystemData } from '../../../fileSystem/data'
2020
import * as Watcher from '../../../fileSystem/watcher'
2121
import { ExperimentsModel } from '../../../experiments/model'
22+
import { ColumnsModel } from '../../../experiments/columns/model'
2223

2324
const hasCheckpoints = (data: ExperimentsOutput) => {
2425
const [experimentsWithBaseline] = Object.values(omit(data, 'workspace'))
@@ -73,6 +74,8 @@ export const buildExperiments = (
7374
cliExecutor,
7475
cliReader,
7576
cliRunner,
77+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
78+
columnsModel: (experiments as any).columns as ColumnsModel,
7679
experiments,
7780
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7881
experimentsModel: (experiments as any).experiments as ExperimentsModel,

0 commit comments

Comments
 (0)