Skip to content

Commit 59829d9

Browse files
committed
Update unit tests
1 parent 786b31c commit 59829d9

2 files changed

Lines changed: 42 additions & 8 deletions

File tree

src/solutions/problem-diagnostic-action-resolver.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ import * as vscode from 'vscode';
1919
import { MANAGE_COMPONENTS_PACKS_COMMAND_ID, MERGE_FILE_COMMAND_ID, RUN_GENERATOR_COMMAND_ID } from '../manifest';
2020
import { stripVendor, stripVersion } from '../utils/string-utils';
2121

22-
export const MERGE_VIEW_LINK_LABEL = 'Open in Merge View';
2322

24-
type MergeUpdateLevel = 'required' | 'recommended' | 'suggested' | 'mandatory';
23+
type MergeUpdateLevel = 'recommended' | 'suggested' | 'required';
2524

2625
interface MergeMessageMatch {
2726
localPath: string;
@@ -52,7 +51,7 @@ type ProblemActionDescriptor =
5251

5352
const mergeMessagePatterns = [
5453
{
55-
pattern: /update\s+(required|recommended|suggested|mandatory)\s+for\s+file\s+'([^']+)'/i,
54+
pattern: /update\s+(recommended|suggested|required)\s+for\s+file\s+'([^']+)'/i,
5655
getLocalPath: (match: RegExpExecArray) => match[2],
5756
getUpdateLevel: (match: RegExpExecArray) => match[1],
5857
},
@@ -93,7 +92,7 @@ export class ProblemDiagnosticActionResolver {
9392
return {
9493
message: this.createMergeDiagnosticMessage(descriptor.localPath, descriptor.updateLevel, descriptor.componentId),
9594
code: {
96-
value: MERGE_VIEW_LINK_LABEL,
95+
value: 'Open in Merge View',
9796
target: this.createMergeCommandUri(descriptor.localPath),
9897
},
9998
};

src/solutions/solution-problems.test.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { describe, it, expect, beforeEach } from '@jest/globals';
1818
import * as vscode from 'vscode';
1919
import { ExtensionContext } from 'vscode';
20-
import { MANAGE_COMPONENTS_PACKS_COMMAND_ID, MERGE_FILE_COMMAND_ID } from '../manifest';
20+
import { MANAGE_COMPONENTS_PACKS_COMMAND_ID, MERGE_FILE_COMMAND_ID, RUN_GENERATOR_COMMAND_ID } from '../manifest';
2121
import * as fsUtils from '../utils/fs-utils';
2222
import * as vscodeUtils from '../utils/vscode-utils';
2323
import { ProblemDiagnosticActionResolver } from './problem-diagnostic-action-resolver';
@@ -329,7 +329,7 @@ describe('SolutionProblems', () => {
329329
expect(relativeArgs).toEqual([layerPath]);
330330
});
331331

332-
it('returns undefined merge diagnostic action for non-merge messages', () => {
332+
it('returns generic find in files action for non-merge messages', () => {
333333
const result = diagnosticActionResolver.resolve(
334334
{
335335
message: "component 'Arm::Device@2.3.4' is missing",
@@ -352,7 +352,42 @@ describe('SolutionProblems', () => {
352352
const [command, args] = code.target.toString().split('?');
353353

354354
expect(code.value).toBe('Run Generator');
355-
expect(command).toContain('command:cmsis-csolution.runGenerator');
355+
expect(command).toBe(`command:${RUN_GENERATOR_COMMAND_ID}`);
356+
expect(JSON.parse(decodeURIComponent(args))).toEqual([{ generator: 'CubeMX2', context: 'CubeMX2.Debug+STM32C531CBT6' }]);
357+
});
358+
359+
it('attaches run generator command uri only when parsed diagnostic has no location', async () => {
360+
await solutionProblems.activate({ subscriptions: [] } as unknown as ExtensionContext);
361+
const setSpy = jest.spyOn(vscode.languages.createDiagnosticCollection(), 'set');
362+
363+
await eventHub.fireConvertCompleted({
364+
severity: 'error',
365+
detection: false,
366+
logMessages: {
367+
success: false,
368+
errors: [
369+
"mylayer.clayer.yml - cgen file was not found, run generator 'CubeMX2' for context 'CubeMX2.Debug+STM32C531CBT6'",
370+
"mylayer.clayer.yml:10:2 - cgen file was not found, run generator 'CubeMX2' for context 'CubeMX2.Debug+STM32C531CBT6'",
371+
],
372+
warnings: [],
373+
info: [],
374+
},
375+
});
376+
await waitTimeout();
377+
378+
const setCalls = setSpy.mock.calls as unknown as Array<[vscode.Uri, readonly vscode.Diagnostic[] | undefined]>;
379+
const diagnostics = setCalls.flatMap(([, diagnosticEntries]) => diagnosticEntries ?? []);
380+
const runGeneratorDiagnostics = diagnostics.filter(
381+
d => typeof d.code === 'object' && d.code !== null && 'value' in d.code && d.code.value === 'Run Generator'
382+
);
383+
const diagnosticWithoutCode = diagnostics.find(d => d.code === undefined);
384+
385+
expect(runGeneratorDiagnostics).toHaveLength(1);
386+
expect(diagnosticWithoutCode).toBeDefined();
387+
388+
const code = runGeneratorDiagnostics[0].code as { value: string; target: vscode.Uri };
389+
const [command, args] = code.target.toString().split('?');
390+
expect(command).toBe(`command:${RUN_GENERATOR_COMMAND_ID}`);
356391
expect(JSON.parse(decodeURIComponent(args))).toEqual([{ generator: 'CubeMX2', context: 'CubeMX2.Debug+STM32C531CBT6' }]);
357392
});
358393

@@ -404,7 +439,7 @@ describe('SolutionProblems', () => {
404439
expect(JSON.parse(decodeURIComponent(args))).toEqual([layerPath]);
405440
});
406441

407-
it.each(['required', 'recommended', 'suggested', 'mandatory'] as const)(
442+
it.each(['required', 'recommended', 'suggested'] as const)(
408443
'renders merge diagnostics for current toolbox wording with %s update levels',
409444
async updateLevel => {
410445
await solutionProblems.activate({ subscriptions: [] } as unknown as ExtensionContext);

0 commit comments

Comments
 (0)