-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: validate hx-vals, hx-headers, hx-on works
- Loading branch information
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@page "/hx-headers-escaped" | ||
<button type="button" hx-get="/hx-headers-escaped" hx-headers='{"myHeader": "My Value"}'>Get Some HTML, Including A Custom Header in the Request</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@page "/hx-on" | ||
<div hx-on:click="alert('Clicked!')">Click</div> | ||
|
||
<!-- These two are equivalent --> | ||
<button hx-get="/info" hx-on:htmx:before-request="alert('Making a request 1!')"> | ||
Get Info 1! | ||
</button> | ||
|
||
<button hx-get="/info" hx-on::before-request="alert('Making a request 2!')"> | ||
Get Info 2! | ||
</button> | ||
|
||
<button hx-get="/info" | ||
hx-on::before-request="alert('Making a request 3!')" | ||
hx-on::after-request="alert('Done making a request 3!')"> | ||
Get Info 3 ! | ||
</button> | ||
|
||
<!-- These two are equivalent --> | ||
<button hx-get="/info" hx-on-htmx-before-request="alert('Making a request 4!')"> | ||
Get Info 4! | ||
</button> | ||
|
||
<button hx-get="/info" hx-on--before-request="alert('Making a request 5!')"> | ||
Get Info 5! | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@page "/hx-vals-escaped" | ||
<button hx-post="/hx-vals-escaped" | ||
hx-vals='{"myVal": "My Value"}' | ||
type="button"> | ||
VALS | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Htmxor.DemoTestCases; | ||
|
||
public class HxValsTest : TestAppTestBase | ||
{ | ||
public HxValsTest(TestAppFixture fixture) : base(fixture) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task HxVals_correctly_escaped_by_renderer() | ||
{ | ||
await Host.Scenario(s => | ||
{ | ||
s.Get.Url("/hx-vals-escaped"); | ||
|
||
s.StatusCodeShouldBe(HttpStatusCode.OK); | ||
s.ContentShouldBeHtml(FullPageContent($$""" | ||
<button hx-post="/hx-vals-escaped" | ||
hx-vals='{"myVal": "My Value"}' | ||
type="button"> | ||
VALS | ||
</button> | ||
""")); | ||
}); | ||
} | ||
} |