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