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

Commit b724525

Browse files
committed
Change close issue caption when comment has body.
1 parent abeb1b8 commit b724525

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

src/GitHub.App/ViewModels/Documents/IssueishCommentViewModel.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.ComponentModel.Composition;
33
using System.Reactive;
4+
using System.Reactive.Linq;
45
using System.Threading.Tasks;
56
using GitHub.Models;
67
using GitHub.Services;
@@ -15,6 +16,8 @@ namespace GitHub.ViewModels.Documents
1516
[PartCreationPolicy(CreationPolicy.NonShared)]
1617
public class IssueishCommentViewModel : CommentViewModel, IIssueishCommentViewModel
1718
{
19+
ObservableAsPropertyHelper<string> closeIssueishCaption;
20+
1821
/// <summary>
1922
/// Initializes a new instance of the <see cref="CommentViewModel"/> class.
2023
/// </summary>
@@ -29,7 +32,7 @@ public IssueishCommentViewModel(ICommentService commentService)
2932
public bool CanCloseIssueish { get; private set; }
3033

3134
/// <inheritdoc/>
32-
public string CloseIssueishCaption { get; private set; }
35+
public string CloseIssueishCaption => closeIssueishCaption?.Value;
3336

3437
/// <inheritdoc/>
3538
public ReactiveCommand<Unit, Unit> CloseIssueish { get; }
@@ -49,7 +52,13 @@ await base.InitializeAsync(
4952
.ConfigureAwait(true);
5053

5154
CanCloseIssueish = closeCaption != null;
52-
CloseIssueishCaption = closeCaption;
55+
56+
if (closeCaption != null)
57+
{
58+
closeIssueishCaption = this.WhenAnyValue(x => x.Body)
59+
.Select(x => string.IsNullOrWhiteSpace(x) ? closeCaption : Resources.CloseAndComment)
60+
.ToProperty(this, x => x.CloseIssueishCaption);
61+
}
5362
}
5463
}
5564
}

src/GitHub.Resources/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GitHub.Resources/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,4 +848,7 @@ https://git-scm.com/download/win</value>
848848
<data name="CloseIssue" xml:space="preserve">
849849
<value>Close issue</value>
850850
</data>
851+
<data name="CloseAndComment" xml:space="preserve">
852+
<value>Close and comment</value>
853+
</data>
851854
</root>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using GitHub.Models;
7+
using GitHub.Services;
8+
using GitHub.ViewModels;
9+
using GitHub.ViewModels.Documents;
10+
using NSubstitute;
11+
using NUnit.Framework;
12+
13+
namespace GitHub.App.UnitTests.ViewModels.Documents
14+
{
15+
public class IssueishCommentViewModelTests
16+
{
17+
[Test]
18+
public async Task CloseIssueishCaption_Is_Set_When_Body_Empty()
19+
{
20+
var target = await CreateAndInitializeTarget(
21+
new CommentModel(),
22+
"Close issue");
23+
24+
Assert.That(target.CloseIssueishCaption, Is.EqualTo("Close issue"));
25+
}
26+
27+
[Test]
28+
public async Task CommitCaption_Is_Update_When_Body_Not_Empty()
29+
{
30+
var target = await CreateAndInitializeTarget(
31+
new CommentModel(),
32+
"Close issue");
33+
34+
target.Body = "Body";
35+
36+
Assert.That(target.CloseIssueishCaption, Is.EqualTo("Close and comment"));
37+
}
38+
39+
async Task<IssueishCommentViewModel> CreateAndInitializeTarget(
40+
CommentModel comment,
41+
string closeCaption,
42+
ICommentService commentService = null,
43+
ICommentThreadViewModel thread = null,
44+
ActorModel currentUser = null)
45+
{
46+
thread = thread ?? Substitute.For<ICommentThreadViewModel>();
47+
currentUser = currentUser ?? new ActorModel { Login = "grokys" };
48+
49+
var target = CreateTarget(commentService);
50+
await target.InitializeAsync(
51+
thread,
52+
currentUser,
53+
comment,
54+
closeCaption);
55+
return target;
56+
}
57+
58+
IssueishCommentViewModel CreateTarget(
59+
ICommentService commentService = null)
60+
{
61+
commentService = commentService ?? Substitute.For<ICommentService>();
62+
63+
return new IssueishCommentViewModel(commentService);
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)