DeleteForm Complete With Tests of It Rendering/Beahavioral/submission
This commit is contained in:
@@ -50,4 +50,9 @@ export const handler = [
|
||||
ctx.status(200),
|
||||
);
|
||||
}),
|
||||
rest.delete(`${EXPERT_MANAGEMENT}/:id`, (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
);
|
||||
}),
|
||||
]
|
||||
@@ -3,6 +3,7 @@ import React from 'react';
|
||||
import CreateContent from "../../CreateContent";
|
||||
import MockAppWithProviders from "../../../../../../../../mocks/AppWithProvider";
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import CreateForm from "@/components/dashboard/expert-management/Form/CreateForm";
|
||||
|
||||
function selectDropdownItem(screen, openerTestId, itemText) {
|
||||
const opener = screen.getByTestId(openerTestId);
|
||||
|
||||
@@ -62,8 +62,8 @@ const CreateContent = ({setOpenCreateDialog, mutate, fetchUrl}) => {
|
||||
|
||||
requestServer(`${EXPERT_MANAGEMENT}`, 'post', {auth: true, data: formData})
|
||||
.then((response) => {
|
||||
mutate(fetchUrl)
|
||||
setOpenCreateDialog(false)
|
||||
mutate(fetchUrl)
|
||||
}).catch(() => {
|
||||
}).finally(() => {
|
||||
setSubmitting(false);
|
||||
|
||||
@@ -39,45 +39,44 @@ describe("CreateForm Component From Expert Management", () => {
|
||||
});
|
||||
});
|
||||
describe("Form Submission", () => {
|
||||
// ask about this part
|
||||
// it('Should request to api and if get success close dialog', async () => {
|
||||
// render(<MockAppWithProviders><CreateForm/></MockAppWithProviders>);
|
||||
//
|
||||
// const CreateButton = screen.getByRole('button', {name: "افزودن کارشناس"});
|
||||
// fireEvent.click(CreateButton);
|
||||
//
|
||||
// const submitButton = screen.queryByText('ثبت');
|
||||
//
|
||||
// const nameInput = screen.queryByLabelText('نام کامل');
|
||||
// const usernameInput = screen.queryByLabelText('نام کاربری');
|
||||
// const emailInput = screen.queryByLabelText('پست الکترونیک');
|
||||
// const phoneNumberInput = screen.queryByLabelText('شماره همراه');
|
||||
// const telephoneIdInput = screen.queryByLabelText('کد تلفن');
|
||||
// const nationalIdInput = screen.queryByLabelText('کد ملی');
|
||||
// const passwordInput = screen.queryByLabelText('رمز عبور');
|
||||
// const positionInput = screen.queryByLabelText('سمت');
|
||||
//
|
||||
// selectDropdownItem(screen, "option-opener-province", "آذربایجان شرقی");
|
||||
// selectDropdownItem(screen, "option-opener-role", "ادمین");
|
||||
// selectDropdownItem(screen, "option-opener-gender", "مرد");
|
||||
//
|
||||
// setInputValue(screen, nameInput, 'nameTest');
|
||||
// setInputValue(screen, usernameInput, 'usernameTest');
|
||||
// setInputValue(screen, emailInput, 'emailTest@gmail.com');
|
||||
// setInputValue(screen, phoneNumberInput, '0914577458');
|
||||
// setInputValue(screen, telephoneIdInput, '091');
|
||||
// setInputValue(screen, nationalIdInput, 'nationalIdTest');
|
||||
// setInputValue(screen, passwordInput, 'passwordTest12');
|
||||
// setInputValue(screen, positionInput, 'positionTest');
|
||||
//
|
||||
// expect(submitButton).not.toBeDisabled();
|
||||
// await fireEvent.click(submitButton);
|
||||
//
|
||||
// await waitFor(() => {
|
||||
// const dialogContent = screen.getByTestId('create-dialog-content');
|
||||
// expect(dialogContent).not.toBeInTheDocument();
|
||||
// });
|
||||
// });
|
||||
it('Should request to api and if get success close dialog', async () => {
|
||||
render(<MockAppWithProviders><CreateForm/></MockAppWithProviders>);
|
||||
|
||||
const CreateButton = screen.getByRole('button', {name: "افزودن کارشناس"});
|
||||
fireEvent.click(CreateButton);
|
||||
|
||||
const submitButton = screen.queryByText('ثبت');
|
||||
|
||||
const nameInput = screen.queryByLabelText('نام کامل');
|
||||
const usernameInput = screen.queryByLabelText('نام کاربری');
|
||||
const emailInput = screen.queryByLabelText('پست الکترونیک');
|
||||
const phoneNumberInput = screen.queryByLabelText('شماره همراه');
|
||||
const telephoneIdInput = screen.queryByLabelText('کد تلفن');
|
||||
const nationalIdInput = screen.queryByLabelText('کد ملی');
|
||||
const passwordInput = screen.queryByLabelText('رمز عبور');
|
||||
const positionInput = screen.queryByLabelText('سمت');
|
||||
|
||||
selectDropdownItem(screen, "option-opener-province", "آذربایجان شرقی");
|
||||
selectDropdownItem(screen, "option-opener-role", "ادمین");
|
||||
selectDropdownItem(screen, "option-opener-gender", "مرد");
|
||||
|
||||
setInputValue(screen, nameInput, 'nameTest');
|
||||
setInputValue(screen, usernameInput, 'usernameTest');
|
||||
setInputValue(screen, emailInput, 'emailTest@gmail.com');
|
||||
setInputValue(screen, phoneNumberInput, '0914577458');
|
||||
setInputValue(screen, telephoneIdInput, '091');
|
||||
setInputValue(screen, nationalIdInput, 'nationalIdTest');
|
||||
setInputValue(screen, passwordInput, 'passwordTest12');
|
||||
setInputValue(screen, positionInput, 'positionTest');
|
||||
|
||||
expect(submitButton).not.toBeDisabled();
|
||||
fireEvent.click(submitButton);
|
||||
|
||||
await waitFor(() => {
|
||||
const dialogContent = screen.queryByTestId('create-dialog-content');
|
||||
expect(dialogContent).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
it('Should request to api and if get error keep previous data', async () => {
|
||||
render(<MockAppWithProviders><CreateForm/></MockAppWithProviders>);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {act, fireEvent, render, screen} from "@testing-library/react";
|
||||
import {fireEvent, render, screen, waitFor} from "@testing-library/react";
|
||||
import MockAppWithProviders from "../../../../../../../mocks/AppWithProvider";
|
||||
import React from "react";
|
||||
import DeleteForm from "@/components/dashboard/expert-management/Form/DeleteForm";
|
||||
@@ -44,10 +44,23 @@ describe("CreateForm Component From Expert Management", () => {
|
||||
render(<MockAppWithProviders><DeleteForm/></MockAppWithProviders>);
|
||||
const DeleteButton = screen.getByTestId('delete-button');
|
||||
fireEvent.click(DeleteButton);
|
||||
await act(() => {
|
||||
await waitFor(() => {
|
||||
const DeleteDialog = screen.getByRole('dialog', {name: "حذف کارشناس"})
|
||||
expect(DeleteDialog).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe("Form Submission", () => {
|
||||
it("By Clicking Delete Button Request To Api And Delete Item", async () => {
|
||||
render(<MockAppWithProviders><DeleteForm rowId={1}/></MockAppWithProviders>);
|
||||
const DeleteButton = screen.getByTestId('delete-button');
|
||||
fireEvent.click(DeleteButton);
|
||||
const DeleteButtonDialog = screen.getByRole('button', {name: "حذف"});
|
||||
fireEvent.click(DeleteButtonDialog);
|
||||
await waitFor(() => {
|
||||
const DeleteDialog = screen.queryByRole('dialog', {name: "حذف کارشناس"});
|
||||
expect(DeleteDialog).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -24,13 +24,13 @@ const Delete = ({rowId, fetchUrl, mutate}) => {
|
||||
setIsSubmitting(true)
|
||||
requestServer(`${EXPERT_MANAGEMENT}/${rowId}`, 'DELETE')
|
||||
.then((response) => {
|
||||
setOpenDeleteDialog(false);
|
||||
mutate(fetchUrl)
|
||||
})
|
||||
.catch(() => {
|
||||
})
|
||||
.finally(() => {
|
||||
setIsSubmitting(false)
|
||||
setOpenDeleteDialog(false);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user