Skip to content

Commit 556a920

Browse files
authored
Add integration tests for UI
1 parent 73767d0 commit 556a920

15 files changed

+412
-20
lines changed

src/LibraryManager.Vsix/ErrorList/ErrorList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public bool HandleErrors(IEnumerable<ILibraryOperationResult> results)
4242

4343
private static void AddLineAndColumn(IEnumerable<string> lines, ILibraryInstallationState state, DisplayError[] errors)
4444
{
45-
if(string.IsNullOrEmpty(state?.LibraryId))
45+
if (string.IsNullOrEmpty(state?.LibraryId))
4646
{
4747
return;
4848
}

src/LibraryManager.Vsix/Microsoft.Web.LibraryManager.Vsix.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<ItemGroup>
5555
<Compile Include="Commands\InstallLibraryCommand.cs" />
5656
<Compile Include="Shared\DefaultSolutionEvents.cs" />
57+
<Compile Include="UI\InstallDialogProvider.cs" />
5758
<Compile Include="UI\Controls\BindingProxy.cs" />
5859
<Compile Include="UI\Controls\BindLibraryNameToTargetLocation.cs" />
5960
<Compile Include="UI\Controls\PackageContentsTreeView.xaml.cs">
@@ -70,6 +71,7 @@
7071
<Compile Include="UI\Converters\NotConverter.cs" />
7172
<Compile Include="UI\Converters\PackageItemIconConverter.cs" />
7273
<Compile Include="UI\Converters\VisibleIfNonNullConverter.cs" />
74+
<Compile Include="UI\IInstallDialog.cs" />
7375
<Compile Include="UI\InstallDialog.xaml.cs">
7476
<DependentUpon>InstallDialog.xaml</DependentUpon>
7577
</Compile>

src/LibraryManager.Vsix/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Microsoft.Web.LibraryManager.Vsix;
55
using System.Reflection;
6+
using System.Runtime.CompilerServices;
67
using System.Runtime.InteropServices;
78
using System.Runtime.CompilerServices;
89

@@ -17,3 +18,4 @@
1718
[assembly: InternalsVisibleTo("Microsoft.Web.LibraryManager.Vsix.Test")]
1819

1920
[assembly: ComVisible(false)]
21+
[assembly: InternalsVisibleTo("Microsoft.Web.LibraryManager.IntegrationTest")]

src/LibraryManager.Vsix/Shared/LibraryCommandService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public bool IsOperationInProgress
6565

6666
public async Task RestoreAsync(string configFilePath, CancellationToken cancellationToken)
6767
{
68-
Dictionary<string, Manifest> manifests = await GetManifestFromConfigAsync(new[] { configFilePath }, cancellationToken);
68+
Dictionary<string, Manifest> manifests = await GetManifestFromConfigAsync(new[] { configFilePath }, cancellationToken).ConfigureAwait(false);
6969

7070
if (manifests.Count > 0)
7171
{
@@ -75,7 +75,7 @@ public async Task RestoreAsync(string configFilePath, CancellationToken cancella
7575

7676
public async Task RestoreAsync(IEnumerable<string> configFilePaths, CancellationToken cancellationToken)
7777
{
78-
Dictionary<string, Manifest> manifests = await GetManifestFromConfigAsync(configFilePaths, cancellationToken);
78+
Dictionary<string, Manifest> manifests = await GetManifestFromConfigAsync(configFilePaths, cancellationToken).ConfigureAwait(false);
7979
await RestoreAsync(manifests, cancellationToken);
8080
}
8181

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Microsoft.Web.LibraryManager.Vsix.UI
4+
{
5+
/// <summary>
6+
/// Test contract for add client side libraries dialog.
7+
/// </summary>
8+
public interface IInstallDialog
9+
{
10+
string Library { get; set; }
11+
12+
Task ClickInstallAsync();
13+
14+
bool IsAnyFileSelected { get; }
15+
}
16+
}

src/LibraryManager.Vsix/UI/InstallDialog.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@
167167
Name="InstallButton"
168168
Width="65"
169169
DockPanel.Dock="Right"
170-
Margin="0 0 6 0" IsDefault="True"
171-
Command="{Binding InstallPackageCommand}"
172-
Click="InstallButton_Clicked"
170+
Margin="0 0 6 0"
171+
IsDefault="True"
172+
Click="InstallButton_ClickedAsync"
173173
KeyboardNavigation.TabIndex="1" />
174174
</DockPanel>
175175
</Grid>

src/LibraryManager.Vsix/UI/InstallDialog.xaml.cs

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace Microsoft.Web.LibraryManager.Vsix.UI
1818
{
19-
internal partial class InstallDialog : DialogWindow
19+
internal partial class InstallDialog : DialogWindow, IInstallDialog
2020
{
2121
private readonly IDependencies _deps;
2222
private readonly string _fullPath;
@@ -47,6 +47,22 @@ public InstallDialog(IDependencies dependencies, ILibraryCommandService libraryC
4747
Loaded += OnLoaded;
4848
}
4949

50+
protected override void OnActivated(EventArgs e)
51+
{
52+
base.OnActivated(e);
53+
OnActivateTestContract();
54+
}
55+
56+
private void OnActivateTestContract()
57+
{
58+
InstallDialogProvider.Window = this;
59+
}
60+
61+
protected override void OnClosed(EventArgs e)
62+
{
63+
InstallDialogProvider.Window = null;
64+
}
65+
5066
internal InstallDialogViewModel ViewModel
5167
{
5268
get { return DataContext as InstallDialogViewModel; }
@@ -186,18 +202,26 @@ private void ProviderComboBox_SelectionChanged(object sender, SelectionChangedEv
186202
}
187203
}
188204

189-
private void InstallButton_Clicked(object sender, RoutedEventArgs e)
205+
private async void InstallButton_ClickedAsync(object sender, RoutedEventArgs e)
190206
{
191-
bool isLibraryInstallationStateValid = false;
207+
await ClickInstallButtonAsync();
208+
}
192209

193-
Shell.ThreadHelper.JoinableTaskFactory.Run(async () =>
194-
{
195-
isLibraryInstallationStateValid = await ViewModel.IsLibraryInstallationStateValidAsync().ConfigureAwait(false);
196-
});
210+
private async Task<bool> IsLibraryInstallationStateValidAsync()
211+
{
212+
bool isLibraryInstallationStateValid = await ViewModel.IsLibraryInstallationStateValidAsync().ConfigureAwait(false);
213+
return isLibraryInstallationStateValid;
214+
}
215+
216+
async Task ClickInstallButtonAsync()
217+
{
218+
bool isLibraryInstallationStateValid = await IsLibraryInstallationStateValidAsync().ConfigureAwait(false);
197219

198220
if (isLibraryInstallationStateValid)
199221
{
222+
await Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
200223
CloseDialog(true);
224+
ViewModel.InstallPackageCommand.Execute(null);
201225
}
202226
else
203227
{
@@ -217,5 +241,30 @@ private void InstallButton_Clicked(object sender, RoutedEventArgs e)
217241
pnResult: out result);
218242
}
219243
}
244+
245+
string IInstallDialog.Library
246+
{
247+
get
248+
{
249+
return LibrarySearchBox.Text;
250+
}
251+
set
252+
{
253+
this.LibrarySearchBox.Text = value;
254+
}
255+
}
256+
257+
async Task IInstallDialog.ClickInstallAsync()
258+
{
259+
await ClickInstallButtonAsync();
260+
}
261+
262+
bool IInstallDialog.IsAnyFileSelected
263+
{
264+
get
265+
{
266+
return !ViewModel.IsTreeViewEmpty;
267+
}
268+
}
220269
}
221270
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
3+
namespace Microsoft.Web.LibraryManager.Vsix.UI
4+
{
5+
/// <summary>
6+
/// This class gives apex access to opened - add client side libraries dialog.
7+
/// </summary>
8+
internal class InstallDialogProvider
9+
{
10+
private static IInstallDialog _installDialog;
11+
public static event EventHandler WindowChanged;
12+
13+
public static IInstallDialog Window
14+
{
15+
get { return _installDialog; }
16+
set
17+
{
18+
_installDialog = value;
19+
20+
WindowChanged?.Invoke(null, new EventArgs());
21+
}
22+
}
23+
}
24+
}

src/LibraryManager.Vsix/UI/Models/InstallDialogViewModel.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public InstallDialogViewModel(Dispatcher dispatcher, ILibraryCommandService libr
8484
}
8585

8686
Providers = providers;
87-
InstallPackageCommand = ActionCommand.Create(InstallPackageAsync, CanInstallPackage, false);
87+
InstallPackageCommand = ActionCommand.Create(InstallPackage, CanInstallPackage, false);
8888
Task t = LoadPackagesAsync();
8989
}
9090

@@ -416,7 +416,12 @@ private static bool IsAnyFileSelected(IReadOnlyList<PackageItem> children)
416416
return false;
417417
}
418418

419-
private async void InstallPackageAsync()
419+
private void InstallPackage()
420+
{
421+
Shell.ThreadHelper.JoinableTaskFactory.RunAsync(async() => await InstallPackageAsync()).Task.ConfigureAwait(false);
422+
}
423+
424+
private async Task InstallPackageAsync()
420425
{
421426
try
422427
{

src/LibraryManager/Providers/Cdnjs/CdnjsProvider.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Threading;
99
using System.Threading.Tasks;
1010
using Microsoft.Web.LibraryManager.Contracts;
11-
using Microsoft.Web.LibraryManager.LibraryNaming;
1211
using Microsoft.Web.LibraryManager.Resources;
1312

1413
namespace Microsoft.Web.LibraryManager.Providers.Cdnjs

0 commit comments

Comments
 (0)