180 lines
5.1 KiB
TypeScript
180 lines
5.1 KiB
TypeScript
describe("Roles - Advanced Tests", () => {
|
|
beforeEach(() => {
|
|
cy.login();
|
|
});
|
|
|
|
describe("Role CRUD Operations", () => {
|
|
it("should create a new role", () => {
|
|
cy.visit("/roles");
|
|
cy.get(".bg-primary-600.rounded-full").first().click();
|
|
|
|
// Fill role information
|
|
cy.get('input[name="name"]').type("نقش تست");
|
|
cy.get('textarea[name="description"]').type("توضیحات نقش تست");
|
|
|
|
// Enable role
|
|
cy.get('input[name="enabled"]').check({ force: true });
|
|
|
|
// Submit form
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
// Verify redirect and success
|
|
cy.url().should("include", "/roles");
|
|
cy.contains("نقش تست").should("be.visible");
|
|
});
|
|
|
|
it("should edit an existing role", () => {
|
|
cy.visit("/roles");
|
|
|
|
// Click edit on first role
|
|
cy.get("tbody tr")
|
|
.first()
|
|
.within(() => {
|
|
cy.get(
|
|
'[data-testid="edit-button"], [title="ویرایش"], .text-blue-600'
|
|
)
|
|
.first()
|
|
.click();
|
|
});
|
|
|
|
// Update role name
|
|
cy.get('input[name="name"]').clear().type("نقش ویرایش شده");
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
// Verify changes
|
|
cy.url().should("include", "/roles");
|
|
cy.contains("نقش ویرایش شده").should("be.visible");
|
|
});
|
|
|
|
it("should delete a role with confirmation", () => {
|
|
cy.visit("/roles");
|
|
|
|
// Click delete on first role (skip admin role)
|
|
cy.get("tbody tr")
|
|
.eq(1)
|
|
.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("Role Form Validation", () => {
|
|
beforeEach(() => {
|
|
cy.visit("/roles");
|
|
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 role name", () => {
|
|
cy.get('input[name="name"]').type("a");
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
cy.contains("نام نقش باید حداقل", { timeout: 5000 }).should("be.visible");
|
|
});
|
|
});
|
|
|
|
describe("Role Permissions Management", () => {
|
|
beforeEach(() => {
|
|
cy.visit("/roles");
|
|
});
|
|
|
|
it("should manage role permissions", () => {
|
|
// Click permissions on first role
|
|
cy.get("tbody tr")
|
|
.first()
|
|
.within(() => {
|
|
cy.get('[data-testid="permissions-button"], [title="مجوزها"], button')
|
|
.contains("مجوزها")
|
|
.click();
|
|
});
|
|
|
|
// Should navigate to permissions page
|
|
cy.url().should("include", "/roles/");
|
|
cy.url().should("include", "/permissions");
|
|
cy.contains("مدیریت مجوزهای نقش").should("be.visible");
|
|
});
|
|
|
|
it("should assign permissions to role", () => {
|
|
cy.get("tbody tr")
|
|
.first()
|
|
.within(() => {
|
|
cy.get('[data-testid="permissions-button"], [title="مجوزها"], button')
|
|
.contains("مجوزها")
|
|
.click();
|
|
});
|
|
|
|
// Toggle some permissions
|
|
cy.get('input[type="checkbox"]').first().click({ force: true });
|
|
|
|
// Save changes
|
|
cy.get('button[type="submit"]').click();
|
|
|
|
cy.contains("مجوزهای نقش با موفقیت بهروزرسانی شد").should("be.visible");
|
|
});
|
|
});
|
|
|
|
describe("Role Search and Filter", () => {
|
|
beforeEach(() => {
|
|
cy.visit("/roles");
|
|
});
|
|
|
|
it("should search roles 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 roles 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("Role Status Management", () => {
|
|
beforeEach(() => {
|
|
cy.visit("/roles");
|
|
});
|
|
|
|
it("should toggle role status", () => {
|
|
// Skip admin role, use second role
|
|
cy.get("tbody tr")
|
|
.eq(1)
|
|
.within(() => {
|
|
cy.get('input[type="checkbox"], .toggle')
|
|
.first()
|
|
.click({ force: true });
|
|
});
|
|
|
|
cy.contains("وضعیت نقش با موفقیت تغییر کرد").should("be.visible");
|
|
});
|
|
});
|
|
});
|