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] [Feature] Acceleration components' data implementation #1536

Merged
merged 1 commit into from
Mar 15, 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
1 change: 1 addition & 0 deletions common/constants/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const DSL_BASE = '/api/dsl';
export const DSL_SEARCH = '/search';
export const DSL_CAT = '/cat.indices';
export const DSL_MAPPING = '/indices.getFieldMapping';
export const DSL_SETTINGS = '/indices.getFieldSettings';
export const OBSERVABILITY_BASE = '/api/observability';
export const INTEGRATIONS_BASE = '/api/integrations';
export const JOBS_BASE = '/query/jobs';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,7 @@ exports[`Panels View Component renders panel view container with visualizations
"fetch": [Function],
"fetchFields": [Function],
"fetchIndices": [Function],
"fetchSettings": [Function],
"http": [MockFunction],
}
}
Expand Down Expand Up @@ -1754,6 +1755,7 @@ exports[`Panels View Component renders panel view container with visualizations
"fetch": [Function],
"fetchFields": [Function],
"fetchIndices": [Function],
"fetchSettings": [Function],
"http": [MockFunction],
}
}
Expand Down Expand Up @@ -3520,6 +3522,7 @@ exports[`Panels View Component renders panel view container without visualizatio
"fetch": [Function],
"fetchFields": [Function],
"fetchIndices": [Function],
"fetchSettings": [Function],
"http": [MockFunction],
}
}
Expand Down Expand Up @@ -3985,6 +3988,7 @@ exports[`Panels View Component renders panel view container without visualizatio
"fetch": [Function],
"fetchFields": [Function],
"fetchIndices": [Function],
"fetchSettings": [Function],
"http": [MockFunction],
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { mount, configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { AccelerationDetailsFlyout } from '../manage/accelerations/acceleration_details_flyout';
import * as coreRefsModule from '../../../../framework/core_refs';

jest.mock('../../../../framework/core_refs', () => {
const actualModule = jest.requireActual('../../../../framework/core_refs');
return {
coreRefs: {
...actualModule.coreRefs,
dslService: {
fetchFields: jest.fn().mockResolvedValue({ data: 'mockFieldData' }),
fetchSettings: jest.fn().mockResolvedValue({ data: 'mockSettingsData' }),
fetchIndices: jest.fn().mockResolvedValue({ data: 'mockIndexData' }),
},
},
};
});

jest.mock('../../../../framework/core_refs', () => {
return {
coreRefs: {
dslService: {
fetchFields: jest.fn().mockResolvedValue({ data: 'mockFieldData' }),
fetchSettings: jest.fn().mockResolvedValue({ data: 'mockSettingsData' }),
fetchIndices: jest.fn().mockResolvedValue({
status: 'fulfilled',
action: 'getIndexInfo',
data: [
{
health: 'yellow',
status: 'open',
index: 'flint_mys3_default_http_count_view',
uuid: 'VImREbK4SMqJ-i6hSB84eQ',
pri: '1',
rep: '1',
'docs.count': '0',
'docs.deleted': '0',
'store.size': '208b',
'pri.store.size': '208b',
},
],
}),
},
},
};
});

const mockAcceleration = {
index: 'mockIndex',
dataSourceName: 'mockDataSource',
acceleration: {
flintIndexName: 'testIndex',
},
};

configure({ adapter: new Adapter() });

describe('AccelerationDetailsFlyout Component Tests', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('fetches acceleration details on mount', async () => {
mount(<AccelerationDetailsFlyout acceleration={mockAcceleration} />);

expect(coreRefsModule.coreRefs.dslService!.fetchFields).toHaveBeenCalledWith('testIndex');
expect(coreRefsModule.coreRefs.dslService!.fetchSettings).toHaveBeenCalledWith('testIndex');
expect(coreRefsModule.coreRefs.dslService!.fetchIndices).toHaveBeenCalledWith('testIndex');
});

it('switches tabs correctly', async () => {
const wrapper = mount(<AccelerationDetailsFlyout acceleration={mockAcceleration} />);
await new Promise(setImmediate);
wrapper.update();

const schemaTabExists = wrapper.find('EuiTab').someWhere((node) => node.text() === 'Schema');
expect(schemaTabExists).toBeTruthy();

const schemaTab = wrapper.find('EuiTab').filterWhere((node) => node.text() === 'Schema');
schemaTab.simulate('click');
await new Promise(setImmediate);
wrapper.update();

expect(wrapper.find('AccelerationSchemaTab').exists()).toBe(true);

// TODO: SQL DEFINATION TAB CHECK
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { mount, configure } from 'enzyme';
import { EuiLoadingSpinner } from '@elastic/eui';
import { AccelerationTable } from '../manage/accelerations/acceleration_table';
import { act } from 'react-dom/test-utils';
import Adapter from 'enzyme-adapter-react-16';
import { ACC_LOADING_MSG } from '../manage/accelerations/utils/acceleration_utils';
import { ReactWrapper } from 'enzyme';

const accelerationCache = {
accelerations: [
{
flintIndexName: 'flint_mys3_default_http_count_view',
type: 'materialized',
database: 'default',
table: null,
indexName: 'http_count_view',
autoRefresh: true,
status: 'refreshing',
},
{
flintIndexName: 'flint_mys3_default_http_count_view_alt',
type: 'materialized',
database: 'default',
table: null,
indexName: 'http_count_view_alt',
autoRefresh: true,
status: 'refreshing',
},
{
flintIndexName: 'flint_mys3_default_http_logs',
type: 'materialized',
database: 'default',
table: null,
indexName: 'http_logs',
autoRefresh: true,
status: 'deleted',
},
{
flintIndexName: 'flint_mys3_default_http_logs_skipping_index',
type: 'skipping',
database: 'default',
table: 'http_logs',
indexName: null,
autoRefresh: false,
status: 'active',
},
{
flintIndexName: 'flint_mys3_other_http_count_view',
type: 'materialized',
database: 'other',
table: null,
indexName: 'http_count_view',
autoRefresh: true,
status: 'refreshing',
},
],
lastUpdated: 'Thu, 14 Mar 2024 04:05:53 GMT',
status: 'Updated',
};

jest.mock('../../../../framework/catalog_cache/cache_manager', () => ({
CatalogCacheManager: {
getOrCreateAccelerationsByDataSource: jest.fn().mockReturnValue(accelerationCache),
},
}));

jest.mock('../../../../framework/catalog_cache/cache_loader', () => ({
useLoadAccelerationsToCache: jest.fn(() => ({
loadStatus: 'success',
startLoading: jest.fn(),
})),
}));

jest.mock('../../../../plugin', () => ({
getRenderAccelerationDetailsFlyout: jest.fn(() => jest.fn()),
}));

describe('AccelerationTable Component', () => {
configure({ adapter: new Adapter() });

it('renders without crashing', () => {
const wrapper = mount(<AccelerationTable dataSourceName="testDataSource" />);
expect(wrapper).toBeDefined();
});

it('shows loading spinner when refreshing accelerations', async () => {
jest.mock('../../../../framework/catalog_cache/cache_loader', () => ({
useLoadAccelerationsToCache: jest.fn(() => ({
loadStatus: 'loading',
startLoading: jest.fn(),
})),
}));

let wrapper: ReactWrapper;
await act(async () => {
wrapper = mount(<AccelerationTable dataSourceName="testDataSource" />);
});

wrapper!.update();

await act(async () => {
wrapper!.find('[data-test-subj="refreshButton"]').simulate('click');
});
wrapper!.update();

expect(wrapper!.find(EuiLoadingSpinner).exists()).toBe(true);
expect(wrapper!.text()).toContain(ACC_LOADING_MSG);

jest.restoreAllMocks();
});

it('correctly displays accelerations in the table', async () => {
let wrapper: ReactWrapper;
await act(async () => {
wrapper = mount(<AccelerationTable dataSourceName="testDataSource" />);
});
wrapper!.update();

const tableRows = wrapper!.find('EuiTableRow');
expect(tableRows.length).toBe(accelerationCache.accelerations.length);
});

it('filters rows based on active status correctly', async () => {
jest.mock('../../../../framework/catalog_cache/cache_loader', () => ({
useLoadAccelerationsToCache: jest.fn(() => ({
loadStatus: 'loading',
startLoading: jest.fn(),
})),
}));

let wrapper: ReactWrapper;
await act(async () => {
wrapper = mount(<AccelerationTable dataSourceName="testDataSource" />);
await new Promise((resolve) => setTimeout(resolve, 0));
wrapper!.update();
});

const activeStatusRows = wrapper!.find('tr.euiTableRow').filterWhere((node) => {
return node.find('.euiFlexItem').someWhere((subNode) => subNode.text() === 'active');
});

expect(activeStatusRows.length).toBe(
accelerationCache.accelerations.filter((acc) => acc.status === 'active').length
);
jest.restoreAllMocks();
});

it('displays updated time correctly', async () => {
let wrapper: ReactWrapper;
await act(async () => {
wrapper = mount(<AccelerationTable dataSourceName="testDataSource" />);
});
wrapper!.update();

expect(wrapper!.text()).toContain(accelerationCache.lastUpdated);
});
});
Loading
Loading