Skip to content

Commit

Permalink
Add extra test on template order when merging responses
Browse files Browse the repository at this point in the history
See #48
  • Loading branch information
wimdeblauwe committed Jul 19, 2023
1 parent d273897 commit e31b257
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/test/java/io/github/wimdeblauwe/hsbt/mvc/HtmxResponseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public void addingAResponseToExistingMergesTemplatesAndTriggers() {

sut.and(new HtmxResponse().addTemplate("myTemplate2")
.addTrigger("myEvent2")
.addTrigger(myTrigger)
.addTemplate(myTemplate));
.addTrigger(myTrigger)
.addTemplate(myTemplate));

assertThat(sut.getTriggers()).hasSize(2);
assertThat(sut.getTemplates()).hasSize(2);
Expand All @@ -70,9 +70,9 @@ public void addingAResponseToExistingMergesTemplatesAndTriggers() {
@Test
public void extraHxHeaders() {
sut.pushHistory("/a/history")
.browserRedirect("/a/new/page")
.browserRefresh(true)
.retarget("#theThing");
.browserRedirect("/a/new/page")
.browserRefresh(true)
.retarget("#theThing");

assertThat(sut.getHeaderPushHistory()).isEqualTo("/a/history");
assertThat(sut.getHeaderRedirect()).isEqualTo("/a/new/page");
Expand All @@ -94,4 +94,21 @@ public void addedTemplatesPreserveTheirOrder() {
assertThat(sut.getTemplates()).containsExactly(template1, template2);
}

@Test
public void mergingResponsesPreserveTemplateOrder() {
HtmxResponse response1 = new HtmxResponse().addTemplate("response1 :: template 11")
.addTemplate("response1 :: template 12");
HtmxResponse response2 = new HtmxResponse().addTemplate("response2 :: template 21")
.addTemplate("response2 :: template 22");

response1.and(response2);

assertThat(response1.getTemplates())
.hasSize(4)
.containsExactly("response1 :: template 11",
"response1 :: template 12",
"response2 :: template 21",
"response2 :: template 22");

}
}

0 comments on commit e31b257

Please sign in to comment.