Skip to content

Commit 9399ec1

Browse files
committed
Fix tests
1 parent e48767c commit 9399ec1

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

LinkDotNet.Blog.IntegrationTests/Web/Shared/ProfileTests.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void ShouldRenderAllItemsSortedByOrder()
1919
{
2020
var entry1 = new ProfileInformationEntryBuilder().WithContent("key 1").WithSortOrder(1).Build();
2121
var entry2 = new ProfileInformationEntryBuilder().WithContent("key 2").WithSortOrder(2).Build();
22-
var repoMock = RegisterServices();
22+
var (repoMock, _) = RegisterServices();
2323
repoMock.Setup(r => r.GetAllAsync())
2424
.ReturnsAsync(new List<ProfileInformationEntry> { entry1, entry2 });
2525
var cut = RenderComponent<Profile>();
@@ -49,7 +49,7 @@ public void ShouldShowAdminActionsWhenLoggedIn()
4949
[Fact]
5050
public void ShouldAddEntry()
5151
{
52-
var repo = RegisterServices();
52+
var (repo, _) = RegisterServices();
5353
ProfileInformationEntry entryToDb = null;
5454
repo.Setup(p => p.StoreAsync(It.IsAny<ProfileInformationEntry>()))
5555
.Callback<ProfileInformationEntry>(p => entryToDb = p);
@@ -69,7 +69,7 @@ public void ShouldDeleteEntryWhenConfirmed()
6969
{
7070
var entryToDelete = new ProfileInformationEntryBuilder().WithContent("key 2").Build();
7171
entryToDelete.Id = "SomeId";
72-
var repoMock = RegisterServices();
72+
var (repoMock, _) = RegisterServices();
7373
repoMock.Setup(r => r.GetAllAsync()).ReturnsAsync(new[] { entryToDelete });
7474
var cut = RenderComponent<Profile>(p => p.Add(s => s.IsAuthenticated, true));
7575
cut.Find(".profile-keypoints li button").Click();
@@ -84,7 +84,7 @@ public void ShouldNotDeleteEntryWhenNotConfirmed()
8484
{
8585
var entryToDelete = new ProfileInformationEntryBuilder().WithContent("key 2").Build();
8686
entryToDelete.Id = "SomeId";
87-
var repoMock = RegisterServices();
87+
var (repoMock, _) = RegisterServices();
8888
repoMock.Setup(r => r.GetAllAsync()).ReturnsAsync(new[] { entryToDelete });
8989
var cut = RenderComponent<Profile>(p => p.Add(s => s.IsAuthenticated, true));
9090
cut.Find(".profile-keypoints li button").Click();
@@ -97,7 +97,7 @@ public void ShouldNotDeleteEntryWhenNotConfirmed()
9797
[Fact]
9898
public void ShouldAddEntryWithCorrectSortOrder()
9999
{
100-
var repo = RegisterServices();
100+
var (repo, _) = RegisterServices();
101101
var entry = new ProfileInformationEntryBuilder().WithSortOrder(1).Build();
102102
repo.Setup(p => p.GetAllAsync()).ReturnsAsync(new[] { entry });
103103
ProfileInformationEntry entryToDb = null;
@@ -114,6 +114,12 @@ public void ShouldAddEntryWithCorrectSortOrder()
114114
entryToDb.SortOrder.Should().Be(1001);
115115
}
116116

117+
[Fact]
118+
public void ShouldSetNewOrderWhenItemDragAndDropped()
119+
{
120+
121+
}
122+
117123
private static AppConfiguration CreateEmptyConfiguration()
118124
{
119125
return new()
@@ -122,13 +128,15 @@ private static AppConfiguration CreateEmptyConfiguration()
122128
};
123129
}
124130

125-
private Mock<IProfileRepository> RegisterServices()
131+
private (Mock<IProfileRepository> repoMock, Mock<ISortOrderCalculator> calcMock) RegisterServices()
126132
{
127133
var repoMock = new Mock<IProfileRepository>();
134+
var calcMock = new Mock<ISortOrderCalculator>();
128135
Services.AddScoped(_ => CreateEmptyConfiguration());
129136
Services.AddScoped(_ => repoMock.Object);
137+
Services.AddScoped(_ => calcMock.Object);
130138
repoMock.Setup(r => r.GetAllAsync()).ReturnsAsync(new List<ProfileInformationEntry>());
131-
return repoMock;
139+
return (repoMock, calcMock);
132140
}
133141
}
134142
}

LinkDotNet.Blog.UnitTests/Web/Shared/SortOrderCalculatorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace LinkDotNet.Blog.UnitTests.Web.Shared
77
{
88
public class SortOrderCalculatorTests
99
{
10-
private SortOrderCalculator sut;
10+
private readonly SortOrderCalculator sut;
1111

1212
public SortOrderCalculatorTests()
1313
{

LinkDotNet.Blog.Web/Shared/Profile.razor

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
<div class="profile-image">
1515
<img src="@appConfiguration.ProfileInformation.ProfilePictureUrl" alt="Profile Picture" />
1616
</div>
17-
<ul class="profile-keypoints inverted-colors" ondragover="event.preventDefault();">
17+
<ul class="profile-keypoints inverted-colors"
18+
ondragover="event.preventDefault();">
1819
@foreach (var entry in profileInformationEntries)
1920
{
2021
@if (IsAuthenticated)
2122
{
2223
<li
23-
style="cursor: move"
24+
class="item-draggable"
2425
draggable="true"
2526
@ondrag="@(() => currentDragItem = entry)"
2627
@ondrop="@(() => HandleDrop(entry))">
@@ -54,6 +55,7 @@ OnYesPressed="DeleteItem"></ConfirmDialog>
5455
private ConfirmDialog Dialog { get; set; }
5556
private string currentDeleteKey;
5657
private ProfileInformationEntry currentDragItem;
58+
private string dropClass = string.Empty;
5759

5860
protected override async Task OnInitializedAsync()
5961
{
@@ -94,6 +96,7 @@ OnYesPressed="DeleteItem"></ConfirmDialog>
9496

9597
private async Task HandleDrop(ProfileInformationEntry dropTarget)
9698
{
99+
dropClass = string.Empty;
97100
if (currentDragItem == null || dropTarget == currentDragItem)
98101
{
99102
return;
@@ -106,5 +109,4 @@ OnYesPressed="DeleteItem"></ConfirmDialog>
106109
profileInformationEntries.Sort((a, b) => a.SortOrder.CompareTo(b.SortOrder));
107110
StateHasChanged();
108111
}
109-
110112
}

LinkDotNet.Blog.Web/Shared/Profile.razor.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@
4949
/* As the MarkupComponent is a base class we have to use deep */
5050
::deep .profile-keypoints li p {
5151
display: inline;
52+
}
53+
54+
.item-draggable {
55+
cursor: grab;
5256
}

0 commit comments

Comments
 (0)