Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <[email protected]>
  • Loading branch information
Hailong-am committed Mar 8, 2024
1 parent 6d473d8 commit 740479d
Showing 1 changed file with 58 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,9 @@ describe('SavedObjectsTable', () => {
);
expect(component.state('selectedSavedObjects').length).toBe(0);
});
});

describe('workspace filter', () => {
it('show workspace filter when workspace turn on and not in any workspace', async () => {
const applications = applicationServiceMock.createStartContract();
applications.capabilities = {
Expand Down Expand Up @@ -742,7 +744,8 @@ describe('SavedObjectsTable', () => {
expect(wsFilter[0].options[0].value).toBe('foo');
});

it('workspace exists in query options when workspace on', async () => {
it('workspace exists in find options when workspace on', async () => {
findObjectsMock.mockClear();
const applications = applicationServiceMock.createStartContract();
applications.capabilities = {
navLinks: {},
Expand Down Expand Up @@ -779,17 +782,61 @@ describe('SavedObjectsTable', () => {
// 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']),
})
);
await waitFor(() => {
expect(findObjectsMock).toBeCalledWith(
http,
expect.objectContaining({
workspaces: expect.arrayContaining(['workspace1']),
})
);
});
});

it('workspace exists in find options when workspace on and not in any workspace', async () => {
findObjectsMock.mockClear();
const applications = applicationServiceMock.createStartContract();
applications.capabilities = {
navLinks: {},
management: {},
catalogue: {},
savedObjectsManagement: {
read: true,
edit: false,
delete: false,
},
{ timeout: 1000 }
);
workspaces: {
enabled: true,
},
};

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

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

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

await waitFor(() => {
expect(findObjectsMock).toBeCalledWith(
http,
expect.objectContaining({
workspaces: expect.arrayContaining(['workspace1', 'default']),
workspacesSearchOperator: expect.stringMatching('OR'),
})
);
});
});
});
});

0 comments on commit 740479d

Please sign in to comment.