212 lines
6.2 KiB
TypeScript
212 lines
6.2 KiB
TypeScript
describe("Categories - Advanced Tests", () => {
|
|
beforeEach(() => {
|
|
cy.login();
|
|
});
|
|
|
|
describe("Category CRUD Operations", () => {
|
|
it("should create a new category", () => {
|
|
cy.visit("/categories");
|
|
cy.get(".bg-primary-600.rounded-full").first().click();
|
|
|
|
// Fill category information
|
|
cy.get('input[name="name"]').type("دستهبندی تست");
|
|
cy.get('textarea[name="description"]').type("توضیحات دستهبندی تست");
|
|
cy.get('input[name="sort_order"]').clear().type("1");
|
|
|
|
// Enable category
|
|
cy.get('input[name="enabled"]').check({ force: true });
|
|
|
|
// Submit form
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
// Verify redirect and success
|
|
cy.url().should("include", "/categories");
|
|
cy.contains("دستهبندی تست").should("be.visible");
|
|
});
|
|
|
|
it("should edit an existing category", () => {
|
|
cy.visit("/categories");
|
|
|
|
// Click edit on first category
|
|
cy.get("tbody tr")
|
|
.first()
|
|
.within(() => {
|
|
cy.get(
|
|
'[data-testid="edit-button"], [title="ویرایش"], .text-blue-600'
|
|
)
|
|
.first()
|
|
.click();
|
|
});
|
|
|
|
// Update category name
|
|
cy.get('input[name="name"]').clear().type("دستهبندی ویرایش شده");
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
// Verify changes
|
|
cy.url().should("include", "/categories");
|
|
cy.contains("دستهبندی ویرایش شده").should("be.visible");
|
|
});
|
|
|
|
it("should delete a category with confirmation", () => {
|
|
cy.visit("/categories");
|
|
|
|
// Click delete on first category
|
|
cy.get("tbody tr")
|
|
.first()
|
|
.within(() => {
|
|
cy.get('[data-testid="delete-button"], [title="حذف"], .text-red-600')
|
|
.first()
|
|
.click();
|
|
});
|
|
|
|
// Confirm deletion in modal
|
|
cy.get('.modal, [role="dialog"]').should("be.visible");
|
|
cy.get("button").contains("حذف").click();
|
|
|
|
// Verify success message
|
|
cy.contains("دستهبندی با موفقیت حذف شد", { timeout: 10000 }).should(
|
|
"be.visible"
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("Category Form Validation", () => {
|
|
beforeEach(() => {
|
|
cy.visit("/categories");
|
|
cy.get(".bg-primary-600.rounded-full").first().click();
|
|
});
|
|
|
|
it("should show validation errors for empty required fields", () => {
|
|
// Try to submit empty form
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
// Check for validation messages
|
|
cy.contains("نام دستهبندی الزامی است", { timeout: 5000 }).should(
|
|
"be.visible"
|
|
);
|
|
});
|
|
|
|
it("should validate minimum length for category name", () => {
|
|
cy.get('input[name="name"]').type("a");
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
cy.contains("نام دستهبندی باید حداقل", { timeout: 5000 }).should(
|
|
"be.visible"
|
|
);
|
|
});
|
|
|
|
it("should validate sort order is a number", () => {
|
|
cy.get('input[name="name"]').type("دستهبندی تست");
|
|
cy.get('input[name="sort_order"]').clear().type("abc");
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
cy.contains("ترتیب نمایش باید عدد باشد").should("be.visible");
|
|
});
|
|
});
|
|
|
|
describe("Category Search and Filter", () => {
|
|
beforeEach(() => {
|
|
cy.visit("/categories");
|
|
});
|
|
|
|
it("should search categories by name", () => {
|
|
cy.get('input[placeholder*="جستجو"], input[name="search"]').type("دسته");
|
|
cy.get('button[type="submit"], button').contains("جستجو").click();
|
|
|
|
// Wait for results
|
|
cy.wait(2000);
|
|
|
|
// Check search results
|
|
cy.get("tbody tr").should("have.length.at.least", 0);
|
|
});
|
|
|
|
it("should filter categories by status", () => {
|
|
cy.get('select[name="enabled"], select').first().select("true");
|
|
cy.get("button").contains("اعمال فیلتر").click();
|
|
|
|
cy.wait(2000);
|
|
|
|
// Results should be filtered
|
|
cy.get("tbody tr").should("have.length.at.least", 0);
|
|
});
|
|
});
|
|
|
|
describe("Category Status Management", () => {
|
|
beforeEach(() => {
|
|
cy.visit("/categories");
|
|
});
|
|
|
|
it("should toggle category status", () => {
|
|
cy.get("tbody tr")
|
|
.first()
|
|
.within(() => {
|
|
cy.get('input[type="checkbox"], .toggle')
|
|
.first()
|
|
.click({ force: true });
|
|
});
|
|
|
|
cy.contains("وضعیت دستهبندی با موفقیت تغییر کرد").should("be.visible");
|
|
});
|
|
});
|
|
|
|
describe("Category Image Upload", () => {
|
|
beforeEach(() => {
|
|
cy.visit("/categories");
|
|
cy.get(".bg-primary-600.rounded-full").first().click();
|
|
});
|
|
|
|
it("should upload category image", () => {
|
|
cy.get('input[name="name"]').type("دستهبندی با تصویر");
|
|
|
|
// Upload image
|
|
cy.get('input[type="file"]').selectFile(
|
|
"cypress/fixtures/category-image.jpg",
|
|
{ force: true }
|
|
);
|
|
|
|
// Wait for upload
|
|
cy.wait(2000);
|
|
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
// Verify success
|
|
cy.url().should("include", "/categories");
|
|
cy.contains("دستهبندی با تصویر").should("be.visible");
|
|
});
|
|
|
|
it("should validate image format", () => {
|
|
cy.get('input[type="file"]').selectFile(
|
|
"cypress/fixtures/invalid-file.txt",
|
|
{ force: true }
|
|
);
|
|
|
|
cy.contains("فرمت فایل باید تصویر باشد").should("be.visible");
|
|
});
|
|
});
|
|
|
|
describe("Category Import/Export", () => {
|
|
beforeEach(() => {
|
|
cy.visit("/categories");
|
|
});
|
|
|
|
it("should show import modal", () => {
|
|
cy.get("button").contains("وارد کردن").click();
|
|
|
|
cy.get('.modal, [role="dialog"]').should("be.visible");
|
|
cy.contains("وارد کردن دستهبندیها از فایل Excel").should("be.visible");
|
|
});
|
|
|
|
it("should validate Excel file upload", () => {
|
|
cy.get("button").contains("وارد کردن").click();
|
|
|
|
// Upload valid Excel file
|
|
cy.get('input[type="file"]').selectFile(
|
|
"cypress/fixtures/categories.xlsx",
|
|
{ force: true }
|
|
);
|
|
|
|
cy.get("button").contains("شروع وارد کردن").should("not.be.disabled");
|
|
});
|
|
});
|
|
});
|