Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow basic markup syntax custom previews #6232

Merged
Prev Previous commit
Next Next commit
Remove AssertJ in favor of plain JUnit5
  • Loading branch information
AlexanderGirgis committed Apr 1, 2020
commit b13832575ebfd45df3b5381f5e6e424113bf5714
Original file line number Diff line number Diff line change
@@ -3,8 +3,10 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

class MarkdownFormatterTest {

@@ -17,44 +19,48 @@ void setUp() {

@Test
void formatWhenFormattingPlainTextThenReturnsTextWrappedInParagraph() {
assertThat(markdownFormatter.format("Hello World")).isEqualTo("<p>Hello World</p>");
assertEquals("<p>Hello World</p>", markdownFormatter.format("Hello World"));
}

@Test
void formatWhenFormattingComplexMarkupThenReturnsOnlyOneLine() {
String source = "Markup\n\n* list item one\n* list item 2\n\n rest";
assertThat(markdownFormatter.format(source))
.contains("Markup<br />")
.contains("<li>list item one</li>")
.contains("<li>list item 2</li>")
.contains("> rest")
.doesNotContain("\n");

String actual = markdownFormatter.format(source);

// Only test relevant bits and ignore possible whitespace introduced by html-renderer
assertTrue(actual.contains("Markup<br />"));
assertTrue(actual.contains("<li>list item one</li>"));
assertTrue(actual.contains("<li>list item 2</li>"));
assertTrue(actual.contains("> rest"));
assertFalse(actual.contains("\n"));
}

@Test
void formatWhenFormattingEmptyStringThenReturnsEmptyString() {
assertThat(markdownFormatter.format("")).isEqualTo("");
assertEquals("", markdownFormatter.format(""));
}

@Test
void formatWhenFormattingNullThenThrowsException() {
assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> markdownFormatter.format(null))
.withMessageContaining("Field Text should not be null, when handed to formatter")
.withNoCause();
Exception exception = assertThrows(NullPointerException.class, () -> markdownFormatter.format(null));
assertEquals("Field Text should not be null, when handed to formatter", exception.getMessage());
}

@Test
void formatWhenMarkupContainingStrikethroughThenContainsMatchingDel() {
assertThat(markdownFormatter.format("a ~~b~~ b")).contains("<del>b</del>");
// Only test strikethrough extension
assertTrue(markdownFormatter.format("a ~~b~~ b").contains("<del>b</del>"));
}

@Test
void formatWhenMarkupContainingTaskListThenContainsFormattedTaskList() {
assertThat(markdownFormatter.format("Some text\n" +
String actual = markdownFormatter.format("Some text\n" +
"* [ ] open task\n" +
"* [x] closed task\n\n" +
"some other text"))
.contains("<li class=\"task-list-item\"><input type=\"checkbox\" class=\"task-list-item-checkbox\" disabled=\"disabled\" readonly=\"readonly\" />&nbsp;open task</li>")
.contains("<li class=\"task-list-item\"><input type=\"checkbox\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" readonly=\"readonly\" />&nbsp;closed task</li>");
"some other text");
// Only test list items
assertTrue(actual.contains("<li class=\"task-list-item\"><input type=\"checkbox\" class=\"task-list-item-checkbox\" disabled=\"disabled\" readonly=\"readonly\" />&nbsp;open task</li>"));
assertTrue(actual.contains("<li class=\"task-list-item\"><input type=\"checkbox\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" readonly=\"readonly\" />&nbsp;closed task</li>"));
}
}