Skip to content

Commit

Permalink
fix failing test for OrgList component
Browse files Browse the repository at this point in the history
  • Loading branch information
meetulr committed Feb 11, 2024
1 parent 7b2efcd commit b64cd98
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
60 changes: 36 additions & 24 deletions src/screens/OrgList/OrgList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ describe('Organisations Page testing as SuperAdmin', () => {
name: 'Dummy Organization',
description: 'This is a dummy organization',
address: {
city: 'Delhi',
countryCode: 'IN',
dependentLocality: 'Some Dependent Locality',
line1: '123 Random Street',
city: 'Kingston',
countryCode: 'JM',
dependentLocality: 'Sample Dependent Locality',
line1: '123 Jamaica Street',
line2: 'Apartment 456',
postalCode: '110001',
postalCode: 'JM12345',
sortingCode: 'ABC-123',
state: 'Delhi',
state: 'Kingston Parish',
},
image: new File(['hello'], 'hello.png', { type: 'image/png' }),
image: '',
};

test('Testing search functionality by pressing enter', async () => {
Expand Down Expand Up @@ -205,6 +205,11 @@ describe('Organisations Page testing as SuperAdmin', () => {
screen.getByPlaceholderText(/Postal Code/i),
formData.address.postalCode
);
userEvent.type(
screen.getByPlaceholderText(/State \/ Province/i),
formData.address.state
);

userEvent.selectOptions(
screen.getByTestId('countrycode'),
formData.address.countryCode
Expand All @@ -227,7 +232,6 @@ describe('Organisations Page testing as SuperAdmin', () => {
);
userEvent.click(screen.getByTestId(/userRegistrationRequired/i));
userEvent.click(screen.getByTestId(/visibleInSearch/i));
userEvent.upload(screen.getByLabelText(/Display Image/i), formData.image);

expect(screen.getByTestId(/modalOrganizationName/i)).toHaveValue(
formData.name
Expand All @@ -238,6 +242,9 @@ describe('Organisations Page testing as SuperAdmin', () => {
//Checking the fields for the address object in the formdata.
const { address } = formData;
expect(screen.getByPlaceholderText(/City/i)).toHaveValue(address.city);
expect(screen.getByPlaceholderText(/State \/ Province/i)).toHaveValue(
address.state
);
expect(screen.getByPlaceholderText(/Dependent Locality/i)).toHaveValue(
address.dependentLocality
);
Expand All @@ -255,14 +262,11 @@ describe('Organisations Page testing as SuperAdmin', () => {
expect(screen.getByLabelText(/Display Image/i)).toBeTruthy();

userEvent.click(screen.getByTestId(/submitOrganizationForm/i));
// await act(async () => {
// await new Promise((resolve) => setTimeout(resolve, 1000));
// });
// await waitFor(() =>
// expect(
// screen.queryByText(/Congratulation the Organization is created/i)
// ).toBeInTheDocument()
// );
await waitFor(() => {
expect(
screen.queryByText(/Congratulation the Organization is created/i)
).toBeInTheDocument();
});
});

test('Plugin Notification model should work properly', async () => {
Expand Down Expand Up @@ -297,6 +301,10 @@ describe('Organisations Page testing as SuperAdmin', () => {
formData.description
);
userEvent.type(screen.getByPlaceholderText(/City/i), formData.address.city);
userEvent.type(
screen.getByPlaceholderText(/State \/ Province/i),
formData.address.state
);
userEvent.type(
screen.getByPlaceholderText(/Postal Code/i),
formData.address.postalCode
Expand All @@ -323,7 +331,6 @@ describe('Organisations Page testing as SuperAdmin', () => {
);
userEvent.click(screen.getByTestId(/userRegistrationRequired/i));
userEvent.click(screen.getByTestId(/visibleInSearch/i));
userEvent.upload(screen.getByLabelText(/Display Image/i), formData.image);

expect(screen.getByTestId(/modalOrganizationName/i)).toHaveValue(
formData.name
Expand All @@ -334,6 +341,9 @@ describe('Organisations Page testing as SuperAdmin', () => {
//Checking the fields for the address object in the formdata.
const { address } = formData;
expect(screen.getByPlaceholderText(/City/i)).toHaveValue(address.city);
expect(screen.getByPlaceholderText(/State \/ Province/i)).toHaveValue(
address.state
);
expect(screen.getByPlaceholderText(/Dependent Locality/i)).toHaveValue(
address.dependentLocality
);
Expand All @@ -354,14 +364,16 @@ describe('Organisations Page testing as SuperAdmin', () => {
// await act(async () => {
// await new Promise((resolve) => setTimeout(resolve, 1000));
// });
// await waitFor(() =>
// expect(
// screen.queryByText(/Congratulation the Organization is created/i)
// ).toBeInTheDocument()
// );
await screen.findByTestId(/pluginNotificationHeader/i);
await waitFor(() =>
expect(
screen.queryByText(/Congratulation the Organization is created/i)
).toBeInTheDocument()
);
await waitFor(() => {
screen.findByTestId(/pluginNotificationHeader/i);
});
// userEvent.click(screen.getByTestId(/enableEverythingForm/i));
userEvent.click(screen.getByTestId(/goToStore/i));
userEvent.click(screen.getByTestId(/enableEverythingForm/i));
});

test('Testing create sample organization working properly', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/OrgList/OrgList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function orgList(): JSX.Element {
function closeDialogModal() {
setdialogModalIsOpen(false);
}
const toggleDialogModal = (): void =>
const toggleDialogModal = /* istanbul ignore next */ (): void =>
setdialogModalIsOpen(!dialogModalisOpen);
document.title = t('title');

Expand Down

0 comments on commit b64cd98

Please sign in to comment.