diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx index f86859f4b58b..8075a7d7698e 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.test.tsx @@ -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 = { @@ -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: {}, @@ -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'), + }) + ); + }); }); }); });