Skip to content

Commit

Permalink
UTs for newSavedQueries UI
Browse files Browse the repository at this point in the history
Signed-off-by: Riya Saxena <riysaxen@amazon.com>
  • Loading branch information
riysaxen-amzn committed Nov 3, 2024
1 parent ed9fcae commit dbeeb88
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
4 changes: 0 additions & 4 deletions src/plugins/data/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ describe('#DataPublicPlugin setup', () => {
};

beforeEach(() => {
// Define the initializer context with all necessary config
const initializerContext = {
config: {
get: jest.fn().mockReturnValue({
Expand All @@ -49,10 +48,8 @@ describe('#DataPublicPlugin setup', () => {
},
};

// Create a new instance of DataPublicPlugin with the initializer context
plugin = new DataPublicPlugin(initializerContext);

// Mock the core setup
coreSetup = {
...coreMock.createSetup({ pluginStartContract: mockDataPublicPluginStart }),
uiSettings: {
Expand All @@ -77,7 +74,6 @@ describe('#DataPublicPlugin setup', () => {
coreStart = coreMock.createStart();
});

// Add the actual test case
it('should setup the plugin and set useNewSavedQueriesUI', () => {
const setupContract = plugin.setup(coreSetup, {
expressions: expressionsMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,13 @@ describe('saved query service', () => {

describe('saveQuery', function () {
it('should create a saved object for the given attributes', async () => {
// Mock the response for the saved objects client
mockSavedObjectsClient.create.mockReturnValue({
id: 'foo',
attributes: savedAttributesWithTemplate,
});

const response = await saveQuery(savedAttributesWithTemplate);

// Assert the creation with the correct structure
expect(mockSavedObjectsClient.create).toHaveBeenCalledWith(
'query',
{
Expand Down Expand Up @@ -223,7 +221,6 @@ describe('saved query service', () => {
expect(error).not.toBe(null);
});
it('should include dataset in the query when query enhancement is enabled and dataset exists', async () => {
// Mock the behavior
uiSettingsServiceMock.createStartContract().get.mockReturnValue(true); // query enhancements enabled
getUseNewSavedQueriesUI.mockReturnValue(true); // using new saved queries UI

Expand All @@ -233,26 +230,23 @@ describe('saved query service', () => {
query: {
language: 'kuery',
query: 'response:200',
dataset: 'my_dataset', // Include the dataset
dataset: 'my_dataset',
},
isTemplate: false, // Ensure isTemplate is set correctly if needed
isTemplate: false,
};

// Adjust the return value to match what the saveQuery function is expected to create
mockSavedObjectsClient.create.mockReturnValue({
id: 'foo',
attributes: {
...savedQueryAttributesWithTemplate, // Spread the savedQueryAttributes to include all properties
...savedQueryAttributesWithTemplate,
query: {
...savedQueryAttributesWithTemplate.query, // Spread to ensure we keep all query properties
...savedQueryAttributesWithTemplate.query,
},
},
});

// Act
const response = await saveQuery(savedQueryAttributesWithTemplate);

// Assert
expect(response).toEqual({
id: 'foo',
attributes: {
Expand All @@ -261,13 +255,12 @@ describe('saved query service', () => {
query: {
language: 'kuery',
query: 'response:200',
dataset: 'my_dataset', // Ensure the dataset is included
dataset: 'my_dataset',
},
isTemplate: false, // Include isTemplate in the expected response
isTemplate: false,
},
});

// Ensure dataset is included
expect(mockSavedObjectsClient.create).toHaveBeenCalledWith(
'query',
expect.objectContaining({
Expand Down Expand Up @@ -311,7 +304,6 @@ describe('saved query service', () => {
},
});

// Ensure isTemplate is included
expect(mockSavedObjectsClient.create).toHaveBeenCalledWith(
'query',
expect.objectContaining({
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/data_source_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { i18n } from '@osd/i18n';
Expand Down

0 comments on commit dbeeb88

Please sign in to comment.