feat(shop): show available products first
This commit is contained in:
1 parent
73bfe0d893
commit
12861288f2
2 files changed
+76
-30
No files matched your search
@@ -2,7 +2,7 @@
|
||||
import React from "react";
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
||||
import ArchivePage from "../ArchivePage";
|
||||
import ArchivePage, { orderProductsByAvailability } from "../ArchivePage";
|
||||
import { productService } from "../../lib/services/productService";
|
||||
import { useCartStore } from "../../lib/store/cartStore";
|
||||
import { usePetStore } from "../../lib/store/usePetStore";
|
||||
@@ -117,6 +117,32 @@ const mockProducts = [
|
||||
},
|
||||
];
|
||||
|
||||
it("puts available products first while preserving descending-price sort order within groups", () => {
|
||||
const sortedByPriceDesc = [
|
||||
{ id: "out-high", stock: 0 },
|
||||
{ id: "in-mid", stock: 5 },
|
||||
{ id: "in-low", stock: 2 },
|
||||
{ id: "out-low", stock: 0 },
|
||||
] as any;
|
||||
|
||||
expect(orderProductsByAvailability(sortedByPriceDesc).map(product => product.id)).toEqual([
|
||||
"in-mid", "in-low", "out-high", "out-low",
|
||||
]);
|
||||
});
|
||||
|
||||
it("puts available products first while preserving ascending-price sort order and groups status fields", () => {
|
||||
const sortedByPriceAsc = [
|
||||
{ id: "in-low", stockStatus: "IN_STOCK" },
|
||||
{ id: "out-mid", stockStatus: "OUT_OF_STOCK" },
|
||||
{ id: "in-high", stockStatus: "IN_STOCK" },
|
||||
{ id: "out-discontinued", stockStatus: "DISCONTINUED" },
|
||||
] as any;
|
||||
|
||||
expect(orderProductsByAvailability(sortedByPriceAsc).map(product => product.id)).toEqual([
|
||||
"in-low", "in-high", "out-mid", "out-discontinued",
|
||||
]);
|
||||
});
|
||||
|
||||
describe("ArchivePage Component", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
Reference in new issue
Block a user