diff --git a/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.test.tsx b/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.test.tsx index e8239e85f9ec3c..091057a2f4a4ca 100644 --- a/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.test.tsx +++ b/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.test.tsx @@ -19,7 +19,6 @@ import { mountWithIntl, shallowWithIntl } from '@kbn/test-jest-helpers'; import { SpacesGridPage } from './spaces_grid_page'; import { SpaceAvatarInternal } from '../../space_avatar/space_avatar_internal'; -import type { SpacesManager } from '../../spaces_manager'; import { spacesManagerMock } from '../../spaces_manager/mocks'; const spaces = [ @@ -73,7 +72,7 @@ describe('SpacesGridPage', () => { const wrapper = shallowWithIntl( { const wrapper = shallowWithIntl( { }); it('renders a "current" badge for the current space', async () => { - spacesManager.getActiveSpace.mockResolvedValue(spaces[2]); - const current = await spacesManager.getActiveSpace(); - expect(current.id).toBe('custom-2'); + const spacesWithCurrent = [ + { id: 'default', name: 'Default', disabledFeatures: [], _reserved: true }, + { id: 'test-1', name: 'Test', disabledFeatures: [] }, + { id: 'test-2', name: 'Test', disabledFeatures: [] }, + ]; + const spacesManagerWithCurrent = spacesManagerMock.create(); + spacesManagerWithCurrent.getSpaces = jest.fn().mockResolvedValue(spacesWithCurrent); + spacesManagerWithCurrent.getActiveSpace.mockResolvedValue(spacesWithCurrent[2]); + + const current = await spacesManagerWithCurrent.getActiveSpace(); + expect(current.id).toBe('test-2'); const wrapper = mountWithIntl( { await act(async () => {}); wrapper.update(); - const activeRow = wrapper.find('[data-test-subj="spacesListTableRow-custom-2"]'); + const activeRow = wrapper.find('[data-test-subj="spacesListTableRow-test-2"]'); const nameCell = activeRow.find('[data-test-subj="spacesListTableRowNameCell"]'); const activeBadge = nameCell.find('EuiBadge'); expect(activeBadge.text()).toBe('current'); + + // ensure that current badge appears only once + const currentBadges = wrapper.findWhere((node) => { + return ( + node.type() === 'span' && + node.prop('data-test-subj') && + node.prop('data-test-subj').includes('spacesListCurrentBadge') + ); + }); + expect(currentBadges.length).toBe(1); }); it('renders a non-clickable "switch" action for the current space', async () => { @@ -202,7 +219,7 @@ describe('SpacesGridPage', () => { const wrapper = mountWithIntl( { const wrapper = mountWithIntl( { const wrapper = mountWithIntl( { const wrapper = mountWithIntl( { const wrapper = shallowWithIntl( { const wrapper = shallowWithIntl( Promise.reject(error)} notifications={notifications} getUrlForApp={getUrlForApp} diff --git a/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.tsx b/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.tsx index 95ef9a563162f3..2bbcc290a8a83d 100644 --- a/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.tsx +++ b/x-pack/plugins/spaces/public/management/spaces_grid/spaces_grid_page.tsx @@ -284,7 +284,7 @@ export class SpacesGridPage extends Component { {value} - {this.state.activeSpace?.name === rowRecord.name && ( + {this.state.activeSpace?.id === rowRecord.id && ( {i18n.translate('xpack.spaces.management.spacesGridPage.currentSpaceMarkerText', {