Skip to content

Commit 03defda

Browse files
Fix tests
1 parent d81c499 commit 03defda

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

JournalApp.Tests/ManageCategoriesTests.razor

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public void EditDialog_Open()
1515
{
1616
var dbf = Services.GetService<IDbContextFactory<AppDbContext>>();
17-
var guid = "0fb54aff-9ecc-4c17-bab5-b908b794cea9"; // Anxiety.
17+
var guid = "de394b38-9007-4349-ae31-429541aab947"; // Physical activity.
1818
1919
var layout = Render(
2020
@<MainLayout>
@@ -30,18 +30,19 @@
3030
return db.Categories.Single(c => c.Guid == new Guid(guid));
3131
}
3232

33+
layout.Find($"#manage-category-{guid} > .manage-category-edit-button").HasAttribute("disabled").Should().BeFalse();
3334
layout.Find($"#manage-category-{guid} > .manage-category-edit-button").Click();
3435
var editDialog = layout.FindComponent<EditCategoryDialog>();
3536

3637
// Assert.
37-
Category().Name.Should().Be("Anxiety");
38-
editDialog.FindAll(".mud-input-text input")[0].GetAttribute("value").Should().Be("Anxiety");
38+
Category().Name.Should().Be("Physical activity");
39+
editDialog.FindAll(".mud-input-text input")[0].GetAttribute("value").Should().Be("Physical activity");
3940

4041
layout.Find(".submit-button").Click();
4142
}
4243

4344
[Fact]
44-
public void EditDialog_UpdatesList()
45+
public void EditDialog_ShouldNotOpenWhenCategoryIsDisabled()
4546
{
4647
var dbf = Services.GetService<IDbContextFactory<AppDbContext>>();
4748
var guid = "0fb54aff-9ecc-4c17-bab5-b908b794cea9"; // Anxiety.
@@ -54,6 +55,44 @@
5455
</MainLayout>
5556
);
5657

58+
layout.Find($"#manage-category-{guid} > .manage-category-edit-button").HasAttribute("disabled").Should().BeTrue();
59+
layout.Find($"#manage-category-{guid} > .manage-category-edit-button").Click();
60+
layout.HasComponent<EditCategoryDialog>().Should().BeFalse();
61+
}
62+
63+
[Fact]
64+
public void EditDialog_ShouldNotOpenWhenCategoryIsReadOnly()
65+
{
66+
var dbf = Services.GetService<IDbContextFactory<AppDbContext>>();
67+
var guid = "d90d89fb-f5b9-47cf-ae4e-3ec0d635e783"; // Overall mood.
68+
69+
var layout = Render(
70+
@<MainLayout>
71+
<Body>
72+
<ManageCategoriesPage />
73+
</Body>
74+
</MainLayout>
75+
);
76+
77+
layout.Find($"#manage-category-{guid} > .manage-category-edit-button").HasAttribute("disabled").Should().BeTrue();
78+
layout.Find($"#manage-category-{guid} > .manage-category-edit-button").Click();
79+
layout.HasComponent<EditCategoryDialog>().Should().BeFalse();
80+
}
81+
82+
[Fact]
83+
public void EditDialog_UpdatesList()
84+
{
85+
var dbf = Services.GetService<IDbContextFactory<AppDbContext>>();
86+
var guid = "de394b38-9007-4349-ae31-429541aab947"; // Physical activity.
87+
88+
var layout = Render(
89+
@<MainLayout>
90+
<Body>
91+
<ManageCategoriesPage />
92+
</Body>
93+
</MainLayout>
94+
);
95+
5796
DataPointCategory Category()
5897
{
5998
using var db = dbf.CreateDbContext();
@@ -62,7 +101,7 @@
62101

63102
layout.Find($"#manage-category-{guid} > .manage-category-edit-button").Click();
64103

65-
Category().Name.Should().Be("Anxiety");
104+
Category().Name.Should().Be("Physical activity");
66105
layout.FindAll(".category-dialog .mud-input-text input")[0].Input("New name");
67106

68107
// Submit changes and confirm they have changed on the main list.
@@ -89,7 +128,7 @@
89128

90129
// Open the dialog to create a new category.
91130
layout.Find(".add-category-button").Click();
92-
layout.Markup.Should().Contain("New card");
131+
layout.Markup.Should().Contain("New element");
93132

94133
// Set up the new category.
95134
layout.FindAll(".category-dialog .mud-input-text input")[0].Input("New name");
@@ -111,7 +150,7 @@
111150
);
112151

113152
// Initial state.
114-
layout.FindAll(".manage-category-edit-button").Count.Should().Be(5);
153+
layout.FindAll(".manage-category-edit-button").Count.Should().Be(3);
115154

116155
// Open the dialog to create a new category.
117156
layout.Find(".add-category-button").Click();
@@ -122,7 +161,7 @@
122161

123162
// Submit changes and confirm there is a new category in the list.
124163
layout.Find(".category-dialog .submit-button").Click();
125-
layout.FindAll(".manage-category-edit-button").Count.Should().Be(6);
164+
layout.FindAll(".manage-category-edit-button").Count.Should().Be(4);
126165
}
127166

128167
[Fact]

JournalApp/Components/EditCategoryDialog.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<MudDialog Class="category-dialog" DefaultFocus="DefaultFocus.FirstChild" OnBackdropClick="Submit">
77
<TitleContent>
8-
<MudText Typo="Typo.h6">@(Category == null ? "New" : "Edit") @(Group == "Medications" ? "medication" : "card")</MudText>
8+
<MudText Typo="Typo.h6">@(Category == null ? "New" : "Edit") @(Group == "Medications" ? "medication" : "element")</MudText>
99
</TitleContent>
1010

1111
<DialogContent>

0 commit comments

Comments
 (0)