Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Aug 10, 2023
1 parent 378a33d commit 295c067
Show file tree
Hide file tree
Showing 17 changed files with 612 additions and 18 deletions.
11 changes: 11 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkiverse.quinoa</groupId>
<artifactId>quarkus-quinoa-testing</artifactId>
<version>2.0.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devtools-testing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ $(document).ready(() => {
setTimeout(() => {
$message.html("Unleash the script!!!!").css("font-weight", "bold");
console.log("Message has been defined with Jquery");
}, 2000);
}, 200);

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


.calendar {
h1 {
background-color: red;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="calendar">
<h1>Calendar</h1>
<a href="page1">page1</a>
<a href="page1" id="page1">page1</a>
</div>
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "_imported";

.calendar {
h1 {
font-size: 4rem;
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/main/resources/web/page1/page1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ $(document).ready(() => {
setTimeout(() => {
$message.html("This is page 1").css("font-weight", "bold");
console.log("Message has been defined with Jquery");
}, 2000);
}, 200);
});
75 changes: 75 additions & 0 deletions integration-tests/src/main/resources/web/public/images/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# hello
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.quarkiverse.web.bundler.it;

import java.nio.file.Files;
import java.nio.file.Path;

import jakarta.inject.Inject;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

import io.quarkiverse.web.bundler.runtime.Bundled;
import io.quarkus.devtools.testing.SnapshotTesting;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.response.Response;

@QuarkusTest
public class BundledTest {

@Inject
Bundled bundled;

@Test
void testBundled(TestInfo info) throws Throwable {
final Path temp = Files.createTempDirectory("bundled-test");
assertBundledFileMatchSnapshot(info, temp, "main.css", bundled.style("main"));

Assertions.assertThat(bundled.mapping().names())
.containsExactlyInAnyOrder(
"ajax-loader.gif",
"slick.eot",
"main.css",
"main.css.map",
"slick.ttf",
"page1.css.map",
"chunk.js.map",
"chunk.js",
"page1.css",
"page1.js.map",
"main.js",
"slick.woff",
"slick.svg",
"page1.js",
"main.js.map");

for (String name : bundled.mapping().names()) {
RestAssured.get(bundled.resolve(name))
.then()
.statusCode(200);
}
}

private static void assertBundledFileMatchSnapshot(TestInfo info, Path dir, String name, String path) throws Throwable {
final Response response = RestAssured.get(path)
.then()
.statusCode(200)
.extract().response();
final String body = response.body().asString();
Files.writeString(dir.resolve(name), body);
SnapshotTesting.assertThatMatchSnapshot(info, dir, name);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.quarkiverse.web.bundler.it;

import static org.hamcrest.Matchers.is;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;

import org.junit.jupiter.api.Test;

import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;

@QuarkusTest
public class PublicAssetsTest {

@TestHTTPResource("/images/logo.svg")
URL logo;

@TestHTTPResource("/hello.txt")
URL txt;

@TestHTTPResource("/static/hello.md")
URL md;

@Test
void testLogo() throws IOException {
RestAssured.get(logo)
.then()
.statusCode(200)
.body(is(asString("/web/public/images/logo.svg")));
}

@Test
void testMD() throws IOException {
RestAssured.get(md)
.then()
.statusCode(200)
.body(is(asString("/web/public/static/hello.md")));
}

@Test
void testTXT() throws IOException {
RestAssured.get(txt)
.then()
.statusCode(200)
.body(is(asString("/web/public/hello.txt")));
}

private static String asString(String name) throws IOException {
try (InputStream resourceAsStream = PublicAssetsTest.class.getResourceAsStream(name)) {
return new String(resourceAsStream.readAllBytes(), StandardCharsets.UTF_8);
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.quarkiverse.web.bundler.it;

import static org.assertj.core.api.Assertions.assertThat;

import java.net.URL;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.microsoft.playwright.BrowserContext;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Response;
import com.microsoft.playwright.assertions.PlaywrightAssertions;

import io.quarkiverse.quinoa.testing.QuarkusPlaywrightManager;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
@QuarkusTestResource(QuarkusPlaywrightManager.class)
public class WebTest {
@QuarkusPlaywrightManager.InjectPlaywright
BrowserContext context;

@TestHTTPResource("/")
URL url;

@Test
void root() {
final Page page = context.newPage();
Response response = page.navigate(url.toString());
Assertions.assertEquals("OK", response.statusText());

page.waitForLoadState();

PlaywrightAssertions.assertThat(page).hasTitle("QWA");

page.waitForCondition(() -> page.innerText("#message")
.equals("Unleash the script!!!!"));

assertThat(
page.querySelector("#message").evaluate("element => getComputedStyle(element).color"))
.isEqualTo("rgb(255, 127, 80)");

assertThat(
page.querySelector(".calendar h1").evaluate("element => getComputedStyle(element).color"))
.isEqualTo("rgb(0, 0, 255)");

assertThat(
page.querySelector(".calendar h1").evaluate("element => getComputedStyle(element).backgroundColor"))
.isEqualTo("rgb(255, 0, 0)");

page.click("#page1");
page.waitForLoadState();

PlaywrightAssertions.assertThat(page).hasTitle("Page 1");

page.waitForCondition(() -> page.innerText("#message")
.equals("This is page 1"));

assertThat(
page.querySelector("#message").evaluate("element => getComputedStyle(element).color"))
.isEqualTo("rgb(0, 191, 255)");

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.quarkiverse.web.bundler.it;

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
public class WebTestIT extends WebTest {

// Run the same tests

}
Loading

0 comments on commit 295c067

Please sign in to comment.