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 54007c7 commit 9d5763e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import org.junit.jupiter.api.Nested
*/
@DynaTestDsl
fun DynaNodeGroup.allTests19(isModuleTest: Boolean) {
group("MultiselectComboBox") {
multiselectComboBoxTests()
}

group("SideNav") {
sideNavTests()
}
Expand All @@ -29,4 +25,5 @@ abstract class AbstractAllTests19(val isModuleTest: Boolean) {
@Nested inner class RenderersVaadin22Tests : AbstractRenderers22Tests()
@Nested inner class Dialog23_1Tests : AbstractDialog23_1tests()
@Nested inner class VirtualListTests : AbstractVirtualListTests()
@Nested inner class MultiSelectComboBoxTests : AbstractMultiselectComboBoxTests()
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,41 @@ import com.vaadin.flow.component.combobox.MultiSelectComboBox
import com.vaadin.flow.component.html.Span
import com.vaadin.flow.component.select.Select
import com.vaadin.flow.data.renderer.ComponentRenderer
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import kotlin.test.expect

@DynaTestDsl
internal fun DynaNodeGroup.multiselectComboBoxTests() {
beforeEach { MockVaadin.setup() }
afterEach { MockVaadin.tearDown() }
abstract class AbstractMultiselectComboBoxTests {
@BeforeEach fun fakeVaadin() { MockVaadin.setup() }
@AfterEach fun tearDownVaadin() { MockVaadin.tearDown() }

test("basic") {
@Test fun basic() {
val cb = MultiSelectComboBox<String>("Hello!")
cb.setItems("a", "b", "c")
expect(true) { (cb as Component).dataProvider != null }
expect("MultiSelectComboBox[label='Hello!', value='[]', dataprovider='ListDataProvider<String>(3 items)']") { cb.toPrettyString() }
}

group("MultiSelectComboBox") {
group("getSuggestionItems()") {
test("by default shows all items") {
@Nested inner class MultiSelectComboBoxTests {
@Nested inner class getSuggestionItems {
@Test fun `by default shows all items`() {
val cb = MultiSelectComboBox<String>().apply {
setItems(listOf("aaa", "bbb", "ccc"))
}
expectList("aaa", "bbb", "ccc") { cb.getSuggestionItems() }
}

test("setting user input filters out stuff") {
@Test fun `setting user input filters out stuff`() {
val cb = MultiSelectComboBox<String>().apply {
setItems(listOf("aaa", "bbb", "ccc"))
}
cb.setUserInput("a")
expectList("aaa") { cb.getSuggestionItems() }
}

test("full-blown example") {
@Test fun `full-blown example`() {
val cb = MultiSelectComboBox<TestPerson>().apply {
setItems((0..10).map { TestPerson("foo $it", it) })
setItemLabelGenerator { it.name }
Expand All @@ -51,42 +54,40 @@ internal fun DynaNodeGroup.multiselectComboBoxTests() {
expectList("foo 1", "foo 10") { cb.getSuggestions() }
}
}
group("selectByLabel") {
fun withBypassSetUserInput(bypassSetUserInput: Boolean) {
group("bypassSetUserInput=$bypassSetUserInput") {
test("simple") {
val cb = MultiSelectComboBox<String>().apply {
setItems(listOf("aaa", "bbb", "ccc"))
}
cb.selectByLabel("aaa")
expect(setOf("aaa")) { cb._value }
@Nested inner class selectByLabel {
abstract inner class withBypassSetUserInput(val bypassSetUserInput: Boolean) {
@Test fun simple() {
val cb = MultiSelectComboBox<String>().apply {
setItems(listOf("aaa", "bbb", "ccc"))
}
cb.selectByLabel("aaa")
expect(setOf("aaa")) { cb._value }
}
@Test fun `fails on no match`() {
val cb = MultiSelectComboBox<String>().apply {
setItems(listOf("aaa", "bbb", "ccc"))
}
test("fails on no match") {
val cb = MultiSelectComboBox<String>().apply {
setItems(listOf("aaa", "bbb", "ccc"))
}
expectThrows<AssertionError>("MultiSelectComboBox[value='[]', dataprovider='ListDataProvider<String>(3 items)']: No item found with label 'd'. Available items: ['aaa'=>aaa, 'bbb'=>bbb, 'ccc'=>ccc]") {
cb.selectByLabel("d")
}
expectThrows<AssertionError>("MultiSelectComboBox[value='[]', dataprovider='ListDataProvider<String>(3 items)']: No item found with label 'd'. Available items: ['aaa'=>aaa, 'bbb'=>bbb, 'ccc'=>ccc]") {
cb.selectByLabel("d")
}
test("fails on multiple match") {
val cb = MultiSelectComboBox<String>().apply {
setItems(listOf("aaa", "aaa", "ccc"))
}
expectThrows<AssertionError>("MultiSelectComboBox[value='[]', dataprovider='ListDataProvider<String>(3 items)']: Multiple items found with label 'aaa': [aaa, aaa]") {
cb.selectByLabel("aaa")
}
}
@Test fun `fails on multiple match`() {
val cb = MultiSelectComboBox<String>().apply {
setItems(listOf("aaa", "aaa", "ccc"))
}
expectThrows<AssertionError>("MultiSelectComboBox[value='[]', dataprovider='ListDataProvider<String>(3 items)']: Multiple items found with label 'aaa': [aaa, aaa]") {
cb.selectByLabel("aaa")
}
}
}

withBypassSetUserInput(false)
withBypassSetUserInput(true)
@Nested inner class WithoutBypassSetUserInput : withBypassSetUserInput(false)
@Nested inner class WithBypassSetUserInput : withBypassSetUserInput(true)
}
}

group("_getRenderedComponentFor") {
test("MultiSelectComboBox") {
@Nested inner class _getRenderedComponentFor {
@Test fun MultiSelectComboBox() {
val cb = MultiSelectComboBox<String>().apply {
setRenderer(ComponentRenderer { it -> Span(it) })
}
Expand Down

0 comments on commit 9d5763e

Please sign in to comment.