Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap with tag integration tests #8116

Merged
merged 8 commits into from
Feb 14, 2023
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System.Threading.Tasks;
using Xunit;

namespace Microsoft.VisualStudio.Razor.IntegrationTests;

public class WrapWithTagTests : AbstractRazorEditorTest
{
[IdeFact]
public async Task WrapWithTag_RootLevelElement()
{
// Open the file
await TestServices.SolutionExplorer.OpenFileAsync(RazorProjectConstants.BlazorProjectName, RazorProjectConstants.CounterRazorFile, ControlledHangMitigatingCancellationToken);

await TestServices.Editor.PlaceCaretAsync("h1", charsOffset: -1, ControlledHangMitigatingCancellationToken);

await TestServices.Editor.WaitForComponentClassificationAsync(ControlledHangMitigatingCancellationToken);

// Act
// % == Alt, + == Shift, so this is Alt+Shift+W
TestServices.Input.Send("%+w");
davidwengier marked this conversation as resolved.
Show resolved Hide resolved

// Assert
await TestServices.Editor.WaitForCurrentLineTextAsync("<div><h1>Counter</h1></div>", ControlledHangMitigatingCancellationToken);
}

[IdeFact]
public async Task WrapWithTag_ChildElement()
{
// Open the file
await TestServices.SolutionExplorer.OpenFileAsync(RazorProjectConstants.BlazorProjectName, RazorProjectConstants.FetchDataRazorFile, ControlledHangMitigatingCancellationToken);

await TestServices.Editor.PlaceCaretAsync("<em", charsOffset: 1, ControlledHangMitigatingCancellationToken);

await TestServices.Editor.WaitForComponentClassificationAsync(ControlledHangMitigatingCancellationToken);

// Act
// % == Alt, + == Shift, so this is Alt+Shift+W
TestServices.Input.Send("%+w");

// Assert
await TestServices.Editor.WaitForCurrentLineTextAsync("<p><div><em>Loading...</em></div></p>", ControlledHangMitigatingCancellationToken);
}

[IdeFact]
public async Task WrapWithTag_Multiline()
{
// Open the file
await TestServices.SolutionExplorer.OpenFileAsync(RazorProjectConstants.BlazorProjectName, RazorProjectConstants.IndexRazorFile, ControlledHangMitigatingCancellationToken);

await TestServices.Editor.SetTextAsync("""
@{
var items = new[] { 1, 2, 3, 4 };
}
<PageTitle>Temp</PageTitle>
<div>
<table>
@foreach (var item in items) {
<tr>
<td>@item</td>
</tr>
}
</table>
</div>
""", ControlledHangMitigatingCancellationToken);

await TestServices.Editor.PlaceCaretAsync("table", charsOffset: -1, ControlledHangMitigatingCancellationToken);

await TestServices.Editor.WaitForComponentClassificationAsync(ControlledHangMitigatingCancellationToken);

// Act
// % == Alt, + == Shift, so this is Alt+Shift+W
TestServices.Input.Send("%+w");

// Assert
await TestServices.Editor.WaitForTextChangeAsync("""
@{
var items = new[] { 1, 2, 3, 4 };
}
<PageTitle>Temp</PageTitle>
<div>
<div>
<table>
@foreach (var item in items) {
<tr>
<td>@item</td>
</tr>
}
</table>
</div>
</div>
""", ControlledHangMitigatingCancellationToken);
}

[IdeFact]
public async Task WrapWithTag_SelfClosingTag()
{
// Open the file
await TestServices.SolutionExplorer.OpenFileAsync(RazorProjectConstants.BlazorProjectName, RazorProjectConstants.IndexRazorFile, ControlledHangMitigatingCancellationToken);

await TestServices.Editor.PlaceCaretAsync("SurveyPrompt", charsOffset: -1, ControlledHangMitigatingCancellationToken);

await TestServices.Editor.WaitForComponentClassificationAsync(ControlledHangMitigatingCancellationToken);

// Act
// % == Alt, + == Shift, so this is Alt+Shift+W
TestServices.Input.Send("%+w");

// Assert
await TestServices.Editor.WaitForCurrentLineTextAsync("<div><SurveyPrompt Title=\"How is Blazor working for you?\" /></div>", ControlledHangMitigatingCancellationToken);
davidwengier marked this conversation as resolved.
Show resolved Hide resolved
}
}