CFE-4 correct act mistakes

This commit is contained in:
2023-10-10 15:36:25 +03:30
parent 86cbefd60c
commit 752e8a3662
4 changed files with 77 additions and 46 deletions

View File

@@ -4,45 +4,51 @@ import CreateContent from "@/components/dashboard/role-management/Form/CreateFor
describe("Create Content component from Create Form Component in Role Management Component",()=>{
describe("Rendering", ()=>{
it('should see AddDialog text in the top ', () => {
it('should see AddDialog text in the top ', async () => {
render(
<MockAppWithProviders>
<CreateContent/>
</MockAppWithProviders>
)
const textElement = screen.queryByText("افزودن")
expect(textElement).toBeInTheDocument()
await waitFor(()=>{
expect(textElement).toBeInTheDocument()
})
});
it('should see name_en text', () => {
it('should see name_en text', async () => {
render(
<MockAppWithProviders>
<CreateContent/>
</MockAppWithProviders>
)
const textElement = screen.queryByLabelText("نام انگلیسی")
expect(textElement).toBeInTheDocument()
await waitFor(()=>{
expect(textElement).toBeInTheDocument()
})
});
it('should see name_fa text', () => {
it('should see name_fa text', async () => {
render(
<MockAppWithProviders>
<CreateContent/>
</MockAppWithProviders>
)
const textElement = screen.queryByLabelText("نام فارسی")
expect(textElement).toBeInTheDocument()
await waitFor(()=>{
expect(textElement).toBeInTheDocument()
})
});
it('should see name_fa text', () => {
it('should see name_fa text', async () => {
render(
<MockAppWithProviders>
<CreateContent/>
</MockAppWithProviders>
)
const textElement = screen.queryByLabelText("نام فارسی")
expect(textElement).toBeInTheDocument()
await waitFor(()=>{
expect(textElement).toBeInTheDocument()
})
});
})
describe("Behavior",()=>{
it('should see what fill in the name_en input', async () => {
render(
@@ -81,8 +87,7 @@ describe("Create Content component from Create Form Component in Role Management
const checkboxElement = await screen.findAllByTestId("PermissionList-checkbox")
expect(checkboxElement).toHaveLength(2)
});
it('should get checked if permission list item get clicked', () => {
it('should get checked if permission list item get clicked', async () => {
render(
<MockAppWithProviders>
<CreateContent/>
@@ -90,11 +95,15 @@ describe("Create Content component from Create Form Component in Role Management
)
const checkboxElement = screen.getByLabelText("مدیریت کارتابل رییس اداره مسافری استان")
expect(checkboxElement).not.toBeChecked();
await waitFor(()=>{
expect(checkboxElement).not.toBeChecked();
})
fireEvent.click(checkboxElement);
expect(checkboxElement).toBeChecked();
await waitFor(()=>{
expect(checkboxElement).toBeChecked();
})
});
})
describe("Validation",()=>{

View File

@@ -1,21 +1,23 @@
import {fireEvent, queryByText, render, screen} from "@testing-library/react";
import {fireEvent, queryByText, render, screen, waitFor} from "@testing-library/react";
import CreateForm from "@/components/dashboard/role-management/Form/CreateForm";
import MockAppWithProviders from "../../../../../../../mocks/AppWithProvider";
describe("Create Form Component from Role Management Component",()=>{
describe("Rendering",()=>{
it('should see Dialog text', () => {
it('should see Dialog text', async () => {
render(
<MockAppWithProviders>
<CreateForm />
</MockAppWithProviders>
)
const textElement = screen.queryByText("افزودن")
expect(textElement).toBeInTheDocument()
await waitFor(()=>{
expect(textElement).toBeInTheDocument()
})
});
it('should see Tooltip text when mouse over', () => {
it('should see Tooltip text when mouse over', async () => {
render(
<MockAppWithProviders>
<CreateForm />
@@ -24,7 +26,9 @@ describe("Create Form Component from Role Management Component",()=>{
const buttonElement = screen.getByText("افزودن");
fireEvent.mouseOver(buttonElement);
const tooltipTextElement = screen.getByText("افزودن");
expect(tooltipTextElement).toBeInTheDocument();
await waitFor(()=>{
expect(tooltipTextElement).toBeInTheDocument()
})
});
})
})

View File

@@ -36,7 +36,7 @@ describe("Create Content component from Create Form Component in Role Management
</MockAppWithProviders>
)
const textElement = screen.queryByText("ویرایش")
act(()=>{
await waitFor(()=>{
expect(textElement).toBeInTheDocument()
})
});
@@ -47,7 +47,7 @@ describe("Create Content component from Create Form Component in Role Management
</MockAppWithProviders>
)
const textElement = screen.queryByLabelText("نام انگلیسی")
act(()=>{
await waitFor(()=>{
expect(textElement).toBeInTheDocument()
})
});
@@ -58,29 +58,29 @@ describe("Create Content component from Create Form Component in Role Management
</MockAppWithProviders>
)
const textElement = screen.queryByLabelText("نام فارسی")
act(()=>{
await waitFor(()=>{
expect(textElement).toBeInTheDocument()
})
});
it('should see update text in the submit button ', () => {
it('should see update text in the submit button ', async () => {
render(
<MockAppWithProviders>
<UpdateContent row={row}/>
</MockAppWithProviders>
)
const buttonElement = screen.queryByText("ثبت")
act(()=>{
await waitFor(()=>{
expect(buttonElement).toBeInTheDocument()
})
});
it('should see cancel text in the cancel button ', () => {
it('should see cancel text in the cancel button ', async () => {
render(
<MockAppWithProviders>
<UpdateContent row={row}/>
</MockAppWithProviders>
)
const buttonElement = screen.queryByText("بستن")
act(()=>{
await waitFor(()=>{
expect(buttonElement).toBeInTheDocument()
})
});
@@ -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 act(()=>{
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 act(()=>{
await waitFor(()=>{
// Simulate user input
expect(nameFarsiInput).toHaveValue('testuser');
})
@@ -122,35 +122,43 @@ describe("Create Content component from Create Form Component in Role Management
</MockAppWithProviders>
)
const checkboxElement = await screen.findAllByTestId("PermissionList-checkbox")
expect(checkboxElement).toHaveLength(2)
await waitFor(()=>{
expect(checkboxElement).toHaveLength(2)
})
});
it('should see the value of the name_en that pass to input value', () => {
it('should see the value of the name_en that pass to input value', async () => {
render(
<MockAppWithProviders>
<UpdateContent row={row}/>
</MockAppWithProviders>
)
const name_enElement = screen.getByLabelText("نام انگلیسی")
expect(name_enElement).toHaveValue("manage_passenger_office_navgan")
await waitFor(()=>{
expect(name_enElement).toHaveValue("manage_passenger_office_navgan")
})
});
it('should see the value of the name_fa that pass to input value', () => {
it('should see the value of the name_fa that pass to input value', async () => {
render(
<MockAppWithProviders>
<UpdateContent row={row}/>
</MockAppWithProviders>
)
const name_enElement = screen.getByLabelText("نام فارسی")
expect(name_enElement).toHaveValue("مدیریت کارتابل رییس اداره مسافری استان")
await waitFor(()=>{
expect(name_enElement).toHaveValue("مدیریت کارتابل رییس اداره مسافری استان")
})
});
it('should get checked if the id exists in permission lists', () => {
it('should get checked if the id exists in permission lists', async () => {
render(
<MockAppWithProviders>
<UpdateContent row={row}/>
</MockAppWithProviders>
)
const checkboxElement = screen.getByLabelText("مدیریت کارتابل رییس اداره مسافری استان")
await waitFor(()=>{
expect(checkboxElement).toBeChecked();
})
expect(checkboxElement).toBeChecked();
});
})
describe("Validation", ()=>{

View File

@@ -1,53 +1,63 @@
import {render, screen} from "@testing-library/react";
import {render, screen, waitFor} from "@testing-library/react";
import MockAppWithProviders from "../../../../../mocks/AppWithProvider";
import RoleManagementComponent from "@/components/dashboard/role-management/RoleManagementComponent";
describe("Role Management", ()=>{
describe("Rendering", ()=>{
it('should see id title of data table', () => {
it('should see id title of data table', async () => {
render(
<MockAppWithProviders>
<RoleManagementComponent />
</MockAppWithProviders>
)
const idEelement = screen.queryByText("کد یکتا")
expect(idEelement).toBeInTheDocument()
await waitFor(()=>{
expect(idEelement).toBeInTheDocument()
})
});
it('should see name title of data table', () => {
it('should see name title of data table', async () => {
render(
<MockAppWithProviders>
<RoleManagementComponent />
</MockAppWithProviders>
)
const nameEelement = screen.queryByText("نام انگلیسی")
expect(nameEelement).toBeInTheDocument()
await waitFor(()=>{
expect(nameEelement).toBeInTheDocument()
})
});
it('should see name_fa title of data table', () => {
it('should see name_fa title of data table', async () => {
render(
<MockAppWithProviders>
<RoleManagementComponent />
</MockAppWithProviders>
)
const name_faEelement = screen.queryByText("نام فارسی")
expect(name_faEelement).toBeInTheDocument()
await waitFor(()=>{
expect(name_faEelement).toBeInTheDocument()
})
});
it('should see created at title of data table', () => {
it('should see created at title of data table', async () => {
render(
<MockAppWithProviders>
<RoleManagementComponent />
</MockAppWithProviders>
)
const createdEelement = screen.queryByText("تاریخ درخواست")
expect(createdEelement).toBeInTheDocument()
await waitFor(()=>{
expect(createdEelement).toBeInTheDocument()
})
});
it('should see updated at title of data table', () => {
it('should see updated at title of data table', async () => {
render(
<MockAppWithProviders>
<RoleManagementComponent />
</MockAppWithProviders>
)
const updateEelement = screen.queryByText("تاریخ بروزرسانی")
expect(updateEelement).toBeInTheDocument()
await waitFor(()=>{
expect(updateEelement).toBeInTheDocument()
})
});
})
})