152 lines
5.2 KiB
TypeScript
152 lines
5.2 KiB
TypeScript
describe("Category Management", () => {
|
|
beforeEach(() => {
|
|
cy.login();
|
|
cy.visit("/categories");
|
|
cy.waitForLoading();
|
|
});
|
|
|
|
it("should display categories list page", () => {
|
|
cy.contains("مدیریت دستهبندیها").should("be.visible");
|
|
cy.contains("مدیریت دستهبندیهای محصولات").should("be.visible");
|
|
cy.get('[title="دستهبندی جدید"]').should("be.visible");
|
|
});
|
|
|
|
it("should create a new category", () => {
|
|
cy.get('[title="دستهبندی جدید"]').click();
|
|
|
|
cy.url().should("include", "/categories/create");
|
|
cy.contains("دستهبندی جدید").should("be.visible");
|
|
|
|
// Fill category form
|
|
cy.get('input[name="name"]').type("الکترونیک");
|
|
cy.get('textarea[name="description"]').type("دستهبندی محصولات الکترونیکی");
|
|
|
|
// Basic category creation without parent selection
|
|
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
cy.url().should("include", "/categories");
|
|
cy.contains("دستهبندی با موفقیت ایجاد شد").should("be.visible");
|
|
cy.contains("الکترونیک").should("be.visible");
|
|
});
|
|
|
|
it("should edit a category", () => {
|
|
cy.get('[title="ویرایش"]').first().click();
|
|
|
|
cy.url().should("include", "/categories/");
|
|
cy.url().should("include", "/edit");
|
|
|
|
// Update category
|
|
cy.get('input[name="name"]').clear().type("کامپیوتر و لپتاپ");
|
|
cy.get('textarea[name="description"]')
|
|
.clear()
|
|
.type("انواع کامپیوتر و لپتاپ");
|
|
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
cy.url().should("include", "/categories");
|
|
cy.contains("دستهبندی با موفقیت ویرایش شد").should("be.visible");
|
|
cy.contains("کامپیوتر و لپتاپ").should("be.visible");
|
|
});
|
|
|
|
it("should delete a category", () => {
|
|
cy.get('[title="حذف"]').first().click();
|
|
|
|
cy.get(".modal").should("be.visible");
|
|
cy.contains("آیا از حذف این دستهبندی اطمینان دارید؟").should("be.visible");
|
|
cy.get("button").contains("حذف").click();
|
|
|
|
cy.contains("دستهبندی با موفقیت حذف شد").should("be.visible");
|
|
});
|
|
|
|
it("should search categories", () => {
|
|
cy.get('input[placeholder*="جستجو"]').type("الکترونیک");
|
|
cy.get("button").contains("جستجو").click();
|
|
|
|
cy.waitForLoading();
|
|
cy.get("table tbody tr").should("contain", "الکترونیک");
|
|
});
|
|
|
|
it("should display category list", () => {
|
|
// Should show categories table
|
|
cy.get("table").should("be.visible");
|
|
cy.contains("نام دستهبندی").should("be.visible");
|
|
});
|
|
|
|
it("should validate category form", () => {
|
|
cy.get('[title="دستهبندی جدید"]').click();
|
|
|
|
// Try to submit empty form
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
cy.contains("نام دستهبندی الزامی است").should("be.visible");
|
|
});
|
|
|
|
it("should display category status", () => {
|
|
// Check if categories show status correctly
|
|
cy.get("table tbody tr").should("have.length.at.least", 0);
|
|
});
|
|
|
|
it("should show products count for each category", () => {
|
|
cy.get("table tbody tr").each(($row) => {
|
|
cy.wrap($row).find(".products-count").should("be.visible");
|
|
});
|
|
});
|
|
|
|
it("should handle category with products deletion warning", () => {
|
|
// Try to delete category that has products
|
|
cy.get('[data-testid="category-with-products"]')
|
|
.find('[title="حذف"]')
|
|
.click();
|
|
|
|
cy.get(".modal").should("be.visible");
|
|
cy.contains("این دستهبندی دارای محصول است").should("be.visible");
|
|
cy.contains("ابتدا محصولات را به دستهبندی دیگری منتقل کنید").should(
|
|
"be.visible"
|
|
);
|
|
});
|
|
|
|
it("should bulk delete categories", () => {
|
|
// Select multiple categories
|
|
cy.get('input[type="checkbox"]').check(["1", "2"]);
|
|
cy.get("button").contains("حذف انتخاب شدهها").click();
|
|
|
|
cy.get(".modal").should("be.visible");
|
|
cy.get("button").contains("حذف").click();
|
|
|
|
cy.contains("دستهبندیهای انتخاب شده حذف شدند").should("be.visible");
|
|
});
|
|
|
|
it("should export categories list", () => {
|
|
cy.get("button").contains("خروجی").click();
|
|
|
|
// Should download file
|
|
cy.readFile("cypress/downloads/categories.xlsx").should("exist");
|
|
});
|
|
|
|
it("should import categories from file", () => {
|
|
cy.get("button").contains("وارد کردن").click();
|
|
|
|
cy.get('input[type="file"]').selectFile("cypress/fixtures/categories.xlsx");
|
|
cy.get("button").contains("آپلود").click();
|
|
|
|
cy.contains("فایل با موفقیت پردازش شد").should("be.visible");
|
|
});
|
|
|
|
it("should handle category image upload", () => {
|
|
cy.get('[title="دستهبندی جدید"]').click();
|
|
|
|
cy.get('input[name="name"]').type("فشن و مد");
|
|
|
|
// Upload category image
|
|
cy.get('input[type="file"]').selectFile(
|
|
"cypress/fixtures/category-image.jpg"
|
|
);
|
|
cy.get(".image-preview").should("be.visible");
|
|
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
cy.contains("دستهبندی با موفقیت ایجاد شد").should("be.visible");
|
|
});
|
|
});
|