Fix tests

This commit is contained in:
Arnaud 2025-02-25 16:36:01 +01:00
parent cf432a07f6
commit 19e16e4383
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663

View File

@ -1,121 +1,146 @@
import test, { expect } from "@playwright/test"; import test, { expect } from "@playwright/test";
import { Bytes } from "../src/utils/bytes" import { Bytes } from "../src/utils/bytes";
import { GB } from "../src/utils/constants" import { GB } from "../src/utils/constants";
test('create an availability', async ({ page }) => { test("create an availability", async ({ page }) => {
await page.goto('/dashboard/availabilities'); await page.goto("/dashboard/availabilities");
await page.waitForTimeout(500); await page.waitForTimeout(500);
await page.locator('.availability-edit button').first().click(); await page.locator(".availability-edit button").first().click();
await page.getByLabel('Total size').click(); await page.getByLabel("Total size").click();
const value = (Math.random() * 0.5) + 0.1; const value = Math.random() * 0.5 + 0.1;
await page.getByLabel('Total size').fill(value.toFixed(1)); await page.getByLabel("Total size").fill(value.toFixed(1));
await page.getByLabel('Duration').click(); await page.getByLabel("Duration").click();
await page.getByLabel('Duration').fill('30'); await page.getByLabel("Duration").fill("30");
await page.getByLabel('Min price').click(); await page.getByLabel("Min price").click();
await page.getByLabel('Min price').fill('5'); await page.getByLabel("Min price").fill("5");
await page.getByLabel('Max collateral').click(); await page.getByLabel("Max collateral").click();
await page.getByLabel('Max collateral').fill('30'); await page.getByLabel("Max collateral").fill("30");
await page.getByLabel('Min price').fill('5'); await page.getByLabel("Min price").fill("5");
await page.getByLabel('Nickname').click(); await page.getByLabel("Nickname").click();
await page.getByLabel('Nickname').fill('test'); await page.getByLabel("Nickname").fill("test");
await page.getByRole('button', { name: 'Next' }).click(); await page.getByRole("button", { name: "Next" }).click();
await expect(page.getByText('Confirm your new sale')).toBeVisible(); await expect(page.getByText("Confirm your new sale")).toBeVisible();
await page.getByRole('button', { name: 'Next' }).click(); await page.getByRole("button", { name: "Next" }).click();
await expect(page.getByText('Success', { exact: true })).toBeVisible(); await expect(page.getByText("Success", { exact: true })).toBeVisible();
await page.getByRole('button', { name: 'Finish' }).click(); await page.getByRole("button", { name: "Finish" }).click();
await expect(page.getByText(Bytes.pretty(parseFloat(value.toFixed(1)) * GB)).first()).toBeVisible(); await expect(
}) page.getByText(Bytes.pretty(parseFloat(value.toFixed(1)) * GB)).first()
).toBeVisible();
});
test('availability navigation buttons', async ({ page }) => { test("availability navigation buttons", async ({ page }) => {
await page.goto('/dashboard/availabilities'); await page.goto("/dashboard/availabilities");
await page.waitForTimeout(500); await page.waitForTimeout(500);
await page.locator('.availability-edit button').first().click(); await page.locator(".availability-edit button").first().click();
await expect(page.locator('.stepper-number-done')).not.toBeVisible() await expect(page.locator(".stepper-number-done")).not.toBeVisible();
await expect(page.locator('.step--active')).toBeVisible() await expect(page.locator(".step--active")).toBeVisible();
await expect(page.locator('footer .button--primary')).not.toHaveAttribute("disabled"); await expect(page.locator("footer .button--primary")).not.toHaveAttribute(
await expect(page.locator('footer .button--outline').first()).not.toHaveAttribute("disabled"); "disabled"
await page.getByLabel('Total size').click(); );
await page.getByLabel('Total size').fill('19'); await expect(
await expect(page.locator('footer .button--outline').first()).not.toHaveAttribute("disabled"); page.locator("footer .button--outline").first()
await expect(page.locator('footer .button--primary')).toHaveAttribute("disabled"); ).not.toHaveAttribute("disabled");
await page.getByLabel('Total size').click(); await page.getByLabel("Total size").click();
await page.getByLabel('Total size').fill('0.5'); await page.getByLabel("Total size").fill("19");
await page.getByRole('button', { name: 'Next' }).click(); await expect(
await expect(page.locator('footer .button--outline').first()).not.toHaveAttribute("disabled"); page.locator("footer .button--outline").first()
await expect(page.locator('footer .button--primary')).not.toHaveAttribute("disabled"); ).not.toHaveAttribute("disabled");
await expect(page.locator('.step--done')).toBeVisible() await page.locator("footer .button--outline").blur();
await expect(page.locator('.step--active')).toBeVisible() await expect(page.locator("footer .button--primary")).toHaveAttribute(
await page.getByRole('button', { name: 'Back' }).click(); "disabled"
await expect(page.locator('.step--done')).not.toBeVisible() );
await expect(page.locator('.step--active')).toBeVisible() await page.getByLabel("Total size").click();
await page.getByRole('button', { name: 'Next' }).click(); await page.getByLabel("Total size").fill("0.5");
await page.getByRole('button', { name: 'Next' }).click(); await page.getByRole("button", { name: "Next" }).click();
await expect(page.locator('.step--done')).toHaveCount(2) await expect(
await expect(page.locator('.step--active')).toBeVisible() page.locator("footer .button--outline").first()
await expect(page.locator('footer .button--outline').first()).toHaveAttribute("disabled"); ).not.toHaveAttribute("disabled");
await expect(page.locator('footer .button--primary')).not.toHaveAttribute("disabled"); await expect(page.locator("footer .button--primary")).not.toHaveAttribute(
await page.getByRole('button', { name: 'Finish' }).click(); "disabled"
await expect(page.locator('.modal--open')).not.toBeVisible(); );
}) await expect(page.locator(".step--done")).toBeVisible();
await expect(page.locator(".step--active")).toBeVisible();
await page.getByRole("button", { name: "Back" }).click();
await expect(page.locator(".step--done")).not.toBeVisible();
await expect(page.locator(".step--active")).toBeVisible();
await page.getByRole("button", { name: "Next" }).click();
await page.getByRole("button", { name: "Next" }).click();
await expect(page.locator(".step--done")).toHaveCount(2);
await expect(page.locator(".step--active")).toBeVisible();
await expect(page.locator("footer .button--outline").first()).toHaveAttribute(
"disabled"
);
await expect(page.locator("footer .button--primary")).not.toHaveAttribute(
"disabled"
);
await page.getByRole("button", { name: "Finish" }).click();
await expect(page.locator(".modal--open")).not.toBeVisible();
});
test('create an availability with changing the duration to months', async ({ page }) => { test("create an availability with changing the duration to months", async ({
await page.goto('/dashboard/availabilities'); page,
await page.waitForTimeout(500); }) => {
await page.locator('.availability-edit button').first().click(); await page.goto("/dashboard/availabilities");
await page.getByLabel('Total size').click(); await page.waitForTimeout(500);
await page.locator(".availability-edit button").first().click();
await page.getByLabel("Total size").click();
await page.getByLabel('Total size').fill("0.1"); await page.getByLabel("Total size").fill("0.1");
await page.getByLabel('Duration').click(); await page.getByLabel("Duration").click();
await page.getByLabel('Duration').fill("3"); await page.getByLabel("Duration").fill("3");
await page.getByRole('combobox').nth(1).selectOption('months'); await page.getByRole("combobox").nth(1).selectOption("months");
await page.getByLabel('Min price').click(); await page.getByLabel("Min price").click();
await page.getByLabel('Min price').fill('5'); await page.getByLabel("Min price").fill("5");
await page.getByLabel('Max collateral').click(); await page.getByLabel("Max collateral").click();
await page.getByLabel('Max collateral').fill('30'); await page.getByLabel("Max collateral").fill("30");
await page.getByLabel('Min price').fill('5'); await page.getByLabel("Min price").fill("5");
await page.getByLabel('Nickname').click(); await page.getByLabel("Nickname").click();
await page.getByLabel('Nickname').fill('test'); await page.getByLabel("Nickname").fill("test");
await page.getByRole('button', { name: 'Next' }).click(); await page.getByRole("button", { name: "Next" }).click();
await expect(page.getByText('Confirm your new sale')).toBeVisible(); await expect(page.getByText("Confirm your new sale")).toBeVisible();
await page.getByRole('button', { name: 'Next' }).click(); await page.getByRole("button", { name: "Next" }).click();
await expect(page.getByText('Success', { exact: true })).toBeVisible(); await expect(page.getByText("Success", { exact: true })).toBeVisible();
await page.getByRole('button', { name: 'Finish' }).click(); await page.getByRole("button", { name: "Finish" }).click();
await expect(page.getByText("3 months").first()).toBeVisible(); await expect(page.getByText("3 months").first()).toBeVisible();
}) });
test("create an availability after checking max size and invalid input", async ({
page,
}) => {
await page.goto("/dashboard/availabilities");
await page.waitForTimeout(500);
await page.locator(".availability-edit button").first().click();
await page.getByLabel("Total size").click();
test('create an availability after checking max size and invalid input', async ({ page }) => { await page.getByLabel("Total size").fill("9999");
await page.goto('/dashboard/availabilities'); await expect(page.getByLabel("Total size")).toHaveAttribute("aria-invalid");
await page.waitForTimeout(500);
await page.locator('.availability-edit button').first().click();
await page.getByLabel('Total size').click();
await page.getByText("Use max size").click();
await expect(page.getByLabel("Total size")).not.toHaveAttribute(
"aria-invalid"
);
await page.getByLabel('Total size').fill("9999"); const value = 0.2;
await expect(page.getByLabel('Total size')).toHaveAttribute("aria-invalid"); await page.getByLabel("Total size").fill(value.toString());
await page.getByText("Use max size").click() await page.getByLabel("Duration").click();
await expect(page.getByLabel('Total size')).not.toHaveAttribute("aria-invalid"); await page.getByLabel("Duration").fill("30");
await page.getByLabel("Min price").click();
const value = (Math.random() * 0.5); await page.getByLabel("Min price").fill("5");
await page.getByLabel('Total size').fill(value.toFixed(1)); await page.getByLabel("Max collateral").click();
await page.getByLabel("Max collateral").fill("30");
await page.getByLabel('Duration').click(); await page.getByLabel("Min price").fill("5");
await page.getByLabel('Duration').fill('30'); await page.getByLabel("Nickname").click();
await page.getByLabel('Min price').click(); await page.getByLabel("Nickname").fill("test");
await page.getByLabel('Min price').fill('5'); await page.getByRole("button", { name: "Next" }).click();
await page.getByLabel('Max collateral').click(); await expect(page.getByText("Confirm your new sale")).toBeVisible();
await page.getByLabel('Max collateral').fill('30'); await page.getByRole("button", { name: "Next" }).click();
await page.getByLabel('Min price').fill('5'); await expect(page.getByText("Success", { exact: true })).toBeVisible();
await page.getByLabel('Nickname').click(); await page.getByRole("button", { name: "Finish" }).click();
await page.getByLabel('Nickname').fill('test'); await expect(
await page.getByRole('button', { name: 'Next' }).click(); page.getByText(Bytes.pretty(parseFloat(value.toFixed(1)) * GB)).first()
await expect(page.getByText('Confirm your new sale')).toBeVisible(); ).toBeVisible();
await page.getByRole('button', { name: 'Next' }).click(); });
await expect(page.getByText('Success', { exact: true })).toBeVisible();
await page.getByRole('button', { name: 'Finish' }).click();
await expect(page.getByText(Bytes.pretty(parseFloat(value.toFixed(1)) * GB)).first()).toBeVisible();
})