CFE-10 write mock for permission lists
This commit is contained in:
@@ -51,6 +51,22 @@ export const rolesHandler = [
|
||||
),
|
||||
);
|
||||
}),
|
||||
rest.get(GET_ROLE_LIST, (req, res, ctx) => {
|
||||
return res(ctx.json({
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
name: "admin",
|
||||
name_fa: "ادمین"
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "manager",
|
||||
name_fa: "مدیر"
|
||||
}
|
||||
]
|
||||
}))
|
||||
}),
|
||||
rest.get(GET_PERMISSIONS_LIST, (req, res, ctx) => {
|
||||
return res(ctx.json({
|
||||
data: [
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import {fireEvent, render, screen, waitFor} from "@testing-library/react";
|
||||
import MockAppWithProviders from "../../../../../../../mocks/AppWithProvider";
|
||||
import UpdateContent from "@/components/dashboard/role-management/Form/UpdateForm/UpdateContent";
|
||||
|
||||
const row = {
|
||||
id : 0,
|
||||
getValue : name => {
|
||||
id: 0,
|
||||
getValue: name => {
|
||||
if (name === "name") {
|
||||
return "manage_passenger_office_navgan";
|
||||
}
|
||||
else if (name === "name_fa") {
|
||||
} else if (name === "name_fa") {
|
||||
return "مدیریت کارتابل رییس اداره مسافری استان";
|
||||
}
|
||||
},
|
||||
original : {
|
||||
permissions : [
|
||||
original: {
|
||||
permissions: [
|
||||
{
|
||||
id: 1,
|
||||
name: "manage_passenger_office_navgan",
|
||||
@@ -27,8 +27,8 @@ const row = {
|
||||
}
|
||||
}
|
||||
|
||||
describe("Create Content component from Create Form Component in Role Management Component",()=>{
|
||||
describe("Rendering", ()=>{
|
||||
describe("Create Content component from Create Form Component in Role Management Component", () => {
|
||||
describe("Rendering", () => {
|
||||
it('should see AddDialog text in the top ', async () => {
|
||||
render(
|
||||
<MockAppWithProviders>
|
||||
@@ -36,8 +36,8 @@ describe("Create Content component from Create Form Component in Role Management
|
||||
</MockAppWithProviders>
|
||||
)
|
||||
const textElement = screen.queryByText("ویرایش")
|
||||
await waitFor(()=>{
|
||||
expect(textElement).toBeInTheDocument()
|
||||
await waitFor(() => {
|
||||
expect(textElement).toBeInTheDocument()
|
||||
})
|
||||
});
|
||||
it('should see name_en text', async () => {
|
||||
@@ -47,8 +47,8 @@ describe("Create Content component from Create Form Component in Role Management
|
||||
</MockAppWithProviders>
|
||||
)
|
||||
const textElement = screen.queryByLabelText("نام انگلیسی")
|
||||
await waitFor(()=>{
|
||||
expect(textElement).toBeInTheDocument()
|
||||
await waitFor(() => {
|
||||
expect(textElement).toBeInTheDocument()
|
||||
})
|
||||
});
|
||||
it('should see name_fa text', async () => {
|
||||
@@ -58,8 +58,8 @@ describe("Create Content component from Create Form Component in Role Management
|
||||
</MockAppWithProviders>
|
||||
)
|
||||
const textElement = screen.queryByLabelText("نام فارسی")
|
||||
await waitFor(()=>{
|
||||
expect(textElement).toBeInTheDocument()
|
||||
await waitFor(() => {
|
||||
expect(textElement).toBeInTheDocument()
|
||||
})
|
||||
});
|
||||
it('should see update text in the submit button ', async () => {
|
||||
@@ -69,7 +69,7 @@ describe("Create Content component from Create Form Component in Role Management
|
||||
</MockAppWithProviders>
|
||||
)
|
||||
const buttonElement = screen.queryByText("ثبت")
|
||||
await waitFor(()=>{
|
||||
await waitFor(() => {
|
||||
expect(buttonElement).toBeInTheDocument()
|
||||
})
|
||||
});
|
||||
@@ -80,13 +80,13 @@ describe("Create Content component from Create Form Component in Role Management
|
||||
</MockAppWithProviders>
|
||||
)
|
||||
const buttonElement = screen.queryByText("بستن")
|
||||
await waitFor(()=>{
|
||||
await waitFor(() => {
|
||||
expect(buttonElement).toBeInTheDocument()
|
||||
})
|
||||
});
|
||||
})
|
||||
|
||||
describe("Behavior", ()=>{
|
||||
describe("Behavior", () => {
|
||||
it('should see what fill in the name_en input', async () => {
|
||||
render(
|
||||
<MockAppWithProviders>
|
||||
@@ -96,7 +96,7 @@ describe("Create Content component from Create Form Component in Role Management
|
||||
const nameEnglishInput = screen.getByLabelText('نام انگلیسی');
|
||||
|
||||
fireEvent.change(nameEnglishInput, {target: {value: 'testuser'}});
|
||||
await waitFor(()=>{
|
||||
await waitFor(() => {
|
||||
// Simulate user input
|
||||
expect(nameEnglishInput).toHaveValue('testuser');
|
||||
})
|
||||
@@ -110,7 +110,7 @@ describe("Create Content component from Create Form Component in Role Management
|
||||
const nameFarsiInput = screen.getByLabelText('نام فارسی');
|
||||
|
||||
fireEvent.change(nameFarsiInput, {target: {value: 'testuser'}});
|
||||
await waitFor(()=>{
|
||||
await waitFor(() => {
|
||||
// Simulate user input
|
||||
expect(nameFarsiInput).toHaveValue('testuser');
|
||||
})
|
||||
@@ -122,7 +122,7 @@ describe("Create Content component from Create Form Component in Role Management
|
||||
</MockAppWithProviders>
|
||||
)
|
||||
const checkboxElement = await screen.findAllByTestId("PermissionList-checkbox")
|
||||
await waitFor(()=>{
|
||||
await waitFor(() => {
|
||||
expect(checkboxElement).toHaveLength(2)
|
||||
})
|
||||
});
|
||||
@@ -133,7 +133,7 @@ describe("Create Content component from Create Form Component in Role Management
|
||||
</MockAppWithProviders>
|
||||
)
|
||||
const name_enElement = screen.getByLabelText("نام انگلیسی")
|
||||
await waitFor(()=>{
|
||||
await waitFor(() => {
|
||||
expect(name_enElement).toHaveValue("manage_passenger_office_navgan")
|
||||
})
|
||||
});
|
||||
@@ -144,7 +144,7 @@ describe("Create Content component from Create Form Component in Role Management
|
||||
</MockAppWithProviders>
|
||||
)
|
||||
const name_enElement = screen.getByLabelText("نام فارسی")
|
||||
await waitFor(()=>{
|
||||
await waitFor(() => {
|
||||
expect(name_enElement).toHaveValue("مدیریت کارتابل رییس اداره مسافری استان")
|
||||
})
|
||||
});
|
||||
@@ -155,13 +155,13 @@ describe("Create Content component from Create Form Component in Role Management
|
||||
</MockAppWithProviders>
|
||||
)
|
||||
const checkboxElement = screen.getByLabelText("مدیریت کارتابل رییس اداره مسافری استان")
|
||||
await waitFor(()=>{
|
||||
await waitFor(() => {
|
||||
expect(checkboxElement).toBeChecked();
|
||||
})
|
||||
|
||||
});
|
||||
})
|
||||
describe("Validation", ()=>{
|
||||
describe("Validation", () => {
|
||||
it('should see error text when name_fa input is empty', async () => {
|
||||
render(
|
||||
<MockAppWithProviders>
|
||||
@@ -170,16 +170,16 @@ describe("Create Content component from Create Form Component in Role Management
|
||||
)
|
||||
const name_faInput = screen.getByLabelText("نام فارسی")
|
||||
expect(screen.queryByText("وارد کردن نام فارسی الزامیست")).not.toBeInTheDocument()
|
||||
fireEvent.change(name_faInput, {target : {value : ''}});
|
||||
fireEvent.change(name_faInput, {target: {value: ''}});
|
||||
|
||||
fireEvent.blur(name_faInput)
|
||||
|
||||
await waitFor(()=>{
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByText("وارد کردن نام فارسی الزامیست")).toBeInTheDocument()
|
||||
})
|
||||
fireEvent.change(name_faInput, {target : {value : "نام فارسی"}})
|
||||
fireEvent.change(name_faInput, {target: {value: "نام فارسی"}})
|
||||
|
||||
await waitFor(()=>{
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByText("وارد کردن نام فارسی الزامیست")).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -192,16 +192,16 @@ describe("Create Content component from Create Form Component in Role Management
|
||||
const name_enInput = screen.getByLabelText("نام انگلیسی")
|
||||
expect(screen.queryByText("وارد کردن نام انگلیسی الزامیست")).not.toBeInTheDocument()
|
||||
|
||||
fireEvent.change(name_enInput, {target : {value : null}});
|
||||
fireEvent.change(name_enInput, {target: {value: null}});
|
||||
fireEvent.blur(name_enInput)
|
||||
|
||||
await waitFor(()=>{
|
||||
await waitFor(() => {
|
||||
|
||||
expect(screen.queryByText("وارد کردن نام انگلیسی الزامیست")).toBeInTheDocument()
|
||||
})
|
||||
fireEvent.change(name_enInput, {target : {value : "english name"}})
|
||||
fireEvent.change(name_enInput, {target: {value: "english name"}})
|
||||
|
||||
await waitFor(()=>{
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByText("وارد کردن نام انگلیسی الزامیست")).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user