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

[Backport 2.x] [Navigation-next]Register workspace list card into home page #7350

Merged
merged 1 commit into from
Jul 22, 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/7247.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Register workspace list card into home page ([#7247](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7247))
1 change: 1 addition & 0 deletions src/core/types/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface WorkspaceAttribute {
icon?: string;
reserved?: boolean;
uiSettings?: Record<string, any>;
lastUpdatedTime?: string;
}

export interface WorkspaceAttributeWithPermission extends WorkspaceAttribute {
Expand Down

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
@@ -0,0 +1,6 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export { WorkspaceListCard } from './workspace_list_card';
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
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';

describe('workspace list card render normally', () => {
const coreStart = coreMock.createStart();

beforeAll(() => {
const workspaceList = [
{
id: 'ws-1',
name: 'foo',
lastUpdatedTime: new Date().toISOString(),
},
{
id: 'ws-2',
name: 'bar',
lastUpdatedTime: new Date().toISOString(),
},
];
coreStart.workspaces.workspaceList$.next(workspaceList);
});

it('should show workspace list card correctly', () => {
const { container } = render(<WorkspaceListCard core={coreStart} />);
expect(container).toMatchSnapshot();
});

it('should show empty state if no recently viewed workspace', () => {
const { getByTestId, getByText } = render(<WorkspaceListCard core={coreStart} />);
expect(getByTestId('workspace_filter')).toHaveDisplayValue('Recently viewed');

// empty statue for recently viewed
expect(getByText('Workspaces you have recently viewed will appear here.')).toBeInTheDocument();
});

it('should show default filter as recently viewed', () => {
recentWorkspaceManager.addRecentWorkspace('foo');
const { getByTestId, getByText } = render(<WorkspaceListCard core={coreStart} />);
expect(getByTestId('workspace_filter')).toHaveDisplayValue('Recently viewed');

waitFor(() => {
expect(getByText('foo')).toBeInTheDocument();
});
});

it('should show updated filter correctly', () => {
const { getByTestId, getByText } = render(<WorkspaceListCard core={coreStart} />);
expect(getByTestId('workspace_filter')).toHaveDisplayValue('Recently viewed');

const filterSelector = getByTestId('workspace_filter');
fireEvent.change(filterSelector, { target: { value: 'updated' } });
expect(getByTestId('workspace_filter')).toHaveDisplayValue('Recently updated');

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