Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 53995e8

Browse files
authored
Merge pull request #542 from OlsonAndrewD/480-fix-pr-refresh-showing-create-form
Fix refresh of PR list switching to "create" form.
2 parents 18fbdfc + 54e4182 commit 53995e8

File tree

6 files changed

+144
-4
lines changed

6 files changed

+144
-4
lines changed

src/GitHub.VisualStudio/PkgCmdID.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// MUST match PkgCmdID.h
33
namespace GitHub.VisualStudio
44
{
5-
static class PkgCmdIDList
5+
public static class PkgCmdIDList
66
{
77
public const int addConnectionCommand = 0x110;
88
public const int idGitHubToolbar = 0x1120;

src/GitHub.VisualStudio/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
[assembly: AssemblyTitle("GitHub.VisualStudio")]
55
[assembly: AssemblyDescription("GitHub for Visual Studio VSPackage")]
6-
[assembly: Guid("fad77eaa-3fe1-4c4b-88dc-3753b6263cd7")]
6+
[assembly: Guid("fad77eaa-3fe1-4c4b-88dc-3753b6263cd7")]

src/GitHub.VisualStudio/UI/Views/GitHubPaneViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ void StartFlow(UIControllerFlow controllerFlow, [AllowNull]IConnection conn, Vie
279279
void GoForward(ViewWithData data)
280280
{
281281
currentNavItem++;
282-
if (currentNavItem < navStack.Count - 1)
283-
navStack.RemoveRange(currentNavItem, navStack.Count - 1 - currentNavItem);
282+
if (currentNavItem < navStack.Count)
283+
navStack.RemoveRange(currentNavItem, navStack.Count - currentNavItem);
284284
navStack.Add(data);
285285
}
286286

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
using GitHub.Api;
2+
using GitHub.Exports;
3+
using GitHub.Models;
4+
using GitHub.Primitives;
5+
using GitHub.Services;
6+
using GitHub.UI;
7+
using GitHub.VisualStudio;
8+
using GitHub.VisualStudio.UI.Views;
9+
using NSubstitute;
10+
using System;
11+
using System.Collections.Generic;
12+
using System.Collections.ObjectModel;
13+
using System.ComponentModel.Composition;
14+
using System.ComponentModel.Design;
15+
using System.Linq;
16+
using System.Reactive.Linq;
17+
using UnitTests;
18+
using Xunit;
19+
20+
public class GitHubPaneViewModelTests : TestBaseClass
21+
{
22+
readonly IServiceProvider serviceProvider;
23+
readonly IUIController uiController;
24+
readonly FakeMenuCommandService menuCommandService;
25+
readonly GitHubPaneViewModel viewModel;
26+
UIViewType lastUiControllerJump;
27+
28+
public GitHubPaneViewModelTests()
29+
{
30+
var repositoryHosts = Substitutes.RepositoryHosts;
31+
repositoryHosts.IsLoggedInToAnyHost.Returns(true);
32+
33+
var teamExplorerServiceHolder = Substitute.For<ITeamExplorerServiceHolder>();
34+
var activeRepo = Substitute.For<ILocalRepositoryModel>();
35+
activeRepo.CloneUrl.Returns(new UriString("https://github.com/foo/foo"));
36+
teamExplorerServiceHolder
37+
.When(x => x.Subscribe(Arg.Any<object>(), Arg.Any<Action<ILocalRepositoryModel>>()))
38+
.Do(x =>
39+
{
40+
var invokeAction = x.Arg<Action<ILocalRepositoryModel>>();
41+
invokeAction(activeRepo);
42+
});
43+
44+
var connectionManager = Substitutes.ConnectionManager;
45+
var connection = Substitutes.Connection;
46+
var connectionHostAddress = HostAddress.Create(activeRepo.CloneUrl.ToString());
47+
connection.HostAddress.Returns(connectionHostAddress);
48+
connectionManager.Connections.Returns(new ObservableCollection<IConnection>(new[] {
49+
connection
50+
}));
51+
connection.Login().Returns(Observable.Return(connection));
52+
53+
var host = Substitute.For<IRepositoryHost>();
54+
host.IsLoggedIn.Returns(true);
55+
repositoryHosts.LookupHost(connectionHostAddress).Returns(host);
56+
57+
serviceProvider = Substitutes.GetFullyMockedServiceProvider();
58+
menuCommandService = new FakeMenuCommandService();
59+
serviceProvider.GetService(typeof(IMenuCommandService)).Returns(menuCommandService);
60+
61+
var uiProvider = serviceProvider as IUIProvider;
62+
uiProvider.TryGetService(typeof(IUIProvider)).Returns(serviceProvider);
63+
64+
uiController = Substitute.For<IUIController>();
65+
uiController.CurrentFlow.Returns(UIControllerFlow.PullRequests);
66+
uiController.SelectedFlow.Returns(UIControllerFlow.PullRequests);
67+
uiController
68+
.When(x => x.Jump(Arg.Any<ViewWithData>()))
69+
.Do(x => lastUiControllerJump = x.Arg<ViewWithData>().ViewType);
70+
71+
var exportFactoryProvider = Substitutes.ExportFactoryProvider;
72+
uiProvider.TryGetService(typeof(IExportFactoryProvider)).Returns(exportFactoryProvider);
73+
exportFactoryProvider.UIControllerFactory.Returns(new ExportFactory<IUIController>(
74+
() => Tuple.Create<IUIController, Action>(uiController, () => { })));
75+
76+
viewModel = new GitHubPaneViewModel(
77+
Substitute.For<ISimpleApiClientFactory>(),
78+
teamExplorerServiceHolder,
79+
connectionManager,
80+
repositoryHosts,
81+
Substitute.For<INotificationDispatcher>());
82+
83+
viewModel.ActiveRepo = activeRepo;
84+
}
85+
86+
[Fact]
87+
public void ListRefreshKeepsListVisible_DoesNotSwitchToPRCreation()
88+
{
89+
RunSteps(new[]
90+
{
91+
new NavStep(LoadDirection.Forward, UIViewType.PRList),
92+
new NavStep(LoadDirection.Forward, UIViewType.PRCreation),
93+
new NavStep(LoadDirection.Back, UIViewType.PRList),
94+
new NavStep(LoadDirection.Forward, UIViewType.PRCreation),
95+
new NavStep(LoadDirection.Forward, UIViewType.PRList),
96+
});
97+
98+
menuCommandService.ExecuteCommand(PkgCmdIDList.refreshCommand);
99+
100+
Assert.Equal(UIViewType.PRList, lastUiControllerJump);
101+
}
102+
103+
private void RunSteps(IEnumerable<NavStep> steps)
104+
{
105+
var observableSteps = steps
106+
.Select(x => new LoadData
107+
{
108+
Direction = x.Direction,
109+
Data = new ViewWithData() { ViewType = x.ViewType },
110+
View = Substitute.For<IView>()
111+
})
112+
.ToObservable();
113+
114+
uiController.SelectFlow(UIControllerFlow.PullRequests).Returns(observableSteps);
115+
116+
viewModel.Initialize(serviceProvider);
117+
}
118+
119+
private class NavStep
120+
{
121+
public NavStep(LoadDirection direction, UIViewType viewtype)
122+
{
123+
Direction = direction;
124+
ViewType = viewtype;
125+
}
126+
127+
public LoadDirection Direction { get; private set; }
128+
public UIViewType ViewType { get; private set; }
129+
}
130+
}

src/UnitTests/TestDoubles/FakeMenuCommandService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ public void AddCommand(MenuCommand command)
1717
addedCommands.Add(command);
1818
}
1919

20+
public void ExecuteCommand(int commandId)
21+
{
22+
var command = addedCommands.Find(_ => _.CommandID.ID == commandId);
23+
if (command != null)
24+
{
25+
command.Invoke();
26+
}
27+
}
28+
2029
public void AddVerb(DesignerVerb verb)
2130
{
2231
throw new NotImplementedException();

src/UnitTests/UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
<Compile Include="GitHub.VisualStudio\Services\ConnectionManagerTests.cs" />
191191
<Compile Include="GitHub.VisualStudio\Services\RepositoryPublishServiceTests.cs" />
192192
<Compile Include="GitHub.VisualStudio\TeamExplorer\Home\GraphsNavigationItemTests.cs" />
193+
<Compile Include="GitHub.VisualStudio\UI\Views\GitHubPaneViewModelTests.cs" />
193194
<Compile Include="GitHubPackageTests.cs" />
194195
<Compile Include="Helpers\CommandTestHelpers.cs" />
195196
<Compile Include="Helpers\LazySubstitute.cs" />

0 commit comments

Comments
 (0)