Debug e2e tests

This commit is contained in:
Arnaud 2025-02-07 15:54:16 +01:00
parent 6a0f2f8f99
commit b2e82efc78
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
2 changed files with 139 additions and 102 deletions

View File

@ -5,109 +5,147 @@ import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
test('create a storage request', async ({ page }) => {
await page.goto('/dashboard');
await page.locator('a').filter({ hasText: 'Purchases' }).click();
await page.getByRole('button', { name: 'Storage Request' }).click();
test("create a storage request", async ({ page }) => {
await page.goto("/dashboard");
await page.locator("a").filter({ hasText: "Purchases" }).click();
await page.getByRole("button", { name: "Storage Request" }).click();
await page.locator('div').getByTestId("upload").setInputFiles([
path.join(__dirname, "assets", 'chatgpt.jpg'),
]);
await expect(page.locator('#cid')).not.toBeEmpty()
await expect(page.getByText('Success, the CID has been')).toBeVisible();
await page.getByRole('button', { name: 'Next' }).click();
await page.getByRole('button', { name: 'Next' }).click();
await expect(page.getByText('Your request is being processed.')).toBeVisible();
await page.getByRole('button', { name: 'Finish' }).click();
await expect(page.getByText('No data.')).not.toBeVisible();
await expect(page.getByTestId('cell-pending').first()).toBeVisible();
})
await page
.locator("div")
.getByTestId("upload")
.setInputFiles([path.join(__dirname, "assets", "chatgpt.jpg")]);
await expect(page.locator("#cid")).not.toBeEmpty();
await expect(page.getByText("Success, the CID has been")).toBeVisible();
await page.getByRole("button", { name: "Next" }).click();
await page.getByRole("button", { name: "Next" }).click();
await expect(
page.getByText("Your request is being processed.")
).toBeVisible();
await page.getByRole("button", { name: "Finish" }).click();
await expect(page.getByText("No data.")).not.toBeVisible();
await expect(page.getByTestId("cell-pending").first()).toBeVisible();
});
test('select a uploaded cid when creating a storage request', async ({ page }) => {
await page.goto('/dashboard');
await page.locator('div').getByTestId("upload").setInputFiles([
path.join(__dirname, "assets", 'chatgpt.jpg'),
]);
await page.locator('a').filter({ hasText: 'Purchases' }).click();
await page.getByRole('button', { name: 'Storage Request' }).click();
await page.getByPlaceholder('CID').click();
await page.locator('.dropdown ul li').nth(1).click();
await expect(page.getByText('button[disabled]')).not.toBeVisible();
})
test("select a uploaded cid when creating a storage request", async ({
page,
}) => {
await page.goto("/dashboard");
await page
.locator("div")
.getByTestId("upload")
.setInputFiles([path.join(__dirname, "assets", "chatgpt.jpg")]);
await page.locator("a").filter({ hasText: "Purchases" }).click();
await page.getByRole("button", { name: "Storage Request" }).click();
await page.getByPlaceholder("CID").click();
await page.locator(".dropdown ul li").nth(1).click();
await expect(page.getByText("button[disabled]")).not.toBeVisible();
});
test('storage request navigation buttons', async ({ page }) => {
await page.goto('/dashboard/purchases');
await page.getByRole('button', { name: 'Storage Request' }).click();
await expect(page.locator('.step--done')).not.toBeVisible()
await expect(page.locator('.step--active')).toBeVisible()
await expect(page.locator('footer .button--primary')).toHaveAttribute("disabled");
await expect(page.locator('footer .button--outline').first()).not.toHaveAttribute("disabled");
await page.locator('div').getByTestId("upload").setInputFiles([
path.join(__dirname, "assets", 'chatgpt.jpg'),
]);
await expect(page.locator('footer .button--outline').first()).not.toHaveAttribute("disabled");
await expect(page.locator('footer .button--primary')).not.toHaveAttribute("disabled");
await page.getByRole('button', { name: 'Next' }).click();
await expect(page.locator('footer .button--outline').first()).not.toHaveAttribute("disabled");
await expect(page.locator('footer .button--primary')).not.toHaveAttribute("disabled");
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("storage request navigation buttons", async ({ page }) => {
await page.goto("/dashboard/purchases");
await page.getByRole("button", { name: "Storage Request" }).click();
await expect(page.locator(".step--done")).not.toBeVisible();
await expect(page.locator(".step--active")).toBeVisible();
await expect(page.locator("footer .button--primary")).toHaveAttribute(
"disabled"
);
await expect(
page.locator("footer .button--outline").first()
).not.toHaveAttribute("disabled");
await page
.locator("div")
.getByTestId("upload")
.setInputFiles([path.join(__dirname, "assets", "chatgpt.jpg")]);
await expect(
page.locator("footer .button--outline").first()
).not.toHaveAttribute("disabled");
await expect(page.locator("footer .button--primary")).not.toHaveAttribute(
"disabled"
);
await page.getByRole("button", { name: "Next" }).click();
await expect(
page.locator("footer .button--outline").first()
).not.toHaveAttribute("disabled");
await expect(page.locator("footer .button--primary")).not.toHaveAttribute(
"disabled"
);
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('remove the CID when the file is deleted', async ({ page }) => {
await page.goto('/dashboard');
await page.locator('a').filter({ hasText: 'Purchases' }).click();
await page.getByRole('button', { name: 'Storage Request' }).click();
await page.locator('div').getByTestId("upload").setInputFiles([
path.join(__dirname, "assets", 'chatgpt.jpg'),
]);
await expect(page.locator('#cid')).not.toBeEmpty()
await page.locator('.button-icon--small').nth(1).click();
await expect(page.locator('#cid')).toBeEmpty()
})
test("remove the CID when the file is deleted", async ({ page }) => {
await page.goto("/dashboard");
await page.locator("a").filter({ hasText: "Purchases" }).click();
await page.getByRole("button", { name: "Storage Request" }).click();
await page
.locator("div")
.getByTestId("upload")
.setInputFiles([path.join(__dirname, "assets", "chatgpt.jpg")]);
await expect(page.locator("#cid")).not.toBeEmpty();
await page.locator(".button-icon--small").nth(1).click();
await expect(page.locator("#cid")).toBeEmpty();
});
test('create a storage request by using decimal values', async ({ page }) => {
await page.goto('/dashboard');
await page.locator('a').filter({ hasText: 'Purchases' }).click();
await page.getByRole('button', { name: 'Storage Request' }).click();
test("create a storage request by using decimal values", async ({ page }) => {
await page.goto("/dashboard");
await page.locator("a").filter({ hasText: "Purchases" }).click();
await page.getByRole("button", { name: "Storage Request" }).click();
await page.locator('div').getByTestId("upload").setInputFiles([
path.join(__dirname, "assets", 'chatgpt.jpg'),
]);
await expect(page.locator('#cid')).not.toBeEmpty()
await expect(page.getByText('Success, the CID has been')).toBeVisible();
await page.getByRole('button', { name: 'Next' }).click();
await page
.locator("div")
.getByTestId("upload")
.setInputFiles([path.join(__dirname, "assets", "chatgpt.jpg")]);
await expect(page.locator("#cid")).not.toBeEmpty();
await expect(page.getByText("Success, the CID has been")).toBeVisible();
await page.getByRole("button", { name: "Next" }).click();
await page.getByLabel("Full period of the contract").fill("10")
await expect(page.locator('footer .button--primary')).toHaveAttribute("disabled");
await page.getByLabel("Full period of the contract").fill("10");
await expect(page.locator("footer .button--primary")).toHaveAttribute(
"disabled"
);
await page.getByLabel("Full period of the contract").fill("1")
await expect(page.locator('footer .button--primary')).not.toHaveAttribute("disabled");
await page.getByLabel("Full period of the contract").fill("1");
await expect(page.locator("footer .button--primary")).not.toHaveAttribute(
"disabled"
);
await page.getByLabel("Full period of the contract").fill("0")
await expect(page.locator('footer .button--primary')).toHaveAttribute("disabled");
await page.getByLabel("Full period of the contract").fill("0");
await expect(page.locator("footer .button--primary")).toHaveAttribute(
"disabled"
);
const value = (Math.random() * 7);
await page.getByLabel("Full period of the contract").fill(value.toFixed(1))
await expect(page.locator('footer .button--primary')).not.toHaveAttribute("disabled");
const days = Math.random() * 7;
await page.getByRole('button', { name: 'Next' }).click();
await expect(page.getByText('Your request is being processed.')).toBeVisible();
await page.getByRole('button', { name: 'Finish' }).click();
await expect(page.getByText('No data.')).not.toBeVisible();
await expect(page.getByText(value.toFixed(1) + " days").first()).toBeVisible();
})
console.debug("Got days", days, days.toFixed(1));
await page.getByLabel("Full period of the contract").fill(days.toFixed(1));
await expect(page.locator("footer .button--primary")).not.toHaveAttribute(
"disabled"
);
await page.getByRole("button", { name: "Next" }).click();
await expect(
page.getByText("Your request is being processed.")
).toBeVisible();
await page.getByRole("button", { name: "Finish" }).click();
await expect(page.getByText("No data.")).not.toBeVisible();
await expect(page.getByText(days.toFixed(1) + " days").first()).toBeVisible();
});
// test('create a storage request by using months', async ({ page }) => {
// await page.goto('/dashboard');
@ -130,4 +168,4 @@ test('create a storage request by using decimal values', async ({ page }) => {
// await page.getByRole('button', { name: 'Finish' }).click();
// await expect(page.getByText('No data.')).not.toBeVisible();
// await expect(page.getByText("3 months").first()).toBeVisible();
// })
// })

View File

@ -7,9 +7,9 @@ export type TimesUnit =
| "seconds";
const plural = (value: number, unit: TimesUnit) => {
const val = Number.isInteger(value) ? value : value.toFixed(1)
const val = value.toFixed(1);
return value > 1 ? val + ` ${unit}` : val + ` ${unit.slice(0, -1)}`;
}
};
export const Times = {
toSeconds(value: number, unit: TimesUnit) {
@ -73,24 +73,23 @@ export const Times = {
seconds /= 30;
if (value >= seconds) {
return "days"
return "days";
}
return "hours"
return "hours";
},
value(unit: "hours" | "days" | "months") {
switch (unit) {
case "months": {
return 30 * 24 * 60 * 60
return 30 * 24 * 60 * 60;
}
case "days": {
return 24 * 60 * 60
return 24 * 60 * 60;
}
default: {
return 60 * 60
return 60 * 60;
}
}
}
},
};