Skip to content

Commit

Permalink
mds changes for notebooks -s
Browse files Browse the repository at this point in the history
  • Loading branch information
sumukhswamy committed Jul 16, 2024
1 parent d091987 commit 907fc93
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 765 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ describe('<NoteTable /> spec', () => {
fireEvent.click(utils.getByText('Cancel'));
fireEvent.click(utils.getAllByLabelText('Select this row')[0]);
fireEvent.click(utils.getByText('Actions'));
fireEvent.click(utils.getByText('Rename'));
});

it('create notebook modal', async () => {
Expand Down Expand Up @@ -123,70 +122,6 @@ describe('<NoteTable /> spec', () => {
expect(props.createNotebook).toHaveBeenCalledTimes(1);
});

it('renames a notebook', () => {
const notebooks = [
{
path: 'path-1',
id: 'id-1',
dateCreated: 'date-created',
dateModified: 'date-modified',
},
];
const { getByText, getByLabelText, getAllByText, getByTestId } = renderNoteTable({ notebooks });

// Select a notebook
fireEvent.click(getByLabelText('Select this row'));

// Open Actions dropdown and click Rename
fireEvent.click(getByText('Actions'));
fireEvent.click(getByText('Rename'));

// Ensure the modal is open (you may need to adjust based on your modal implementation)
expect(getAllByText('Rename notebook')).toHaveLength(1);

// Mock user input and submit
fireEvent.input(getByTestId('custom-input-modal-input'), {
target: { value: 'test-notebook-newname' },
});
fireEvent.click(getByTestId('custom-input-modal-confirm-button'));

// Assert that the renameNotebook function is called
expect(props.renameNotebook).toHaveBeenCalledTimes(1);
expect(props.renameNotebook).toHaveBeenCalledWith('test-notebook-newname', 'id-1');
});

it('clones a notebook', () => {
const notebooks = [
{
path: 'path-1',
id: 'id-1',
dateCreated: 'date-created',
dateModified: 'date-modified',
},
];
const { getByText, getByLabelText, getAllByText, getByTestId } = renderNoteTable({ notebooks });

// Select a notebook
fireEvent.click(getByLabelText('Select this row'));

// Open Actions dropdown and click Duplicate
fireEvent.click(getByText('Actions'));
fireEvent.click(getByText('Duplicate'));

// Ensure the modal is open (you may need to adjust based on your modal implementation)
expect(getAllByText('Duplicate notebook')).toHaveLength(1);

// Mock user input and submit
fireEvent.input(getByTestId('custom-input-modal-input'), {
target: { value: 'new-copy' },
});
fireEvent.click(getByTestId('custom-input-modal-confirm-button'));

// Assert that the cloneNotebook function is called
expect(props.cloneNotebook).toHaveBeenCalledTimes(1);
expect(props.cloneNotebook).toHaveBeenCalledWith('new-copy', 'id-1');
});

it('deletes a notebook', () => {
const notebooks = [
{
Expand Down Expand Up @@ -244,14 +179,14 @@ describe('<NoteTable /> spec', () => {
fireEvent.click(getByText('Actions'));

// Ensure the action panel is open
expect(queryByTestId('renameNotebookBtn')).toBeInTheDocument();
expect(queryByTestId('deleteNotebookBtn')).toBeInTheDocument();

await act(async () => {
fireEvent.click(getByText('Actions'));
});

// Ensure the action panel is closed
expect(queryByTestId('renameNotebookBtn')).not.toBeInTheDocument();
expect(queryByTestId('deleteNotebookBtn')).not.toBeInTheDocument();
});

it('closes the delete modal', () => {
Expand Down
65 changes: 19 additions & 46 deletions public/components/notebooks/components/__tests__/notebook.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('<Notebook /> spec', () => {
const utils = render(
<Notebook
pplService={pplService}
openedNoteId="mock-id"
openedNoteId="458e1320-3f05-11ef-bd29-e58626f102c0"
DashboardContainerByValueRenderer={jest.fn()}
http={httpClient}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
Expand All @@ -75,50 +75,14 @@ describe('<Notebook /> spec', () => {
setToast={setToast}
location={location}
history={history}
dataSourceEnabled={false}
/>
);
await waitFor(() => {
expect(utils.getByText('sample-notebook-1')).toBeInTheDocument();
});
expect(utils.container.firstChild).toMatchSnapshot();
});

it('test reporting action button', async () => {
httpClient.get = jest.fn(() => Promise.resolve((emptyNotebook as unknown) as HttpResponse));
const utils = render(
<Notebook
pplService={pplService}
openedNoteId="mock-id"
DashboardContainerByValueRenderer={jest.fn()}
http={httpClient}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
setBreadcrumbs={setBreadcrumbs}
renameNotebook={renameNotebook}
cloneNotebook={cloneNotebook}
deleteNotebook={deleteNotebook}
setToast={setToast}
location={location}
history={history}
/>
);
await waitFor(() => {
expect(utils.getByText('sample-notebook-1')).toBeInTheDocument();
});
expect(utils.container.firstChild).toMatchSnapshot();

act(() => {
fireEvent.click(utils.getByText('Reporting actions'));
});

expect(utils.queryByTestId('download-notebook-pdf')).toBeInTheDocument();

act(() => {
fireEvent.click(utils.getByText('Reporting actions'));
});

await waitFor(() => {
expect(utils.queryByTestId('download-notebook-pdf')).toBeNull();
});
});

it('Adds a code block', async () => {
Expand All @@ -133,7 +97,7 @@ describe('<Notebook /> spec', () => {
const utils = render(
<Notebook
pplService={pplService}
openedNoteId="mock-id"
openedNoteId="458e1320-3f05-11ef-bd29-e58626f102c0"
DashboardContainerByValueRenderer={jest.fn()}
http={httpClient}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
Expand All @@ -144,6 +108,7 @@ describe('<Notebook /> spec', () => {
setToast={setToast}
location={location}
history={history}
dataSourceEnabled={false}
/>
);
await waitFor(() => {
Expand Down Expand Up @@ -171,7 +136,7 @@ describe('<Notebook /> spec', () => {
const utils = render(
<Notebook
pplService={pplService}
openedNoteId="mock-id"
openedNoteId="458e1320-3f05-11ef-bd29-e58626f102c0"
DashboardContainerByValueRenderer={jest.fn()}
http={httpClient}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
Expand All @@ -182,6 +147,7 @@ describe('<Notebook /> spec', () => {
setToast={setToast}
location={location}
history={history}
dataSourceEnabled={false}
/>
);
await waitFor(() => {
Expand Down Expand Up @@ -217,7 +183,7 @@ describe('<Notebook /> spec', () => {
const utils = render(
<Notebook
pplService={pplService}
openedNoteId="mock-id"
openedNoteId="458e1320-3f05-11ef-bd29-e58626f102c0"
DashboardContainerByValueRenderer={jest.fn()}
http={httpClient}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
Expand All @@ -228,6 +194,7 @@ describe('<Notebook /> spec', () => {
setToast={setToast}
location={location}
history={history}
dataSourceEnabled={false}
/>
);
await waitFor(() => {
Expand Down Expand Up @@ -260,7 +227,7 @@ describe('<Notebook /> spec', () => {
const utils = render(
<Notebook
pplService={pplService}
openedNoteId="mock-id"
openedNoteId="458e1320-3f05-11ef-bd29-e58626f102c0"
DashboardContainerByValueRenderer={jest.fn()}
http={httpClient}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
Expand All @@ -271,6 +238,7 @@ describe('<Notebook /> spec', () => {
setToast={setToast}
location={location}
history={history}
dataSourceEnabled={false}
/>
);
await waitFor(() => {
Expand Down Expand Up @@ -327,7 +295,7 @@ describe('<Notebook /> spec', () => {
const utils = render(
<Notebook
pplService={pplService}
openedNoteId="mock-id"
openedNoteId="458e1320-3f05-11ef-bd29-e58626f102c0"
DashboardContainerByValueRenderer={jest.fn()}
http={httpClient}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
Expand All @@ -338,6 +306,7 @@ describe('<Notebook /> spec', () => {
setToast={setToast}
location={location}
history={history}
dataSourceEnabled={false}
/>
);
await waitFor(() => {
Expand Down Expand Up @@ -411,7 +380,7 @@ describe('<Notebook /> spec', () => {
const utils = render(
<Notebook
pplService={pplService}
openedNoteId="mock-id"
openedNoteId="458e1320-3f05-11ef-bd29-e58626f102c0"
DashboardContainerByValueRenderer={jest.fn()}
http={httpClient}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
Expand All @@ -422,6 +391,7 @@ describe('<Notebook /> spec', () => {
setToast={setToast}
location={location}
history={history}
dataSourceEnabled={false}
/>
);
await waitFor(() => {
Expand Down Expand Up @@ -470,7 +440,7 @@ describe('<Notebook /> spec', () => {
const utils = render(
<Notebook
pplService={pplService}
openedNoteId="mock-id"
openedNoteId="458e1320-3f05-11ef-bd29-e58626f102c0"
DashboardContainerByValueRenderer={jest.fn()}
http={httpClient}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
Expand All @@ -481,6 +451,7 @@ describe('<Notebook /> spec', () => {
setToast={setToast}
location={location}
history={history}
dataSourceEnabled={false}
/>
);
await waitFor(() => {
Expand Down Expand Up @@ -524,7 +495,7 @@ describe('<Notebook /> spec', () => {
const utils = render(
<Notebook
pplService={pplService}
openedNoteId="mock-id"
openedNoteId="458e1320-3f05-11ef-bd29-e58626f102c0"
DashboardContainerByValueRenderer={jest.fn()}
http={httpClient}
parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }}
Expand All @@ -535,6 +506,7 @@ describe('<Notebook /> spec', () => {
setToast={setToast}
location={location}
history={history}
dataSourceEnabled={false}
/>
);
await waitFor(() => {
Expand Down Expand Up @@ -605,6 +577,7 @@ describe('<Notebook /> spec', () => {
setToast={setToast}
location={location}
history={history}
dataSourceManagement={{ ui: { DataSourceSelector: <></> } }}
/>
);

Expand Down
15 changes: 13 additions & 2 deletions public/components/notebooks/components/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import React, { ReactChild } from 'react';
// eslint-disable-next-line @osd/eslint/module_migration
import { Route, Switch } from 'react-router';
import { HashRouter, RouteComponentProps } from 'react-router-dom';
import { ChromeBreadcrumb, CoreStart } from '../../../../../../src/core/public';
import { ChromeBreadcrumb, CoreStart, MountPoint, SavedObjectsStart } from '../../../../../../src/core/public';
import { DashboardStart } from '../../../../../../src/plugins/dashboard/public';
import {
DataSourceManagementPluginSetup
} from '../../../../../../src/plugins/data_source_management/public';
import {
NOTEBOOKS_API_PREFIX,
NOTEBOOKS_DOCUMENTATION_URL,
Expand All @@ -19,7 +22,6 @@ import PPLService from '../../../services/requests/ppl';
import { isValidUUID } from './helpers/notebooks_parser';
import { NoteTable } from './note_table';
import { Notebook } from './notebook';

/*
* "Main" component renders the whole Notebooks as a single page application
*
Expand All @@ -38,6 +40,10 @@ type MainProps = RouteComponentProps & {
notifications: CoreStart['notifications'];
parentBreadcrumb: ChromeBreadcrumb;
setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => void;
dataSourceEnabled: boolean;
dataSourceManagement: DataSourceManagementPluginSetup;
setActionMenu: (menuMount: MountPoint | undefined) => void;
savedObjectsMDSClient: SavedObjectsStart;
};

interface MainState {
Expand Down Expand Up @@ -401,6 +407,11 @@ export class Main extends React.Component<MainProps, MainState> {
location={props.location}
history={props.history}
migrateNotebook={this.migrateNotebook}
dataSourceManagement={this.props.dataSourceManagement}
setActionMenu={this.props.setActionMenu}
notifications={this.props.notifications}
dataSourceEnabled={this.props.dataSourceEnabled}
savedObjectsMDSClient={this.props.savedObjectsMDSClient}
/>
)}
/>
Expand Down
Loading

0 comments on commit 907fc93

Please sign in to comment.