From 0dfc89efeec2d163ad7db93ab2787e498205d257 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sun, 4 Mar 2018 23:48:11 +0100 Subject: HTML table components. --- .../test/pl/treksoft/kvision/table/CellSpec.kt | 25 ++++++++++++ .../pl/treksoft/kvision/table/HeaderCellSpec.kt | 29 ++++++++++++++ .../test/pl/treksoft/kvision/table/RowSpec.kt | 28 +++++++++++++ .../test/pl/treksoft/kvision/table/TableSpec.kt | 46 ++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/table/CellSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/table/HeaderCellSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/table/RowSpec.kt create mode 100644 src/test/kotlin/test/pl/treksoft/kvision/table/TableSpec.kt (limited to 'src/test') diff --git a/src/test/kotlin/test/pl/treksoft/kvision/table/CellSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/table/CellSpec.kt new file mode 100644 index 00000000..7f39f133 --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/table/CellSpec.kt @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2018. Robert Jaros + */ +package test.pl.treksoft.kvision.table + +import pl.treksoft.kvision.panel.Root +import pl.treksoft.kvision.table.Cell +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test + +class CellSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test") + val cell = Cell("This is a cell") + root.add(cell) + val element = document.getElementById("test") + assertEqualsHtml("This is a cell", element?.innerHTML, "Should render correct table cell") + } + } + +} diff --git a/src/test/kotlin/test/pl/treksoft/kvision/table/HeaderCellSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/table/HeaderCellSpec.kt new file mode 100644 index 00000000..ef417fc8 --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/table/HeaderCellSpec.kt @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018. Robert Jaros + */ +package test.pl.treksoft.kvision.table + +import pl.treksoft.kvision.panel.Root +import pl.treksoft.kvision.table.HeaderCell +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test + +class HeaderCellSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test") + val cell = HeaderCell("This is a header cell") + root.add(cell) + val element = document.getElementById("test") + assertEqualsHtml( + "This is a header cell", + element?.innerHTML, + "Should render correct table header cell" + ) + } + } + +} diff --git a/src/test/kotlin/test/pl/treksoft/kvision/table/RowSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/table/RowSpec.kt new file mode 100644 index 00000000..04cd5a2d --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/table/RowSpec.kt @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2018. Robert Jaros + */ +package test.pl.treksoft.kvision.table + +import pl.treksoft.kvision.panel.Root +import pl.treksoft.kvision.table.Cell.Companion.cell +import pl.treksoft.kvision.table.Row +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test + +class RowSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test") + val row = Row { + cell("A") + } + root.add(row) + val element = document.getElementById("test") + assertEqualsHtml("A", element?.innerHTML, "Should render correct table row") + } + } + +} diff --git a/src/test/kotlin/test/pl/treksoft/kvision/table/TableSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/table/TableSpec.kt new file mode 100644 index 00000000..b544a346 --- /dev/null +++ b/src/test/kotlin/test/pl/treksoft/kvision/table/TableSpec.kt @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018. Robert Jaros + */ +package test.pl.treksoft.kvision.table + +import pl.treksoft.kvision.panel.Root +import pl.treksoft.kvision.table.Cell.Companion.cell +import pl.treksoft.kvision.table.Row.Companion.row +import pl.treksoft.kvision.table.Table +import pl.treksoft.kvision.table.TableType +import test.pl.treksoft.kvision.DomSpec +import kotlin.browser.document +import kotlin.test.Test + +class TableSpec : DomSpec { + + @Test + fun render() { + run { + val root = Root("test") + val table = Table(listOf("a", "b")) { + row { + cell("A") + cell("B") + } + } + root.add(table) + val element = document.getElementById("test") + assertEqualsHtml( + "
ab
AB
", + element?.innerHTML, + "Should render correct table" + ) + table.caption = "Caption" + table.responsive = true + table.types = setOf(TableType.BORDERED) + val element2 = document.getElementById("test") + assertEqualsHtml( + "
Caption
ab
AB
", + element2?.innerHTML, + "Should render correct responsive table" + ) + } + } + +} -- cgit