Skip to content

Commit

Permalink
Update UT for useWorkspaceForm
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <[email protected]>
  • Loading branch information
wanglam committed Nov 29, 2024
1 parent 6e4084c commit 50f1fac
Showing 1 changed file with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import { renderHook, act } from '@testing-library/react-hooks';

import { applicationServiceMock } from '../../../../../core/public/mocks';
import { WorkspacePermissionMode } from '../../../common/constants';
import { WorkspaceOperationType, WorkspacePermissionItemType } from './constants';
import { PermissionModeId } from '../../../../../core/public';
import {
optionIdToWorkspacePermissionModesMap,
WorkspaceOperationType,
WorkspacePermissionItemType,
WorkspacePrivacyItemType,
} from './constants';
import { WorkspaceFormSubmitData, WorkspaceFormErrorCode } from './types';
import { useWorkspaceForm } from './use_workspace_form';
import { waitFor } from '@testing-library/dom';
Expand Down Expand Up @@ -195,4 +201,38 @@ describe('useWorkspaceForm', () => {
expect(renderResult.result.current.formData.permissionSettings).toStrictEqual([]);
});
});

it('should return permissions settings after setPrivacyType called', async () => {
const onSubmitMock = jest.fn().mockResolvedValue({ success: true });
const { renderResult } = setup({
defaultValues: {
name: 'current-workspace-name',
features: ['use-case-observability'],
},
onSubmit: onSubmitMock,
});
act(() => {
renderResult.result.current.setPrivacyType(WorkspacePrivacyItemType.AnyoneCanEdit);
});
await waitFor(() => {
expect(renderResult.result.current.formData.permissionSettings).toEqual(
expect.arrayContaining([
expect.objectContaining({
type: 'user',
userId: '*',
modes: optionIdToWorkspacePermissionModesMap[PermissionModeId.ReadAndWrite],
}),
])
);
});

const oldPermissionSettings = renderResult.result.current.formData.permissionSettings;

act(() => {
renderResult.result.current.setPrivacyType(WorkspacePrivacyItemType.AnyoneCanEdit);
});
await waitFor(() => {
expect(renderResult.result.current.formData.permissionSettings).toBe(oldPermissionSettings);
});
});
});

0 comments on commit 50f1fac

Please sign in to comment.