diff --git a/karibu-testing-v10/kt10-tests/build.gradle.kts b/karibu-testing-v10/kt10-tests/build.gradle.kts index ad75b5da..ddd712e9 100644 --- a/karibu-testing-v10/kt10-tests/build.gradle.kts +++ b/karibu-testing-v10/kt10-tests/build.gradle.kts @@ -3,6 +3,7 @@ dependencies { // for testing purposes api(libs.dynatest) + api(libs.junit.jupiterapi) api(libs.slf4j.simple) api(libs.karibudsl) { exclude(module = "javax.el") diff --git a/karibu-testing-v10/kt10-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/AllTests.kt b/karibu-testing-v10/kt10-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/AllTests.kt index e49b6bca..615f349d 100644 --- a/karibu-testing-v10/kt10-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/AllTests.kt +++ b/karibu-testing-v10/kt10-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/AllTests.kt @@ -6,8 +6,19 @@ import com.github.mvysny.kaributesting.v10.pro.confirmDialogTestbatch import com.github.mvysny.kaributesting.v10.pro.gridProTestbatch import com.github.mvysny.kaributesting.v10.pro.richTextEditorTests import npmPolymerTemplateTestBatch +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Nested import java.util.* +open class AbstractAllTests10(val isModuleTest: Boolean) { + @BeforeEach fun resetLocale() { + // make sure that Validator produces messages in English + Locale.setDefault(Locale.ENGLISH) + } + + @Nested inner class RoutesTests : AbstractRoutesTests() +} + /** * @param isModuleTest if true then this test run simulates a jar reusable component. */ @@ -18,9 +29,6 @@ fun DynaNodeGroup.allTests(isModuleTest: Boolean) { Locale.setDefault(Locale.ENGLISH) } - group("routes test") { - routesTestBatch() - } group("basic utils") { basicUtilsTestbatch() } diff --git a/karibu-testing-v10/kt10-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/RoutesTest.kt b/karibu-testing-v10/kt10-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/RoutesTest.kt index 625d685f..54fc5159 100644 --- a/karibu-testing-v10/kt10-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/RoutesTest.kt +++ b/karibu-testing-v10/kt10-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/RoutesTest.kt @@ -1,22 +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.github.mvysny.kaributesting.v10.mock.MockVaadinHelper -import com.github.mvysny.kaributools.VaadinVersion import com.vaadin.flow.component.Component import com.vaadin.flow.component.UI import com.vaadin.flow.router.HasErrorParameter import com.vaadin.flow.router.InternalServerError import com.vaadin.flow.router.NotFoundException -import com.vaadin.flow.router.PreserveOnRefresh -import com.vaadin.flow.router.RouteNotFoundError import com.vaadin.flow.server.VaadinContext -import com.vaadin.flow.server.VaadinSession import com.vaadin.flow.server.startup.ApplicationRouteRegistry +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Test import test.app.MyRouteNotFoundError -import java.lang.Boolean import kotlin.test.expect val allViews: Set> = setOf>( @@ -30,24 +25,23 @@ val allViews: Set> = setOf>( ) val allErrorRoutes: Set>> = setOf(ErrorView::class.java, MockRouteNotFoundError::class.java, MockRouteAccessDeniedError::class.java) -@DynaTestDsl -fun DynaNodeGroup.routesTestBatch() { - afterEach { MockVaadin.tearDown() } +abstract class AbstractRoutesTests { + @AfterEach fun tearDownVaadin() { MockVaadin.tearDown() } - test("All views discovered") { + @Test fun `All views discovered`() { val routes: Routes = Routes().autoDiscoverViews("com.github") expect(allViews) { routes.routes.toSet() } expect(allErrorRoutes) { routes.errorRoutes.toSet() } } - test("calling autoDiscoverViews() multiple times won't fail") { + @Test fun `calling autoDiscoverViews() multiple times won't fail`() { repeat(5) { expect(allViews) { Routes().autoDiscoverViews("com.github").routes } } } // https://github.com/mvysny/karibu-testing/issues/50 - test("app-specific NotFoundException handler removes MockRouteNotFoundError") { + @Test fun `app-specific NotFoundException handler removes MockRouteNotFoundError`() { val routes: Routes = Routes().autoDiscoverViews() val expectedRouteClasses = setOf(ErrorView::class.java, InternalServerError::class.java, MyRouteNotFoundError::class.java, MockRouteAccessDeniedError::class.java) expect(expectedRouteClasses) { routes.errorRoutes.toSet() } @@ -55,7 +49,7 @@ fun DynaNodeGroup.routesTestBatch() { MockVaadin.setup(routes) } - test("PWA is ignored by default") { + @Test fun `PWA is ignored by default`() { val routes: Routes = Routes().autoDiscoverViews("com.github") val ctx: VaadinContext = MockVaadinHelper.createMockVaadinContext() routes.register(ctx) @@ -65,7 +59,7 @@ fun DynaNodeGroup.routesTestBatch() { } } - test("PWA is discovered properly if need be") { + @Test fun `PWA is discovered properly if need be`() { val routes: Routes = Routes().autoDiscoverViews("com.github") routes.skipPwaInit = false val ctx: VaadinContext = MockVaadinHelper.createMockVaadinContext() @@ -76,7 +70,7 @@ fun DynaNodeGroup.routesTestBatch() { } } - test("MockRouteNotFoundError is called when the route doesn't exist, and it fails immediately with an informative error message") { + @Test fun `MockRouteNotFoundError is called when the route doesn't exist, and it fails immediately with an informative error message`() { val routes: Routes = Routes().autoDiscoverViews("com.github") MockVaadin.setup(routes) expectThrows(NotFoundException::class, "No route found for 'A_VIEW_THAT_DOESNT_EXIST'\nAvailable routes:") { diff --git a/karibu-testing-v23/kt23-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/AllTests19.kt b/karibu-testing-v23/kt23-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/AllTests19.kt index f807600f..562b3468 100644 --- a/karibu-testing-v23/kt23-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/AllTests19.kt +++ b/karibu-testing-v23/kt23-tests/src/main/kotlin/com/github/mvysny/kaributesting/v10/AllTests19.kt @@ -2,6 +2,7 @@ package com.github.mvysny.kaributesting.v10 import com.github.mvysny.dynatest.DynaNodeGroup import com.github.mvysny.dynatest.DynaTestDsl +import org.junit.jupiter.api.Nested /** * @param isModuleTest if true then this test run simulates a jar reusable component. @@ -42,3 +43,7 @@ fun DynaNodeGroup.allTests19(isModuleTest: Boolean) { tabsTests() } } + +abstract class AbstractAllTests19(val isModuleTest: Boolean) { + @Nested inner class AllTests10 : AbstractAllTests10(isModuleTest) +} diff --git a/karibu-testing-v24/kt10-testrun-vaadin24-module/src/test/kotlin/AllTests.kt b/karibu-testing-v24/kt10-testrun-vaadin24-module/src/test/kotlin/AllTests.kt index 3daf41f6..22d1c70a 100644 --- a/karibu-testing-v24/kt10-testrun-vaadin24-module/src/test/kotlin/AllTests.kt +++ b/karibu-testing-v24/kt10-testrun-vaadin24-module/src/test/kotlin/AllTests.kt @@ -2,6 +2,10 @@ import com.github.mvysny.dynatest.DynaTest import com.github.mvysny.dynatest.jvmVersion import com.github.mvysny.kaributesting.v10.* import com.github.mvysny.kaributools.VaadinVersion +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 java.net.URL import kotlin.test.expect @@ -22,3 +26,22 @@ class AllTests : DynaTest({ } allTests19(isModuleTest = true) }) + +class AllTests24 { + @Test fun `flow-build-info-json doesn't exist`() { + val res: URL? = Thread.currentThread().contextClassLoader.getResource("META-INF/VAADIN/config/flow-build-info.json") + expect(null, "flow-build-info.json exists on the classpath!") { res } + } + + @Nested inner class VaadinEnv { + @BeforeEach fun fakeVaadin() { MockVaadin.setup() } + @AfterEach fun tearDownVaadin() { MockVaadin.tearDown() } + + @Test fun vaadinVersion() { + expect(24) { VaadinVersion.get.major } + expect(false) { VaadinMeta.isCompatibilityMode } + } + } + + @Nested inner class AllTests19 : AbstractAllTests19(true) +} diff --git a/karibu-testing-v24/kt10-testrun-vaadin24/src/test/kotlin/AllTests.kt b/karibu-testing-v24/kt10-testrun-vaadin24/src/test/kotlin/AllTests.kt index c386fccf..4be29294 100644 --- a/karibu-testing-v24/kt10-testrun-vaadin24/src/test/kotlin/AllTests.kt +++ b/karibu-testing-v24/kt10-testrun-vaadin24/src/test/kotlin/AllTests.kt @@ -2,6 +2,10 @@ import com.github.mvysny.dynatest.DynaTest import com.github.mvysny.dynatest.jvmVersion import com.github.mvysny.kaributesting.v10.* import com.github.mvysny.kaributools.VaadinVersion +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 java.net.URL import kotlin.test.expect @@ -22,3 +26,22 @@ class AllTests : DynaTest({ } allTests19(isModuleTest = false) }) + +class AllTests24 { + @Test fun `flow-build-info-json exists`() { + val res: URL? = Thread.currentThread().contextClassLoader.getResource("META-INF/VAADIN/config/flow-build-info.json") + expect(true, "flow-build-info.json is not on the classpath!") { res != null } + } + + @Nested inner class VaadinEnv { + @BeforeEach fun fakeVaadin() { MockVaadin.setup() } + @AfterEach fun tearDownVaadin() { MockVaadin.tearDown() } + + @Test fun vaadinVersion() { + expect(24) { VaadinVersion.get.major } + expect(false) { VaadinMeta.isCompatibilityMode } + } + } + + @Nested inner class AllTests19 : AbstractAllTests19(false) +} diff --git a/karibu-testing-v24/kt10-testrun-vaadin24next-module/src/test/kotlin/AllTests.kt b/karibu-testing-v24/kt10-testrun-vaadin24next-module/src/test/kotlin/AllTests.kt index 3daf41f6..22d1c70a 100644 --- a/karibu-testing-v24/kt10-testrun-vaadin24next-module/src/test/kotlin/AllTests.kt +++ b/karibu-testing-v24/kt10-testrun-vaadin24next-module/src/test/kotlin/AllTests.kt @@ -2,6 +2,10 @@ import com.github.mvysny.dynatest.DynaTest import com.github.mvysny.dynatest.jvmVersion import com.github.mvysny.kaributesting.v10.* import com.github.mvysny.kaributools.VaadinVersion +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 java.net.URL import kotlin.test.expect @@ -22,3 +26,22 @@ class AllTests : DynaTest({ } allTests19(isModuleTest = true) }) + +class AllTests24 { + @Test fun `flow-build-info-json doesn't exist`() { + val res: URL? = Thread.currentThread().contextClassLoader.getResource("META-INF/VAADIN/config/flow-build-info.json") + expect(null, "flow-build-info.json exists on the classpath!") { res } + } + + @Nested inner class VaadinEnv { + @BeforeEach fun fakeVaadin() { MockVaadin.setup() } + @AfterEach fun tearDownVaadin() { MockVaadin.tearDown() } + + @Test fun vaadinVersion() { + expect(24) { VaadinVersion.get.major } + expect(false) { VaadinMeta.isCompatibilityMode } + } + } + + @Nested inner class AllTests19 : AbstractAllTests19(true) +} diff --git a/karibu-testing-v24/kt10-testrun-vaadin24next/src/test/kotlin/AllTests.kt b/karibu-testing-v24/kt10-testrun-vaadin24next/src/test/kotlin/AllTests.kt index c386fccf..4be29294 100644 --- a/karibu-testing-v24/kt10-testrun-vaadin24next/src/test/kotlin/AllTests.kt +++ b/karibu-testing-v24/kt10-testrun-vaadin24next/src/test/kotlin/AllTests.kt @@ -2,6 +2,10 @@ import com.github.mvysny.dynatest.DynaTest import com.github.mvysny.dynatest.jvmVersion import com.github.mvysny.kaributesting.v10.* import com.github.mvysny.kaributools.VaadinVersion +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 java.net.URL import kotlin.test.expect @@ -22,3 +26,22 @@ class AllTests : DynaTest({ } allTests19(isModuleTest = false) }) + +class AllTests24 { + @Test fun `flow-build-info-json exists`() { + val res: URL? = Thread.currentThread().contextClassLoader.getResource("META-INF/VAADIN/config/flow-build-info.json") + expect(true, "flow-build-info.json is not on the classpath!") { res != null } + } + + @Nested inner class VaadinEnv { + @BeforeEach fun fakeVaadin() { MockVaadin.setup() } + @AfterEach fun tearDownVaadin() { MockVaadin.tearDown() } + + @Test fun vaadinVersion() { + expect(24) { VaadinVersion.get.major } + expect(false) { VaadinMeta.isCompatibilityMode } + } + } + + @Nested inner class AllTests19 : AbstractAllTests19(false) +}