Skip to content

Commit

Permalink
remove unused tests
Browse files Browse the repository at this point in the history
Signed-off-by: Eric <[email protected]>
  • Loading branch information
mengweieric committed Oct 6, 2023
1 parent 5ab664b commit bea8e75
Showing 1 changed file with 1 addition and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,9 @@

import React from 'react';
import { render, act } from '@testing-library/react';
import {
DataSourceSelectable,
getSourceOptions,
fetchDataSetWithSource,
isIndexPatterns,
} from './datasource_selectable';
import { DataSourceSelectable } from './datasource_selectable';
import { DataSourceType, GenericDataSource } from '../datasource_services';
import { DataSourceGroup, DataSourceOption } from './types';
import { DataSource } from '../datasource/datasource';
import { IndexPatternsService } from '../../index_patterns';

class MockDataSource extends DataSource<any, any, any, any, any> {
private readonly indexPattern;

constructor({
name,
type,
metadata,
indexPattern,
}: {
name: string;
type: string;
metadata: any;
indexPattern: IndexPatternsService;
}) {
super(name, type, metadata);
this.indexPattern = indexPattern;
}

async getDataSet(dataSetParams?: any) {
await this.indexPattern.ensureDefaultIndexPattern();
return await this.indexPattern.getCache();
}

async testConnection(): Promise<boolean> {
return true;
}

async runQuery(queryParams: any) {
return undefined;
}
}

const mockIndexPattern = {} as IndexPatternsService;

const mockConfig = {
name: 'test_datasource1',
type: 'mock1',
metadata: null,
indexPattern: mockIndexPattern,
};

describe('DataSourceSelectable', () => {
let dataSourcesMock: GenericDataSource[];
Expand All @@ -64,25 +16,6 @@ describe('DataSourceSelectable', () => {
let setSelectedSourcesMock: (sources: DataSourceOption[]) => void = jest.fn();
let setDataSourceOptionListMock: (sources: DataSourceGroup[]) => void = jest.fn();
let onFetchDataSetErrorMock: (error: Error) => void = jest.fn();
const mockDataSources = {
getType: jest.fn().mockReturnValue('type1'),
getName: jest.fn().mockReturnValue('source1'),
};

it('should fetch data set and return structured data', async () => {
const mockDs = {
getDataSet: jest.fn().mockResolvedValue(['dataItem1', 'dataItem2']),
getType: jest.fn(),
getName: jest.fn(),
};

const result = await fetchDataSetWithSource(mockDs as any);
expect(result).toEqual({
ds: mockDs,
data_sets: ['dataItem1', 'dataItem2'],
});
});
const ds = new MockDataSource(mockConfig);

beforeEach(() => {
dataSourcesMock = [
Expand Down Expand Up @@ -148,78 +81,4 @@ describe('DataSourceSelectable', () => {

expect(onFetchDataSetErrorMock).toHaveBeenCalledWith(new Error('Fetch error'));
});

it('returns the matched option when found', () => {
const allDataSets = [
{
ds: mockDataSources,
data_sets: [
{ title: 'index1', id: 'id1' },
{ title: 'index', id: 'id2' },
],
},
{
ds: mockDataSources,
data_sets: [
{ title: 'index1', id: 'id1' },
{ title: 'index', id: 'id2' },
],
},
];

const result = getSourceOptions(ds, allDataSets);
const expected = [
{
label: 'Type Display Name for type1 or Default Group', // Assuming your DATASOURCE_TYPE_DISPLAY_NAME_MAP maps type1 to this
options: [
{ label: 'index1', value: 'id1', type: 'type1', name: 'source1', ds: mockDataSources },
{ label: 'index1', value: 'id2', type: 'type1', name: 'source1', ds: mockDataSources },
],
},
];

expect(result).toEqual(expected);
});

it('handles nested data source groups correctly', () => {
const allDataSets = [
// ... Your mock data that tests the nested group handling ...
];

const result = getSourceOptions(allDataSets);

// Write your expected output here
const expected = [
// ... Your expected data source groups ...
];

expect(result).toEqual(expected);
});

it('returns undefined in option value when no match is found', () => {
const allDataSets = [
{
ds: mockDataSources,
data_sets: ['data1'], // This should not match because it's a string
},
];

const result = getSourceOptions(allDataSets);
const expected = [
{
label: 'Type Display Name for type1 or Default Group',
options: [
{
label: 'source1',
value: 'source1',
type: 'type1',
name: 'source1',
ds: mockDataSources,
},
],
},
];

expect(result).toEqual(expected);
});
});

0 comments on commit bea8e75

Please sign in to comment.