Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

Commit fe6dfa3

Browse files
committed
fix: tests for handlers
1 parent a5ff9ac commit fe6dfa3

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

tests/commands/handlers.spec.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { describe, it, expect, jest } from '@jest/globals';
22
import * as cmd from '../../src/commands/handlers';
33

4-
import { window, ExtensionContext } from 'vscode';
4+
import * as vsce from 'vscode';
55
import * as core from 'lightning-flow-scanner-core';
66
import { CacheProvider } from '../../src/providers/cache-provider';
77
import { OutputChannel } from '../../src/providers/outputChannel';
8+
import * as cp from '../../src/providers/config-provider';
89

910
jest.mock('lightning-flow-scanner-core');
1011
jest.mock('../../src/providers/cache-provider');
1112
jest.mock('../../src/providers/outputChannel');
13+
jest.mock('../../src/providers/config-provider');
14+
jest.mock('vscode');
1215

1316
describe('Commands', () => {
1417
it('should be defined', () => {
@@ -43,7 +46,7 @@ describe('Commands', () => {
4346
]),
4447
} as any;
4548

46-
const spy = jest.spyOn(window, 'showQuickPick').mockReturnValue([
49+
const spy = jest.spyOn(vsce.window, 'showQuickPick').mockReturnValue([
4750
{ label: 'Flow Name', value: 'FlowName' },
4851
{ label: 'API Version', value: 'APIVersion' },
4952
] as any);
@@ -57,19 +60,39 @@ describe('Commands', () => {
5760

5861
const extensionContext = jest.fn();
5962
const command = new cmd.default(
60-
extensionContext as unknown as ExtensionContext
63+
extensionContext as unknown as vsce.ExtensionContext
6164
);
6265

6366
await expect(async () => await command['configRules']()).not.toThrow();
6467
});
6568

6669
it('should read from configuration', async () => {
6770
const command = new cmd.default({} as any);
71+
jest
72+
.spyOn(cp.ConfigProvider.prototype, 'discover')
73+
.mockImplementation(() =>
74+
Promise.resolve({
75+
fspath: '/fake/path',
76+
config: { rules: { APIName: { severity: 'error' } } },
77+
} as any)
78+
);
79+
(vsce.workspace as any).openTextDocument = jest.fn();
80+
(vsce.window as any).showTextDocument = jest.fn();
6881
await expect(command['ruleConfiguration']()).resolves.not.toThrow();
6982
});
7083

7184
it('should write to configuration', async () => {
7285
const command = new cmd.default({} as any);
86+
jest
87+
.spyOn(cp.ConfigProvider.prototype, 'discover')
88+
.mockImplementation(() =>
89+
Promise.resolve({
90+
fspath: '/fake/path',
91+
config: { rules: { APIName: { severity: 'error' } } },
92+
} as any)
93+
);
94+
(vsce.workspace as any).openTextDocument = jest.fn();
95+
(vsce.window as any).showTextDocument = jest.fn();
7396
await expect(command['ruleConfiguration']()).resolves.not.toThrow();
7497
});
7598
});

0 commit comments

Comments
 (0)