Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <[email protected]>
  • Loading branch information
Hailong-am committed Oct 23, 2023
1 parent 25b62bd commit 94627b0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('Header', () => {
onRefresh: () => {},
totalCount: 4,
filteredCount: 2,
hideImport: false,
title: '',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ export const Header = ({
onImport,
onRefresh,
filteredCount,
hideImport = false,
hideImport,
title,
}: {
onExportAll: () => void;
onImport: () => void;
onRefresh: () => void;
filteredCount: number;
hideImport: boolean;
hideImport?: boolean;
title: string;
}) => (
<Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { Flyout, Relationships } from './components';
import { SavedObjectWithMetadata } from '../../types';
import { WorkspaceObject } from 'opensearch-dashboards/public';
import { TableProps } from './components/table';
import { waitFor } from '@testing-library/dom';

const allowedTypes = ['index-pattern', 'visualization', 'dashboard', 'search'];

Expand Down Expand Up @@ -670,5 +671,55 @@ describe('SavedObjectsTable', () => {
expect(wsFilter[0].options.length).toBe(1);
expect(wsFilter[0].options[0].value).toBe('foo');
});

it('workspace exists in query options when workspace on', async () => {
const applications = applicationServiceMock.createStartContract();
applications.capabilities = {
navLinks: {},
management: {},
catalogue: {},
savedObjectsManagement: {
read: true,
edit: false,
delete: false,
},
workspaces: {
enabled: true,
},
};

const workspaceList: WorkspaceObject[] = [
{
id: 'workspace1',
name: 'foo',
},
{
id: 'workspace2',
name: 'bar',
},
];
workspaces.workspaceList$.next(workspaceList);
workspaces.currentWorkspaceId$.next('workspace1');
workspaces.currentWorkspace$.next(workspaceList[0]);

const component = shallowRender({ applications, workspaces });

// Ensure all promises resolve
await new Promise((resolve) => process.nextTick(resolve));
// Ensure the state changes are reflected
component.update();

waitFor(
() => {
expect(http.get).toHaveBeenCalledWith(
expect.stringMatching('/api/opensearch-dashboards/management/saved_objects/_find'),
expect.objectContaining({
workspaces: expect.arrayContaining(['workspace1']),
})
);
},
{ timeout: 1000 }
);
});
});
});

0 comments on commit 94627b0

Please sign in to comment.