describe("Users - Advanced Tests", () => { beforeEach(() => { cy.login(); }); describe("User CRUD Operations", () => { it("should create a new admin user", () => { cy.visit("/admin-users"); cy.get(".bg-primary-600.rounded-full").first().click(); // Fill user information cy.get('input[name="first_name"]').type("کاربر"); cy.get('input[name="last_name"]').type("تست"); cy.get('input[name="username"]').type("test-user-" + Date.now()); cy.get('input[name="password"]').type("Test123456"); cy.get('input[name="password_confirmation"]').type("Test123456"); // Enable user cy.get('input[name="enabled"]').check({ force: true }); // Submit form cy.get('button[type="submit"]').click(); // Verify redirect cy.url().should("include", "/admin-users"); cy.contains("کاربر تست").should("be.visible"); }); it("should edit an existing user", () => { cy.visit("/admin-users"); // Click edit on first user cy.get("tbody tr") .first() .within(() => { cy.get( '[data-testid="edit-button"], [title="ویرایش"], .text-blue-600' ) .first() .click(); }); // Update user info cy.get('input[name="first_name"]').clear().type("کاربر ویرایش شده"); cy.get('button[type="submit"]').click(); // Verify changes cy.url().should("include", "/admin-users"); cy.contains("کاربر ویرایش شده").should("be.visible"); }); it("should delete a user with confirmation", () => { cy.visit("/admin-users"); // Click delete on first user 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("User Form Validation", () => { beforeEach(() => { cy.visit("/admin-users"); 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 password confirmation", () => { cy.get('input[name="first_name"]').type("تست"); cy.get('input[name="last_name"]').type("کاربر"); cy.get('input[name="username"]').type("testuser"); cy.get('input[name="password"]').type("password123"); cy.get('input[name="password_confirmation"]').type("different"); cy.get('button[type="submit"]').click(); cy.contains("تأیید رمز عبور مطابقت ندارد").should("be.visible"); }); it("should validate minimum password length", () => { cy.get('input[name="password"]').type("123"); cy.get('button[type="submit"]').click(); cy.contains("رمز عبور باید حداقل", { timeout: 5000 }).should( "be.visible" ); }); }); describe("User Search and Filter", () => { beforeEach(() => { cy.visit("/admin-users"); }); it("should search users by name", () => { cy.get('input[placeholder*="جستجو"], input[name="search"]').type("admin"); 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 users 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("User Status Management", () => { beforeEach(() => { cy.visit("/admin-users"); }); it("should toggle user status", () => { cy.get("tbody tr") .first() .within(() => { cy.get('input[type="checkbox"], .toggle') .first() .click({ force: true }); }); cy.contains("وضعیت کاربر با موفقیت تغییر کرد").should("be.visible"); }); }); describe("User Import/Export", () => { beforeEach(() => { cy.visit("/admin-users"); }); 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 file upload format", () => { cy.get("button").contains("وارد کردن").click(); // Upload invalid file type cy.get('input[type="file"]').selectFile( "cypress/fixtures/invalid-file.txt", { force: true } ); cy.contains("فرمت فایل باید xlsx باشد").should("be.visible"); }); }); });