Skip to content

Commit

Permalink
TSI-3005 link with empty href is not clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Zarakovskiy committed Jan 15, 2018
1 parent c639dd8 commit 8de3d4b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ public static AnchorElementBuilder a() {
}

public static AnchorElementBuilder a(String href) {
return a().withHref(href);
AnchorElementBuilder a = a();
if (href == null) {
return a;
}
String _href = href.trim();
return _href.isEmpty() ? a : a.withHref(_href);
}

public static ButtonElementBuilder button() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;

/**
Expand Down Expand Up @@ -38,6 +39,21 @@ public void testA() {
assertThat(HtmlBuilders.a("http://localhost:8080").build().toHtml(), is("<a href=\"http://localhost:8080\"></a>"));
}

@Test
public void shouldNotAddHref_IfItsEmpty() {
//given

//when
AnchorElementBuilder nullA = HtmlBuilders.a(null);
AnchorElementBuilder emptyA = HtmlBuilders.a("");
AnchorElementBuilder trimA = HtmlBuilders.a(" ");

//then
assertFalse(nullA.build().renderHtml().contains("href"));
assertFalse(emptyA.build().renderHtml().contains("href"));
assertFalse(trimA.build().renderHtml().contains("href"));
}

@Test
public void testButton() {
assertThat(HtmlBuilders.button().build().toHtml(), is("<button></button>"));
Expand Down

0 comments on commit 8de3d4b

Please sign in to comment.