Skip to content

Commit

Permalink
test: useTransition to wait for states
Browse files Browse the repository at this point in the history
This approach could probably be applied across other flakey tests and could also be documented as a good approach of if there is user-feedback for a specific action when running integration tests.
  • Loading branch information
jacob-ebey committed Dec 2, 2022
1 parent 37364c7 commit 15a21f1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions integration/transition-state-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ test.describe("rendering", () => {
<html lang="en">
<body>
<Outlet />
<pre>
{transition.state != "idle" && (
<p id="loading-indicator">Loading...</p>
)}
<p>
<code id="transitions">
{JSON.stringify(transitions, null, 2)}
</code>
</pre>
</p>
<Scripts />
</body>
</html>
Expand Down Expand Up @@ -199,6 +202,8 @@ test.describe("rendering", () => {
await app.goto("/", true);
await app.clickLink(`/${STATES.NORMAL_LOAD}`);
await page.waitForSelector(`#${STATES.NORMAL_LOAD}`);
await page.waitForSelector("#loading-indicator", { state: "hidden" });

let transitionsCode = await app.getElement("#transitions");
let transitionsJson = transitionsCode.text();
let transitions = JSON.parse(transitionsJson);
Expand All @@ -224,6 +229,7 @@ test.describe("rendering", () => {
await app.goto("/", true);
await app.clickLink(`/${STATES.LOADING_REDIRECT}`);
await page.waitForURL(/\?redirected/);
await page.waitForSelector("#loading-indicator", { state: "hidden" });
let transitionsCode = await app.getElement("#transitions");
let transitionsJson = transitionsCode.text();
let transitions = JSON.parse(transitionsJson);
Expand Down Expand Up @@ -266,6 +272,7 @@ test.describe("rendering", () => {
await app.goto("/", true);
await app.clickSubmitButton(`/${STATES.SUBMITTING_LOADER}`);
await page.waitForSelector(`#${STATES.SUBMITTING_LOADER}`);
await page.waitForSelector("#loading-indicator", { state: "hidden" });
let transitionsCode = await app.getElement("#transitions");
let transitionsJson = transitionsCode.text();
let transitions = JSON.parse(transitionsJson);
Expand Down Expand Up @@ -300,6 +307,7 @@ test.describe("rendering", () => {
await app.goto("/", true);
await app.clickSubmitButton(`/${STATES.SUBMITTING_LOADER_REDIRECT}`);
await page.waitForURL(/\?redirected/);
await page.waitForSelector("#loading-indicator", { state: "hidden" });
let transitionsCode = await app.getElement("#transitions");
let transitionsJson = transitionsCode.text();
let transitions = JSON.parse(transitionsJson);
Expand Down Expand Up @@ -356,6 +364,7 @@ test.describe("rendering", () => {
await app.goto("/", true);
await app.clickSubmitButton(`/${STATES.SUBMITTING_ACTION}`);
await page.waitForSelector(`#${STATES.SUBMITTING_ACTION}`);
await page.waitForSelector("#loading-indicator", { state: "hidden" });
let transitionsCode = await app.getElement("#transitions");
let transitionsJson = transitionsCode.text();
let transitions = JSON.parse(transitionsJson);
Expand Down Expand Up @@ -408,6 +417,7 @@ test.describe("rendering", () => {
await app.goto("/", true);
await app.clickSubmitButton(`/${STATES.SUBMITTING_ACTION_REDIRECT}`);
await page.waitForURL(/\?redirected/);
await page.waitForSelector("#loading-indicator", { state: "hidden" });
let transitionsCode = await app.getElement("#transitions");
let transitionsJson = transitionsCode.text();
let transitions = JSON.parse(transitionsJson);
Expand Down Expand Up @@ -464,6 +474,7 @@ test.describe("rendering", () => {
await app.goto("/", true);
await app.clickSubmitButton(`/${STATES.FETCHER_REDIRECT}`);
await page.waitForURL(/\?redirected/);
await page.waitForSelector("#loading-indicator", { state: "hidden" });
let transitionsCode = await app.getElement("#transitions");
let transitionsJson = transitionsCode.text();
let transitions = JSON.parse(transitionsJson);
Expand Down

0 comments on commit 15a21f1

Please sign in to comment.