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

[Workspace] Refactor: Workspace list card #7748

Merged
merged 5 commits into from
Aug 23, 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
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://github.com/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
Loading