Skip to content

Commit

Permalink
refactor: Improve time and use waitForSelector in auto-login tests (l…
Browse files Browse the repository at this point in the history
…angflow-ai#4603)

* improve usage of waitForSelector

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and diogocabral committed Nov 26, 2024
1 parent 1853814 commit 62655d3
Showing 1 changed file with 47 additions and 41 deletions.
88 changes: 47 additions & 41 deletions src/frontend/tests/core/features/auto-login-off.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,38 +47,39 @@ test("when auto_login is false, admin can CRUD user's and should see just your o
await page.locator('input[name="password"]').fill(randomPassword);
await page.locator('input[name="confirmpassword"]').fill(randomPassword);

await page.waitForTimeout(1000);
await page.waitForSelector("#is_active", {
timeout: 1500,
});

await page.locator("#is_active").click();

await page.getByText("Save", { exact: true }).click();

await page.waitForSelector("text=new user added", { timeout: 30000 });

await page.waitForTimeout(1000);

expect(await page.getByText(randomName, { exact: true }).isVisible()).toBe(
true,
);
await expect(page.getByText(randomName, { exact: true })).toBeVisible({
timeout: 2000,
});

await page.getByTestId("icon-Trash2").last().click();
await page.getByText("Delete", { exact: true }).last().click();

await page.waitForSelector("text=user deleted", { timeout: 30000 });

await page.waitForTimeout(1000);

expect(await page.getByText(randomName, { exact: true }).isVisible()).toBe(
false,
);
await expect(page.getByText(randomName, { exact: true })).toBeVisible({
timeout: 2000,
visible: false,
});

await page.getByText("New User", { exact: true }).click();

await page.getByPlaceholder("Username").last().fill(randomName);
await page.locator('input[name="password"]').fill(randomPassword);
await page.locator('input[name="confirmpassword"]').fill(randomPassword);

await page.waitForTimeout(1000);
await page.waitForSelector("#is_active", {
timeout: 1500,
});

await page.locator("#is_active").click();

Expand All @@ -96,11 +97,9 @@ test("when auto_login is false, admin can CRUD user's and should see just your o

await page.waitForSelector("text=user edited", { timeout: 30000 });

await page.waitForTimeout(1000);

expect(
await page.getByText(secondRandomName, { exact: true }).isVisible(),
).toBe(true);
await expect(page.getByText(secondRandomName, { exact: true })).toBeVisible({
timeout: 2000,
});

//user must see just your own flows
await page.waitForSelector('[data-testid="icon-ChevronLeft"]', {
Expand All @@ -125,7 +124,9 @@ test("when auto_login is false, admin can CRUD user's and should see just your o

while (modalCount === 0) {
await page.getByText("New Flow", { exact: true }).click();
await page.waitForTimeout(3000);
await page.waitForSelector('[data-testid="modal-title"]', {
timeout: 30000,
});
modalCount = await page.getByTestId("modal-title")?.count();
}

Expand All @@ -151,7 +152,9 @@ test("when auto_login is false, admin can CRUD user's and should see just your o
state: "visible",
});

await page.waitForTimeout(1000);
await page.waitForSelector('[data-testid="icon-ChevronLeft"]', {
timeout: 1500,
});

await page.getByTestId("icon-ChevronLeft").first().click();

Expand All @@ -160,13 +163,13 @@ test("when auto_login is false, admin can CRUD user's and should see just your o
state: "visible",
});

await page.waitForTimeout(2000);

expect(
await page.getByText(randomFlowName, { exact: true }).last().isVisible(),
).toBe(true);
await expect(page.getByText(randomFlowName, { exact: true })).toBeVisible({
timeout: 2000,
});

await page.waitForTimeout(500);
await page.waitForSelector("[data-testid='user-profile-settings']", {
timeout: 1500,
});

await page.getByTestId("user-profile-settings").click();

Expand All @@ -176,7 +179,10 @@ test("when auto_login is false, admin can CRUD user's and should see just your o

await page.getByPlaceholder("Username").fill(secondRandomName);
await page.getByPlaceholder("Password").fill(randomPassword);
await page.waitForTimeout(1000);

await page.waitForSelector("text=Sign in", {
timeout: 1500,
});

await page.getByRole("button", { name: "Sign In" }).click();

Expand All @@ -197,7 +203,9 @@ test("when auto_login is false, admin can CRUD user's and should see just your o

while (modalCount === 0) {
await page.getByText("New Flow", { exact: true }).click();
await page.waitForTimeout(3000);
await page.waitForSelector('[data-testid="modal-title"]', {
timeout: 30000,
});
modalCount = await page.getByTestId("modal-title")?.count();
}

Expand Down Expand Up @@ -234,17 +242,16 @@ test("when auto_login is false, admin can CRUD user's and should see just your o
timeout: 30000,
});

await page.waitForTimeout(1000);

expect(
await page.getByText(secondRandomFlowName, { exact: true }).isVisible(),
).toBe(true);

await page.waitForTimeout(500);
await expect(
page.getByText(secondRandomFlowName, { exact: true }),
).toBeVisible({
timeout: 2000,
});

expect(
await page.getByText(randomFlowName, { exact: true }).isVisible(),
).toBe(false);
await expect(page.getByText(randomFlowName, { exact: true })).toBeVisible({
timeout: 2000,
visible: false,
});

await page.getByTestId("user-profile-settings").click();

Expand All @@ -268,9 +275,8 @@ test("when auto_login is false, admin can CRUD user's and should see just your o
expect(
await page.getByText(secondRandomFlowName, { exact: true }).isVisible(),
).toBe(false);
await page.waitForTimeout(500);

expect(
await page.getByText(randomFlowName, { exact: true }).isVisible(),
).toBe(true);
await expect(page.getByText(randomFlowName, { exact: true })).toBeVisible({
timeout: 2000,
});
});

0 comments on commit 62655d3

Please sign in to comment.