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

Commit a5c0f99

Browse files
committed
add OnExit back in and place reset method in IViewModel
1 parent 124b8d5 commit a5c0f99

File tree

7 files changed

+19
-12
lines changed

7 files changed

+19
-12
lines changed

src/GitHub.App/Controllers/UIController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ void ConfigureUIHandlingStates()
339339
.OnEntry(tr => RunView(UIViewType.PRCreation, CalculateDirection(tr)))
340340
.PermitDynamic(Trigger.Next, () => Go(Trigger.Next))
341341
.PermitDynamic(Trigger.Cancel, () => Go(Trigger.Cancel))
342-
.PermitDynamic(Trigger.Finish, () => Go(Trigger.Finish));
342+
.PermitDynamic(Trigger.Finish, () => Go(Trigger.Finish))
343+
.OnExit(() => Reset());
343344

344345
uiStateMachine.Configure(UIViewType.Login)
345346
.OnEntry(tr => RunView(UIViewType.Login, CalculateDirection(tr)))

src/GitHub.App/SampleData/SampleViewModels.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,6 @@ public ReactivePropertyValidator<string> RepositoryNameValidator
122122
private set;
123123
}
124124

125-
public ICommand Reset
126-
{
127-
get;
128-
private set;
129-
}
130-
131125
public string SafeRepositoryName
132126
{
133127
get;

src/GitHub.App/ViewModels/BaseViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,9 @@ public bool IsBusy
2929
public virtual void Initialize([AllowNull] ViewWithData data)
3030
{
3131
}
32+
33+
public virtual void Reset()
34+
{
35+
}
3236
}
3337
}

src/GitHub.App/ViewModels/PullRequestCreationViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public void Dispose()
189189
GC.SuppressFinalize(this);
190190
}
191191

192-
void Reset()
192+
public override void Reset()
193193
{
194194
this.PRTitle = string.Empty;
195195
this.Description = string.Empty;

src/GitHub.Exports/ViewModels/IViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ public interface IViewModel
99
ICommand Cancel { get; }
1010
bool IsShowing { get; }
1111
void Initialize(ViewWithData data);
12+
void Reset();
1213
}
1314
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,5 +397,9 @@ protected override void Dispose(bool disposing)
397397
}
398398
base.Dispose(disposing);
399399
}
400+
401+
public void Reset()
402+
{
403+
}
400404
}
401405
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,29 +193,32 @@ public void TemplateIsUsedIfPresent()
193193
}
194194

195195
[Fact]
196-
public void FormClearsOnCancel()
196+
public async Task FormClearsOnCancel()
197197
{
198198
var data = PrepareTestData("octokit.net", "shana", "master", "octokit", "notmaster", "origin", true, true);
199199
var prservice = new PullRequestService(data.GitClient, data.GitService, data.ServiceProvider.GetOperatingSystem(), Substitute.For<IUsageTracker>());
200+
200201
var vm = new PullRequestCreationViewModel(data.RepositoryHost, data.ActiveRepo, prservice, data.NotificationService);
202+
vm.Initialize();
201203
vm.PRTitle = "a title";
202204
vm.Description = "a description";
203-
vm.CancelCommand.ExecuteAsync();
205+
vm.TargetBranch = new BranchModel("notmaster", data.TargetRepo);
206+
await vm.CancelCommand.ExecuteAsync();
204207

205208
Assert.Equal("master", vm.TargetBranch.Name);
206209
Assert.Equal(string.Empty, vm.PRTitle);
207210
Assert.Equal(string.Empty, vm.Description);
208211
}
209212

210213
[Fact]
211-
public void FormClearsOnCreation()
214+
public async Task FormClearsOnCreation()
212215
{
213216
var data = PrepareTestData("octokit.net", "shana", "master", "octokit", "notmaster", "origin", true, true);
214217
var prservice = new PullRequestService(data.GitClient, data.GitService, data.ServiceProvider.GetOperatingSystem(), Substitute.For<IUsageTracker>());
215218
var vm = new PullRequestCreationViewModel(data.RepositoryHost, data.ActiveRepo, prservice, data.NotificationService);
216219
vm.PRTitle = "a title";
217220
vm.Description = "a description";
218-
vm.CreatePullRequest.ExecuteAsync();
221+
await vm.CreatePullRequest.ExecuteAsync();
219222

220223
Assert.Equal("master", vm.TargetBranch.Name);
221224
Assert.Equal(string.Empty, vm.PRTitle);

0 commit comments

Comments
 (0)