describe("Product Management", () => { beforeEach(() => { cy.login(); cy.visit("/products"); cy.waitForLoading(); }); it("should display products list page", () => { cy.contains("مدیریت محصولات").should("be.visible"); cy.contains("مدیریت محصولات، قیمت‌ها و موجودی").should("be.visible"); cy.get('[title="محصول جدید"]').should("be.visible"); }); it("should navigate to create product page", () => { cy.get('[title="محصول جدید"]').click(); cy.url().should("include", "/products/create"); cy.contains("محصول جدید").should("be.visible"); }); it("should create a new product", () => { cy.get('[title="محصول جدید"]').click(); // Fill product form cy.get('input[name="name"]').type("محصول تست"); cy.get('textarea[name="description"]').type("توضیحات محصول تست"); cy.get('input[name="design_style"]').type("مدرن"); // Enable product cy.get('input[name="enabled"]').check(); // Set product type cy.get('select[name="type"]').select("0"); // Submit form cy.get('button[type="submit"]').click(); // Should redirect to products list cy.url().should("include", "/products"); cy.contains("محصول با موفقیت ایجاد شد").should("be.visible"); cy.contains("محصول تست").should("be.visible"); }); it("should search products", () => { cy.get('input[placeholder*="جستجو"]').type("تست"); cy.get("button").contains("جستجو").click(); // Should filter results cy.waitForLoading(); cy.get("table tbody tr").should("contain", "تست"); }); it("should filter products by category", () => { cy.get("select").first().select("1"); // Assuming category with id 1 exists cy.get("button").contains("اعمال فیلتر").click(); cy.waitForLoading(); // Results should be filtered by category }); it("should edit a product", () => { // Click edit button on first product cy.get('[title="ویرایش"]').first().click(); cy.url().should("include", "/products/"); cy.url().should("include", "/edit"); // Update product name cy.get('input[name="name"]').clear().type("محصول ویرایش شده"); cy.get('button[type="submit"]').click(); // Should redirect back to list cy.url().should("include", "/products"); cy.contains("محصول با موفقیت ویرایش شد").should("be.visible"); cy.contains("محصول ویرایش شده").should("be.visible"); }); it("should delete a product", () => { // Click delete button on first product cy.get('[title="حذف"]').first().click(); // Confirm deletion cy.get("button").contains("حذف").click(); cy.contains("محصول با موفقیت حذف شد").should("be.visible"); }); it("should manage product variants", () => { cy.get('[title="محصول جدید"]').click(); // Fill basic product info cy.get('input[name="name"]').type("محصول با واریانت"); cy.get('textarea[name="description"]').type("محصول تست با واریانت"); // Add variant cy.get("button").contains("افزودن واریانت").click(); // Fill variant details cy.get('input[name="variants[0].enabled"]').check(); cy.get('input[name="variants[0].fee_percentage"]').type("10"); cy.get('input[name="variants[0].profit_percentage"]').type("20"); cy.get('button[type="submit"]').click(); cy.contains("محصول با موفقیت ایجاد شد").should("be.visible"); }); it("should validate product form", () => { cy.get('[title="محصول جدید"]').click(); // Try to submit empty form cy.get('button[type="submit"]').click(); // Should show validation errors cy.contains("نام محصول الزامی است").should("be.visible"); }); it("should handle pagination", () => { // Assuming there are multiple pages of products cy.get('[data-testid="pagination"]').should("be.visible"); // Go to next page cy.get("button").contains("بعدی").click(); cy.waitForLoading(); // URL should change cy.url().should("include", "page=2"); }); it("should sort products", () => { // Click on sortable column header cy.get("th").contains("نام").click(); cy.waitForLoading(); // Should sort by name cy.url().should("include", "sort=name"); }); it("should export products list", () => { cy.get("button").contains("خروجی").click(); // Should download file cy.readFile("cypress/downloads/products.xlsx").should("exist"); }); });