Skip to content

Commit

Permalink
navigates to use case overview page
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <[email protected]>

click on workspace name navigates to use case overview page

Signed-off-by: Hailong Cui <[email protected]>

Changeset file for PR #7748 created/updated

support customized width

Signed-off-by: Hailong Cui <[email protected]>

style adjustment

Signed-off-by: Hailong Cui <[email protected]>

update test snapshot

Signed-off-by: Hailong Cui <[email protected]>
  • Loading branch information
Hailong-am committed Aug 19, 2024
1 parent 389ad1b commit bc617bd
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 101 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/7748.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- [Workspace]Fix click on workspace name not navigates to use case overview page ([#7748](https:/opensearch-project/OpenSearch-Dashboards/pull/7748))

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,40 @@ import { coreMock } from '../../../../../core/public/mocks';
import { fireEvent, render, waitFor } from '@testing-library/react';
import { WorkspaceListCard } from './workspace_list_card';
import { recentWorkspaceManager } from '../../recent_workspace_manager';
import { BehaviorSubject } from 'rxjs';
import { NavGroupItemInMap } from 'opensearch-dashboards/public';

describe('workspace list card render normally', () => {
const coreStart = coreMock.createStart();
const navGroupMap: Record<string, NavGroupItemInMap> = {
group1: {
id: 'group1',
title: 'title',
description: 'desc',
navLinks: [
{
id: 'link1',
},
],
},
};
const coreStart = {
...coreMock.createStart(),
chrome: {
...coreMock.createStart().chrome,
navGroup: {
...coreMock.createStart().chrome.navGroup,
getNavGroupsMap$: () => new BehaviorSubject(navGroupMap),
},
},
};

beforeAll(() => {
const workspaceList = [
{
id: 'ws-1',
name: 'foo',
lastUpdatedTime: new Date().toISOString(),
features: ['use-case-group1'],
},
{
id: 'ws-2',
Expand All @@ -38,7 +62,11 @@ describe('workspace list card render normally', () => {
expect(getByTestId('workspace_filter')).toHaveDisplayValue('Recently viewed');

// empty statue for recently viewed
expect(getByText('Workspaces you have recently viewed will appear here.')).toBeInTheDocument();
expect(
getByText(
'Contact your administrator to create a workspace or to be added to an existing one.'
)
).toBeInTheDocument();
});

it('should show default filter as recently viewed', () => {
Expand All @@ -64,6 +92,21 @@ describe('workspace list card render normally', () => {
expect(getByText('bar')).toBeInTheDocument();
});

it('should navigate to workspace use case overview page when click on workspace name', () => {
const { getByTestId, getByText } = render(<WorkspaceListCard core={coreStart} />);
const filterSelector = getByTestId('workspace_filter');
fireEvent.change(filterSelector, { target: { value: 'updated' } });
expect(getByTestId('workspace_filter')).toHaveDisplayValue('Recently updated');

// workspace list
expect(getByText('foo')).toBeInTheDocument();

fireEvent.click(getByText('foo'));
expect(coreStart.application.getUrlForApp).toHaveBeenLastCalledWith('link1', {
absolute: true,
});
});

it('should render create workspace button when is dashboard admin and navigate to create new workspace page when clicking on plus button', () => {
coreStart.application.capabilities = {
...coreStart.application.capabilities,
Expand All @@ -79,7 +122,10 @@ describe('workspace list card render normally', () => {
});

it('should navigate to workspace list page when click on View all button', () => {
const { getByText } = render(<WorkspaceListCard core={coreStart} />);
const { getByText, getByTestId } = render(<WorkspaceListCard core={coreStart} />);
const filterSelector = getByTestId('workspace_filter');
fireEvent.change(filterSelector, { target: { value: 'updated' } });
expect(getByTestId('workspace_filter')).toHaveDisplayValue('Recently updated');
const mockButton = getByText('View all');
fireEvent.click(mockButton);
expect(coreStart.application.navigateToApp).toHaveBeenCalledWith('workspace_list');
Expand Down
Loading

0 comments on commit bc617bd

Please sign in to comment.