Skip to content

Commit

Permalink
Fix types and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
stratoula committed Aug 12, 2022
1 parent 7c77bf1 commit b43a72a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugins/lens/public/indexpattern_datasource/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const createMockedIndexPattern = (): IndexPattern => {
hasRestrictions: false,
fields,
getFieldByName: getFieldByNameFactory(fields),
spec: undefined,
};
};

Expand Down Expand Up @@ -140,6 +141,7 @@ export const createMockedRestrictedIndexPattern = () => {
fieldFormatMap: { bytes: { id: 'bytes', params: { pattern: '0.0' } } },
fields,
getFieldByName: getFieldByNameFactory(fields),
spec: undefined,
typeMeta: {
params: {
rollup_index: 'my-fake-index-pattern',
Expand Down
13 changes: 9 additions & 4 deletions x-pack/plugins/lens/public/indexpattern_service/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('loader', () => {
id: 'foo',
title: 'Foo index',
metaFields: [],
isPersisted: () => true,
typeMeta: {
aggs: {
date_histogram: {
Expand Down Expand Up @@ -100,7 +101,8 @@ describe('loader', () => {
id: 'foo',
title: 'Foo index',
})),
} as unknown as Pick<DataViewsContract, 'get' | 'getIdsWithTitle'>,
create: jest.fn(),
} as unknown as Pick<DataViewsContract, 'get' | 'getIdsWithTitle' | 'create'>,
});

expect(cache.foo.getFieldByName('bytes')!.aggregationRestrictions).toEqual({
Expand All @@ -120,6 +122,7 @@ describe('loader', () => {
id: 'foo',
title: 'Foo index',
metaFields: ['timestamp'],
isPersisted: () => true,
typeMeta: {
aggs: {
date_histogram: {
Expand Down Expand Up @@ -156,7 +159,8 @@ describe('loader', () => {
id: 'foo',
title: 'Foo index',
})),
} as unknown as Pick<DataViewsContract, 'get' | 'getIdsWithTitle'>,
create: jest.fn(),
} as unknown as Pick<DataViewsContract, 'get' | 'getIdsWithTitle' | 'create'>,
});

expect(cache.foo.getFieldByName('timestamp')!.meta).toEqual(true);
Expand Down Expand Up @@ -198,12 +202,13 @@ describe('loader', () => {
timeFieldName: 'timestamp',
hasRestrictions: false,
fields: [],
isPersisted: () => true,
};
}
return Promise.reject();
}),
getIdsWithTitle: jest.fn(),
} as unknown as Pick<DataViewsContract, 'get' | 'getIdsWithTitle'>;
} as unknown as Pick<DataViewsContract, 'get' | 'getIdsWithTitle' | 'create'>;
const cache = await loadIndexPatterns({
cache: {},
patterns: ['1', '2'],
Expand Down Expand Up @@ -234,7 +239,7 @@ describe('loader', () => {
throw err;
}),
getIdsWithTitle: jest.fn(),
} as unknown as Pick<DataViewsContract, 'get' | 'getIdsWithTitle'>,
} as unknown as Pick<DataViewsContract, 'get' | 'getIdsWithTitle' | 'create'>,
onError,
});

Expand Down
11 changes: 9 additions & 2 deletions x-pack/plugins/lens/public/indexpattern_service/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const indexPattern1 = {
title: 'my-fake-index-pattern',
timeFieldName: 'timestamp',
hasRestrictions: false,
isPersisted: () => true,
fields: [
{
name: 'timestamp',
Expand Down Expand Up @@ -127,6 +128,7 @@ const indexPattern2 = {
title: 'my-fake-restricted-pattern',
timeFieldName: 'timestamp',
hasRestrictions: true,
isPersisted: () => true,
fieldFormatMap: { bytes: { id: 'bytes', params: { pattern: '0.0' } } },
fields: [
{
Expand Down Expand Up @@ -198,7 +200,11 @@ export const sampleIndexPatterns = {
export function mockDataViewsService() {
return {
get: jest.fn(async (id: '1' | '2') => {
const result = { ...sampleIndexPatternsFromService[id], metaFields: [] };
const result = {
...sampleIndexPatternsFromService[id],
metaFields: [],
isPersisted: () => true,
};
if (!result.fields) {
result.fields = [];
}
Expand All @@ -216,5 +222,6 @@ export function mockDataViewsService() {
},
];
}),
} as unknown as Pick<DataViewsContract, 'get' | 'getIdsWithTitle'>;
create: jest.fn(),
} as unknown as Pick<DataViewsContract, 'get' | 'getIdsWithTitle' | 'create'>;
}

0 comments on commit b43a72a

Please sign in to comment.