From de5cf4177aa509f5828e3d8bfa0dfb17fe27e060 Mon Sep 17 00:00:00 2001 From: Shenoy Pratik Date: Thu, 4 Jan 2024 16:14:53 -0800 Subject: [PATCH] snapshot updates and adding missing tests Signed-off-by: Shenoy Pratik --- .../__snapshots__/notebook.test.tsx.snap | 2 +- .../components/__tests__/notebook.test.tsx | 55 +++++++++++-------- .../notebooks/components/notebook.tsx | 23 +++++--- .../__snapshots__/para_output.test.tsx.snap | 27 ++++++--- .../__tests__/para_output.test.tsx | 43 ++++++++++++++- test/sample_default_notebooks.tsx | 27 +++++++++ 6 files changed, 135 insertions(+), 42 deletions(-) diff --git a/public/components/notebooks/components/__tests__/__snapshots__/notebook.test.tsx.snap b/public/components/notebooks/components/__tests__/__snapshots__/notebook.test.tsx.snap index 6103f85cf..deb0475bc 100644 --- a/public/components/notebooks/components/__tests__/__snapshots__/notebook.test.tsx.snap +++ b/public/components/notebooks/components/__tests__/__snapshots__/notebook.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` spec renders the empty component 1`] = ` +exports[` spec renders the empty component and test reporting action button 1`] = `
diff --git a/public/components/notebooks/components/__tests__/notebook.test.tsx b/public/components/notebooks/components/__tests__/notebook.test.tsx index 08520bc76..e0462821a 100644 --- a/public/components/notebooks/components/__tests__/notebook.test.tsx +++ b/public/components/notebooks/components/__tests__/notebook.test.tsx @@ -9,7 +9,7 @@ import { configure } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; import React from 'react'; import { HttpResponse } from '../../../../../../../src/core/public'; -import httpClientMock from '../../../../../test/__mocks__/httpClientMock'; +import { getOSDHttp } from '../../../../../common/utils'; import { addCodeBlockResponse, clearOutputNotebook, @@ -45,7 +45,8 @@ global.fetch = jest.fn(() => describe(' spec', () => { configure({ adapter: new Adapter() }); - const pplService = new PPLService(httpClientMock); + const httpClient = getOSDHttp(); + const pplService = new PPLService(httpClient); const setBreadcrumbs = jest.fn(); const renameNotebook = jest.fn(); const cloneNotebook = jest.fn(); @@ -56,14 +57,14 @@ describe(' spec', () => { const history = jest.fn() as any; history.replace = jest.fn(); - it('renders the empty component', async () => { - httpClientMock.get = jest.fn(() => Promise.resolve((emptyNotebook as unknown) as HttpResponse)); + it('renders the empty component and test reporting action button', async () => { + httpClient.get = jest.fn(() => Promise.resolve((emptyNotebook as unknown) as HttpResponse)); const utils = render( spec', () => { 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('renders the empty component and checks code block operations', async () => { - httpClientMock.get = jest.fn(() => Promise.resolve((emptyNotebook as unknown) as HttpResponse)); + httpClient.get = jest.fn(() => Promise.resolve((emptyNotebook as unknown) as HttpResponse)); let postFlag = 1; - httpClientMock.post = jest.fn(() => { + httpClient.post = jest.fn(() => { if (postFlag === 1) { postFlag += 1; return Promise.resolve((addCodeBlockResponse as unknown) as HttpResponse); @@ -94,7 +109,7 @@ describe(' spec', () => { pplService={pplService} openedNoteId="mock-id" DashboardContainerByValueRenderer={jest.fn()} - http={httpClientMock} + http={httpClient} parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }} setBreadcrumbs={setBreadcrumbs} renameNotebook={renameNotebook} @@ -160,13 +175,11 @@ describe(' spec', () => { }); it('renders a notebook and checks paragraph actions', async () => { - httpClientMock.get = jest.fn(() => - Promise.resolve((codeBlockNotebook as unknown) as HttpResponse) - ); - httpClientMock.put = jest.fn(() => + httpClient.get = jest.fn(() => Promise.resolve((codeBlockNotebook as unknown) as HttpResponse)); + httpClient.put = jest.fn(() => Promise.resolve((clearOutputNotebook as unknown) as HttpResponse) ); - httpClientMock.delete = jest.fn(() => + httpClient.delete = jest.fn(() => Promise.resolve(({ paragraphs: [] } as unknown) as HttpResponse) ); @@ -175,7 +188,7 @@ describe(' spec', () => { pplService={pplService} openedNoteId="mock-id" DashboardContainerByValueRenderer={jest.fn()} - http={httpClientMock} + http={httpClient} parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }} setBreadcrumbs={setBreadcrumbs} renameNotebook={renameNotebook} @@ -244,15 +257,13 @@ describe(' spec', () => { Promise.resolve((notebookPutResponse as unknown) as HttpResponse) ); const cloneNotebookMock = jest.fn(() => Promise.resolve('dummy-string')); - httpClientMock.get = jest.fn(() => - Promise.resolve((codeBlockNotebook as unknown) as HttpResponse) - ); + httpClient.get = jest.fn(() => Promise.resolve((codeBlockNotebook as unknown) as HttpResponse)); - httpClientMock.put = jest.fn(() => { + httpClient.put = jest.fn(() => { return Promise.resolve((notebookPutResponse as unknown) as HttpResponse); }); - httpClientMock.post = jest.fn(() => { + httpClient.post = jest.fn(() => { return Promise.resolve((addCodeBlockResponse as unknown) as HttpResponse); }); @@ -261,7 +272,7 @@ describe(' spec', () => { pplService={pplService} openedNoteId="mock-id" DashboardContainerByValueRenderer={jest.fn()} - http={httpClientMock} + http={httpClient} parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }} setBreadcrumbs={setBreadcrumbs} renameNotebook={renameNotebookMock} @@ -347,7 +358,7 @@ describe(' spec', () => { observabilityObjectList: [{ savedVisualization: sampleSavedVisualization }], }); - httpClientMock.get = jest.fn(() => + httpClient.get = jest.fn(() => Promise.resolve(({ ...sampleNotebook1, path: sampleNotebook1.name, @@ -372,7 +383,7 @@ describe(' spec', () => { pplService={pplService} openedNoteId={sampleNotebook1.id} DashboardContainerByValueRenderer={jest.fn()} - http={httpClientMock} + http={httpClient} parentBreadcrumb={{ href: 'parent-href', text: 'parent-text' }} setBreadcrumbs={setBreadcrumbs} renameNotebook={renameNotebook} diff --git a/public/components/notebooks/components/notebook.tsx b/public/components/notebooks/components/notebook.tsx index 2059bb452..9db011412 100644 --- a/public/components/notebooks/components/notebook.tsx +++ b/public/components/notebooks/components/notebook.tsx @@ -193,7 +193,7 @@ export class Notebook extends Component { paragraphId: para.uniqueId, }, }) - .then((res) => { + .then((_res) => { const paragraphs = [...this.state.paragraphs]; paragraphs.splice(index, 1); const parsedPara = [...this.state.parsedPara]; @@ -205,6 +205,7 @@ export class Notebook extends Component { 'Error deleting paragraph, please make sure you have the correct permission.', 'danger' ); + console.error(err); }); } }; @@ -246,6 +247,7 @@ export class Notebook extends Component { 'Error deleting paragraph, please make sure you have the correct permission.', 'danger' ); + console.error(err); }); }, 'Delete all paragraphs', @@ -354,6 +356,7 @@ export class Notebook extends Component { 'Error deleting visualization, please make sure you have the correct permission.', 'danger' ); + console.error(err); }); }; @@ -388,6 +391,7 @@ export class Notebook extends Component { 'Error adding paragraph, please make sure you have the correct permission.', 'danger' ); + console.error(err); }); }; @@ -421,13 +425,14 @@ export class Notebook extends Component { .post(`${NOTEBOOKS_API_PREFIX}/set_paragraphs/`, { body: JSON.stringify(moveParaObj), }) - .then((res) => this.setState({ paragraphs, parsedPara })) - .then((res) => this.scrollToPara(targetIndex)) + .then((_res) => this.setState({ paragraphs, parsedPara })) + .then((_res) => this.scrollToPara(targetIndex)) .catch((err) => { this.props.setToast( 'Error moving paragraphs, please make sure you have the correct permission.', 'danger' ); + console.error(err); }); }; @@ -460,6 +465,7 @@ export class Notebook extends Component { 'Error clearing paragraphs, please make sure you have the correct permission.', 'danger' ); + console.error(err); }); }; @@ -530,9 +536,9 @@ export class Notebook extends Component { } }; - runForAllParagraphs = (reducer: (para: ParaType, index: number) => Promise) => { + runForAllParagraphs = (reducer: (para: ParaType, _index: number) => Promise) => { return this.state.parsedPara - .map((para: ParaType, index: number) => () => reducer(para, index)) + .map((para: ParaType, _index: number) => () => reducer(para, _index)) .reduce((chain, func) => chain.then(func), Promise.resolve()); }; @@ -588,6 +594,7 @@ export class Notebook extends Component { 'Error fetching notebooks, please make sure you have the correct permission.', 'danger' ); + console.error(err); }); }; @@ -604,6 +611,7 @@ export class Notebook extends Component { }) .catch((err) => { this.props.setToast('Error getting query output', 'danger'); + console.error(err); }); }; @@ -655,6 +663,7 @@ export class Notebook extends Component { }) .catch((error) => { this.props.setToast('Error checking Reporting Plugin Installation status.', 'danger'); + console.error(error); }); } @@ -743,7 +752,7 @@ export class Notebook extends Component { disabled: this.state.parsedPara.length === 0, onClick: () => { this.setState({ isParaActionsPopoverOpen: false }); - this.runForAllParagraphs((para: ParaType, index: number) => { + this.runForAllParagraphs((para: ParaType, _index: number) => { return para.paraRef.current?.runParagraph(); }); if (this.state.selectedViewId === 'input_only') { @@ -847,7 +856,7 @@ export class Notebook extends Component { items: [ { name: 'Download PDF', - icon: , + icon: , onClick: () => { this.setState({ isReportingActionsPopoverOpen: false }); generateInContextReport('pdf', this.props, this.toggleReportingLoadingModal); diff --git a/public/components/notebooks/components/paragraph_components/__tests__/__snapshots__/para_output.test.tsx.snap b/public/components/notebooks/components/paragraph_components/__tests__/__snapshots__/para_output.test.tsx.snap index 0853177f7..029f9e027 100644 --- a/public/components/notebooks/components/paragraph_components/__tests__/__snapshots__/para_output.test.tsx.snap +++ b/public/components/notebooks/components/paragraph_components/__tests__/__snapshots__/para_output.test.tsx.snap @@ -1,5 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[` spec renders dashboards visualization outputs 1`] = ` +
+ 2020-Jul-21 18:37:44 - 2020-Aug-20 18:37:44 +
+`; + exports[` spec renders markdown outputs 1`] = `
spec renders markdown outputs 1`] = `
`; +exports[` spec renders observability visualization outputs 1`] = ` +
+ 2020-Jul-21 18:37:44 - 2020-Aug-20 18:37:44 +
+`; + exports[` spec renders other types of outputs 1`] = `
spec renders query outputs with error 1`] = `
`; - -exports[` spec renders visualization outputs 1`] = ` -
- 2020-Jul-21 18:37:44 - 2020-Aug-20 18:37:44 -
-`; diff --git a/public/components/notebooks/components/paragraph_components/__tests__/para_output.test.tsx b/public/components/notebooks/components/paragraph_components/__tests__/para_output.test.tsx index 5dcb8a34d..c19ebd2c6 100644 --- a/public/components/notebooks/components/paragraph_components/__tests__/para_output.test.tsx +++ b/public/components/notebooks/components/paragraph_components/__tests__/para_output.test.tsx @@ -3,16 +3,29 @@ * SPDX-License-Identifier: Apache-2.0 */ +jest.mock('../../../../../test/__mocks__/httpClientMock'); import { render } from '@testing-library/react'; import { configure } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; import React from 'react'; -import { uiSettingsService } from '../../../../../../common/utils/core_services'; -import { sampleParsedParagraghs1 } from '../../../../../../test/sample_default_notebooks'; +import { Provider } from 'react-redux'; +import { legacy_createStore as createStore } from 'redux'; +import { + getOSDHttp, + setPPLService, + uiSettingsService, +} from '../../../../../../common/utils/core_services'; +import { + sampleObservabilityVizParagraph, + sampleParsedParagraghs1, +} from '../../../../../../test/sample_default_notebooks'; +import { rootReducer } from '../../../../../framework/redux/reducers'; +import PPLService from '../../../../../services/requests/ppl'; import { ParaOutput } from '../para_output'; describe(' spec', () => { configure({ adapter: new Adapter() }); + const store = createStore(rootReducer); it('renders markdown outputs', () => { const para = sampleParsedParagraghs1[0]; @@ -63,7 +76,7 @@ describe(' spec', () => { expect(utils.container.firstChild).toMatchSnapshot(); }); - it('renders visualization outputs', () => { + it('renders dashboards visualization outputs', () => { const para = sampleParsedParagraghs1[2]; para.isSelected = true; @@ -84,6 +97,30 @@ describe(' spec', () => { expect(utils.container.firstChild).toMatchSnapshot(); }); + it('renders observability visualization outputs', () => { + setPPLService(new PPLService(getOSDHttp())); + const para = sampleObservabilityVizParagraph; + para.isSelected = true; + + uiSettingsService.get = jest.fn().mockReturnValue('YYYY-MMM-DD HH:mm:ss'); + const setVisInput = jest.fn(); + const utils = render( + + null} + /> + + ); + expect(utils.container.textContent).toMatch('2020-Jul-21 18:37:44 - 2020-Aug-20 18:37:44'); + expect(utils.container.firstChild).toMatchSnapshot(); + }); + it('renders other types of outputs', () => { const para = sampleParsedParagraghs1[0]; para.isSelected = true; diff --git a/test/sample_default_notebooks.tsx b/test/sample_default_notebooks.tsx index 0356d3a65..09a0c18f1 100644 --- a/test/sample_default_notebooks.tsx +++ b/test/sample_default_notebooks.tsx @@ -168,6 +168,33 @@ export const sampleParsedParagraghs1 = [ }, ]; +export const sampleObservabilityVizParagraph = { + uniqueId: 'paragraph_6d3237a9-6486-4f93-aa25-0a1c838faahh', + isRunning: false, + inQueue: false, + isSelected: false, + isInputHidden: false, + isOutputHidden: false, + showAddPara: false, + isVizualisation: true, + vizObjectInput: + '{"viewMode":"view","panels":{"1":{"gridData":{"x":0,"y":0,"w":50,"h":20,"i":"1"},"type":"visualization","explicitInput":{"id":"1","savedObjectId":"xmcchIwB5xYbk0tldrMA"}}},"isFullScreenMode":false,"filters":[],"useMargins":false,"id":"id2ae6b50-aa91-11ee-b006-2351d419df89","timeRange":{"to":"2024-01-03T23:42:52.909Z","from":"2023-12-04T23:42:52.909Z"},"title":"embed_viz_id2ae6b50-aa91-11ee-b006-2351d419df89","query":{"query":"","language":"lucene"},"refreshConfig":{"pause":true,"value":15}}', + id: 3, + inp: + '{"viewMode":"view","panels":{"1":{"gridData":{"x":0,"y":0,"w":50,"h":20,"i":"1"},"type":"visualization","explicitInput":{"id":"1","savedObjectId":"xmcchIwB5xYbk0tldrMA"}}},"isFullScreenMode":false,"filters":[],"useMargins":false,"id":"id2ae6b50-aa91-11ee-b006-2351d419df89","timeRange":{"to":"2024-01-03T23:42:52.909Z","from":"2023-12-04T23:42:52.909Z"},"title":"embed_viz_id2ae6b50-aa91-11ee-b006-2351d419df89","query":{"query":"","language":"lucene"},"refreshConfig":{"pause":true,"value":15}}', + lang: 'text/x-', + isInputExpanded: false, + isOutputStale: false, + paraDivRef: undefined, + paraRef: undefined, + visEndTime: '2020-08-20T18:37:44.710Z', + visSavedObjId: '935afa20-e0cd-11e7-9d07-1398ccfcefa3', + visStartTime: '2020-07-21T18:37:44.710Z', + editorLanguage: '', + typeOut: ['OBSERVABILITY_VISUALIZATION'], + out: [''], +}; + // Sample notebook with all input and cleared outputs export const sampleNotebook2 = { id: 'note_5f4b9eed-5898-4b39-ba6c-755c0fadd84e',