Skip to content

Commit

Permalink
test: add e2e test for creating a cube collection
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanlundberg committed Sep 20, 2024
1 parent 5eca39d commit 64070ad
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 28 deletions.
23 changes: 23 additions & 0 deletions e2e/create-new-collection.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { test, expect } from "@playwright/test";

test("should create a cube", async ({ page }) => {
await page.locator("body").click();
await expect(page.getByTestId("main-cube-selector")).toBeVisible();
await page.getByTestId("main-cube-selector").click();
await expect(
page.getByRole("button", { name: "New collection" })
).toBeVisible();
await page.getByRole("button", { name: "New collection" }).click();
await expect(page.getByTestId("empty-cubes-container")).toBeVisible();
await expect(page.getByTestId("create-collection-button")).toBeVisible();
await page.getByTestId("create-collection-button").click();
await expect(page.getByTestId("drawer-create-collection")).toBeVisible();
await expect(page.getByTestId("drawer-input-name")).toBeVisible();
await expect(page.getByTestId("drawer-accept-button")).toBeVisible();
await expect(page.getByTestId("drawer-cancel-button")).toBeVisible();
await page.getByTestId("drawer-input-name").click();
await page.getByTestId("drawer-input-name").fill("experimental");
await page.getByTestId("checkbox-category-3x3").click();
await page.getByTestId("drawer-accept-button").click();
await expect(page.getByTestId("cube-name-experimental")).toBeVisible();
});
12 changes: 0 additions & 12 deletions e2e/test-2.spec.ts

This file was deleted.

11 changes: 0 additions & 11 deletions e2e/test-3.spec.ts

This file was deleted.

5 changes: 4 additions & 1 deletion src/app/[locale]/cubes/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ export default function Page() {
onOpenChange={setIsOpenDrawerNewCollection}
>
<DrawerTrigger asChild>
<Button className="p-2">
<Button
className="p-2"
data-testId="create-collection-button"
>
<PlusIcon className="size-4" strokeWidth={5} />{" "}
<span className="hidden sm:inline">
{t("CubesPage.new-collection")}
Expand Down
1 change: 1 addition & 0 deletions src/components/cubes/EmptyCubes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function EmptyCubes({ ...rest }: EmptyCubesProps) {
<>
<div
{...rest}
data-testId="empty-cubes-container"
className="flex flex-col items-center justify-center h-full m-3 overflow-auto border border-dashed rounded-md cursor-pointer grow min-h-96"
>
<div className="flex flex-col items-center justify-center gap-1 p-3 font-medium">
Expand Down
3 changes: 2 additions & 1 deletion src/components/cubes/cubes-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function CubesTable({
const { openDialogType } = useDialogCubesOptions();
return (
<>
<Card className="overflow-auto">
<Card className="overflow-auto" data-testId="table-of-cubes">
<Table>
<TableHeader>
<TableRow>
Expand Down Expand Up @@ -73,6 +73,7 @@ export default function CubesTable({
<TableCell
onClick={() => handleRedirectToTimer(cube.id)}
className="hover:cursor-pointer"
data-testId={"cube-name-" + cube.name}
>
{cube.name}
</TableCell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ export default function DrawerCreateCollection({
};

return (
<DrawerContent className="max-w-[850px] mx-auto">
<DrawerContent
className="max-w-[850px] mx-auto"
data-testId="drawer-create-collection"
>
<DrawerHeader>
<DrawerTitle>{t("Cubes-modal.new-collection")}</DrawerTitle>
<DrawerDescription>
Expand All @@ -87,6 +90,7 @@ export default function DrawerCreateCollection({
<div className="p-3">
<Label htmlFor="name">{t("Cubes-modal.name")}</Label>
<Input
data-testId="drawer-input-name"
id="name"
placeholder="E.g: X Man Tornado V3 M"
onChange={(e) => {
Expand All @@ -103,6 +107,7 @@ export default function DrawerCreateCollection({
{cubeCollection.map((e) => {
return (
<Image
data-testId={"checkbox-category-" + e.name}
key={genId()}
src={e.src}
alt={e.event || ""}
Expand Down Expand Up @@ -131,11 +136,18 @@ export default function DrawerCreateCollection({
</div>

<DrawerFooter>
<Button onClick={handleSubmitNewCollection}>
<Button
onClick={handleSubmitNewCollection}
data-testId="drawer-accept-button"
>
{t("Inputs.create")}
</Button>
<DrawerClose asChild>
<Button variant="outline" className="w-full">
<Button
variant="outline"
className="w-full"
data-testId="drawer-cancel-button"
>
{t("Inputs.cancel")}
</Button>
</DrawerClose>
Expand Down

0 comments on commit 64070ad

Please sign in to comment.