Skip to content

Commit

Permalink
fix unit test error
Browse files Browse the repository at this point in the history
Signed-off-by: yubonluo <yubonluo@amazon.com>
  • Loading branch information
yubonluo committed Mar 26, 2024
1 parent cf1a8ac commit c3f0ce6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe('copy saved objects', () => {
const targetWorkspace = '1';
await duplicateSavedObjects(httpClient, objects, includeReferencesDeep, targetWorkspace);
expect(httpClient.post).toMatchInlineSnapshot(
'',
`
[MockFunction] {
"calls": Array [
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ describe('DuplicateModal', () => {
expect(component).toMatchSnapshot();
});

it('should Unmount normally', async () => {
const component = shallowWithI18nProvider(
<SavedObjectsDuplicateModal {...selectedModeProps} />
);
expect(component.unmount()).toMatchSnapshot();
});

it('should show all target workspace options when not in any workspace', async () => {
workspaces.workspaceList$.next(workspaceList);
workspaces.currentWorkspaceId$.next('');
Expand Down Expand Up @@ -177,16 +184,35 @@ describe('DuplicateModal', () => {
});

it('should show saved objects type when duplicate mode is all', async () => {
workspaces.workspaceList$.next(workspaceList);
workspaces.currentWorkspaceId$.next('');
workspaces.currentWorkspace$.next(null);
allModeProps = { ...allModeProps, workspaces };
const component = shallowWithI18nProvider(<SavedObjectsDuplicateModal {...allModeProps} />);
const savedObjectTypeInfoMap = component.state('savedObjectTypeInfoMap') as Map<
string,
[number, boolean]
>;
expect(savedObjectTypeInfoMap.get('dashboard')).toEqual([2, true]);

const euiCheckbox = component.find('EuiCheckbox').at(0);
expect(euiCheckbox.prop('checked')).toEqual(true);
expect(euiCheckbox.prop('id')).toEqual('includeSavedObjectType.dashboard');

euiCheckbox.simulate('change', { target: { checked: false } });
const euiCheckboxUnCheced = component.find('EuiCheckbox').at(0);
expect(euiCheckboxUnCheced.prop('checked')).toEqual(false);
expect(savedObjectTypeInfoMap.get('dashboard')).toEqual([2, false]);
});

it('should uncheck duplicate related objects', async () => {
const component = shallowWithI18nProvider(
<SavedObjectsDuplicateModal {...selectedModeProps} />
);

const euiCheckbox = component.find('EuiCheckbox').at(0);
expect(euiCheckbox.prop('checked')).toEqual(true);
expect(euiCheckbox.prop('id')).toEqual('includeReferencesDeep');
expect(component.state('isIncludeReferencesDeepChecked')).toEqual(true);

euiCheckbox.simulate('change', { target: { checked: false } });
expect(component.state('isIncludeReferencesDeepChecked')).toEqual(false);
});

it('should call onClose function when cancle button is clicked', () => {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/workspace/public/workspace_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ describe('#WorkspaceClient', () => {
expect(workspaceMock.workspaceList$.getValue()).toEqual([
{
id: 'foo',
libraryReadonly: false,
},
]);
expect(httpSetupMock.fetch).toBeCalledWith('/api/workspaces/_list', {
Expand Down

0 comments on commit c3f0ce6

Please sign in to comment.