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 Aug 18, 2024
1 parent bad3389 commit 291f33b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package com.vaadin.starter.beveragebuddy.ui

import com.github.mvysny.dynatest.DynaTest
import com.github.mvysny.kaributesting.v10.*
import com.vaadin.flow.component.button.Button
import com.vaadin.flow.component.textfield.TextField
import com.vaadin.starter.beveragebuddy.AbstractAppTest
import com.vaadin.starter.beveragebuddy.backend.Category
import com.vaadin.starter.beveragebuddy.ui.categories.CategoryEditorDialog
import org.junit.jupiter.api.Test
import kotlin.test.expect

/**
* Tests the UI. Uses the Browserless Testing approach as provided by the [Karibu Testing](https://github.com/mvysny/karibu-testing) library.
*/
class CategoryEditorDialogTest : DynaTest({

usingApp()

test("create new category") {
class CategoryEditorDialogTest : AbstractAppTest() {
@Test fun `create new category`() {
CategoryEditorDialog {} .createNew()

// make sure that the "New Category" dialog is opened
Expand All @@ -30,7 +28,7 @@ class CategoryEditorDialogTest : DynaTest({
expect("Beer") { Category.single().name }
}

test("edit existing category") {
@Test fun `edit existing category`() {
val cat = Category(name = "Foo")
cat.save()

Expand All @@ -47,4 +45,4 @@ class CategoryEditorDialogTest : DynaTest({
_expectNone<EditorDialogFrame<*>>() // expect the dialog to close
expect("Beer") { Category.single().name }
}
})
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
package com.vaadin.starter.beveragebuddy.ui

import com.github.mvysny.dynatest.DynaTest
import com.github.mvysny.kaributesting.v10.*
import com.vaadin.flow.component.button.Button
import com.vaadin.flow.component.combobox.ComboBox
import com.vaadin.flow.component.textfield.IntegerField
import com.vaadin.flow.component.textfield.TextField
import com.vaadin.starter.beveragebuddy.AbstractAppTest
import com.vaadin.starter.beveragebuddy.backend.Category
import com.vaadin.starter.beveragebuddy.backend.Review
import com.vaadin.starter.beveragebuddy.ui.reviews.ReviewEditorDialog
import org.junit.jupiter.api.Test
import kotlin.test.expect

class ReviewEditorDialogTest : DynaTest({
usingApp()

test("smoke") {
class ReviewEditorDialogTest : AbstractAppTest() {
@Test fun smoke() {
ReviewEditorDialog({}).createNew()
_expectOne<EditorDialogFrame<*>>()
}

test("'cancel' closes the dialog") {
@Test fun `'cancel' closes the dialog`() {
ReviewEditorDialog({}).createNew()
_get<Button> { text = "Cancel" }._click()
_expectNone<EditorDialogFrame<*>>()
}

test("simple validation failure") {
@Test fun `simple validation failure`() {
ReviewEditorDialog({}).createNew()
_expectOne<EditorDialogFrame<*>>()
_get<Button> { text = "Create" } ._click()
Expand All @@ -35,7 +34,7 @@ class ReviewEditorDialogTest : DynaTest({
_get<TextField> { label = "Beverage name"} ._expectInvalid("must not be blank")
}

test("create review without setting a category fails") {
@Test fun `create review without setting a category fails`() {
ReviewEditorDialog({}).createNew()
_expectOne<EditorDialogFrame<*>>()
_get<TextField> { label = "Beverage name" } ._value = "FooBar"
Expand All @@ -46,7 +45,7 @@ class ReviewEditorDialogTest : DynaTest({
expectList() { Review.findAll() }
}

test("create new review") {
@Test fun `create new review`() {
val cat = Category(name = "Beers")
cat.save()

Expand All @@ -68,4 +67,4 @@ class ReviewEditorDialogTest : DynaTest({
expect(cat.id) { review.category }
expect(1) { review.count }
}
})
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.vaadin.starter.beveragebuddy.ui

import com.github.mvysny.dynatest.DynaTest
import com.github.mvysny.kaributesting.v10._click
import com.github.mvysny.kaributesting.v10._expectNone
import com.github.mvysny.kaributesting.v10._expectOne
Expand All @@ -9,27 +8,26 @@ import com.github.mvysny.kaributesting.v23.expectRows
import com.vaadin.flow.component.UI
import com.vaadin.flow.component.button.Button
import com.vaadin.flow.component.virtuallist.VirtualList
import com.vaadin.starter.beveragebuddy.AbstractAppTest
import com.vaadin.starter.beveragebuddy.backend.Category
import com.vaadin.starter.beveragebuddy.backend.Review
import com.vaadin.starter.beveragebuddy.backend.ReviewWithCategory
import org.junit.jupiter.api.Test

class ReviewsListTest : DynaTest({

usingApp()

test("no reviews initially") {
class ReviewsListTest : AbstractAppTest() {
@Test fun `no reviews initially`() {
_get<VirtualList<ReviewWithCategory>>().expectRows(0)
}

test("reviews listed") {
@Test fun reviewsListed() {
// prepare testing data
val cat = Category(name = "Beers")
cat.save()
Review(score = 1, name = "Good!", category = cat.id).save()
_get<VirtualList<ReviewWithCategory>>().expectRows(1)
}

test("'new review' smoke test") {
@Test fun `'new review' smoke test`() {
UI.getCurrent().navigate("")
_get<Button> { text = "New review (Alt+N)" }._click()

Expand All @@ -41,4 +39,4 @@ class ReviewsListTest : DynaTest({

_expectNone<EditorDialogFrame<*>>()
}
})
}

0 comments on commit 291f33b

Please sign in to comment.