Skip to content

Commit

Permalink
fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Doraemon012 authored May 23, 2024
1 parent d55f74f commit 9407be7
Showing 1 changed file with 0 additions and 152 deletions.
152 changes: 0 additions & 152 deletions src/components/OrgMemberDetail/OrgMemberDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,6 @@ jest.mock('@mui/x-date-pickers/DateTimePicker', () => {

jest.mock('react-toastify');

jest.mock('../../utils/errorHandler.tsx'); // Mock the errorHandler function

describe('OrgMemberDetail', () => {
global.alert = jest.fn();

Expand Down Expand Up @@ -448,156 +446,6 @@ describe('OrgMemberDetail', () => {
expect(screen.getByText(/Display Image/i)).toBeInTheDocument();
});

test('should render props and text elements test for the page component', async () => {
const props = {
id: '1',
};

const formData = {
firstName: 'Ansh',
lastName: 'Goyal',
email: 'ansh@gmail.com',
image: new File(['hello'], 'hello.png', { type: 'image/png' }),
address: 'abc',
countryCode: 'IN',
state: 'abc',
city: 'abc',
phoneNumber: '1234567890',
birthDate: '',
};
render(
<MockedProvider addTypename={false} link={link2}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<OrgMemberDetail {...props} />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);
expect(screen.queryByText('Loading data...')).not.toBeInTheDocument();
await wait();
expect(screen.getAllByText(/Email/i)).toBeTruthy();
expect(screen.getByText('User')).toBeInTheDocument();
const birthDateDatePicker = screen.getByTestId('birthDate');
fireEvent.change(birthDateDatePicker, {
target: { value: formData.birthDate },
});

userEvent.type(
screen.getByPlaceholderText(/First Name/i),
formData.firstName,
);
userEvent.type(
screen.getByPlaceholderText(/Last Name/i),
formData.lastName,
);
userEvent.type(screen.getByPlaceholderText(/Address/i), formData.address);
userEvent.type(
screen.getByPlaceholderText(/Country Code/i),
formData.countryCode,
);
userEvent.type(screen.getByPlaceholderText(/State/i), formData.state);
userEvent.type(screen.getByPlaceholderText(/City/i), formData.city);
userEvent.type(screen.getByPlaceholderText(/Email/i), formData.email);
userEvent.type(screen.getByPlaceholderText(/Phone/i), formData.phoneNumber);
userEvent.click(screen.getByPlaceholderText(/pluginCreationAllowed/i));
userEvent.selectOptions(screen.getByTestId('applangcode'), 'Français');
userEvent.upload(screen.getByLabelText(/Display Image:/i), formData.image);
await wait();

userEvent.click(screen.getByText(/Save Changes/i));

expect(screen.getByPlaceholderText(/First Name/i)).toHaveValue(
formData.firstName,
);
expect(screen.getByPlaceholderText(/Last Name/i)).toHaveValue(
formData.lastName,
);
expect(birthDateDatePicker).toHaveValue(formData.birthDate);
expect(screen.getByPlaceholderText(/Email/i)).toHaveValue(formData.email);
expect(screen.getByPlaceholderText(/First Name/i)).toBeInTheDocument();
expect(screen.getByPlaceholderText(/Last Name/i)).toBeInTheDocument();
expect(screen.getByPlaceholderText(/Email/i)).toBeInTheDocument();
expect(screen.getByText(/Display Image/i)).toBeInTheDocument();
});

test('should render props and text elements test for the page component', async () => {
const props = {
id: '1',
};

const formData = {
firstName: 'Ansh',
lastName: 'Goyal',
email: 'ansh@gmail.com',
image: '',
address: 'abc',
countryCode: 'IN',
state: 'abc',
city: 'abc',
phoneNumber: '1234567890',
birthDate: '03/28/2022',
};
render(
<MockedProvider addTypename={false} link={link2}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<OrgMemberDetail {...props} />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>,
);
expect(screen.queryByText('Loading data...')).not.toBeInTheDocument();
await wait();
expect(screen.getAllByText(/Email/i)).toBeTruthy();
expect(screen.getByText('User')).toBeInTheDocument();
const birthDateDatePicker = screen.getByTestId('birthDate');
fireEvent.change(birthDateDatePicker, {
target: { value: formData.birthDate },
});

userEvent.type(
screen.getByPlaceholderText(/First Name/i),
formData.firstName,
);
userEvent.type(
screen.getByPlaceholderText(/Last Name/i),
formData.lastName,
);
userEvent.type(screen.getByPlaceholderText(/Address/i), formData.address);
userEvent.type(
screen.getByPlaceholderText(/Country Code/i),
formData.countryCode,
);
userEvent.type(screen.getByPlaceholderText(/State/i), formData.state);
userEvent.type(screen.getByPlaceholderText(/City/i), formData.city);
userEvent.type(screen.getByPlaceholderText(/Email/i), formData.email);
userEvent.type(screen.getByPlaceholderText(/Phone/i), formData.phoneNumber);
userEvent.click(screen.getByPlaceholderText(/pluginCreationAllowed/i));
userEvent.selectOptions(screen.getByTestId('applangcode'), 'Français');
userEvent.upload(screen.getByLabelText(/Display Image:/i), formData.image);
await wait();

userEvent.click(screen.getByText(/Save Changes/i));

expect(screen.getByPlaceholderText(/First Name/i)).toHaveValue(
formData.firstName,
);
expect(screen.getByPlaceholderText(/Last Name/i)).toHaveValue(
formData.lastName,
);
expect(birthDateDatePicker).toHaveValue(formData.birthDate);
expect(screen.getByPlaceholderText(/Email/i)).toHaveValue(formData.email);
expect(screen.getByPlaceholderText(/First Name/i)).toBeInTheDocument();
expect(screen.getByPlaceholderText(/Last Name/i)).toBeInTheDocument();
expect(screen.getByPlaceholderText(/Email/i)).toBeInTheDocument();
expect(screen.getByText(/Display Image/i)).toBeInTheDocument();
});

test('should display warnings for blank form submission', async () => {
jest.spyOn(toast, 'warning');
const props = {
Expand Down

0 comments on commit 9407be7

Please sign in to comment.