From f4d003f36eefe64b9e8d7e351b61590730e71a97 Mon Sep 17 00:00:00 2001 From: Sean Li Date: Wed, 6 Mar 2024 15:43:42 -0800 Subject: [PATCH] adding tests for accelerations components Signed-off-by: Sean Li --- .../acceleration_details_flyout.test.tsx.snap | 1127 ++++++ .../acceleration_table.test.tsx.snap | 3067 +++++++++++++++++ .../acceleration_details_flyout.test.tsx | 32 + .../__tests__/acceleration_table.test.tsx | 30 + .../acceleration_details_flyout.tsx | 25 +- .../accelerations/acceleration_table.tsx | 16 +- .../components/manage/data_connection.tsx | 19 +- test/datasources.ts | 17 + 8 files changed, 4307 insertions(+), 26 deletions(-) create mode 100644 public/components/datasources/components/manage/accelerations/__tests__/__snapshots__/acceleration_details_flyout.test.tsx.snap create mode 100644 public/components/datasources/components/manage/accelerations/__tests__/__snapshots__/acceleration_table.test.tsx.snap create mode 100644 public/components/datasources/components/manage/accelerations/__tests__/acceleration_details_flyout.test.tsx create mode 100644 public/components/datasources/components/manage/accelerations/__tests__/acceleration_table.test.tsx diff --git a/public/components/datasources/components/manage/accelerations/__tests__/__snapshots__/acceleration_details_flyout.test.tsx.snap b/public/components/datasources/components/manage/accelerations/__tests__/__snapshots__/acceleration_details_flyout.test.tsx.snap new file mode 100644 index 000000000..952b9411d --- /dev/null +++ b/public/components/datasources/components/manage/accelerations/__tests__/__snapshots__/acceleration_details_flyout.test.tsx.snap @@ -0,0 +1,1127 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Acceleration Details Flyout test Render acceleration detail flyout 1`] = ` + + +
+ +
+ +
+ +
+

+ dummy_acceleration_1 +

+
+
+
+
+ +
+ + + + + +
+
+ +
+ + + + + +
+
+ +
+ + + + + +
+
+
+
+ +
+ + +
+ + + + + + + + + +
+
+
+ + +
+
+
+ + +
+ + +
+ + } + title="Status" + > + +
+ +
+ +
+ Status +
+
+ +
+ + +
+ +
+ +
+ + + + + + + +
+
+ +
+ Active +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + +
+ +
+ +
+ Acceleration Type +
+
+ +
+ skip +
+
+
+
+
+
+
+ + +
+ +
+ +
+ Creation Date +
+
+ +
+ Tue, 20 Jan 1970 18:48:59 GMT +
+
+
+
+
+
+
+
+
+ +
+ + +
+ +
+ +
+ Last Updated +
+
+ +
+ Tue, 20 Jan 1970 18:48:59 GMT +
+
+
+
+
+
+
+
+
+ +
+ + + +

+ Data source details +

+
+ +
+
+
+ +
+ + security_logs_2022 + + } + title="Data source connection" + > + +
+ +
+ +
+ Data source connection +
+
+ +
+ + + +
+
+
+
+
+
+
+ + +
+ +
+ +
+ Database +
+
+ +
+ default +
+
+
+
+
+
+
+ + +
+ +
+ +
+ Table +
+
+ +
+ table1 +
+
+
+
+
+
+
+
+
+ +
+ + + +

+ Index details +

+
+ +
+
+
+ +
+ + +
+ +
+ +
+ Index name +
+
+ +
+ security_logs_2022 +
+
+
+
+
+
+
+ + } + title="Health" + > + +
+ +
+ +
+ Health +
+
+ +
+ + +
+ +
+ +
+ + + + + + + +
+
+ +
+ Active +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + +
+ +
+ +
+ Refresh interval +
+
+ +
+ 2s +
+
+
+
+
+
+
+
+
+ +
+
+
+ + +`; + +exports[`Acceleration Details Flyout test Render acceleration detail flyout and click on schema tab 1`] = ` +
+
+
+
+

+ dummy_acceleration_1 +

+
+
+
+ +
+
+ +
+
+ +
+
+
+
+ + + +
+
+`; diff --git a/public/components/datasources/components/manage/accelerations/__tests__/__snapshots__/acceleration_table.test.tsx.snap b/public/components/datasources/components/manage/accelerations/__tests__/__snapshots__/acceleration_table.test.tsx.snap new file mode 100644 index 000000000..bebadf0fd --- /dev/null +++ b/public/components/datasources/components/manage/accelerations/__tests__/__snapshots__/acceleration_table.test.tsx.snap @@ -0,0 +1,3067 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Acceleration Table Test Render acceleration table with dummy acceleration 1`] = ` + + +
+ + +
+ + +
+ +
+ +
+

+ Accelerations +

+

+ Accelerations optimize query performance by indexing external data into OpenSearch. +

+
+
+
+
+ +
+ + + + + + + +
+
+ +
+ + + + + + + +
+
+
+
+
+ +
+
+ +
+ + + +
+
+ +
+ +
+ +
+ + +
+ +
+ + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > +
+
+ + + +
+
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + Actions + + + + + +
+
+ Name +
+
+ + + +
+
+
+ Status +
+
+ + +
+ +
+ +
+ + + + + + + +
+
+ +
+ Active +
+
+
+
+
+
+
+
+
+
+ Type +
+
+ +
+ Skipping Index +
+
+
+
+
+ Database +
+
+ +
+ default +
+
+
+
+
+ Table +
+
+ +
+ table1 +
+
+
+
+
+ Destination Index +
+
+ + + +
+
+
+ + +
+ + + [Function] + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + id="0-actions" + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + popoverRef={[Function]} + > +
+
+ + + + + + + + + + + +
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+ + + +
+ +
+ + + : + 10 + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > +
+
+ + + +
+
+
+
+
+ +
+ + + +
+
+
+
+
+
+ +
+ + +
+ + +`; + +exports[`Acceleration Table Test Render empty acceleration table 1`] = ` + + +
+ + +
+ + +
+ +
+ +
+

+ Accelerations +

+

+ Accelerations optimize query performance by indexing external data into OpenSearch. +

+
+
+
+
+ +
+ + + + + + + +
+
+ +
+ + + + + + + +
+
+
+
+
+ +
+
+ +
+ + + +
+
+ +
+ +
+ +
+ + +
+ +
+ + + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > +
+
+ + + +
+
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + Actions + + + + + +
+
+ + No items found + +
+
+
+
+
+ + +
+ + +`; + \ No newline at end of file diff --git a/public/components/datasources/components/manage/accelerations/__tests__/acceleration_details_flyout.test.tsx b/public/components/datasources/components/manage/accelerations/__tests__/acceleration_details_flyout.test.tsx new file mode 100644 index 000000000..40e63b4fa --- /dev/null +++ b/public/components/datasources/components/manage/accelerations/__tests__/acceleration_details_flyout.test.tsx @@ -0,0 +1,32 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { configure, mount } from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; +import React from 'react'; +import { dummyAccelerations } from '../../../../../../../test/datasources'; +import { AccelerationDetailsFlyout } from '../acceleration_details_flyout'; +import { cleanup, fireEvent, render } from '@testing-library/react'; + +describe('Acceleration Details Flyout test', () => { + configure({ adapter: new Adapter() }); + + afterEach(() => { + cleanup(); + }); + + it('Render acceleration detail flyout', () => { + const wrapper = mount(); + + expect(wrapper).toMatchSnapshot(); + }); + + it('Render acceleration detail flyout and click on schema tab', () => { + const utils = render(); + + fireEvent.click(utils.getByTestId('accelerationDetailsFlyoutTab_schema')); + expect(utils.container.firstChild).toMatchSnapshot(); + }); +}); diff --git a/public/components/datasources/components/manage/accelerations/__tests__/acceleration_table.test.tsx b/public/components/datasources/components/manage/accelerations/__tests__/acceleration_table.test.tsx new file mode 100644 index 000000000..6524f9348 --- /dev/null +++ b/public/components/datasources/components/manage/accelerations/__tests__/acceleration_table.test.tsx @@ -0,0 +1,30 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { configure, mount } from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; +import { AccelerationTable } from '../acceleration_table'; + +import React from 'react'; +import { dummyAccelerations } from '../../../../../../../test/datasources'; +import * as Plugin from '../../../../../../plugin'; + +describe('Acceleration Table Test', () => { + configure({ adapter: new Adapter() }); + + Plugin.getRenderAccelerationDetailsFlyout = jest.fn(); + + it('Render empty acceleration table', () => { + const wrapper = mount(); + + expect(wrapper).toMatchSnapshot(); + }); + + it('Render acceleration table with dummy acceleration', () => { + const wrapper = mount(); + + expect(wrapper).toMatchSnapshot(); + }); +}); diff --git a/public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx b/public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx index 89ea00700..3310122f3 100644 --- a/public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx +++ b/public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx @@ -42,7 +42,10 @@ export const AccelerationDetailsFlyout = (props: AccelerationDetailsFlyoutProps) const DiscoverButton = () => { // TODO: display button if can be sent to discover return ( - + ); @@ -50,7 +53,10 @@ export const AccelerationDetailsFlyout = (props: AccelerationDetailsFlyoutProps) const RefreshButton = () => { return ( - + ); @@ -58,7 +64,10 @@ export const AccelerationDetailsFlyout = (props: AccelerationDetailsFlyoutProps) const DeleteButton = () => { return ( - + ); @@ -90,6 +99,7 @@ export const AccelerationDetailsFlyout = (props: AccelerationDetailsFlyoutProps) isSelected={tab.id === selectedTab} disabled={tab.disabled} key={index} + data-test-subj={'accelerationDetailsFlyoutTab_' + tab.id} > {tab.name} @@ -107,7 +117,7 @@ export const AccelerationDetailsFlyout = (props: AccelerationDetailsFlyoutProps) - +

{acceleration.name}

@@ -122,7 +132,12 @@ export const AccelerationDetailsFlyout = (props: AccelerationDetailsFlyoutProps)
- {renderTabs()} + + {renderTabs()} +
{renderTabContent(selectedTab, acceleration)} diff --git a/public/components/datasources/components/manage/accelerations/acceleration_table.tsx b/public/components/datasources/components/manage/accelerations/acceleration_table.tsx index aeda0d7ea..6b2a88e96 100644 --- a/public/components/datasources/components/manage/accelerations/acceleration_table.tsx +++ b/public/components/datasources/components/manage/accelerations/acceleration_table.tsx @@ -47,7 +47,11 @@ export const AccelerationTable = (props: AccelerationTableTabProps) => { // over from dashboards-query-workbench/public/components/acceleration/create/create_accelerations.tsx return ( <> - console.log('clicked on create accelerations button')} fill> + console.log('clicked on create accelerations button')} + fill + > Create acceleration @@ -59,7 +63,7 @@ export const AccelerationTable = (props: AccelerationTableTabProps) => { <> - +

Accelerations

Accelerations optimize query performance by indexing external data into OpenSearch. @@ -164,7 +168,12 @@ export const AccelerationTable = (props: AccelerationTableTabProps) => { name: 'Destination Index', sortable: true, render: (destination: string) => ( - console.log('clicked on', destination)}>{destination} + console.log('clicked on', destination)} + data-test-subj="accelerationTableDiscoverButton" + > + {destination} + ), }, { @@ -200,6 +209,7 @@ export const AccelerationTable = (props: AccelerationTableTabProps) => { columns={accelerationTableColumns} pagination={pagination} sorting={sorting} + data-test-subj="accelerationTable" /> diff --git a/public/components/datasources/components/manage/data_connection.tsx b/public/components/datasources/components/manage/data_connection.tsx index ee10e4a53..561c6d13d 100644 --- a/public/components/datasources/components/manage/data_connection.tsx +++ b/public/components/datasources/components/manage/data_connection.tsx @@ -34,6 +34,7 @@ import { DatasourceType } from '../../../../../common/types/data_connections'; import { AssociatedObjectsTab } from './associated_objects/associated_objects_tab'; import { AccelerationTable } from './accelerations/acceleration_table'; import { mockAssociatedObjects } from './associated_objects/utils/associated_objects_tab_utils'; +import { dummyAccelerations } from '../../../../../test/datasources'; interface DatasourceDetails { allowedRoles: string[]; @@ -64,24 +65,6 @@ export const DataConnection = (props: any) => { const [hasAccess, setHasAccess] = useState(true); const { http, chrome, application } = coreRefs; - // Dummy accelerations variables for mock purposes - // Actual accelerations should be retrieved from the backend - const sampleSql = 'select * from `httplogs`.`default`.`table2` limit 10'; - const dummyAccelerations = [ - { - name: 'dummy_acceleration_1', - status: 'ACTIVE', - type: 'skip', - database: 'default', - table: 'table1', - destination: 'N/A', - dateCreated: 1709339290, - dateUpdated: 1709339290, - index: 'security_logs_2022', - sql: sampleSql, - }, - ]; - const DefaultDatasourceCards = () => { return ( diff --git a/test/datasources.ts b/test/datasources.ts index 6258101fc..915e30fb6 100644 --- a/test/datasources.ts +++ b/test/datasources.ts @@ -806,3 +806,20 @@ export const mockRoleData = { }, }, }; + +export const sampleSql = 'select * from `httplogs`.`default`.`table2` limit 10'; + +export const dummyAccelerations = [ + { + name: 'dummy_acceleration_1', + status: 'ACTIVE', + type: 'skip', + database: 'default', + table: 'table1', + destination: 'N/A', + dateCreated: 1709339290, + dateUpdated: 1709339290, + index: 'security_logs_2022', + sql: sampleSql, + }, +];