diff --git a/src/test/java/org/ericoleg/ndnp/ui/ClaimsDetailPageTests.java b/src/test/java/org/ericoleg/ndnp/ui/ClaimsDetailPageTests.java index 0e1d521..1ad432a 100644 --- a/src/test/java/org/ericoleg/ndnp/ui/ClaimsDetailPageTests.java +++ b/src/test/java/org/ericoleg/ndnp/ui/ClaimsDetailPageTests.java @@ -2,13 +2,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; -import static org.ericoleg.ndnp.ui.PlaywrightTests.RECORD_DIR; import java.time.Duration; import java.util.Optional; -import org.junit.jupiter.api.Test; import org.ericoleg.ndnp.model.Claim; +import org.junit.jupiter.api.Test; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; @@ -16,50 +15,34 @@ import com.microsoft.playwright.Locator; import com.microsoft.playwright.Page; import com.microsoft.playwright.assertions.PlaywrightAssertions; -import io.quarkiverse.playwright.WithPlaywright; import io.quarkiverse.quinoa.testing.QuinoaTestProfiles; @QuarkusTest @TestProfile(QuinoaTestProfiles.Enable.class) -@WithPlaywright(recordVideoDir = RECORD_DIR, slowMo = 500) public class ClaimsDetailPageTests extends PlaywrightTests { @Test void pageLoads() { var claim = Claim.findAll().firstResultOptional().orElseThrow(() -> new IllegalArgumentException("Can not find a claim in the database to use for tests")); var page = loadPage(claim, "%s_pageLoads".formatted(getClass().getSimpleName())); - PlaywrightAssertions.assertThat(page) - .hasTitle("Claim Detail"); - - PlaywrightAssertions.assertThat(page.getByText(claim.claimNumber)) - .isVisible(); - - PlaywrightAssertions.assertThat(page.getByText(claim.summary)) - .isVisible(); - - PlaywrightAssertions.assertThat(page.getByText(claim.sentiment)) - .isVisible(); + PlaywrightAssertions.assertThat(page).hasTitle("Claim Detail"); + PlaywrightAssertions.assertThat(page.getByText(claim.claimNumber)).isVisible(); + PlaywrightAssertions.assertThat(page.getByText(claim.summary)).isVisible(); + PlaywrightAssertions.assertThat(page.getByText(claim.sentiment)).isVisible(); var openChatButton = page.getByLabel("OpenChat"); - PlaywrightAssertions.assertThat(openChatButton) - .isVisible(); - + PlaywrightAssertions.assertThat(openChatButton).isVisible(); openChatButton.click(); - PlaywrightAssertions.assertThat(page.getByText("Hi! I am Parasol Assistant. How can I help you today?")) - .isVisible(); - - assertThat(getChatResponseLocator(page).count()) - .isOne(); + PlaywrightAssertions.assertThat(page.getByText("Hi! I am Parasol Assistant. How can I help you today?")).isVisible(); + assertThat(getChatResponseLocator(page).count()).isOne(); var askMeAnythingField = page.getByPlaceholder("Ask me anything..."); - PlaywrightAssertions.assertThat(askMeAnythingField) - .isVisible(); + PlaywrightAssertions.assertThat(askMeAnythingField).isVisible(); askMeAnythingField.fill("Should I approve this claim?"); var sendQueryButton = page.getByLabel("SendQuery"); - PlaywrightAssertions.assertThat(sendQueryButton) - .isVisible(); + PlaywrightAssertions.assertThat(sendQueryButton).isVisible(); sendQueryButton.click(); // Wait for the answer text to have at least one piece of text in the answer @@ -67,12 +50,8 @@ void pageLoads() { .atMost(Duration.ofMinutes(10)) .until(() -> getChatResponseText(page).isPresent()); - assertThat(getChatResponseText(page)) - .isNotNull() - .isPresent(); - - assertThat(getChatResponseLocator(page).count()) - .isGreaterThanOrEqualTo(2); + assertThat(getChatResponseText(page)).isNotNull().isPresent(); + assertThat(getChatResponseLocator(page).count()).isGreaterThanOrEqualTo(2); } private static Optional getChatResponseText(Page page) { diff --git a/src/test/java/org/ericoleg/ndnp/ui/ClaimsListPageTests.java b/src/test/java/org/ericoleg/ndnp/ui/ClaimsListPageTests.java index cd60705..ac90011 100644 --- a/src/test/java/org/ericoleg/ndnp/ui/ClaimsListPageTests.java +++ b/src/test/java/org/ericoleg/ndnp/ui/ClaimsListPageTests.java @@ -1,12 +1,11 @@ package org.ericoleg.ndnp.ui; import static org.assertj.core.api.Assertions.assertThat; -import static org.ericoleg.ndnp.ui.PlaywrightTests.RECORD_DIR; import java.util.List; -import org.junit.jupiter.api.Test; import org.ericoleg.ndnp.model.Claim; +import org.junit.jupiter.api.Test; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; @@ -15,12 +14,10 @@ import com.microsoft.playwright.Page; import com.microsoft.playwright.assertions.PlaywrightAssertions; import com.microsoft.playwright.options.AriaRole; -import io.quarkiverse.playwright.WithPlaywright; import io.quarkiverse.quinoa.testing.QuinoaTestProfiles; @QuarkusTest @TestProfile(QuinoaTestProfiles.Enable.class) -@WithPlaywright(recordVideoDir = RECORD_DIR, slowMo = 500) public class ClaimsListPageTests extends PlaywrightTests { private static final int NB_CLAIMS = 6; diff --git a/src/test/java/org/ericoleg/ndnp/ui/PlaywrightTests.java b/src/test/java/org/ericoleg/ndnp/ui/PlaywrightTests.java index 25a2b68..8d0b0ff 100644 --- a/src/test/java/org/ericoleg/ndnp/ui/PlaywrightTests.java +++ b/src/test/java/org/ericoleg/ndnp/ui/PlaywrightTests.java @@ -1,6 +1,7 @@ package org.ericoleg.ndnp.ui; import static org.assertj.core.api.Assertions.assertThat; +import static org.ericoleg.ndnp.ui.PlaywrightTests.RECORD_DIR; import java.nio.file.Files; @@ -13,8 +14,10 @@ import com.microsoft.playwright.Response; import com.microsoft.playwright.options.LoadState; import io.quarkiverse.playwright.InjectPlaywright; +import io.quarkiverse.playwright.WithPlaywright; -public abstract class PlaywrightTests { +@WithPlaywright(recordVideoDir = RECORD_DIR, slowMo = 500) +abstract class PlaywrightTests { protected static final String RECORD_DIR = "target/playwright"; @InjectPlaywright