CFE-10 testing disabled button
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import {rest} from "msw";
|
import {rest} from "msw";
|
||||||
import {GET_ROLE_LIST, GET_ROLES} from "@/core/data/apiRoutes";
|
import {GET_PERMISSIONS_LIST, GET_ROLE_LIST, GET_ROLES} from "@/core/data/apiRoutes";
|
||||||
|
|
||||||
export const rolesHandler = [
|
export const rolesHandler = [
|
||||||
rest.get(GET_ROLES, (req, res, ctx) => {
|
rest.get(GET_ROLES, (req, res, ctx) => {
|
||||||
@@ -51,7 +51,7 @@ export const rolesHandler = [
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
rest.get(GET_ROLE_LIST, (req, res, ctx) => {
|
rest.get(GET_PERMISSIONS_LIST, (req, res, ctx) => {
|
||||||
return res(ctx.json({
|
return res(ctx.json({
|
||||||
data: [
|
data: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -108,12 +108,12 @@ const CreateContent = ({mutate, setOpenConfirmDialog}) => {
|
|||||||
: (
|
: (
|
||||||
<Grid container spacing={2}>
|
<Grid container spacing={2}>
|
||||||
<>
|
<>
|
||||||
{permissions_list.map((permission) => (
|
{permissions_list.map((permission, index) => (
|
||||||
<Grid key={permission.id} item xs={6}>
|
<Grid key={permission.id} item xs={6} data-testid= "PermissionList-checkbox">
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={
|
control={
|
||||||
<Checkbox
|
<Checkbox
|
||||||
data-testid="PermissionList-checkbox"
|
data-testid= {`PermissionList-checkbox-${index}`}
|
||||||
checked={formik.values.permissions.includes(permission.id)}
|
checked={formik.values.permissions.includes(permission.id)}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
if (e.target.checked) {
|
if (e.target.checked) {
|
||||||
|
|||||||
@@ -154,5 +154,24 @@ describe("Create Content component from Create Form Component in Role Management
|
|||||||
const submitButtonElement = screen.queryByText("ثبت")
|
const submitButtonElement = screen.queryByText("ثبت")
|
||||||
expect(submitButtonElement).toBeDisabled()
|
expect(submitButtonElement).toBeDisabled()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should submit button be able if inputs get filled', async () => {
|
||||||
|
render(
|
||||||
|
<MockAppWithProviders>
|
||||||
|
<CreateContent/>
|
||||||
|
</MockAppWithProviders>
|
||||||
|
)
|
||||||
|
const submitButtonElement = screen.queryByText("ثبت")
|
||||||
|
expect(submitButtonElement).toBeDisabled()
|
||||||
|
const nameElement = screen.getByLabelText("نام انگلیسی")
|
||||||
|
const name_faElement = screen.getByLabelText("نام فارسی")
|
||||||
|
const roleElement = await screen.findByTestId("PermissionList-checkbox-0");
|
||||||
|
fireEvent.change(nameElement, { target: { value: 'amin' } })
|
||||||
|
fireEvent.change(name_faElement, { target: { value: 'امین' } })
|
||||||
|
fireEvent.click(roleElement)
|
||||||
|
await waitFor(()=>{
|
||||||
|
expect(submitButtonElement).not.toBeDisabled()
|
||||||
|
})
|
||||||
|
});
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user