Skip to content

Commit 9247b44

Browse files
committed
Consolidate unit tests
1 parent c55c78b commit 9247b44

2 files changed

Lines changed: 42 additions & 120 deletions

File tree

src/views/solution-outline/tree-structure/tree-provider.test.ts

Lines changed: 0 additions & 116 deletions
This file was deleted.

src/views/solution-outline/treeview-provider.test.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,40 @@
1414
* limitations under the License.
1515
*/
1616

17+
jest.mock('vscode');
18+
1719
import path from 'path';
20+
import * as vscode from 'vscode';
1821
import { createItemCommand } from './treeview-provider';
1922
import { COutlineItem } from './tree-structure/solution-outline-item';
2023

2124
describe('createItemCommand', () => {
25+
beforeAll(() => {
26+
vscode.Uri.file = (filePath: string) => ({
27+
fsPath: filePath,
28+
path: filePath,
29+
scheme: 'file',
30+
authority: '',
31+
query: '',
32+
fragment: '',
33+
with: () => null as unknown,
34+
toString: () => filePath,
35+
toJSON: () => filePath,
36+
} as unknown as vscode.Uri);
37+
});
38+
2239
it('uses explicit command from item attributes when provided', () => {
2340
const node = new COutlineItem('file');
2441
node.setAttribute('command', 'cmsis-csolution.someExplicitCommand');
2542
node.setAttribute('description', 'Run explicit action');
2643

2744
const command = createItemCommand(node);
2845

29-
expect(command?.command).toBe('cmsis-csolution.someExplicitCommand');
30-
expect(command?.arguments).toEqual([node]);
46+
expect(command).toEqual({
47+
command: 'cmsis-csolution.someExplicitCommand',
48+
title: 'Run explicit action',
49+
arguments: [node],
50+
});
3151
});
3252

3353
it('does not create default command for project and layer nodes', () => {
@@ -50,7 +70,16 @@ describe('createItemCommand', () => {
5070

5171
const command = createItemCommand(markdownNode);
5272

53-
expect(command?.command).toBe('markdown.showPreview');
73+
expect(command).toMatchObject({
74+
command: 'markdown.showPreview',
75+
title: 'Open Preview',
76+
arguments: [
77+
{
78+
fsPath: path.join('tmp', 'notes.md'),
79+
path: path.join('tmp', 'notes.md'),
80+
},
81+
],
82+
});
5483
});
5584

5685
it('routes non-markdown files through smart source open command', () => {
@@ -59,6 +88,15 @@ describe('createItemCommand', () => {
5988

6089
const command = createItemCommand(sourceNode);
6190

62-
expect(command?.command).toBe('cmsis-csolution.openSourceFileSmart');
91+
expect(command).toMatchObject({
92+
command: 'cmsis-csolution.openSourceFileSmart',
93+
title: 'Open',
94+
arguments: [
95+
{
96+
fsPath: path.join('tmp', 'device.h'),
97+
path: path.join('tmp', 'device.h'),
98+
},
99+
],
100+
});
63101
});
64102
});

0 commit comments

Comments
 (0)