Skip to content

Commit

Permalink
fix: reset seenFlows after reset endpoint is called
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVidra committed Jul 12, 2024
1 parent 1c7ed94 commit a5185fc
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion workspaces/e2e/tests/cloud/cloud.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
></div>

<button class="reset-all">Reset all</button>
<button class="reset-my-flow">Reset my-flow</button>
<button class="reset-valid-flow">Reset valid-flow</button>

<script type="module" src="./cloud.ts"></script>
</body>
Expand Down
28 changes: 26 additions & 2 deletions workspaces/e2e/tests/cloud/cloud.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ test("Should call reset all flows endpoint", async ({ page }) => {
await page.click(".reset-all");
await reqPromise;
});
test("Should show flow again after reset all", async ({ page }) => {
await page.route("**/sdk/flows?projectId=my-proj**", (route) =>
route.fulfill({ json: { results: [validFlow] } }),
);
await page.goto("/cloud/cloud.html");
await expect(page.locator(".flows-tooltip")).toBeVisible();
await page.click(".flows-cancel");
await expect(page.locator(".flows-tooltip")).toBeHidden();
await page.route("**/sdk/user/**", (route) => route.fulfill());
await page.click(".reset-all");
await expect(page.locator(".flows-tooltip")).toBeVisible();
});

test("Should call reset flow endpoint", async ({ page }) => {
await page.route("**/sdk/flows?projectId=my-proj**", (route) =>
Expand All @@ -57,10 +69,22 @@ test("Should call reset flow endpoint", async ({ page }) => {
console.log(url);
return (
url.includes(`/sdk/user/${hashedUserId}/progress`) &&
url.includes("flowId=my-flow") &&
url.includes("flowId=valid-flow") &&
url.includes("projectId=my-proj")
);
});
await page.click(".reset-my-flow");
await page.click(".reset-valid-flow");
await reqPromise;
});
test("Should show flow again after reset", async ({ page }) => {
await page.route("**/sdk/flows?projectId=my-proj**", (route) =>
route.fulfill({ json: { results: [validFlow] } }),
);
await page.goto("/cloud/cloud.html");
await expect(page.locator(".flows-tooltip")).toBeVisible();
await page.click(".flows-cancel");
await expect(page.locator(".flows-tooltip")).toBeHidden();
await page.route("**/sdk/user/**", (route) => route.fulfill());
await page.click(".reset-valid-flow");
await expect(page.locator(".flows-tooltip")).toBeVisible();
});
4 changes: 2 additions & 2 deletions workspaces/e2e/tests/cloud/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ document.querySelector(".reset-all")?.addEventListener("click", () => {
resetAllFlows();
});

document.querySelector(".reset-my-flow")?.addEventListener("click", () => {
resetFlow("my-flow");
document.querySelector(".reset-valid-flow")?.addEventListener("click", () => {
resetFlow("valid-flow");
});
4 changes: 2 additions & 2 deletions workspaces/e2e/tests/cloud/flow-mocks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Flow } from "@flows/js";

export const validFlow: Flow = {
id: "valid-local-flow",
id: "valid-flow",
start: { location: "/" },
steps: [
{
Expand All @@ -12,7 +12,7 @@ export const validFlow: Flow = {
};

export const invalidFlow: Flow = {
id: "invalid-local-flow",
id: "invalid-flow",
start: { location: "/" },
steps: [
{
Expand Down
2 changes: 2 additions & 0 deletions workspaces/js/src/cloud/public-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export async function resetAllFlows(): Promise<void> {
projectId,
userHash,
});
FlowsContext.getInstance().resetAllFlowsSeen();
// Reinitialize Flows to load flows that have been reset
const options = FlowsCloudContext.getInstance().options;
if (!options) return;
Expand Down Expand Up @@ -68,6 +69,7 @@ export async function resetFlow(flowId: string): Promise<void> {
userHash,
flowId,
});
FlowsContext.getInstance().resetFlowSeen(flowId);
// Reinitialize Flows to load flows that have been reset
const options = FlowsCloudContext.getInstance().options;
if (!options) return;
Expand Down
12 changes: 12 additions & 0 deletions workspaces/js/src/core/flows-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,16 @@ export class FlowsContext {
this.onSeenFlowsChange?.([...this.seenFlows]);
return this;
}
resetFlowSeen(flowId: string): this {
this.seenFlows = this.seenFlows.filter((seenFlow) => seenFlow.flowId !== flowId);
this.savePersistentState();
this.onSeenFlowsChange?.([...this.seenFlows]);
return this;
}
resetAllFlowsSeen(): this {
this.seenFlows = [];
this.savePersistentState();
this.onSeenFlowsChange?.([...this.seenFlows]);
return this;
}
}

0 comments on commit a5185fc

Please sign in to comment.