Skip to content

Commit

Permalink
Added regression tests for custom attributes for further elements. Fo…
Browse files Browse the repository at this point in the history
…und new bug (#118), added test for it.
  • Loading branch information
john-amiscaray committed Feb 21, 2023
1 parent ace03a6 commit 99df250
Show file tree
Hide file tree
Showing 15 changed files with 147 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/test/java/io/john/amiscaray/stir/tests/ArticleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -44,4 +45,18 @@ public void testArticleFromBuilderWithAll() throws IOException {

}

@Test
public void testArticleWithCustomAttributes() throws IOException {

LinkedHashMap<String, String> attributes = new LinkedHashMap<>();
attributes.put("data-type", "blog");
attributes.put("data-role", "content");
Article article = Article.builder()
.customAttribute("data-todo-id", "1")
.customAttributes(attributes)
.build();
assertEquals(htmlLoader.getHTMLContentOf("html/articleWithCustomAttributes.html"), processor.getMarkup(article));

}

}
17 changes: 17 additions & 0 deletions src/test/java/io/john/amiscaray/stir/tests/ButtonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import io.john.amiscaray.stir.setup.ExpectedHTMLLoader;
Expand Down Expand Up @@ -43,4 +44,20 @@ public void testButtonWithAll() throws IOException {

}

@Test
public void testButtonWithCustomAttributes() throws IOException {

LinkedHashMap<String, String> attributes = new LinkedHashMap<>();
attributes.put("data-todo-id", "1");
attributes.put("data-role", "link");

Button button = Button.builder()
.customAttribute("data-color", "red")
.customAttributes(attributes)
.build();

assertEquals(htmlLoader.getHTMLContentOf("html/buttonWithCustomAttributes.html"), processor.getMarkup(button));

}

}
17 changes: 17 additions & 0 deletions src/test/java/io/john/amiscaray/stir/tests/DivTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -171,4 +172,20 @@ public void testHiddenDiv() throws IOException {

}

@Test
public void testDivWithCustomAttributes() throws IOException {

LinkedHashMap<String, String> attributes = new LinkedHashMap<>();
attributes.put("data-todo-id", "1");
attributes.put("data-role", "link");

Div div = Div.builder()
.customAttribute("data-color", "red")
.customAttributes(attributes)
.build();

assertEquals(htmlLoader.getHTMLContentOf("html/divWithCustomAttributes.html"), processor.getMarkup(div));

}

}
17 changes: 17 additions & 0 deletions src/test/java/io/john/amiscaray/stir/tests/FooterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -64,4 +65,20 @@ public void testHiddenFooter() throws IOException {

}

@Test
public void testFooterWithCustomAttributes() throws IOException {

LinkedHashMap<String, String> attributes = new LinkedHashMap<>();
attributes.put("data-todo-id", "1");
attributes.put("data-role", "link");

Footer footer = Footer.builder()
.customAttribute("data-color", "red")
.customAttributes(attributes)
.build();

assertEquals(htmlLoader.getHTMLContentOf("html/footerWithCustomAttributes.html"), processor.getMarkup(footer));

}

}
17 changes: 17 additions & 0 deletions src/test/java/io/john/amiscaray/stir/tests/FormTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;

import static io.john.amiscaray.stir.util.ElementDescriptorProcessor.element;
Expand Down Expand Up @@ -36,4 +37,20 @@ public void testFormWithAll() throws IOException {

}

@Test
public void testFormWithCustomAttributes() throws IOException {

LinkedHashMap<String, String> attributes = new LinkedHashMap<>();
attributes.put("data-todo-id", "1");
attributes.put("data-role", "link");

Form form = Form.builder()
.customAttribute("data-color", "red")
.customAttributes(attributes)
.build();

assertEquals(htmlLoader.getHTMLContentOf("html/formWithCustomAttributes.html"), processor.getMarkup(form));

}

}
17 changes: 17 additions & 0 deletions src/test/java/io/john/amiscaray/stir/tests/HeaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;

import static io.john.amiscaray.stir.util.ElementDescriptorProcessor.element;
Expand Down Expand Up @@ -33,4 +34,20 @@ public void testHeaderWithAll() throws IOException {

}

@Test
public void testHeaderWithCustomAttributes() throws IOException {

LinkedHashMap<String, String> attributes = new LinkedHashMap<>();
attributes.put("data-todo-id", "1");
attributes.put("data-role", "link");

Header header = Header.builder()
.customAttribute("data-color", "red")
.customAttributes(attributes)
.build();

assertEquals(htmlLoader.getHTMLContentOf("html/headerWithCustomAttributes.html"), processor.getMarkup(header));

}

}
32 changes: 32 additions & 0 deletions src/test/java/io/john/amiscaray/stir/tests/HeadingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import io.john.amiscaray.stir.domain.elements.Div;
import io.john.amiscaray.stir.domain.elements.Heading;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import io.john.amiscaray.stir.setup.ExpectedHTMLLoader;
import io.john.amiscaray.stir.util.ElementProcessor;

import java.io.IOException;
import java.util.LinkedHashMap;

import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -48,4 +50,34 @@ public void testHiddenHeading() throws IOException {

}

@Test
public void testHeadingWithCustomAttributes() throws IOException {

LinkedHashMap<String, String> attributes = new LinkedHashMap<>();
attributes.put("data-todo-id", "1");
attributes.put("data-role", "link");

Heading heading = Heading.builder()
.level(1)
.customAttribute("data-color", "red")
.customAttributes(attributes)
.build();

assertEquals(htmlLoader.getHTMLContentOf("html/headingWithCustomAttributes.html"), processor.getMarkup(heading));

}

// TODO fix this not working
@Test
@Disabled
public void testHeadingWithNoLevelSet() throws IOException {

Heading heading = Heading.builder()
.content("This is the title")
.build();

assertEquals(htmlLoader.getHTMLContentOf("html/headingWithNoLevelSet.html"), processor.getMarkup(heading));

}

}
2 changes: 2 additions & 0 deletions src/test/resources/html/articleWithCustomAttributes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<article data-todo-id="1" data-type="blog" data-role="content">
</article>
2 changes: 2 additions & 0 deletions src/test/resources/html/buttonWithCustomAttributes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<button data-color="red" data-todo-id="1" data-role="link">
</button>
2 changes: 2 additions & 0 deletions src/test/resources/html/divWithCustomAttributes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div data-color="red" data-todo-id="1" data-role="link">
</div>
2 changes: 2 additions & 0 deletions src/test/resources/html/footerWithCustomAttributes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<footer data-color="red" data-todo-id="1" data-role="link">
</footer>
2 changes: 2 additions & 0 deletions src/test/resources/html/formWithCustomAttributes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<form method="get" action="/" data-color="red" data-todo-id="1" data-role="link">
</form>
2 changes: 2 additions & 0 deletions src/test/resources/html/headerWithCustomAttributes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<header data-color="red" data-todo-id="1" data-role="link">
</header>
2 changes: 2 additions & 0 deletions src/test/resources/html/headingWithCustomAttributes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1 data-color="red" data-todo-id="1" data-role="link">
</h1>
1 change: 1 addition & 0 deletions src/test/resources/html/headingWithNoLevelSet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>This is the title</h1>

0 comments on commit 99df250

Please sign in to comment.