Skip to content

Commit

Permalink
[Multiple Datasource Test]Add test for toast button and validation fo…
Browse files Browse the repository at this point in the history
…rm (#6755)

* add test for toast button and validation form

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* Changeset file for PR #6755 created/updated

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* Update src/plugins/data_source_management/public/components/toast_button/manage_data_source_button.tsx

Co-authored-by: Lu Yu <nluyu@amazon.com>
Signed-off-by: Yu Jin <112784385+yujin-emma@users.noreply.github.com>
Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* Update manage_data_source_button.test.tsx

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* [Multiple Datasource Test] Add test for edit data source form (#6742)

* add test for edit data source form

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* Changeset file for PR #6742 created/updated

---------

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* [MQL] support enhancing language selector (#6613)

Enable with `data.enhancements.enabled: true`

Allows for enhancing the data plugin UI service and search service.

#### Remaining work
* Address issue with time range being invalid if previous state successfully queried and set it with a time range format that is invalid for the new query language
  * For example, DQL with quick time range (4 weeks to now), get results. Switch to PPL, even though PPL has a default time range enhancement. The props date range saved in the app state takes priority and sets the time range to quick range causing an error. I can still modify the time range and get a successful query but it will first fail until the user updates it to a non quick time range.
* Add tests
* Disable for plugins that do not support the functionality
  * By default index patterns are created with a unique ID. However, it can be enabled to create an index pattern with a custom ID that matches the name of the index pattern (which in turn maps to indices).
  * For seamless integration, the temp data frame would need to check if the index pattern that maps to the data frame name. And get it's id.
  * This means that dashboards with visualizations that were created with an index pattern unique ID still require the existing index pattern to exist in memory.

### Issues Resolved

closes #6639
closes #6311

partially resolves:
#5504

* add error data frame

Signed-off-by: Paul Sebastian <paulstn@amazon.com>

move language to left, some styling and disable per app name

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>

---------

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
Signed-off-by: Paul Sebastian <paulstn@amazon.com>
Co-authored-by: Paul Sebastian <paulstn@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* Make Field Name Search Filter Case Insensitive (#6759)

* Make Field Name Filter Case Insensitive

Signed-off-by: Suchit Sahoo <suchsah@amazon.com>

* Changeset file for PR #6759 created/updated

---------

Signed-off-by: Suchit Sahoo <suchsah@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

* address naming for manage data source button test id

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>

---------

Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
Signed-off-by: Yu Jin <112784385+yujin-emma@users.noreply.github.com>
Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
Signed-off-by: Paul Sebastian <paulstn@amazon.com>
Signed-off-by: Suchit Sahoo <suchsah@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Co-authored-by: Lu Yu <nluyu@amazon.com>
Co-authored-by: Kawika Avilla <kavilla414@gmail.com>
Co-authored-by: Paul Sebastian <paulstn@amazon.com>
Co-authored-by: Suchit Sahoo <38322563+LDrago27@users.noreply.github.com>
(cherry picked from commit f728b5a)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
6 people committed May 16, 2024
1 parent a44bf8e commit 6629a5f
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/6755.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Add test for toast button and validation form ([#6755](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6755))
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { shallow } from 'enzyme';
import { getManageDataSourceButton } from './manage_data_source_button';
import { coreMock } from '../../../../../core/public/mocks';
import { DSM_APP_ID } from '../../plugin';
import { render } from '@testing-library/react';

describe('ManageDataSourceButton', () => {
const applicationMock = coreMock.createStart().application;

it('renders without crashing', () => {
const wrapper = render(getManageDataSourceButton());
expect(wrapper).toBeTruthy();
});

it('renders a button with correct label', () => {
const { getByTestId } = render(getManageDataSourceButton(applicationMock));
const container = getByTestId('manageDataSourceButtonContainer');
expect(container).toBeInTheDocument();
expect(container).toHaveTextContent('Manage data sources');
});

it('navigates to management app on button click', () => {
const { getByTestId } = render(getManageDataSourceButton(applicationMock));
const button = getByTestId('manageDataSourceButton');
button.click();
expect(applicationMock.navigateToApp).toHaveBeenCalledTimes(1);

expect(applicationMock.navigateToApp).toHaveBeenCalledWith('management', {
path: `opensearch-dashboards/${DSM_APP_ID}`, // Assuming DSM_APP_ID is replaced with a value
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ import { DSM_APP_ID } from '../../plugin';
export const getManageDataSourceButton = (application?: ApplicationStart) => {
return (
<>
<EuiFlexGroup justifyContent="flexEnd" gutterSize="s">
<EuiFlexGroup
data-test-subj="manageDataSourceButtonContainer"
justifyContent="flexEnd"
gutterSize="s"
>
<EuiFlexItem grow={false}>
<EuiButton
data-test-subj="manageDataSourceButton"
size="s"
onClick={() =>
application?.navigateToApp('management', {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { render, fireEvent } from '@testing-library/react';
import { getReloadButton } from './reload_button';

describe('getReloadButton', () => {
it('renders button with correct label', () => {
const { getByText } = render(getReloadButton());
expect(getByText('Refresh the page')).toBeInTheDocument();
});

it('calls window.location.reload() on button click', () => {
const reloadMock = jest.fn();
Object.defineProperty(window, 'location', {
value: { reload: reloadMock },
writable: true,
});

const { getByText } = render(getReloadButton());
fireEvent.click(getByText('Refresh the page'));
expect(reloadMock).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import { AuthType } from '../../types';
import { CreateDataSourceState } from '../create_data_source_wizard/components/create_form/create_data_source_form';
import { EditDataSourceState } from '../edit_data_source/components/edit_form/edit_data_source_form';
import { defaultValidation, performDataSourceFormValidation } from './datasource_form_validation';
import { mockDataSourceAttributesWithAuth } from '../../mocks';
import {
mockDataSourceAttributesWithAuth,
mockDataSourceAttributesWithSigV4Auth,
} from '../../mocks';
import { AuthenticationMethod, AuthenticationMethodRegistry } from '../../auth_registry';

describe('DataSourceManagement: Form Validation', () => {
describe('validate create/edit datasource', () => {
describe('validate create/edit datasource for Username and Password auth type', () => {
let authenticationMethodRegistry = new AuthenticationMethodRegistry();
let form: CreateDataSourceState | EditDataSourceState = {
formErrorsByField: { ...defaultValidation },
Expand Down Expand Up @@ -117,4 +120,113 @@ describe('DataSourceManagement: Form Validation', () => {
expect(result).toBe(true);
});
});

describe('validate create/edit datasource for SigV4 auth type', () => {
let authenticationMethodRegistry = new AuthenticationMethodRegistry();
let form: CreateDataSourceState | EditDataSourceState = {
formErrorsByField: { ...defaultValidation },
title: '',
description: '',
endpoint: '',
auth: {
type: AuthType.SigV4,
credentials: {
accesskey: 'test123',
secretKey: 'test123',
service: 'es',
region: 'us-east-1',
},
},
};
test('should fail validation when title is empty', () => {
const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry);
expect(result).toBe(false);
});
test('should fail validation on duplicate title', () => {
form.title = 'test';
const result = performDataSourceFormValidation(
form,
['oldTitle', 'test'],
'oldTitle',
authenticationMethodRegistry
);
expect(result).toBe(false);
});
test('should fail validation when title is longer than 32 characters', () => {
form.title = 'test'.repeat(10);
const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry);
expect(result).toBe(false);
});
test('should fail validation when endpoint is not valid', () => {
form.endpoint = mockDataSourceAttributesWithSigV4Auth.endpoint;
const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry);
expect(result).toBe(false);
});
test('should fail validation when accesskey is empty', () => {
form.auth.credentials!.accessKey = 'test';
const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry);
expect(result).toBe(false);
});
test('should fail validation when secrectKey is empty', () => {
form.auth.credentials!.accessKey = 'test';
form.auth.credentials!.secretKey = '';
const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry);
expect(result).toBe(false);
});
test('should NOT fail validation on empty accesskey/secretKey when No Auth is selected', () => {
form.auth.type = AuthType.NoAuth;
form.title = 'test';
form.endpoint = mockDataSourceAttributesWithSigV4Auth.endpoint;
const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry);
expect(result).toBe(true);
});
test('should NOT fail validation on all fields', () => {
form = { ...form, ...mockDataSourceAttributesWithSigV4Auth };
const result = performDataSourceFormValidation(
form,
[mockDataSourceAttributesWithSigV4Auth.title],
mockDataSourceAttributesWithSigV4Auth.title,
authenticationMethodRegistry
);
expect(result).toBe(true);
});
test('should NOT fail validation when registered auth type is selected and related credential field not empty', () => {
authenticationMethodRegistry = new AuthenticationMethodRegistry();
const authMethodToBeTested = {
name: 'Some Auth Type',
credentialSourceOption: {
value: 'Some Auth Type',
inputDisplay: 'some input',
},
credentialForm: jest.fn(),
credentialFormField: {
userNameRegistered: 'some filled in userName from registed auth credential form',
passWordRegistered: 'some filled in password from registed auth credential form',
},
} as AuthenticationMethod;

authenticationMethodRegistry.registerAuthenticationMethod(authMethodToBeTested);

const formWithRegisteredAuth: CreateDataSourceState | EditDataSourceState = {
formErrorsByField: { ...defaultValidation },
title: 'test registered auth type',
description: '',
endpoint: 'https://test.com',
auth: {
type: 'Some Auth Type',
credentials: {
userNameRegistered: 'some filled in userName from registed auth credential form',
passWordRegistered: 'some filled in password from registed auth credential form',
},
},
};
const result = performDataSourceFormValidation(
formWithRegisteredAuth,
[],
'',
authenticationMethodRegistry
);
expect(result).toBe(true);
});
});
});
1 change: 1 addition & 0 deletions src/plugins/data_source_management/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export const mockDataSourceAttributesWithSigV4Auth = {
accessKey: 'test123',
secretKey: 'test123',
region: 'us-east-1',
service: 'es',
},
},
};
Expand Down

0 comments on commit 6629a5f

Please sign in to comment.