-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for new by value functionality
- Loading branch information
1 parent
adf14a0
commit b871cc8
Showing
6 changed files
with
492 additions
and
1 deletion.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
src/plugins/discover/common/embeddable/search_inject_extract.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { extract, inject } from './search_inject_extract'; | ||
|
||
describe('search inject extract', () => { | ||
describe('inject', () => { | ||
it('should not inject references if state does not have attributes', () => { | ||
const state = { type: 'type', id: 'id' }; | ||
const injectedReferences = [{ name: 'name', type: 'type', id: 'id' }]; | ||
expect(inject(state, injectedReferences)).toEqual(state); | ||
}); | ||
|
||
it('should inject references if state has references with the same name', () => { | ||
const state = { | ||
type: 'type', | ||
id: 'id', | ||
attributes: { | ||
references: [{ name: 'name', type: 'type', id: '1' }], | ||
}, | ||
}; | ||
const injectedReferences = [{ name: 'name', type: 'type', id: '2' }]; | ||
expect(inject(state, injectedReferences)).toEqual({ | ||
...state, | ||
attributes: { | ||
...state.attributes, | ||
references: injectedReferences, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should clear references if state has no references with the same name', () => { | ||
const state = { | ||
type: 'type', | ||
id: 'id', | ||
attributes: { | ||
references: [{ name: 'name', type: 'type', id: '1' }], | ||
}, | ||
}; | ||
const injectedReferences = [{ name: 'other', type: 'type', id: '2' }]; | ||
expect(inject(state, injectedReferences)).toEqual({ | ||
...state, | ||
attributes: { | ||
...state.attributes, | ||
references: [], | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('extract', () => { | ||
it('should not extract references if state does not have attributes', () => { | ||
const state = { type: 'type', id: 'id' }; | ||
expect(extract(state)).toEqual({ state, references: [] }); | ||
}); | ||
|
||
it('should extract references if state has references', () => { | ||
const state = { | ||
type: 'type', | ||
id: 'id', | ||
attributes: { | ||
references: [{ name: 'name', type: 'type', id: '1' }], | ||
}, | ||
}; | ||
expect(extract(state)).toEqual({ | ||
state, | ||
references: [{ name: 'name', type: 'type', id: '1' }], | ||
}); | ||
}); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
src/plugins/discover/public/embeddable/get_discover_locator_params.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { savedSearchMock } from '../__mocks__/saved_search'; | ||
import { getDiscoverLocatorParams } from './get_discover_locator_params'; | ||
import type { SearchInput } from './types'; | ||
|
||
describe('getDiscoverLocatorParams', () => { | ||
it('should return saved search id if input has savedObjectId', () => { | ||
const input = { savedObjectId: 'savedObjectId' } as SearchInput; | ||
expect(getDiscoverLocatorParams({ input, savedSearch: savedSearchMock })).toEqual({ | ||
savedSearchId: 'savedObjectId', | ||
}); | ||
}); | ||
|
||
it('should return Discover params if input has no savedObjectId', () => { | ||
const input = {} as SearchInput; | ||
expect(getDiscoverLocatorParams({ input, savedSearch: savedSearchMock })).toEqual({ | ||
dataViewId: savedSearchMock.searchSource.getField('index')?.id, | ||
dataViewSpec: savedSearchMock.searchSource.getField('index')?.toSpec(), | ||
timeRange: savedSearchMock.timeRange, | ||
refreshInterval: savedSearchMock.refreshInterval, | ||
filters: savedSearchMock.searchSource.getField('filter'), | ||
query: savedSearchMock.searchSource.getField('query'), | ||
columns: savedSearchMock.columns, | ||
sort: savedSearchMock.sort, | ||
viewMode: savedSearchMock.viewMode, | ||
hideAggregatedPreview: savedSearchMock.hideAggregatedPreview, | ||
breakdownField: savedSearchMock.breakdownField, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.