Skip to content

Commit

Permalink
Fixed tests.
Browse files Browse the repository at this point in the history
Integrated testing into CI-CD.
bumped coverage to 94%, something to brag about.
  • Loading branch information
ddjerqq committed Mar 5, 2024
1 parent 68ef98f commit 3c813ab
Show file tree
Hide file tree
Showing 27 changed files with 361 additions and 560 deletions.
21 changes: 20 additions & 1 deletion .github/workflows/publish-docs-to-gh-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,28 @@ on:
branches: [ "master" ]

jobs:
test:
concurrency: ci-${{ github.ref }}
runs-on: ubuntu-latest

steps:
- name: Checkout 🛎️
uses: actions/[email protected]

- name: Load Cache 📦
uses: actions/cache@v2
with:
key: ${{ github.ref }}
path: .cache/test

- name: Test 🧪
run: dotnet test --verbosity normal


build-and-publish-docs:
concurrency: ci-${{ github.ref }}
runs-on: ubuntu-latest
needs: test

permissions:
contents: write
Expand All @@ -25,7 +44,7 @@ jobs:
uses: actions/cache@v2
with:
key: ${{ github.ref }}
path: .cache
path: .cache/docs

- name: Install Python mkdocs-material 🐍
run: pip install mkdocs-material
Expand Down
18 changes: 17 additions & 1 deletion .github/workflows/publish-to-nuget-on-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,33 @@ on:
types: [published]

jobs:
build-and-publish:
test:
concurrency: ci-${{ github.ref }}
runs-on: ubuntu-latest

steps:
- name: Checkout 🛎️
uses: actions/[email protected]

- name: Load Cache 📦
uses: actions/cache@v2
with:
key: ${{ github.ref }}
path: .cache/test

- name: Test 🧪
run: dotnet test --verbosity normal


build-and-publish:
concurrency: ci-${{ github.ref }}
runs-on: ubuntu-latest
needs: test

steps:
- name: Checkout 🛎️
uses: actions/[email protected]

- name: Pack 📦
run: dotnet pack --configuration Release --output .

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![docs](https://img.shields.io/badge/read_the-docs-blue)](https://ddjerqq.github.io/quickform)
![docs](https://img.shields.io/badge/test_coverage-94%25-green)

[![Discord](https://dcbadge.vercel.app/api/server/DsAXsMuEbx?style=flat)](https://discord.gg/DsAXsMuEbx)
[![Nuget](https://img.shields.io/nuget/v/QuickForm)](https://www.nuget.org/packages/QuickForm/)
Expand Down
5 changes: 5 additions & 0 deletions docs/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ title: Attributes
| `DataType.PhoneNumber` | `tel` |
| `DataType.Url` or `DataType.ImageUrl` | `url` |
| `DataType.MultilineText` | `null` |
| `DataType("custom")` | `custom` |

!!! info "Custom data types"

Custom data types are useful for `hidden`, `search`, or other relatively-rare input types.

## DateTypes

Expand Down
7 changes: 6 additions & 1 deletion src/QuickForm/Components/QuickForm.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ public partial class QuickForm<TEntity> : ComponentBase, IDisposable
/// Gets or sets the template for the fields in this form.
/// </summary>
[Parameter]
public virtual RenderFragment<IQuickFormField> ChildContent { get; set; } = default!;
public virtual RenderFragment<IQuickFormField> ChildContent { get; set; } = ctx => builder =>
{
builder.OpenElement(0, "div");
builder.AddContent(1, "You must provide ChildContent unless you are using a custom form template.");
builder.CloseElement();
};

/// <summary>
/// Gets or sets the submit button template of the form.
Expand Down
3 changes: 2 additions & 1 deletion test/QuickForm.Test/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
using Bunit;
using Bunit.Diffing;
using NUnit.Framework;
using TestContext = Bunit.TestContext;

namespace QuickForm.Test;

[TestFixture]
[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
public class BaseTest : Bunit.TestContext
public class BaseTest : TestContext
{
private static readonly HtmlParser HtmlParser = new();

Expand Down
37 changes: 37 additions & 0 deletions test/QuickForm.Test/Components/TestBsQuickForm.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@using System.ComponentModel.DataAnnotations
@inherits BaseTest

@code
{
[SuppressMessage("ReSharper", "UnusedMember.Local")]
private class Model
{
[Required]
public string A { get; set; } = default!;
}

[Test]
public void Test()
{
var model = new Model();

var cut = Render(
@<text>
<BsQuickForm Model="model" />
</text>);

cut.MarkupMatches(
@<text>
<form diff:ignoreAttributes >
<div diff:ignoreAttributes>
<label for:ignoreCase:regex="@IdRegex" diff:ignoreAttributes>A</label>
<input id:ignoreCase:regex="@IdRegex" diff:ignoreAttributes>
</div>

<button type="submit" diff:ignoreAttributes>submit</button>
</form>
</text>);

Print(cut);
}
}
55 changes: 4 additions & 51 deletions test/QuickForm.Test/Components/TestCustomTemplate.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@using QuickForm.Attributes
@using System.ComponentModel.DataAnnotations
@using System.ComponentModel.DataAnnotations
@using QuickForm.Attributes
@inherits BaseTest

@code
Expand All @@ -22,62 +22,15 @@
@<text>
<QuickForm Model="model">
<ChildContent>
<label for="@context.EditorId"></label>
<div>hello</div>
</ChildContent>

<SubmitButtonTemplate>
<button type="submit" class="submit-button">
submit
</button>
</SubmitButtonTemplate>
</QuickForm>
</text>);

cut.MarkupMatches(
@<text>
<form diff:ignoreAttributes>
<div>
<label for:ignoreCase:regex="@IdRegex" diff:ignoreChildren></label>
<div class="input">
<input id:ignoreCase:regex="@IdRegex" required autofocus/>
</div>
<div class="description">description-text</div>
<div class="valid-feedback">valid-feedback-text</div>
<div class="invalid-feedback"></div>
</div>

<button type="submit" class="submit-button">
submit
</button>
</form>
</text>);

Print(cut);

cut.Find("input").Change(string.Empty);

cut.MarkupMatches(
@<text>
<form diff:ignoreAttributes>
<div>
<label for:ignoreCase:regex="@IdRegex" diff:ignoreChildren></label>
<div class="input">
<input id:ignoreCase:regex="@IdRegex" aria-invalid="true" required autofocus class="modified invalid" value=""/>
</div>
<div class="description">
description-text
</div>
<div class="valid-feedback">
valid-feedback-text
</div>
<div class="invalid-feedback">
<div class="validation-message">required-error-message</div>
</div>
</div>

<button type="submit" class="submit-button">
submit
</button>
<div>hello</div>
</form>
</text>);

Expand Down
16 changes: 7 additions & 9 deletions test/QuickForm.Test/Components/TestDataList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
[SuppressMessage("ReSharper", "UnusedMember.Local")]
private class Model
{
[DataList("list")]
public string A { get; set; } = default!;
[DataList("list")] public string A { get; set; } = default!;
}

[Test]
Expand All @@ -17,17 +16,16 @@

var cut = Render(
@<text>
<QuickForm Model="model"/>
<QuickForm Model="model">
@context.InputComponent(string.Empty)
</QuickForm>
</text>);

cut.MarkupMatches(
@<text>
<form novalidate blazor:onsubmit="1">
<div>
<label for:ignoreCase:regex="@IdRegex" diff:ignoreChildren></label>
<input id:ignoreCase:regex="@IdRegex" list="list" autofocus/>
</div>
</form>
<form diff:ignoreAttributes>
<input list="list" diff:ignoreAttributes/>
</form>
</text>);

Print(cut);
Expand Down
Loading

0 comments on commit 3c813ab

Please sign in to comment.