Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spaces Management] Ensure current badge can only appear for single entry #193195

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -73,7 +72,7 @@ describe('SpacesGridPage', () => {

const wrapper = shallowWithIntl(
<SpacesGridPage
spacesManager={spacesManager as unknown as SpacesManager}
spacesManager={spacesManager}
getFeatures={featuresStart.getFeatures}
notifications={notificationServiceMock.createStartContract()}
getUrlForApp={getUrlForApp}
Expand Down Expand Up @@ -133,7 +132,7 @@ describe('SpacesGridPage', () => {

const wrapper = shallowWithIntl(
<SpacesGridPage
spacesManager={spacesManager as unknown as SpacesManager}
spacesManager={spacesManager}
getFeatures={featuresStart.getFeatures}
notifications={notificationServiceMock.createStartContract()}
getUrlForApp={getUrlForApp}
Expand Down Expand Up @@ -163,13 +162,21 @@ describe('SpacesGridPage', () => {
});

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(
<SpacesGridPage
spacesManager={spacesManager as unknown as SpacesManager}
spacesManager={spacesManagerWithCurrent}
getFeatures={featuresStart.getFeatures}
notifications={notificationServiceMock.createStartContract()}
getUrlForApp={getUrlForApp}
Expand All @@ -189,10 +196,20 @@ describe('SpacesGridPage', () => {
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 () => {
Expand All @@ -202,7 +219,7 @@ describe('SpacesGridPage', () => {

const wrapper = mountWithIntl(
<SpacesGridPage
spacesManager={spacesManager as unknown as SpacesManager}
spacesManager={spacesManager}
getFeatures={featuresStart.getFeatures}
notifications={notificationServiceMock.createStartContract()}
getUrlForApp={getUrlForApp}
Expand Down Expand Up @@ -234,7 +251,7 @@ describe('SpacesGridPage', () => {

const wrapper = mountWithIntl(
<SpacesGridPage
spacesManager={spacesManager as unknown as SpacesManager}
spacesManager={spacesManager}
getFeatures={featuresStart.getFeatures}
notifications={notificationServiceMock.createStartContract()}
getUrlForApp={getUrlForApp}
Expand Down Expand Up @@ -265,7 +282,7 @@ describe('SpacesGridPage', () => {

const wrapper = mountWithIntl(
<SpacesGridPage
spacesManager={spacesManager as unknown as SpacesManager}
spacesManager={spacesManager}
getFeatures={featuresStart.getFeatures}
notifications={notificationServiceMock.createStartContract()}
getUrlForApp={getUrlForApp}
Expand Down Expand Up @@ -295,7 +312,7 @@ describe('SpacesGridPage', () => {

const wrapper = mountWithIntl(
<SpacesGridPage
spacesManager={spacesManager as unknown as SpacesManager}
spacesManager={spacesManager}
getFeatures={featuresStart.getFeatures}
notifications={notificationServiceMock.createStartContract()}
getUrlForApp={getUrlForApp}
Expand Down Expand Up @@ -331,7 +348,7 @@ describe('SpacesGridPage', () => {

const wrapper = shallowWithIntl(
<SpacesGridPage
spacesManager={spacesManager as unknown as SpacesManager}
spacesManager={spacesManager}
getFeatures={featuresStart.getFeatures}
notifications={notifications}
getUrlForApp={getUrlForApp}
Expand Down Expand Up @@ -367,7 +384,7 @@ describe('SpacesGridPage', () => {

const wrapper = shallowWithIntl(
<SpacesGridPage
spacesManager={spacesManager as unknown as SpacesManager}
spacesManager={spacesManager}
getFeatures={() => Promise.reject(error)}
notifications={notifications}
getUrlForApp={getUrlForApp}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export class SpacesGridPage extends Component<Props, State> {
{value}
</EuiLink>
</EuiFlexItem>
{this.state.activeSpace?.name === rowRecord.name && (
{this.state.activeSpace?.id === rowRecord.id && (
<EuiFlexItem grow={false}>
<EuiBadge color="primary" data-test-subj={`spacesListCurrentBadge-${rowRecord.id}`}>
{i18n.translate('xpack.spaces.management.spacesGridPage.currentSpaceMarkerText', {
Expand Down