Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
edeandrea committed Jan 13, 2025
1 parent 8f64322 commit aee57f6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 38 deletions.
45 changes: 12 additions & 33 deletions src/test/java/org/ericoleg/ndnp/ui/ClaimsDetailPageTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,56 @@

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;

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.<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
await()
.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<String> getChatResponseText(Page page) {
Expand Down
5 changes: 1 addition & 4 deletions src/test/java/org/ericoleg/ndnp/ui/ClaimsListPageTests.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down
5 changes: 4 additions & 1 deletion src/test/java/org/ericoleg/ndnp/ui/PlaywrightTests.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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
Expand Down

0 comments on commit aee57f6

Please sign in to comment.