Skip to content

Commit

Permalink
Merge pull request #3072 from glific/fix/forms
Browse files Browse the repository at this point in the history
Fixed form always being in disabled state
  • Loading branch information
kurund authored Sep 10, 2024
2 parents 3588b85 + 4da564e commit 39339ef
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cypress-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
git clone https://github.com/glific/cypress-testing.git
echo done. go to dir.
cd cypress-testing
git checkout main
git checkout fix/forms
cd ..
cp -r cypress-testing/cypress cypress
yarn add [email protected]
Expand Down
4 changes: 3 additions & 1 deletion src/components/UI/Form/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export const Button = ({
type={type}
>
{children}
{loading && <CircularProgress size={28} className={styles.buttonProgress} />}
{loading && (
<CircularProgress data-testid="loadingBtn" size={28} className={styles.buttonProgress} />
)}
</ButtonElement>
);
};
45 changes: 44 additions & 1 deletion src/containers/Flow/Flow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,33 @@ const mocks = [
deleteRoleIds: [],
tag_id: '1',
}),
createFlowQuery,
createFlowQuery({
isActive: true,
isPinned: false,
isBackground: false,
name: 'New Flow',
keywords: ['मदद'],
description: '',
ignoreKeywords: false,
addRoleIds: [],
deleteRoleIds: [],
}),
createTagQuery,
getFlowCountQuery({ isActive: true, isTemplate: false }),
releaseFlow,
getFilterTagQuery,
updateFlowQuery,
createFlowQuery({
isActive: true,
isPinned: false,
isBackground: false,
name: 'New Flow',
keywords: [],
description: '',
ignoreKeywords: false,
addRoleIds: [],
deleteRoleIds: [],
}),
];

const mockUseLocationValue: any = {
Expand Down Expand Up @@ -348,3 +369,25 @@ it('should create copy of a template flow', async () => {
fireEvent.click(button);
await waitFor(() => {});
});

it('should show validate the form and show errors', async () => {
mockUseLocationValue.state = null;
render(flow());

await waitFor(() => {
expect(screen.getByText('Add a new flow')).toBeInTheDocument();
});

fireEvent.click(screen.getByText('Save'));

await waitFor(() => {
expect(screen.getByText('Name is required.')).toBeInTheDocument();
});

fireEvent.change(screen.getAllByRole('textbox')[0], { target: { value: 'New Flow' } });
fireEvent.click(screen.getByText('Save'));

await waitFor(() => {
expect(screen.getByTestId('loadingBtn')).toBeInTheDocument();
});
});
6 changes: 4 additions & 2 deletions src/containers/Form/FormLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,10 @@ export const FormLayout = ({
variant="contained"
color="primary"
onClick={() => {
onSaveButtonClick(formik.errors);
formik.submitForm();
formik.validateForm().then((errors) => {
onSaveButtonClick(errors);
formik.submitForm();
});
}}
className={styles.Button}
data-testid="submitActionButton"
Expand Down
21 changes: 4 additions & 17 deletions src/mocks/Flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -696,39 +696,26 @@ export const copyFlowQuery = (input: any) => {
};
};

export const createFlowQuery = {
export const createFlowQuery = (input: any) => ({
request: {
query: CREATE_FLOW,
variables: {
input: {
isActive: true,
isPinned: false,
isBackground: false,
name: 'New Flow',
keywords: ['मदद'],
description: '',
ignoreKeywords: false,
addRoleIds: [],
deleteRoleIds: [],
},
input,
},
result: {
data: {
createFlow: {
errors: null,
flow: {
description: '',
id: '4',
isActive: true,
name: 'New Flow',
...input,
roles: [],
uuid: 'c18190b4-5f14-47f3-acfd-c301e5edf3a0',
},
},
},
},
},
};
});

export const getAllFlowLabelsQuery = {
request: {
Expand Down

0 comments on commit 39339ef

Please sign in to comment.