132 lines
4.6 KiB
TypeScript
132 lines
4.6 KiB
TypeScript
describe("User Management", () => {
|
|
beforeEach(() => {
|
|
cy.login();
|
|
cy.visit("/admin-users");
|
|
cy.waitForLoading();
|
|
});
|
|
|
|
it("should display admin users list page", () => {
|
|
cy.contains("مدیریت کاربران ادمین").should("be.visible");
|
|
cy.contains("مدیریت کاربران دسترسی به پنل ادمین").should("be.visible");
|
|
cy.get('[title="کاربر ادمین جدید"]').should("be.visible");
|
|
});
|
|
|
|
it("should create a new admin user", () => {
|
|
cy.get('[title="کاربر ادمین جدید"]').click();
|
|
|
|
cy.url().should("include", "/admin-users/create");
|
|
cy.contains("کاربر ادمین جدید").should("be.visible");
|
|
|
|
// Fill user form
|
|
cy.get('input[name="first_name"]').type("احمد");
|
|
cy.get('input[name="last_name"]').type("محمدی");
|
|
cy.get('input[name="username"]').type("ahmad.mohammadi");
|
|
// Email field removed as admin users only need username
|
|
cy.get('input[name="password"]').type("password123");
|
|
// Phone field not available in admin user form
|
|
|
|
// Set status
|
|
cy.get('select[name="status"]').select("active");
|
|
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
cy.url().should("include", "/admin-users");
|
|
cy.contains("کاربر با موفقیت ایجاد شد").should("be.visible");
|
|
cy.contains("احمد محمدی").should("be.visible");
|
|
});
|
|
|
|
it("should search admin users", () => {
|
|
cy.get('input[placeholder*="جستجو"]').type("احمد");
|
|
cy.get("button").contains("جستجو").click();
|
|
|
|
cy.waitForLoading();
|
|
cy.get("table tbody tr").should("contain", "احمد");
|
|
});
|
|
|
|
it("should filter users by role", () => {
|
|
cy.get("select").contains("نقش").select("مدیر");
|
|
cy.get("button").contains("اعمال فیلتر").click();
|
|
|
|
cy.waitForLoading();
|
|
// Results should be filtered by role
|
|
});
|
|
|
|
it("should edit an admin user", () => {
|
|
cy.get('[title="ویرایش"]').first().click();
|
|
|
|
cy.url().should("include", "/admin-users/");
|
|
cy.url().should("include", "/edit");
|
|
|
|
// Update user info
|
|
cy.get('input[name="first_name"]').clear().type("علی");
|
|
cy.get('input[name="last_name"]').clear().type("احمدی");
|
|
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
cy.url().should("include", "/admin-users");
|
|
cy.contains("کاربر با موفقیت ویرایش شد").should("be.visible");
|
|
cy.contains("علی احمدی").should("be.visible");
|
|
});
|
|
|
|
it("should delete an admin user", () => {
|
|
cy.get('[title="حذف"]').first().click();
|
|
|
|
// Confirm deletion in modal
|
|
cy.get(".modal").should("be.visible");
|
|
cy.get("button").contains("حذف").click();
|
|
|
|
cy.contains("کاربر با موفقیت حذف شد").should("be.visible");
|
|
});
|
|
|
|
it("should validate admin user 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");
|
|
cy.contains("نام خانوادگی الزامی است").should("be.visible");
|
|
cy.contains("نام کاربری الزامی است").should("be.visible");
|
|
// Email not required for admin users
|
|
});
|
|
|
|
it("should validate username format", () => {
|
|
cy.get('[title="کاربر ادمین جدید"]').click();
|
|
|
|
cy.get('input[name="username"]').type("ab"); // خیلی کوتاه
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
cy.contains("نام کاربری باید حداقل 3 کاراکتر باشد").should("be.visible");
|
|
});
|
|
|
|
it("should validate username uniqueness", () => {
|
|
cy.get('[title="کاربر ادمین جدید"]').click();
|
|
|
|
// Fill form with existing username
|
|
cy.get('input[name="first_name"]').type("تست");
|
|
cy.get('input[name="last_name"]').type("کاربر");
|
|
cy.get('input[name="username"]').type("admin"); // Assuming 'admin' already exists
|
|
cy.get('input[name="password"]').type("password123");
|
|
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
cy.contains("نام کاربری قبلاً استفاده شده است").should("be.visible");
|
|
});
|
|
|
|
it("should handle user status toggle", () => {
|
|
// Assuming there's a toggle for user status
|
|
cy.get('[data-testid="user-status-toggle"]').first().click();
|
|
|
|
cy.contains("وضعیت کاربر با موفقیت تغییر کرد").should("be.visible");
|
|
});
|
|
|
|
it("should display user activity logs", () => {
|
|
cy.get('[title="لاگ فعالیت"]').first().click();
|
|
|
|
cy.get(".modal").should("be.visible");
|
|
cy.contains("لاگ فعالیت کاربر").should("be.visible");
|
|
cy.get("table").should("be.visible");
|
|
});
|
|
});
|