Skip to content

Commit

Permalink
replace dynatest with junit5
Browse files Browse the repository at this point in the history
  • Loading branch information
mvysny committed Oct 28, 2024
1 parent ee1470c commit 0f1d885
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ open class AbstractAllTests10(val isModuleTest: Boolean) {
@Nested inner class NpmTemplateTests : AbstractNpmPolymerTemplateTests(isModuleTest)
@Nested inner class DialogTests : AbstractDialogTests()
@Nested inner class CompositeTests : AbstractCompositeTests()
@Nested inner class RadioButtonTests : AbstractRadioButtonTests()
@Nested inner class ListBoxTests : AbstractListBoxTests()
}

/**
Expand All @@ -59,12 +61,6 @@ fun DynaNodeGroup.allTests(isModuleTest: Boolean) {
Locale.setDefault(Locale.ENGLISH)
}

group("radio button") {
radioButtonTests()
}
group("ListBox") {
listBoxTestbatch()
}
group("CheckboxGroup") {
checkboxGroupTests()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,43 @@
package com.github.mvysny.kaributesting.v10

import com.github.mvysny.dynatest.DynaNodeGroup
import com.github.mvysny.dynatest.DynaTestDsl
import com.vaadin.flow.component.html.Span
import com.vaadin.flow.component.listbox.ListBox
import com.vaadin.flow.component.listbox.ListBoxBase
import com.vaadin.flow.component.listbox.MultiSelectListBox
import com.vaadin.flow.data.provider.ListDataProvider
import com.vaadin.flow.data.renderer.ComponentRenderer
import com.vaadin.flow.data.renderer.TextRenderer
import com.vaadin.flow.function.SerializableFunction
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test

@DynaTestDsl
internal fun DynaNodeGroup.listBoxTestbatch() {
abstract class AbstractListBoxTests() {
@BeforeEach fun fakeVaadin() { MockVaadin.setup() }
@AfterEach fun tearDownVaadin() { MockVaadin.tearDown() }

beforeEach { MockVaadin.setup() }
afterEach { MockVaadin.tearDown() }

group("ListBox") {
tests { ListBox() }
}
group("MultiSelectListBox") {
tests { MultiSelectListBox() }
}
@Nested inner class ListBoxTests : AbstractListBoxBaseTests({ ListBox() })
@Nested inner class MultiSelectListBoxTests : AbstractListBoxBaseTests({ MultiSelectListBox() })
}

private fun DynaNodeGroup.tests(component: () -> ListBoxBase<*, String, *>) {
group("getRenderedItems()") {
test("empty") {
expectList() { component().getRenderedItems() }
}
test("TextRenderer") {
val lb = component()
lb.setItems2("1", "2", "3")
lb.setRenderer(TextRenderer { "item $it" })
expectList("item 1", "item 2", "item 3") {
lb.getRenderedItems()
}
abstract class AbstractListBoxBaseTests(val component: () -> ListBoxBase<*, String, *>) {
@Test fun empty() {
expectList() { component().getRenderedItems() }
}
@Test fun textRenderer() {
val lb = component()
lb.setItems2("1", "2", "3")
lb.setRenderer(TextRenderer { "item $it" })
expectList("item 1", "item 2", "item 3") {
lb.getRenderedItems()
}
test("ComponentRenderer") {
val lb = component()
lb.setItems2("1", "2", "3")
lb.setRenderer(ComponentRenderer(SerializableFunction { Span("item $it") }))
expectList("Span[text='item 1']", "Span[text='item 2']", "Span[text='item 3']") {
lb.getRenderedItems()
}
}
@Test fun componentRenderer() {
val lb = component()
lb.setItems2("1", "2", "3")
lb.setRenderer(ComponentRenderer(SerializableFunction { Span("item $it") }))
expectList("Span[text='item 1']", "Span[text='item 2']", "Span[text='item 3']") {
lb.getRenderedItems()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package com.github.mvysny.kaributesting.v10

import com.github.mvysny.dynatest.DynaNodeGroup
import com.github.mvysny.dynatest.DynaTestDsl
import com.github.mvysny.dynatest.expectThrows
import com.vaadin.flow.component.checkbox.CheckboxGroup
import com.vaadin.flow.component.radiobutton.RadioButtonGroup
import com.vaadin.flow.data.provider.ListDataProvider
import com.vaadin.flow.data.renderer.TextRenderer
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import kotlin.test.expect

@DynaTestDsl
internal fun DynaNodeGroup.radioButtonTests() {
group("getItemLabels()") {
test("empty") {
abstract class AbstractRadioButtonTests() {
@Nested inner class getItemLabels {
@Test fun empty() {
expectList() { RadioButtonGroup<String>().getItemLabels() }
}
test("no renderer set uses toString()") {
@Test fun `no renderer set uses toString()`() {
expectList("1", "2", "3") {
val rb = RadioButtonGroup<Int>()
rb.setItems2(1, 2, 3)
Expand All @@ -27,7 +23,7 @@ internal fun DynaNodeGroup.radioButtonTests() {
rb.getItemLabels()
}
}
test("text renderer") {
@Test fun `text renderer`() {
expectList("Item #1", "Item #2", "Item #3") {
val rb = RadioButtonGroup<Int>()
rb.setItems2(1, 2, 3)
Expand All @@ -36,20 +32,20 @@ internal fun DynaNodeGroup.radioButtonTests() {
}
}
}
group("selectByLabel()") {
test("empty") {
@Nested inner class selectByLabel {
@Test fun empty() {
expectThrows<AssertionError>("RadioButtonGroup[value='null', dataprovider='ListDataProvider<?>(0 items)']: No item found with label 'foo'") {
RadioButtonGroup<String>().selectByLabel("foo")
}
}
test("fails on no match") {
@Test fun `fails on no match`() {
val c = RadioButtonGroup<String>()
c.setItems2("1", "2", "3")
expectThrows<AssertionError>("RadioButtonGroup[value='null', dataprovider='ListDataProvider<String>(3 items)']: No item found with label 'foo'. Available items: ['1'=>1, '2'=>2, '3'=>3]") {
c.selectByLabel("foo")
}
}
test("simple with itemLabelGenerator") {
@Test fun `simple with itemLabelGenerator`() {
val cg = RadioButtonGroup<String>()
cg.setItems2("1", "2", "3")
cg.setRenderer(TextRenderer { "Item #$it" })
Expand Down

0 comments on commit 0f1d885

Please sign in to comment.