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] Update workspace list page table #7640

Merged
merged 18 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
41c8d00
the table basically works
Qxisylolo Aug 5, 2024
e76395c
the table basically works new
Qxisylolo Aug 6, 2024
d601e94
This time I achieve the functionality and apprearence of the workList…
Qxisylolo Aug 7, 2024
c77079f
This time I achieve the functionality and apprearence of the workList…
Qxisylolo Aug 7, 2024
c6323e8
This time I achieve the functionality and apprearence of the workList…
Qxisylolo Aug 7, 2024
2f03420
Achieve the functionality and apprearence of the workLists table, and…
Qxisylolo Aug 7, 2024
a577aa4
Changeset file for PR #7640 created/updated
opensearch-changeset-bot[bot] Aug 7, 2024
d368602
Changeset file for PR #7640 created/updated
opensearch-changeset-bot[bot] Aug 7, 2024
670b04c
Changeset file for PR #7640 created/updated
opensearch-changeset-bot[bot] Aug 7, 2024
220a4f0
Achieve the functionality and apprearence of the work List table page…
Qxisylolo Aug 8, 2024
3b3850d
Achieve the functionality and apprearence of the work List table page…
Qxisylolo Aug 8, 2024
9b3410f
Achieve the functionality and apprearence of the work List table page…
Qxisylolo Aug 8, 2024
86b4513
Achieve the functionality and apprearence of the work List table page…
Qxisylolo Aug 8, 2024
18ba7ca
Enable multiple deletion and correct the code based on comments
Qxisylolo Aug 8, 2024
62e451a
Enable multiple deletion and correct the code based on comments
Qxisylolo Aug 9, 2024
4b26196
set the advanced date format
Qxisylolo Aug 14, 2024
9fc525c
set advanced time format and tests
Qxisylolo Aug 14, 2024
94703a0
Merge main branch
Qxisylolo Aug 15, 2024
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/7640.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- [Workspace] Update workspace list page table ([#7640](/~https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7640))
169 changes: 137 additions & 32 deletions src/plugins/workspace/public/components/workspace_list/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,61 @@ jest.mock('../delete_workspace_modal', () => ({
),
}));

const formatDate = function (dateString: string) {
const months = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
];

const date = new Date(dateString);

const month = months[date.getUTCMonth()];
const day = String(date.getUTCDate()).padStart(2, '0');
const year = date.getUTCFullYear();

const hours = String(date.getUTCHours()).padStart(2, '0');
const minutes = String(date.getUTCMinutes()).padStart(2, '0');
const seconds = String(date.getUTCSeconds()).padStart(2, '0');
const milliseconds = String(date.getUTCMilliseconds()).padStart(3, '0');

return `${month} ${day},${year}@${hours}:${minutes}:${seconds}.${milliseconds}`;
};

function getWrapWorkspaceListInContext(
workspaceList = [
{ id: 'id1', name: 'name1', features: ['use-case-all'] },
{ id: 'id2', name: 'name2' },
{ id: 'id3', name: 'name3', features: ['use-case-observability'] },
{
id: 'id1',
name: 'name1',
features: ['use-case-all'],
description:
'should be able to see the description tooltip when hovering over the description',
lastUpdatedTime: '1999-08-06T02:00:00.00Z',
},
{
id: 'id2',
name: 'name2',
features: ['use-case-observability'],
description:
'should be able to see the description tooltip when hovering over the description',
lastUpdatedTime: '1999-08-06T00:00:00.00Z',
},
{
id: 'id3',
name: 'name3',
features: ['use-case-search'],
description: '',
lastUpdatedTime: '1999-08-06T01:00:00.00Z',
},
],
isDashboardAdmin = true
) {
Expand Down Expand Up @@ -79,26 +129,27 @@ describe('WorkspaceList', () => {
expect(getByText('All use case')).toBeInTheDocument();
expect(getByText('Observability')).toBeInTheDocument();
});
it('should be able to apply debounce search after input', async () => {
const list = [
{ id: 'id1', name: 'name1' },
{ id: 'id2', name: 'name2' },
{ id: 'id3', name: 'name3' },
{ id: 'id4', name: 'name4' },
{ id: 'id5', name: 'name5' },
{ id: 'id6', name: 'name6' },
];
const { getByText, getByRole, queryByText } = render(getWrapWorkspaceListInContext(list));
expect(getByText('name1')).toBeInTheDocument();
expect(queryByText('name6')).not.toBeInTheDocument();

it('should be able to search and re-render the list', async () => {
const { getByText, getByRole, queryByText } = render(getWrapWorkspaceListInContext());
const input = getByRole('searchbox');
fireEvent.change(input, {
target: { value: 'nam' },
target: { value: 'name2' },
});
expect(getByText('name2')).toBeInTheDocument();
expect(queryByText('name1')).not.toBeInTheDocument();
expect(queryByText('name3')).not.toBeInTheDocument();
});

it('should be able to apply debounce search after input', async () => {
const { getByText, getByRole, queryByText } = render(getWrapWorkspaceListInContext());
const input = getByRole('searchbox');
fireEvent.change(input, {
target: { value: 'name6' },
target: { value: 'name2' },
});
expect(queryByText('name6')).not.toBeInTheDocument();
expect(getByText('name2')).toBeInTheDocument();
expect(queryByText('name1')).not.toBeInTheDocument();
expect(queryByText('name3')).not.toBeInTheDocument();
});

it('should be able to switch workspace after clicking name', async () => {
Expand All @@ -108,16 +159,36 @@ describe('WorkspaceList', () => {
expect(navigateToWorkspaceDetail).toBeCalled();
});

it('should be able to perform the time format transformation', async () => {
const { getByText } = render(getWrapWorkspaceListInContext());
expect(getByText(formatDate('1999-08-06T00:00:00.00Z'))).toBeInTheDocument();
expect(getByText(formatDate('1999-08-06T01:00:00.00Z'))).toBeInTheDocument();
expect(getByText(formatDate('1999-08-06T02:00:00.00Z'))).toBeInTheDocument();
});

it('should be able to see the 3 operations: copy, update, delete after click in the meatballs button', async () => {
const { getAllByTestId, getByText } = render(getWrapWorkspaceListInContext());
const operationIcons = getAllByTestId('euiCollapsedItemActionsButton')[0];
fireEvent.click(operationIcons);
expect(getByText('Copy')).toBeInTheDocument();
expect(getByText('Edit')).toBeInTheDocument();
expect(getByText('Delete')).toBeInTheDocument();
});

it('should be able to update workspace after clicking name', async () => {
const { getAllByTestId } = render(getWrapWorkspaceListInContext());
const editIcon = getAllByTestId('workspace-list-edit-icon')[0];
const { getByText, getAllByTestId } = render(getWrapWorkspaceListInContext());
const operationIcons = getAllByTestId('euiCollapsedItemActionsButton')[0];
fireEvent.click(operationIcons);
const editIcon = getByText('Edit');
fireEvent.click(editIcon);
expect(navigateToWorkspaceDetail).toBeCalled();
});

it('should be able to call delete modal after clicking delete button', async () => {
const { getAllByTestId } = render(getWrapWorkspaceListInContext());
const deleteIcon = getAllByTestId('workspace-list-delete-icon')[0];
const { getByText, getAllByTestId } = render(getWrapWorkspaceListInContext());
const operationIcons = getAllByTestId('euiCollapsedItemActionsButton')[0];
fireEvent.click(operationIcons);
const deleteIcon = getByText('Delete');
fireEvent.click(deleteIcon);
expect(screen.queryByLabelText('mock delete workspace modal')).toBeInTheDocument();
const modalCancelButton = screen.getByLabelText('mock delete workspace modal button');
Expand All @@ -127,12 +198,48 @@ describe('WorkspaceList', () => {

it('should be able to pagination when clicking pagination button', async () => {
const list = [
{ id: 'id1', name: 'name1' },
{ id: 'id2', name: 'name2' },
{ id: 'id3', name: 'name3' },
{ id: 'id4', name: 'name4' },
{ id: 'id5', name: 'name5' },
{ id: 'id6', name: 'name6' },
{
id: 'id1',
name: 'name1',
features: ['use-case-all'],
description: '',
lastUpdatedTime: '2024-08-06T00:00:00.00Z',
},
{
id: 'id2',
name: 'name2',
features: ['use-case-observability'],
description: '',
lastUpdatedTime: '2024-08-06T00:00:00.00Z',
},
{
id: 'id3',
name: 'name3',
features: ['use-case-search'],
description: '',
lastUpdatedTime: '2024-08-06T00:00:00.00Z',
},
{
id: 'id4',
name: 'name4',
features: ['use-case-all'],
description: '',
lastUpdatedTime: '2024-08-06T00:00:00.00Z',
},
{
id: 'id5',
name: 'name5',
features: ['use-case-observability'],
description: '',
lastUpdatedTime: '2024-08-06T00:00:00.00Z',
},
{
id: 'id6',
name: 'name6',
features: ['use-case-search'],
description: '',
lastUpdatedTime: '2024-08-06T00:00:00.00Z',
},
];
const { getByTestId, getByText, queryByText } = render(getWrapWorkspaceListInContext(list));
expect(getByText('name1')).toBeInTheDocument();
Expand All @@ -144,14 +251,12 @@ describe('WorkspaceList', () => {
});

it('should display create workspace button for dashboard admin', async () => {
const { getByText } = render(getWrapWorkspaceListInContext([], true));

expect(getByText('Create workspace')).toBeInTheDocument();
const { getAllByText } = render(getWrapWorkspaceListInContext([], true));
expect(getAllByText('Create workspace')[0]).toBeInTheDocument();
});

it('should hide create workspace button for non dashboard admin', async () => {
const { queryByText } = render(getWrapWorkspaceListInContext([], false));

expect(queryByText('Create workspace')).toBeNull();
});
});
Loading
Loading