Skip to content

Commit afee3a7

Browse files
Merge pull request #7 from IowaComputerGurus/feature/input-tag-helper-addition
Feature/input tag helper addition
2 parents 4499fdb + 790f625 commit afee3a7

21 files changed

+280
-199
lines changed

src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/Index.cshtml

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,21 +253,27 @@
253253
<tr>
254254
<td>
255255
<card>
256-
<card-header></card-header>
256+
<card-header title="Testing Header"></card-header>
257+
<card-body>
258+
This is my card body
259+
</card-body>
257260
</card>
258261
</td>
259262
<td>
260263
<code>
261264
&lt;card&gt;
262-
&lt;card-header &gt;&lt;/card-header&gt;
265+
&lt;card-header title=&quot;Testing Header&quot;&gt;&lt;/card-header&gt;
266+
&lt;card-body&gt;
267+
This is my card body
268+
&lt;/card-body&gt;
263269
&lt;/card&gt;
264270
</code>
265271
</td>
266272
</tr>
267273
<tr>
268274
<td>
269-
<card class="bg-success text-white">
270-
<card-header title="With Title"></card-header>
275+
<card class="bg-success text-white" id="testing-card-id">
276+
<card-header title="With Title and Id"></card-header>
271277
</card>
272278
</td>
273279
<td>
@@ -290,6 +296,9 @@
290296
<card-body>
291297
<p>This is my body</p>
292298
</card-body>
299+
<card-footer>
300+
This is my footer
301+
</card-footer>
293302
</card>
294303
</td>
295304
<td>
@@ -327,15 +336,15 @@
327336
Launch Demo
328337
</modal-toggle>
329338

330-
<modal id="testing" class="im-weird">
339+
<modal id="testing" class="im-weird" vertically-centered="true" >
331340
<modal-header Title="Testing Modal Header">
332341
<modal-header-dismiss></modal-header-dismiss>
333342
</modal-header>
334343
<modal-body>
335344
<form-input asp-for="FirstName"></form-input>
336345
</modal-body>
337346
<modal-footer>
338-
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
347+
<bs-button bs-color="Secondary" dismisses="modal">Close</bs-button>
339348
</modal-footer>
340349
</modal>
341350
</td>
@@ -358,7 +367,45 @@
358367
&lt;/modal&gt;
359368
</code>
360369
</td>
361-
</tr>
370+
</tr>
371+
<tr>
372+
<td>
373+
<modal-toggle Target="testing-secondary">
374+
Launch Demo
375+
</modal-toggle>
376+
377+
<modal id="testing-secondary" class="im-weird" vertically-centered="true" static-backdrop="true" >
378+
<modal-header Title="Testing Modal Header">
379+
<modal-header-dismiss></modal-header-dismiss>
380+
</modal-header>
381+
<modal-body>
382+
<form-input asp-for="FirstName"></form-input>
383+
</modal-body>
384+
<modal-footer>
385+
<bs-button bs-color="Secondary" dismisses="modal">Close</bs-button>
386+
</modal-footer>
387+
</modal>
388+
</td>
389+
<td>
390+
<code>
391+
&lt;modal-toggle Target=&quot;testing&quot;&gt;
392+
Launch Demo
393+
&lt;/modal-toggle&gt;
394+
395+
&lt;modal id=&quot;testing&quot;&gt;
396+
&lt;modal-header Title=&quot;Testing Modal Header&quot;&gt;
397+
&lt;modal-header-dismiss&gt;&lt;/modal-header-dismiss&gt;
398+
&lt;/modal-header&gt;
399+
&lt;modal-body&gt;
400+
&lt;form-input asp-for=&quot;FirstName&quot;&gt;&lt;/form-input&gt;
401+
&lt;/modal-body&gt;
402+
&lt;modal-footer&gt;
403+
&lt;button type=&quot;button&quot; class=&quot;btn btn-secondary&quot; data-dismiss=&quot;modal&quot;&gt;Close&lt;/button&gt;
404+
&lt;/modal-footer&gt;
405+
&lt;/modal&gt;
406+
</code>
407+
</td>
408+
</tr>
362409
</tbody>
363410
</table>
364411

src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/ButtonTagHelperTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,9 @@ public async Task Throws_Error_If_Invalid_ButtonSize()
109109
}
110110

111111
[Fact]
112-
public async Task Adds_Class_If_Block_Button()
112+
public async Task Adds_Attribute_If_Dismisses_Has_Value()
113113
{
114-
var output = await (new ButtonTagHelper() { Block=true }).Render();
115-
output.AssertContainsClass("btn-block");
114+
var output = await (new ButtonTagHelper() { Dismisses = "modal"}).Render();
116115
await VerifyTagHelper(output);
117116
}
118117

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Card;
2+
using Microsoft.AspNetCore.Razor.TagHelpers;
3+
4+
namespace ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Tests.Card;
5+
6+
public class CardFooterTagHelperTests : AbstractTagHelperTest
7+
{
8+
[Fact]
9+
public async Task Should_Render_As_Div()
10+
{
11+
//Arrange
12+
var context = MakeTagHelperContext();
13+
var output = MakeTagHelperOutput(" ");
14+
15+
//Act
16+
var helper = new CardFooterTagHelper();
17+
await helper.ProcessAsync(context, output);
18+
19+
//Assert
20+
Assert.Equal("div", output.TagName);
21+
}
22+
23+
[Fact]
24+
public async Task Should_Render_With_ProperClasses()
25+
{
26+
//Arrange
27+
var context = MakeTagHelperContext();
28+
var output = MakeTagHelperOutput(" ");
29+
30+
//Act
31+
var helper = new CardFooterTagHelper();
32+
await helper.ProcessAsync(context, output);
33+
34+
//Assert
35+
Assert.Equal("card-footer text-muted", output.Attributes["class"].Value.ToString());
36+
}
37+
38+
[Fact]
39+
public async Task Should_Render_With_ClassAdded_PreservingCustomClasses()
40+
{
41+
//Arrange
42+
var customClass = "testing-out";
43+
var expectedClass = $"{customClass} card-footer text-muted";
44+
var existingAttributes = new TagHelperAttributeList(new List<TagHelperAttribute>
45+
{new("class", customClass)});
46+
var context = MakeTagHelperContext();
47+
var output = MakeTagHelperOutput(" ", attributes:existingAttributes);
48+
49+
//Act
50+
var helper = new CardFooterTagHelper();
51+
await helper.ProcessAsync(context, output);
52+
53+
//Assert
54+
Assert.Equal(expectedClass, output.Attributes["class"].Value.ToString());
55+
}
56+
}

src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Card/CardHeaderActionsTagHelperTests.cs

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Card/CardHeaderTagHelperTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ public async Task Should_Render_With_ClassAdded_PreservingCustomClasses()
9090
}
9191

9292
[Theory]
93-
[InlineData("", "", "<div class=\"d-md-flex align-items-center w-100\"></div>")]
94-
[InlineData("Testing", "", "<div class=\"d-md-flex align-items-center w-100\"><h5>Testing</h5></div>")]
95-
[InlineData("Testing", "myCard", "<div class=\"d-md-flex align-items-center w-100\"><h5 id=\"myCardLabel\">Testing</h5></div>")]
93+
[InlineData("", "", "")]
94+
[InlineData("Testing", "", "Testing")]
95+
[InlineData("Testing", "myCard", "<span id=\"myCardLabel\">Testing</span>")]
9696
public async Task Should_Render_WithProper_InnerHtmlContent(string title, string contextId, string expectedOutput)
9797
{
9898
//Arrange

src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Card/CardTagHelperTests.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,28 @@ public async Task Should_Not_Error_With_Missing_Id_Attribute()
2121
Assert.Null(exception);
2222
}
2323

24+
[Fact]
25+
public async Task Should_Add_Context_Object_Without_Id_If_Missing()
26+
{
27+
//Arrange
28+
var context = MakeTagHelperContext();
29+
var output = MakeTagHelperOutput(" ");
30+
31+
//Act
32+
var helper = new CardTagHelper();
33+
await helper.ProcessAsync(context, output);
34+
35+
//Assert
36+
var generatedContext = Assert.IsType<CardContext>(context.Items[typeof(CardContext)]);
37+
Assert.Null(generatedContext.Id);
38+
}
39+
2440
[Fact]
2541
public async Task Should_Add_Context_Object_With_Provided_Id()
2642
{
2743
//Arrange
2844
var context = MakeTagHelperContext();
29-
var providedId = "testingCarg";
45+
var providedId = "testingCard";
3046
var existingAttributes = new TagHelperAttributeList(new List<TagHelperAttribute>
3147
{new("id", providedId)});
3248
var output = MakeTagHelperOutput(" ", existingAttributes);

src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Modal/ModalHeaderDismissTagHelperTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public void Should_Render_As_Button()
2222

2323
[Theory]
2424
[InlineData("aria-label", "Close")]
25-
[InlineData("data-dismiss", "modal")]
26-
[InlineData("class", "close")]
25+
[InlineData("data-bs-dismiss", "modal")]
26+
[InlineData("class", "btn-close")]
2727
[InlineData("type", "button")]
2828
public void Should_Set_Needed_Attributes(string expectedAttribute, string expectedValue)
2929
{

src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Modal/ModalHeaderTagHelperTests.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public async Task Should_NotRender_InnerContent_When_Title_Missing()
105105
}
106106

107107
[Theory]
108-
[InlineData("My Title", "", "<h5 class=\"modal-title\">My Title</h5>")]
109-
[InlineData("My Title", "myModal", "<h5 class=\"modal-title\" id=\"myModalLabel\">My Title</h5>")]
108+
[InlineData("My Title", "", "<h2 class=\"modal-title fs-5\">My Title</h2>")]
109+
[InlineData("My Title", "myModal", "<h2 class=\"modal-title fs-5\" id=\"myModalLabel\">My Title</h2>")]
110110
public async Task Should_Render_InnerContent_Title_When_Title_Provided(string title, string id, string expectedHtml)
111111
{
112112
//Arrange
@@ -121,4 +121,24 @@ public async Task Should_Render_InnerContent_Title_When_Title_Provided(string ti
121121
//Assert
122122
Assert.Equal(expectedHtml, output.Content.GetContent());
123123
}
124+
125+
[Theory]
126+
[InlineData("My Title", "", "", "<h2 class=\"modal-title fs-5\">My Title</h2>")]
127+
[InlineData("My Title", "myModal", "h5", "<h5 class=\"modal-title fs-5\" id=\"myModalLabel\">My Title</h5>")]
128+
public async Task Should_Render_InnerContent_Title_WithCustomTag_When_Title_Provided(string title, string id, string tag, string expectedHtml)
129+
{
130+
//Arrange
131+
TagHelperContext context = MakeTagHelperContext();
132+
context.Items.Add(typeof(ModalContext), new ModalContext { Id = id });
133+
TagHelperOutput output = MakeTagHelperOutput(" ");
134+
135+
//Act
136+
var helper = new ModalHeaderTagHelper { Title = title };
137+
if (!string.IsNullOrEmpty(tag))
138+
helper.TitleTag = tag;
139+
await helper.ProcessAsync(context, output);
140+
141+
//Assert
142+
Assert.Equal(expectedHtml, output.Content.GetContent());
143+
}
124144
}

src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Modal/ModalTagHelperTests.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public async Task Should_Render_Static_Backdrop_Attribute_When_Flagged(bool stat
120120
string expectedAttributeValue)
121121
{
122122
//Arrange
123-
var attributeName = "data-backdrop";
123+
var attributeName = "data-bs-backdrop";
124124
TagHelperContext context = MakeTagHelperContext();
125125
TagHelperOutput output = MakeTagHelperOutput(" ");
126126

@@ -139,6 +139,7 @@ public async Task Should_Render_Static_Backdrop_Attribute_When_Flagged(bool stat
139139
}
140140
}
141141

142+
142143
[Fact]
143144
public async Task Should_Render_Proper_InnerHtmlStructure_WithNoChildContent()
144145
{
@@ -153,4 +154,36 @@ public async Task Should_Render_Proper_InnerHtmlStructure_WithNoChildContent()
153154
//Assert
154155
Assert.Equal(expectedContent, output.Content.GetContent());
155156
}
157+
158+
[Fact]
159+
public async Task Should_Render_Centered_Class_When_Flagged()
160+
{
161+
//Arrange
162+
TagHelperContext context = MakeTagHelperContext();
163+
TagHelperOutput output = MakeTagHelperOutput(" ");
164+
var expectedContent = "<div class=\"modal-dialog modal-dialog-centered\"><div class=\"modal-content\"></div></div>";
165+
166+
//Act
167+
var helper = new ModalTagHelper { VerticallyCentered = true };
168+
await helper.ProcessAsync(context, output);
169+
170+
//Assert
171+
Assert.Equal(expectedContent, output.Content.GetContent());
172+
}
173+
174+
[Fact]
175+
public async Task Should_Render_Scrollable_Class_When_Flagged()
176+
{
177+
//Arrange
178+
TagHelperContext context = MakeTagHelperContext();
179+
TagHelperOutput output = MakeTagHelperOutput(" ");
180+
var expectedContent = "<div class=\"modal-dialog modal-dialog-scrollable\"><div class=\"modal-content\"></div></div>";
181+
182+
//Act
183+
var helper = new ModalTagHelper { Scrollable = true };
184+
await helper.ProcessAsync(context, output);
185+
186+
//Assert
187+
Assert.Equal(expectedContent, output.Content.GetContent());
188+
}
156189
}

0 commit comments

Comments
 (0)