|
| 1 | +// Copyright 2026 The MathWorks, Inc. |
| 2 | +// Integration tests for handleNavigate — the host-side link-click handler shared |
| 3 | +// by the binary and text editors (wired in extension.ts). Run inside a real VS |
| 4 | +// Code so vscode.workspace.findFiles resolves against the fixture workspace, |
| 5 | +// which the vitest suite cannot do (navigate.ts imports `vscode`). This covers |
| 6 | +// the Model Reference / External Data links, whose target is a BARE filename |
| 7 | +// (e.g. "data.sldd") with no "@source" suffix: the handler must look the file up |
| 8 | +// by basename and open it. The pure target grammar is unit-tested in |
| 9 | +// test/navTarget.test.ts; here we prove the end-to-end resolve-and-open. |
| 10 | +import * as assert from 'assert'; |
| 11 | +import * as vscode from 'vscode'; |
| 12 | +import { handleNavigate } from '../../src/host/navigate'; |
| 13 | + |
| 14 | +function wsUri(name: string): vscode.Uri { |
| 15 | + const ws = vscode.workspace.workspaceFolders?.[0]; |
| 16 | + assert.ok(ws, 'a workspace folder must be open'); |
| 17 | + return vscode.Uri.joinPath(ws.uri, name); |
| 18 | +} |
| 19 | + |
| 20 | +suite('handleNavigate — Model Reference / External Data links', () => { |
| 21 | + test('a bare filename target resolves in the workspace and opens that file', async () => { |
| 22 | + const opened: vscode.Uri[] = []; |
| 23 | + // "data.sldd" is a fixture file; the link target for External Data / Model |
| 24 | + // Reference rows is exactly this bare basename (no "@source"). |
| 25 | + await handleNavigate('data.sldd', async (uri) => { |
| 26 | + opened.push(uri); |
| 27 | + }); |
| 28 | + assert.strictEqual(opened.length, 1, 'the target file is opened exactly once'); |
| 29 | + assert.strictEqual( |
| 30 | + opened[0].toString(), |
| 31 | + wsUri('data.sldd').toString(), |
| 32 | + 'the resolved Uri points at the workspace file', |
| 33 | + ); |
| 34 | + }); |
| 35 | + |
| 36 | + test('a bare .slx model-reference target opens the referenced model', async () => { |
| 37 | + const opened: vscode.Uri[] = []; |
| 38 | + await handleNavigate('model.slx', async (uri) => { |
| 39 | + opened.push(uri); |
| 40 | + }); |
| 41 | + assert.strictEqual(opened.length, 1, 'the referenced model is opened'); |
| 42 | + assert.strictEqual(opened[0].toString(), wsUri('model.slx').toString()); |
| 43 | + }); |
| 44 | + |
| 45 | + test('a bare filename with no matching workspace file opens nothing', async () => { |
| 46 | + let called = false; |
| 47 | + await handleNavigate('does-not-exist.slx', async () => { |
| 48 | + called = true; |
| 49 | + }); |
| 50 | + assert.strictEqual(called, false, 'no file is opened when nothing resolves'); |
| 51 | + }); |
| 52 | + |
| 53 | + test('a Usage-link target (name@source) is not treated as a bare file', async () => { |
| 54 | + // "Kp@data.sldd" carries an '@', so the file-target fast path must decline it |
| 55 | + // and the Usage-link path handles it: it resolves the SOURCE (data.sldd) and |
| 56 | + // opens that, not a file literally named "Kp@data.sldd". |
| 57 | + const opened: vscode.Uri[] = []; |
| 58 | + await handleNavigate('Kp@data.sldd', async (uri) => { |
| 59 | + opened.push(uri); |
| 60 | + }); |
| 61 | + assert.strictEqual(opened.length, 1, 'the source file is opened'); |
| 62 | + assert.strictEqual( |
| 63 | + opened[0].toString(), |
| 64 | + wsUri('data.sldd').toString(), |
| 65 | + 'the Usage-link resolves its @source, not the whole target string', |
| 66 | + ); |
| 67 | + }); |
| 68 | +}); |
0 commit comments