Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mvysny committed Aug 8, 2024
1 parent cadf5cd commit ce84689
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.github.mvysny.dynatest.expectThrows
import com.github.mvysny.karibudsl.v10.formItem
import com.github.mvysny.karibudsl.v10.textField
import com.vaadin.flow.component.formlayout.FormLayout
import com.vaadin.flow.component.html.Label
import com.vaadin.flow.component.select.Select
import com.vaadin.flow.component.textfield.TextField
import kotlin.test.expect

Expand Down Expand Up @@ -41,7 +41,7 @@ internal fun DynaNodeGroup.formLayoutTest() {
expect(tf) { f._get<FormLayout.FormItem> { label = "foo" } .field }
}
test("fails with no field") {
val f: FormLayout.FormItem = FormLayout().addFormItem(Label(), "foo")
val f: FormLayout.FormItem = FormLayout().addFormItem(Select<String>(), "foo")
f.removeAll()
expectThrows(IllegalStateException::class, "FormItem: Expected 1 field but got 0. Component tree:\n└── FormItem[]") {
f.field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ import com.vaadin.flow.component.ClickNotifier
import com.vaadin.flow.component.UI
import com.vaadin.flow.component.button.Button
import com.vaadin.flow.component.checkbox.Checkbox
import com.vaadin.flow.component.grid.ColumnReorderEvent
import com.vaadin.flow.component.grid.ColumnResizeEvent
import com.vaadin.flow.component.grid.FooterRow
import com.vaadin.flow.component.grid.Grid
import com.vaadin.flow.component.grid.HeaderRow
import com.vaadin.flow.component.grid.ItemClickEvent
import com.vaadin.flow.component.grid.dnd.GridDropMode
import com.vaadin.flow.component.html.Label
import com.vaadin.flow.component.html.NativeLabel
import com.vaadin.flow.component.textfield.TextField
import com.vaadin.flow.data.binder.Binder
import com.vaadin.flow.data.provider.*
import com.vaadin.flow.data.renderer.ComponentRenderer
import com.vaadin.flow.data.renderer.LocalDateRenderer
Expand Down Expand Up @@ -173,7 +171,7 @@ internal fun DynaNodeGroup.gridTestbatch() {
addColumn(NativeButtonRenderer<TestPerson>("View", { }))
addColumn(ComponentRenderer<Button, TestPerson> { it -> Button(it.name) })
val formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
.withLocale(Locale("fi", "FI"))
.withLocale(Locale.forLanguageTag("fi-FI"))
addColumn(LocalDateRenderer<TestPerson>({ LocalDate.of(2019, 3, 1) }, { formatter }))
}
grid.dataProvider = ListDataProvider<TestPerson>((0 until 7).map { TestPerson("name $it", it) })
Expand Down Expand Up @@ -249,7 +247,7 @@ internal fun DynaNodeGroup.gridTestbatch() {
var called = false
val grid = Grid<TestPerson>().apply {
addColumn(ComponentRenderer<Button, TestPerson> { person -> Button("View").apply {
onLeftClick {
onClick {
called = true
expect("name 8") { person.name }
}
Expand Down Expand Up @@ -285,13 +283,16 @@ internal fun DynaNodeGroup.gridTestbatch() {
}
}
test("fails on unsupported component type") {
expect(false) { Label() is ClickNotifier<*> }
expect(false) {
@Suppress("KotlinConstantConditions")
NativeLabel() is ClickNotifier<*>
}
val grid = Grid<TestPerson>().apply {
setItems2((0..10).map { TestPerson("name $it", it) })
addColumn(ComponentRenderer<Label, TestPerson> { _ -> Label() }).key = "name"
addColumn(ComponentRenderer { _ -> NativeLabel() }).key = "name"
_prepare()
}
expectThrows(AssertionError::class, "Grid[dataprovider='ListDataProvider<TestPerson>(11 items)'] column key='name': ComponentRenderer produced Label[] which is not a button nor a ClickNotifier - please use _getCellComponent() instead") {
expectThrows(AssertionError::class, "Grid[dataprovider='ListDataProvider<TestPerson>(11 items)'] column key='name': ComponentRenderer produced NativeLabel[] which is not a button nor a ClickNotifier - please use _getCellComponent() instead") {
grid._clickRenderer(8, "name")
}
}
Expand All @@ -312,7 +313,7 @@ internal fun DynaNodeGroup.gridTestbatch() {
var called = false
val grid = Grid<TestPerson>().apply {
addColumn(ComponentRenderer<Button, TestPerson> { person -> Button("View").apply {
onLeftClick {
onClick {
called = true
expect("name 8") { person.name }
}
Expand Down Expand Up @@ -867,7 +868,7 @@ fun <T> Grid<T>.setItems2(items: Collection<T>) {
dataProvider = ListDataProvider(items)
}

public fun Grid<*>._prepare() {
fun Grid<*>._prepare() {
// remove attribute added by Vaadin 23.2.0.beta1, so that the _dump() function produces
// same results for all vaadin versions
element.removeAttribute("multi-sort-priority")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.vaadin.flow.component.Component
import com.vaadin.flow.component.UI
import com.vaadin.flow.component.button.Button
import com.vaadin.flow.component.combobox.ComboBox
import com.vaadin.flow.component.html.Label
import com.vaadin.flow.component.html.NativeLabel
import com.vaadin.flow.component.orderedlayout.VerticalLayout
import com.vaadin.flow.component.textfield.PasswordField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.vaadin.flow.component.UI
import com.vaadin.flow.component.button.Button
import com.vaadin.flow.component.combobox.ComboBox
import com.vaadin.flow.component.dialog.Dialog
import com.vaadin.flow.component.html.Label
import com.vaadin.flow.component.html.NativeLabel
import com.vaadin.flow.component.orderedlayout.VerticalLayout
import com.vaadin.flow.component.textfield.PasswordField
import com.vaadin.flow.component.textfield.TextField
Expand Down Expand Up @@ -305,7 +305,7 @@ internal fun DynaNodeGroup.locatorTest() {

test("FailsOnNoComponents") {
expectThrows(AssertionError::class) {
Button()._expectOne(Label::class.java)
Button()._expectOne(NativeLabel::class.java)
}
expectAfterLookupCalled()
}
Expand Down Expand Up @@ -342,19 +342,19 @@ internal fun DynaNodeGroup.locatorTest() {

group("_expect") {
test("FailsOnNoComponents UI") {
expectThrows(AssertionError::class) { _expect<Label>() }
expectThrows(AssertionError::class) { _expect<NativeLabel>() }
expectAfterLookupCalled()
}

test("FailsOnNoComponents") {
expectThrows(AssertionError::class) { Button()._expect<Label>() }
expectThrows(AssertionError::class) { Button()._expect<NativeLabel>() }
expectAfterLookupCalled()
}

test("matching 0 components works") {
_expect<Label>(0)
_expect<NativeLabel>(0)
expectAfterLookupCalled()
Button()._expect<Label>(0)
Button()._expect<NativeLabel>(0)
}

test("fails when the count is wrong") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.vaadin.flow.component.checkbox.CheckboxGroup
import com.vaadin.flow.component.combobox.ComboBox
import com.vaadin.flow.component.datepicker.DatePicker
import com.vaadin.flow.component.html.Input
import com.vaadin.flow.component.html.Label
import com.vaadin.flow.component.html.NativeLabel
import com.vaadin.flow.component.listbox.ListBox
import com.vaadin.flow.component.radiobutton.RadioButtonGroup
import com.vaadin.flow.component.select.Select
Expand All @@ -30,7 +30,7 @@ internal fun DynaNodeGroup.searchSpecTest() {
test("clazz") {
val spec = SearchSpec(Button::class.java)
expect(true) { spec.toPredicate()(Button())}
expect(false) { spec.toPredicate()(Label())}
expect(false) { spec.toPredicate()(NativeLabel())}
}

test("id") {
Expand Down Expand Up @@ -148,6 +148,6 @@ internal fun DynaNodeGroup.searchSpecTest() {
predicates.add(Predicate { it is Button })
}
expect(true) { spec.toPredicate()(Button()) }
expect(false) { spec.toPredicate()(Label()) }
expect(false) { spec.toPredicate()(NativeLabel()) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package com.github.mvysny.kaributesting.v10
import com.github.mvysny.dynatest.DynaNodeGroup
import com.github.mvysny.dynatest.DynaTestDsl
import com.github.mvysny.karibudsl.v10.button
import com.github.mvysny.karibudsl.v10.onLeftClick
import com.github.mvysny.kaributools.ModifierKey
import com.github.mvysny.karibudsl.v10.onClick
import com.github.mvysny.kaributools.ModifierKey.Alt
import com.github.mvysny.kaributools.addClickShortcut
import com.vaadin.flow.component.Key
Expand All @@ -26,7 +25,7 @@ internal fun DynaNodeGroup.shortcutsTestBatch() {
test("simple") {
var clicked = false
currentUI.button {
onLeftClick { clicked = true }
onClick { clicked = true }
addClickShortcut(Key.ENTER)
}
fireShortcut(Key.ENTER)
Expand All @@ -36,7 +35,7 @@ internal fun DynaNodeGroup.shortcutsTestBatch() {
test("button not triggered on different key press") {
var clicked = false
currentUI.button {
onLeftClick { clicked = true }
onClick { clicked = true }
addClickShortcut(Key.KEY_A)
}
fireShortcut(Key.ENTER)
Expand All @@ -48,7 +47,7 @@ internal fun DynaNodeGroup.shortcutsTestBatch() {
test("button not triggered on different modifiers") {
var clicked = false
currentUI.button {
onLeftClick { clicked = true }
onClick { clicked = true }
addClickShortcut(Alt + Key.KEY_A)
}
fireShortcut(Key.KEY_A)
Expand All @@ -65,7 +64,7 @@ internal fun DynaNodeGroup.shortcutsTestBatch() {
// Key.SPACE has multiple key bindings, test that out.
var clicked = false
currentUI.button {
onLeftClick { clicked = true }
onClick { clicked = true }
addClickShortcut(Key.SPACE)
}
fireShortcut(Key.SPACE)
Expand All @@ -75,7 +74,7 @@ internal fun DynaNodeGroup.shortcutsTestBatch() {
test("space not triggered on different modifiers") {
var clicked = false
currentUI.button {
onLeftClick { clicked = true }
onClick { clicked = true }
addClickShortcut(Alt + Key.SPACE)
}
fireShortcut(Key.ENTER)
Expand Down Expand Up @@ -110,7 +109,7 @@ internal fun DynaNodeGroup.shortcutsTestBatch() {

test("button not triggered on different modifiers") {
var clicked = false
Shortcuts.addShortcutListener(currentUI, Command { clicked = true }, Key.KEY_A, KeyModifier.values()[2] /*ALT*/)
Shortcuts.addShortcutListener(currentUI, Command { clicked = true }, Key.KEY_A, KeyModifier.entries[2] /*ALT*/)
fireShortcut(Key.KEY_A)
expect(false) { clicked }
fireShortcut(Key.KEY_A, Key.CONTROL)
Expand All @@ -131,7 +130,7 @@ internal fun DynaNodeGroup.shortcutsTestBatch() {

test("space not triggered on different modifiers") {
var clicked = false
Shortcuts.addShortcutListener(currentUI, Command { clicked = true }, Key.SPACE, KeyModifier.values()[2] /*ALT*/)
Shortcuts.addShortcutListener(currentUI, Command { clicked = true }, Key.SPACE, KeyModifier.entries[2] /*ALT*/)
fireShortcut(Key.ENTER)
expect(false) { clicked }
fireShortcut(Key.SPACE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@ internal fun DynaNodeGroup.treeGridTestbatch() {
test("simple") {
expect(20) {
val g = TreeGrid<Int>()
g.dataProvider = treedp((0 until 20).toList())
g.setDataProvider(treedp((0 until 20).toList()))
g._size()
}
}
test("size calculates sizes of all nodes") {
expect(10) {
val g = TreeGrid<Int>()
g.dataProvider = treedp(listOf(0), { if (it < 9) listOf(it + 1) else listOf<Int>() })
g.setDataProvider(treedp(listOf(0), { if (it < 9) listOf(it + 1) else listOf<Int>() }))
g._expandAll()
g._size()
}
}
test("size ignores collapsed nodes") {
expect(1) {
val g = TreeGrid<Int>()
g.dataProvider = treedp(listOf(0), { if (it < 9) listOf(it + 1) else listOf<Int>() })
g.setDataProvider(treedp(listOf(0), { if (it < 9) listOf(it + 1) else listOf<Int>() }))
// all nodes are by default collapsed
g._size()
}
Expand All @@ -87,7 +87,7 @@ internal fun DynaNodeGroup.treeGridTestbatch() {
val grid = TreeGrid<TestPerson>().apply {
addHierarchyColumn { it -> it.name }
addColumnFor(TestPerson::age)
dataProvider = treedp<TestPerson>(roots, { if (it.age < 9) listOf(TestPerson("name ${it.age + 1}", it.age + 1)) else listOf<TestPerson>() })
setDataProvider(treedp<TestPerson>(roots, { if (it.age < 9) listOf(TestPerson("name ${it.age + 1}", it.age + 1)) else listOf<TestPerson>() }))
_expandAll()
}
grid.expectRow(0, "name 0", "0")
Expand All @@ -99,10 +99,10 @@ internal fun DynaNodeGroup.treeGridTestbatch() {
val grid = TreeGrid<TestPerson>().apply {
addHierarchyColumn { it.name }
addColumnFor(TestPerson::age)
dataProvider = treedp<TestPerson>(roots) {
setDataProvider(treedp<TestPerson>(roots) {
if (it.age < 3) listOf(TestPerson("${it.name} 0", it.age + 1), TestPerson("${it.name} 1", it.age + 1))
else listOf<TestPerson>()
}
})
_expandAll()
}
// expected tree:
Expand Down Expand Up @@ -136,7 +136,7 @@ internal fun DynaNodeGroup.treeGridTestbatch() {
val grid = TreeGrid<TestPerson>().apply {
addColumnFor(TestPerson::name)
addColumnFor(TestPerson::age)
dataProvider = treedp<TestPerson>(roots, { if (it.age < 9) listOf(TestPerson("name ${it.age + 1}", it.age + 1)) else listOf<TestPerson>() })
setDataProvider(treedp<TestPerson>(roots, { if (it.age < 9) listOf(TestPerson("name ${it.age + 1}", it.age + 1)) else listOf<TestPerson>() }))
_prepare()
}
expect("""TreeGrid[dataprovider='TreeDataProvider<TestPerson>(? items)']
Expand Down Expand Up @@ -165,10 +165,10 @@ internal fun DynaNodeGroup.treeGridTestbatch() {
val grid = TreeGrid<TestPerson>().apply {
addColumnFor(TestPerson::name)
addColumnFor(TestPerson::age)
dataProvider = treedp<TestPerson>(roots) {
setDataProvider(treedp<TestPerson>(roots) {
if (it.age < 3) listOf(TestPerson("${it.name} 0", it.age + 1), TestPerson("${it.name} 1", it.age + 1))
else listOf<TestPerson>()
}
})
_prepare()
}
expect("""TreeGrid[dataprovider='TreeDataProvider<TestPerson>(? items)']
Expand Down Expand Up @@ -200,7 +200,7 @@ internal fun DynaNodeGroup.treeGridTestbatch() {
called = true
expect("name 8") { person.name }
}).key = "name"
dataProvider = treedp<TestPerson>(roots, { if (it.age < 9) listOf(TestPerson("name ${it.age + 1}", it.age + 1)) else listOf<TestPerson>() })
setDataProvider(treedp<TestPerson>(roots, { if (it.age < 9) listOf(TestPerson("name ${it.age + 1}", it.age + 1)) else listOf<TestPerson>() }))
}
grid._expandAll()
grid._clickRenderer(8, "name")
Expand Down

0 comments on commit ce84689

Please sign in to comment.