X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpage%2FPageMakerInteractionTest.kt;fp=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpage%2FPageMakerInteractionTest.kt;h=178ef09039fae2acbe66a7487c914c2e85958a47;hp=0000000000000000000000000000000000000000;hb=03cec6a6772c2d836d94864adddaf544cbe9d72f;hpb=6f1f26e3998cfef155b0cf59152827accea70d30 diff --git a/src/test/kotlin/net/pterodactylus/sone/web/page/PageMakerInteractionTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/page/PageMakerInteractionTest.kt new file mode 100644 index 0000000..178ef09 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/page/PageMakerInteractionTest.kt @@ -0,0 +1,67 @@ +package net.pterodactylus.sone.web.page + +import freenet.clients.http.* +import freenet.support.* +import freenet.support.HTMLNode.* +import net.pterodactylus.sone.test.* +import net.pterodactylus.sone.test.TestUtil.* +import org.hamcrest.MatcherAssert.* +import org.hamcrest.Matchers.* +import org.junit.* + +@Dirty +class PageMakerInteractionTest { + + private val toadletContext = deepMock() + private val pageMaker: PageMaker = toadletContext.pageMaker + private val outerNode = HTMLDoctype("html", "-//W3C//DTD XHTML 1.1//EN") + private val htmlNode: HTMLNode = outerNode.addChild("html") + private val headNode: HTMLNode = htmlNode.addChild("head") + private val contentNode: HTMLNode = htmlNode.addChild("body").addChild("div") + private val pageNode: PageNode = createObject(PageNode::class.java, arrayOf(HTMLNode::class.java, HTMLNode::class.java, HTMLNode::class.java), outerNode, headNode, contentNode) + + init { + whenever(pageMaker.getPageNode("page title", toadletContext)).thenReturn(pageNode) + } + + private val pageMakerInteractions = PageMakerInteraction(toadletContext, "page title") + + @Test + fun `interactions can add style sheet`() { + pageMakerInteractions.addStyleSheet("style.sheet") + assertThat(headNode.children.filter { it.name == "link" }.map { it.attributes }, contains( + mapOf("rel" to "stylesheet", "href" to "style.sheet", "type" to "text/css", "media" to "screen") + )) + } + + @Test + fun `link nodes can be added`() { + pageMakerInteractions.addLinkNode(mapOf("foo" to "bar")) + assertThat(headNode.children.filter { it.name == "link" }.map { it.attributes }, contains( + mapOf("foo" to "bar") + )) + } + + @Test + fun `shortcut icon can be added`() { + pageMakerInteractions.addShortcutIcon("shortcut.icon") + assertThat(headNode.children.filter { it.name == "link" }.map { it.attributes }, contains( + mapOf("rel" to "icon", "href" to "shortcut.icon") + )) + } + + @Test + fun `content can be set`() { + pageMakerInteractions.setContent("foo