Skip to content

Commit 01d8f6d

Browse files
author
Andrew Hall
authored
Add razor definition integration tests (#7869)
1 parent e185471 commit 01d8f6d

File tree

2 files changed

+144
-0
lines changed

2 files changed

+144
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as path from 'path';
7+
import * as vscode from 'vscode';
8+
import { beforeAll, afterAll, test, expect, beforeEach } from '@jest/globals';
9+
import testAssetWorkspace from './testAssets/testAssetWorkspace';
10+
import * as integrationHelpers from '../../lsptoolshost/integrationTests/integrationHelpers';
11+
12+
integrationHelpers.describeIfWindows(`Razor Definition ${testAssetWorkspace.description}`, function () {
13+
beforeAll(async function () {
14+
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
15+
return;
16+
}
17+
18+
await integrationHelpers.activateCSharpExtension();
19+
});
20+
21+
beforeEach(async function () {
22+
await integrationHelpers.openFileInWorkspaceAsync(path.join('Pages', 'Definition.razor'));
23+
});
24+
25+
afterAll(async () => {
26+
await testAssetWorkspace.cleanupWorkspace();
27+
});
28+
29+
test('Go To Definition', async () => {
30+
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
31+
return;
32+
}
33+
34+
const position = new vscode.Position(6, 41);
35+
const locations = <vscode.Location[]>(
36+
await vscode.commands.executeCommand(
37+
'vscode.executeDefinitionProvider',
38+
vscode.window.activeTextEditor!.document.uri,
39+
position
40+
)
41+
);
42+
43+
expect(locations.length).toBe(1);
44+
const definitionLocation = locations[0];
45+
46+
expect(definitionLocation.uri.path).toBe(vscode.window.activeTextEditor!.document.uri.path);
47+
expect(definitionLocation.range.start.line).toBe(11);
48+
expect(definitionLocation.range.start.character).toBe(16);
49+
expect(definitionLocation.range.end.line).toBe(11);
50+
expect(definitionLocation.range.end.character).toBe(28);
51+
});
52+
53+
test('Find All References', async () => {
54+
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
55+
return;
56+
}
57+
58+
const position = new vscode.Position(6, 41);
59+
const locations = <vscode.Location[]>(
60+
await vscode.commands.executeCommand(
61+
'vscode.executeReferenceProvider',
62+
vscode.window.activeTextEditor!.document.uri,
63+
position
64+
)
65+
);
66+
67+
expect(locations.length).toBe(3);
68+
69+
let definitionLocation = locations[0];
70+
expect(definitionLocation.uri.path).toBe(vscode.window.activeTextEditor!.document.uri.path);
71+
expect(definitionLocation.range.start.line).toBe(6);
72+
expect(definitionLocation.range.start.character).toBe(33);
73+
expect(definitionLocation.range.end.line).toBe(6);
74+
expect(definitionLocation.range.end.character).toBe(45);
75+
76+
definitionLocation = locations[1];
77+
expect(definitionLocation.uri.path).toBe(vscode.window.activeTextEditor!.document.uri.path);
78+
expect(definitionLocation.range.start.line).toBe(11);
79+
expect(definitionLocation.range.start.character).toBe(16);
80+
expect(definitionLocation.range.end.line).toBe(11);
81+
expect(definitionLocation.range.end.character).toBe(28);
82+
83+
definitionLocation = locations[2];
84+
expect(definitionLocation.uri.path).toBe(vscode.window.activeTextEditor!.document.uri.path);
85+
expect(definitionLocation.range.start.line).toBe(15);
86+
expect(definitionLocation.range.start.character).toBe(8);
87+
expect(definitionLocation.range.end.line).toBe(15);
88+
expect(definitionLocation.range.end.character).toBe(20);
89+
});
90+
91+
test('Go To Implementation', async () => {
92+
if (!integrationHelpers.isRazorWorkspace(vscode.workspace)) {
93+
return;
94+
}
95+
96+
const position = new vscode.Position(18, 18);
97+
const locations = <vscode.Location[]>(
98+
await vscode.commands.executeCommand(
99+
'vscode.executeImplementationProvider',
100+
vscode.window.activeTextEditor!.document.uri,
101+
position
102+
)
103+
);
104+
105+
expect(locations.length).toBe(1);
106+
const definitionLocation = locations[0];
107+
108+
expect(definitionLocation.uri.path).toBe(vscode.window.activeTextEditor!.document.uri.path);
109+
expect(definitionLocation.range.start.line).toBe(23);
110+
expect(definitionLocation.range.start.character).toBe(10);
111+
expect(definitionLocation.range.end.line).toBe(23);
112+
expect(definitionLocation.range.end.character).toBe(19);
113+
});
114+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@page "/definition"
2+
3+
<PageTitle>Counter</PageTitle>
4+
5+
<h1>Counter</h1>
6+
7+
<p role="status">Current count: @currentCount</p>
8+
9+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
10+
11+
@code {
12+
private int currentCount = 0;
13+
14+
private void IncrementCount()
15+
{
16+
currentCount++;
17+
}
18+
19+
interface ITestInterface
20+
{
21+
void TestMethod();
22+
}
23+
24+
class TestClass : ITestInterface
25+
{
26+
public void TestMethod()
27+
{
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)