Skip to content

Commit

Permalink
Added some more cypress test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
david emioma committed Mar 26, 2024
1 parent 108ae54 commit 2d4f3ea
Show file tree
Hide file tree
Showing 20 changed files with 790 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const CategoryForm = ({ data }: Props) => {
};

return (
<div data-testid="category-form">
<div data-testid="category-form" data-cy="category-form">
<AlertModal
isOpen={open}
onClose={() => setOpen(false)}
Expand All @@ -124,16 +124,21 @@ const CategoryForm = ({ data }: Props) => {
{...field}
disabled={isPending}
placeholder="Shoes..."
data-cy="category-name-input"
/>
</FormControl>

<FormMessage />
<FormMessage data-cy="category-name-input-err" />
</FormItem>
)}
/>

<div className="flex items-center gap-3">
<Button type="submit" disabled={isPending}>
<Button
type="submit"
disabled={isPending}
data-cy={data ? "category-save-btn" : "category-create-btn"}
>
{data ? "Save" : "Create"}
</Button>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import {

type Props = {
data: Category;
index: number;
};

const CellActions = ({ data }: Props) => {
const CellActions = ({ data, index }: Props) => {
const params = useParams();

const router = useRouter();
Expand Down Expand Up @@ -60,10 +61,11 @@ const CellActions = ({ data }: Props) => {
onConfirm={onDelete}
loading={isPending}
featureToDelete="category"
testId={`category-${index}-delete`}
/>

<DropdownMenu>
<DropdownMenuTrigger asChild>
<DropdownMenuTrigger asChild data-cy={`category-${index}-trigger`}>
<Button variant="ghost" className="h-8 w-8 p-0">
<span className="sr-only">Open menu</span>

Expand All @@ -81,12 +83,17 @@ const CellActions = ({ data }: Props) => {
router.push(`/dashboard/${data.storeId}/categories/${data.id}`)
}
disabled={isPending}
data-cy={`category-${index}-update-btn`}
>
<Edit className="w-4 h-4 mr-2" />
Update
</DropdownMenuItem>

<DropdownMenuItem onClick={() => setOpen(true)} disabled={isPending}>
<DropdownMenuItem
onClick={() => setOpen(true)}
disabled={isPending}
data-cy={`category-${index}-delete-btn`}
>
<Trash className="w-4 h-4 mr-2" />
Delete
</DropdownMenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export const columns: ColumnDef<CategoryCol>[] = [
},
{
id: "actions",
cell: ({ row }) => <CellActions data={row.original} />,
cell: ({ row }) => <CellActions index={row.index} data={row.original} />,
},
];
1 change: 1 addition & 0 deletions app/(store)/dashboard/[storeId]/categories/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default async function StoreCategoriesPage({
<Link
href={`/dashboard/${storeId}/categories/new`}
className={buttonVariants()}
data-cy="new-category-btn"
>
<Plus className="w-4 h-4 mr-2" />
Add new
Expand Down
13 changes: 10 additions & 3 deletions app/(store)/dashboard/[storeId]/colors/_components/CellActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import {

type Props = {
data: Color;
index: number;
};

const CellActions = ({ data }: Props) => {
const CellActions = ({ data, index }: Props) => {
const params = useParams();

const router = useRouter();
Expand Down Expand Up @@ -58,10 +59,11 @@ const CellActions = ({ data }: Props) => {
onConfirm={onDelete}
loading={isPending}
featureToDelete="color"
testId={`color-${index}-delete`}
/>

<DropdownMenu>
<DropdownMenuTrigger asChild>
<DropdownMenuTrigger asChild data-cy={`color-${index}-trigger`}>
<Button variant="ghost" className="h-8 w-8 p-0">
<span className="sr-only">Open menu</span>

Expand All @@ -79,12 +81,17 @@ const CellActions = ({ data }: Props) => {
router.push(`/dashboard/${data.storeId}/colors/${data.id}`)
}
disabled={isPending}
data-cy={`color-${index}-update-btn`}
>
<Edit className="w-4 h-4 mr-2" />
Update
</DropdownMenuItem>

<DropdownMenuItem onClick={() => setOpen(true)} disabled={isPending}>
<DropdownMenuItem
onClick={() => setOpen(true)}
disabled={isPending}
data-cy={`color-${index}-delete-btn`}
>
<Trash className="w-4 h-4 mr-2" />
Delete
</DropdownMenuItem>
Expand Down
15 changes: 10 additions & 5 deletions app/(store)/dashboard/[storeId]/colors/_components/ColorForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const ColorForm = ({ data }: Props) => {
};

return (
<div data-testid="color-form">
<div data-testid="color-form" data-cy="color-form">
<AlertModal
isOpen={open}
onClose={() => setOpen(false)}
Expand All @@ -122,10 +122,11 @@ const ColorForm = ({ data }: Props) => {
{...field}
disabled={isPending}
placeholder="Black"
data-cy="color-name-input"
/>
</FormControl>

<FormMessage />
<FormMessage data-cy="color-name-input-err" />
</FormItem>
)}
/>
Expand All @@ -134,7 +135,7 @@ const ColorForm = ({ data }: Props) => {
control={form.control}
name="value"
render={({ field }) => (
<FormItem>
<FormItem data-cy="color-value-input">
<FormLabel>Value</FormLabel>

<FormControl>
Expand All @@ -144,14 +145,18 @@ const ColorForm = ({ data }: Props) => {
/>
</FormControl>

<FormMessage />
<FormMessage data-cy="color-value-input-err" />
</FormItem>
)}
/>
</div>

<div className="flex items-center gap-3">
<Button type="submit" disabled={isPending}>
<Button
type="submit"
disabled={isPending}
data-cy={data ? "color-save-btn" : "color-create-btn"}
>
{data ? "Save" : "Create"}
</Button>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ export const columns: ColumnDef<ColorCol>[] = [
},
{
id: "actions",
cell: ({ row }) => <CellActions data={row.original} />,
cell: ({ row }) => <CellActions index={row.index} data={row.original} />,
},
];
1 change: 1 addition & 0 deletions app/(store)/dashboard/[storeId]/colors/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default async function ColorsPage({
<Link
href={`/dashboard/${storeId}/colors/new`}
className={buttonVariants()}
data-cy="new-color-btn"
>
<Plus className="w-4 h-4 mr-2" />
Add new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import {

type Props = {
data: ProductCol;
index: number;
};

const CellActions = ({ data }: Props) => {
const CellActions = ({ data, index }: Props) => {
const params = useParams();

const router = useRouter();
Expand Down Expand Up @@ -63,6 +64,7 @@ const CellActions = ({ data }: Props) => {
onConfirm={onDelete}
loading={isPending}
featureToDelete="product"
testId={`product-${index}-delete`}
/>

<ViewProductModal
Expand All @@ -79,7 +81,7 @@ const CellActions = ({ data }: Props) => {
/>

<DropdownMenu>
<DropdownMenuTrigger asChild data-cy={`${data.id}-trigger`}>
<DropdownMenuTrigger asChild data-cy={`product-${index}-trigger`}>
<Button variant="ghost" className="h-8 w-8 p-0">
<span className="sr-only">Open menu</span>

Expand Down Expand Up @@ -129,7 +131,7 @@ const CellActions = ({ data }: Props) => {
router.push(`/dashboard/${data.storeId}/products/${data.id}`)
}
disabled={isPending}
data-cy={`${data.id}-update`}
data-cy={`product-${index}-update-btn`}
>
<Edit className="w-4 h-4 mr-2" />
Update
Expand All @@ -138,7 +140,7 @@ const CellActions = ({ data }: Props) => {
<DropdownMenuItem
onClick={() => setOpen(true)}
disabled={isPending}
data-cy={`${data.id}-delete`}
data-cy={`product-${index}-delete-btn`}
>
<Trash className="w-4 h-4 mr-2" />
Delete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ export const columns: ColumnDef<ProductCol>[] = [
},
{
id: "actions",
cell: ({ row }) => <CellActions data={row.original} />,
cell: ({ row }) => <CellActions index={row.index} data={row.original} />,
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,7 @@ const ProductForm = ({ data }: Props) => {
};

return (
<div
data-testid="product-form"
data-cy={data ? `product-form-${data.id}` : "product-form"}
>
<div data-testid="product-form" data-cy="product-form">
<AlertModal
isOpen={open}
onClose={() => setOpen(false)}
Expand Down Expand Up @@ -264,13 +261,11 @@ const ProductForm = ({ data }: Props) => {
{...field}
disabled={creating || updating || deletingItem}
placeholder="Name..."
data-cy={
data ? `product-name-${data.id}` : "product-name"
}
data-cy="product-name-input"
/>
</FormControl>

<FormMessage />
<FormMessage data-cy="product-name-input-err" />
</FormItem>
)}
/>
Expand Down Expand Up @@ -300,13 +295,7 @@ const ProductForm = ({ data }: Props) => {
disabled={creating || updating || deletingItem}
>
<FormControl>
<SelectTrigger
data-cy={
data
? `product-select-${data.id}`
: "product-select"
}
>
<SelectTrigger data-cy="product-category-select-trigger">
<SelectValue placeholder="Choose Category" />
</SelectTrigger>
</FormControl>
Expand All @@ -330,11 +319,7 @@ const ProductForm = ({ data }: Props) => {
<SelectItem
key={cat.id}
value={cat.id}
data-cy={
data
? `product-${data.id}-${i}`
: `product-${i}`
}
data-cy={`product-category-select-${i}`}
>
{cat.name}
</SelectItem>
Expand All @@ -345,7 +330,7 @@ const ProductForm = ({ data }: Props) => {
</Select>
</FormControl>

<FormMessage />
<FormMessage data-cy="product-category-input-err" />
</FormItem>
)}
/>
Expand All @@ -363,11 +348,10 @@ const ProductForm = ({ data }: Props) => {
value={field.value}
onChange={field.onChange}
disabled={creating || updating || deletingItem}
data-cy="product-description"
/>
</FormControl>

<FormMessage />
<FormMessage data-cy="product-description-input-err" />
</FormItem>
)}
/>
Expand Down Expand Up @@ -563,7 +547,7 @@ const ProductForm = ({ data }: Props) => {
className="disabled:cursor-not-allowed disabled:opacity-75"
type="submit"
disabled={creating || updating || deletingItem}
data-cy={data ? `save-btn-${data.id}` : "create-btn"}
data-cy={data ? `product-save-btn` : "product-create-btn"}
>
{data ? "Save" : "Create"}
</Button>
Expand Down
13 changes: 10 additions & 3 deletions app/(store)/dashboard/[storeId]/sizes/_components/CellActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import {

type Props = {
data: Size;
index: number;
};

const CellActions = ({ data }: Props) => {
const CellActions = ({ data, index }: Props) => {
const params = useParams();

const router = useRouter();
Expand Down Expand Up @@ -58,10 +59,11 @@ const CellActions = ({ data }: Props) => {
onConfirm={onDelete}
loading={isPending}
featureToDelete="size"
testId={`size-${index}-delete`}
/>

<DropdownMenu>
<DropdownMenuTrigger asChild>
<DropdownMenuTrigger asChild data-cy={`size-${index}-trigger`}>
<Button variant="ghost" className="h-8 w-8 p-0">
<span className="sr-only">Open menu</span>

Expand All @@ -79,12 +81,17 @@ const CellActions = ({ data }: Props) => {
router.push(`/dashboard/${data.storeId}/sizes/${data.id}`)
}
disabled={isPending}
data-cy={`size-${index}-update-btn`}
>
<Edit className="w-4 h-4 mr-2" />
Update
</DropdownMenuItem>

<DropdownMenuItem onClick={() => setOpen(true)} disabled={isPending}>
<DropdownMenuItem
onClick={() => setOpen(true)}
disabled={isPending}
data-cy={`size-${index}-delete-btn`}
>
<Trash className="w-4 h-4 mr-2" />
Delete
</DropdownMenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export const columns: ColumnDef<SizeCol>[] = [
},
{
id: "actions",
cell: ({ row }) => <CellActions data={row.original} />,
cell: ({ row }) => <CellActions index={row.index} data={row.original} />,
},
];
Loading

0 comments on commit 2d4f3ea

Please sign in to comment.