Skip to content

Commit

Permalink
chore: update unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Skwierczyński committed Apr 10, 2024
1 parent bc36390 commit ca9129e
Showing 1 changed file with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TenantType as TenantTypeField } from '@sb/webapp-api-client/constants';
import { commonQueryCurrentUserQuery } from '@sb/webapp-api-client/providers';
import { currentUserFactory, fillCommonQueryWithUser } from '@sb/webapp-api-client/tests/factories';
import { composeMockedQueryResult } from '@sb/webapp-api-client/tests/utils';
import { screen } from '@testing-library/react';
Expand All @@ -24,7 +26,7 @@ describe('TenantGeneralSettings: Component', () => {
const commonQueryMock = fillCommonQueryWithUser(user);

const variables = {
input: { id: '1', name: 'new item name' },
input: { id: '1', name: 'name - new item name' },
};

const data = {
Expand All @@ -38,15 +40,37 @@ describe('TenantGeneralSettings: Component', () => {
data,
});

const currentUserRefetchData = {
...user,
tenants: [
...(user.tenants ?? []),
tenantFactory({
id: '1',
name: variables.input.name,
type: TenantTypeField.ORGANIZATION,
}),
],
};

const refetchMock = composeMockedQueryResult(commonQueryCurrentUserQuery, {
data: currentUserRefetchData,
});

requestMock.newData = jest.fn(() => ({
data,
}));

refetchMock.newData = jest.fn(() => ({
data: {
currentUser: currentUserRefetchData,
},
}));

const routerProps = createMockRouterProps(RoutesConfig.tenant.settings.general, { tenantId: '1' });

render(<Component />, { apolloMocks: [commonQueryMock, requestMock], routerProps });
render(<Component />, { apolloMocks: [commonQueryMock, requestMock, refetchMock], routerProps });

await userEvent.type(await screen.findByPlaceholderText(/name/i), 'new item name');
await userEvent.type(await screen.findByPlaceholderText(/name/i), ' - new item name');
await userEvent.click(screen.getByRole('button', { name: /save/i }));
expect(requestMock.newData).toHaveBeenCalled();
const toast = await screen.findByTestId('toast-1');
Expand Down

0 comments on commit ca9129e

Please sign in to comment.