diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/signup/index.test.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/signup/index.test.tsx index edfd7ad265e..fee869b9f33 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/signup/index.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/signup/index.test.tsx @@ -12,6 +12,7 @@ */ import { act, fireEvent, render } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import React, { ReactNode } from 'react'; import { createUser } from 'rest/userAPI'; import SignUp from '.'; @@ -259,4 +260,46 @@ describe('SignUp page', () => { expect(createUser as jest.Mock).toHaveBeenCalledTimes(0); }); + + it('Create Button Should Work Properly and call the form handler', async () => { + (createUser as jest.Mock).mockImplementationOnce(() => + Promise.resolve(undefined) + ); + + const { getByTestId } = render(); + + const form = getByTestId('create-user-form'); + const fullNameInput = getByTestId('full-name-input'); + const usernameInput = getByTestId('username-input'); + const emailInput = getByTestId('email-input'); + + expect(form).toBeInTheDocument(); + + fullNameInput.onchange = mockChangeHandler; + usernameInput.onchange = mockChangeHandler; + emailInput.onchange = mockChangeHandler; + + await act(async () => { + fireEvent.change(fullNameInput, { + target: { name: 'displayName', value: 'Fname Mname Lname' }, + }); + + fireEvent.change(usernameInput, { + target: { name: 'displayName', value: 'mockUserName' }, + }); + fireEvent.change(emailInput, { + target: { name: 'displayName', value: 'sample@sample.com' }, + }); + + expect(mockChangeHandler).toHaveBeenCalledTimes(3); + + form.onsubmit = mockSubmitHandler; + + const createButton = getByTestId('create-button'); + + userEvent.click(createButton); + + expect(mockSubmitHandler).toHaveBeenCalledTimes(1); + }); + }); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/signup/index.tsx b/openmetadata-ui/src/main/resources/ui/src/pages/signup/index.tsx index 50b4950cdf3..dccd37f4c21 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/signup/index.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/pages/signup/index.tsx @@ -227,6 +227,7 @@ const SignUp = () => { className="tw-text-white tw-text-sm tw-py-2 tw-px-4 tw-font-semibold tw-rounded tw-h-10 tw-justify-self-end" data-testid="create-button" + htmlType="submit" type="primary"> {t('label.create')}