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

Commit 2696454

Browse files
committed
remove unnecessary tests, add IUController test
1 parent 9b82783 commit 2696454

File tree

2 files changed

+59
-36
lines changed

2 files changed

+59
-36
lines changed

src/UnitTests/GitHub.App/Controllers/UIControllerTests.cs

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,6 @@ public void Flow()
637637
Assert.True(uiController.IsStopped);
638638
Assert.True(success.HasValue);
639639
Assert.False(success);
640-
641-
var vm = provider.GetExportFactoryProvider().GetViewModel(GitHub.Exports.UIViewType.PRCreation).Value;
642-
Assert.Equal(2, vm.ReceivedCalls().Where(x => x.GetMethodInfo().Name == nameof(IViewModel.Reset)).Count());
643640
}
644641
}
645642

@@ -705,6 +702,65 @@ public void ShuttingDown()
705702
Assert.True(success);
706703
}
707704
}
705+
706+
[Fact]
707+
void ResetIsCalled()
708+
{
709+
var provider = Substitutes.GetFullyMockedServiceProvider();
710+
var hosts = provider.GetRepositoryHosts();
711+
var factory = SetupFactory(provider);
712+
var cm = provider.GetConnectionManager();
713+
var cons = new ObservableCollection<IConnection>();
714+
cm.Connections.Returns(cons);
715+
716+
// simulate being logged in
717+
cons.Add(SetupConnection(provider, hosts, hosts.GitHubHost));
718+
719+
using (var uiController = new UIController((IUIProvider)provider, hosts, factory, cm))
720+
{
721+
var count = 0;
722+
bool? success = null;
723+
var flow = uiController.SelectFlow(UIControllerFlow.PullRequests);
724+
uiController.ListenToCompletionState()
725+
.Subscribe(s =>
726+
{
727+
success = s;
728+
});
729+
flow.Subscribe(data =>
730+
{
731+
var uc = data.View;
732+
switch (++count)
733+
{
734+
case 1:
735+
Assert.IsAssignableFrom<IViewFor<IPullRequestListViewModel>>(uc);
736+
((ReplaySubject<ViewWithData>)((IHasCreationView)uc).Create).OnNext(null);
737+
break;
738+
case 2:
739+
Assert.IsAssignableFrom<IViewFor<IPullRequestCreationViewModel>>(uc);
740+
TriggerCancel(uc);
741+
break;
742+
case 3:
743+
Assert.IsAssignableFrom<IViewFor<IPullRequestListViewModel>>(uc);
744+
((ReplaySubject<ViewWithData>)((IHasCreationView)uc).Create).OnNext(null);
745+
break;
746+
case 4:
747+
Assert.IsAssignableFrom<IViewFor<IPullRequestCreationViewModel>>(uc);
748+
TriggerDone(uc);
749+
break;
750+
case 5:
751+
Assert.IsAssignableFrom<IViewFor<IPullRequestListViewModel>>(uc);
752+
TriggerCancel(uc);
753+
break;
754+
}
755+
});
756+
757+
uiController.Start(null);
758+
Assert.Equal(5, count);
759+
760+
var vm = provider.GetExportFactoryProvider().GetViewModel(GitHub.Exports.UIViewType.PRCreation).Value;
761+
Assert.Equal(2, vm.ReceivedCalls().Where(x => x.GetMethodInfo().Name == nameof(IViewModel.Reset)).Count());
762+
}
763+
}
708764
}
709765

710766
public class GistFlow : UIControllerTestBase

src/UnitTests/GitHub.App/ViewModels/PullRequestCreationViewModelTests.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -191,37 +191,4 @@ public void TemplateIsUsedIfPresent()
191191

192192
Assert.Equal("Test PR template", vm.Description);
193193
}
194-
195-
[Fact]
196-
public async Task FormClearsOnCancel()
197-
{
198-
var data = PrepareTestData("octokit.net", "shana", "master", "octokit", "notmaster", "origin", true, true);
199-
var prservice = new PullRequestService(data.GitClient, data.GitService, data.ServiceProvider.GetOperatingSystem(), Substitute.For<IUsageTracker>());
200-
201-
var vm = new PullRequestCreationViewModel(data.RepositoryHost, data.ActiveRepo, prservice, data.NotificationService);
202-
vm.Initialize();
203-
vm.PRTitle = "a title";
204-
vm.Description = "a description";
205-
vm.TargetBranch = new BranchModel("notmaster", data.TargetRepo);
206-
await vm.CancelCommand.ExecuteAsync();
207-
208-
Assert.Equal("master", vm.TargetBranch.Name);
209-
Assert.Equal(string.Empty, vm.PRTitle);
210-
Assert.Equal(string.Empty, vm.Description);
211-
}
212-
213-
[Fact]
214-
public async Task FormClearsOnCreation()
215-
{
216-
var data = PrepareTestData("octokit.net", "shana", "master", "octokit", "notmaster", "origin", true, true);
217-
var prservice = new PullRequestService(data.GitClient, data.GitService, data.ServiceProvider.GetOperatingSystem(), Substitute.For<IUsageTracker>());
218-
var vm = new PullRequestCreationViewModel(data.RepositoryHost, data.ActiveRepo, prservice, data.NotificationService);
219-
vm.PRTitle = "a title";
220-
vm.Description = "a description";
221-
await vm.CreatePullRequest.ExecuteAsync();
222-
223-
Assert.Equal("master", vm.TargetBranch.Name);
224-
Assert.Equal(string.Empty, vm.PRTitle);
225-
Assert.Equal(string.Empty, vm.Description);
226-
}
227194
}

0 commit comments

Comments
 (0)