-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...u-testing-v23/kt23-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/TabsTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
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.github.mvysny.kaributesting.v23._select | ||
import com.vaadin.flow.component.Component | ||
import com.vaadin.flow.component.html.Span | ||
import com.vaadin.flow.component.tabs.Tab | ||
import com.vaadin.flow.component.tabs.TabSheet | ||
import com.vaadin.flow.component.tabs.Tabs | ||
import kotlin.test.expect | ||
|
||
|
||
@DynaTestDsl | ||
internal fun DynaNodeGroup.tabsTests() { | ||
group("_select()") { | ||
group("Tabs") { | ||
selectTests( | ||
{ Tabs() }, | ||
{ tabs, tab -> tabs.add(tab) }, | ||
{ it.selectedTab }) | ||
} | ||
group("TabSheet") { | ||
selectTests( | ||
{ TabSheet() }, | ||
{ tabs, tab -> tabs.add(tab, Span("contents of $tab")) }, | ||
{ it.selectedTab }) | ||
} | ||
} | ||
} | ||
|
||
@DynaTestDsl | ||
private fun <T : Component> DynaNodeGroup.selectTests( | ||
create: () -> T, | ||
add: (T, Tab) -> Unit, | ||
selected: (T) -> Tab | ||
) { | ||
test("select already selected tab succeeds") { | ||
val t = create() | ||
val tab = Tab("Foo") | ||
add(t, tab) | ||
expect(tab) { selected(t) } | ||
|
||
tab._select() | ||
expect(tab) { selected(t) } | ||
} | ||
|
||
test("select enabled+visible tab succeeds") { | ||
val t = create() | ||
val tab = Tab("Foo") | ||
add(t, tab) | ||
val tab2 = Tab("Bar") | ||
add(t, tab2) | ||
expect(tab) { selected(t) } | ||
|
||
tab2._select() | ||
expect(tab2) { selected(t) } | ||
} | ||
|
||
test("select disabled tab fails") { | ||
val t = create() | ||
val tab = Tab("Foo") | ||
add(t, tab) | ||
val tab2 = Tab("Bar") | ||
tab2.isEnabled = false | ||
add(t, tab2) | ||
expect(tab) { selected(t) } | ||
|
||
expectThrows<IllegalStateException>("DISABLED, label='Bar', Tab{Bar}] is not enabled") { | ||
tab2._select() | ||
} | ||
expect(tab) { selected(t) } | ||
} | ||
|
||
test("select invisible tab fails") { | ||
val t = create() | ||
val tab = Tab("Foo") | ||
add(t, tab) | ||
val tab2 = Tab("Bar") | ||
tab2.isVisible = false | ||
add(t, tab2) | ||
expect(tab) { selected(t) } | ||
|
||
expectThrows<IllegalStateException>("INVIS, label='Bar', Tab{Bar}] is not effectively visible") { | ||
tab2._select() | ||
} | ||
expect(tab) { selected(t) } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
karibu-testing-v23/src/main/kotlin/com/github/mvysny/kaributesting/v23/Tabs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.github.mvysny.kaributesting.v23 | ||
|
||
import com.github.mvysny.kaributesting.v10._expectEditableByUser | ||
import com.github.mvysny.kaributools.v23.owner | ||
import com.vaadin.flow.component.tabs.Tab | ||
|
||
/** | ||
* Selects this tab, but only if the tab can be selected by the user (it is visible and enabled). | ||
*/ | ||
public fun Tab._select() { | ||
_expectEditableByUser() | ||
owner.selectedTab = this | ||
} |