-
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.
Merge branch 'master' into by-value-export-references
- Loading branch information
Showing
40 changed files
with
4,151,287 additions
and
174 deletions.
There are no files selected for viewing
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
11 changes: 11 additions & 0 deletions
11
...a/public/kibana-plugin-plugins-data-public.searchsourcefields.tracktotalhits.md
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,11 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchSourceFields](./kibana-plugin-plugins-data-public.searchsourcefields.md) > [trackTotalHits](./kibana-plugin-plugins-data-public.searchsourcefields.tracktotalhits.md) | ||
|
||
## SearchSourceFields.trackTotalHits property | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
trackTotalHits?: boolean | number; | ||
``` |
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
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
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
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
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
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
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
177 changes: 177 additions & 0 deletions
177
...rprise_search/public/applications/app_search/components/curations/curations_logic.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,177 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { LogicMounter, mockHttpValues, mockFlashMessageHelpers } from '../../../__mocks__'; | ||
import '../../__mocks__/engine_logic.mock'; | ||
|
||
import { nextTick } from '@kbn/test/jest'; | ||
|
||
import { DEFAULT_META } from '../../../shared/constants'; | ||
|
||
import { CurationsLogic } from './'; | ||
|
||
describe('CurationsLogic', () => { | ||
const { mount } = new LogicMounter(CurationsLogic); | ||
const { http } = mockHttpValues; | ||
const { clearFlashMessages, setSuccessMessage, flashAPIErrors } = mockFlashMessageHelpers; | ||
|
||
const MOCK_CURATIONS_RESPONSE = { | ||
meta: { | ||
page: { | ||
current: 1, | ||
size: 10, | ||
total_results: 1, | ||
total_pages: 1, | ||
}, | ||
}, | ||
results: [ | ||
{ | ||
id: 'some-curation-id', | ||
last_updated: 'January 1, 1970 at 12:00PM', | ||
queries: ['some query'], | ||
promoted: [], | ||
hidden: [], | ||
organic: [], | ||
}, | ||
], | ||
}; | ||
|
||
const DEFAULT_VALUES = { | ||
dataLoading: true, | ||
curations: [], | ||
meta: DEFAULT_META, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('has expected default values', () => { | ||
mount(); | ||
expect(CurationsLogic.values).toEqual(DEFAULT_VALUES); | ||
}); | ||
|
||
describe('actions', () => { | ||
describe('onCurationsLoad', () => { | ||
it('should set curations and meta state, & dataLoading to false', () => { | ||
mount(); | ||
|
||
CurationsLogic.actions.onCurationsLoad(MOCK_CURATIONS_RESPONSE); | ||
|
||
expect(CurationsLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
curations: MOCK_CURATIONS_RESPONSE.results, | ||
meta: MOCK_CURATIONS_RESPONSE.meta, | ||
dataLoading: false, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('onPaginate', () => { | ||
it('should set meta.page.current state', () => { | ||
mount(); | ||
|
||
CurationsLogic.actions.onPaginate(3); | ||
|
||
expect(CurationsLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
meta: { page: { ...DEFAULT_VALUES.meta.page, current: 3 } }, | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('listeners', () => { | ||
describe('loadCurations', () => { | ||
it('should set dataLoading state', () => { | ||
mount({ dataLoading: false }); | ||
|
||
CurationsLogic.actions.loadCurations(); | ||
|
||
expect(CurationsLogic.values).toEqual({ | ||
...DEFAULT_VALUES, | ||
dataLoading: true, | ||
}); | ||
}); | ||
|
||
it('should make an API call and set curations & meta state', async () => { | ||
http.get.mockReturnValueOnce(Promise.resolve(MOCK_CURATIONS_RESPONSE)); | ||
mount(); | ||
jest.spyOn(CurationsLogic.actions, 'onCurationsLoad'); | ||
|
||
CurationsLogic.actions.loadCurations(); | ||
await nextTick(); | ||
|
||
expect(http.get).toHaveBeenCalledWith('/api/app_search/engines/some-engine/curations', { | ||
query: { | ||
'page[current]': 1, | ||
'page[size]': 10, | ||
}, | ||
}); | ||
expect(CurationsLogic.actions.onCurationsLoad).toHaveBeenCalledWith( | ||
MOCK_CURATIONS_RESPONSE | ||
); | ||
}); | ||
|
||
it('handles errors', async () => { | ||
http.get.mockReturnValueOnce(Promise.reject('error')); | ||
mount(); | ||
|
||
CurationsLogic.actions.loadCurations(); | ||
await nextTick(); | ||
|
||
expect(flashAPIErrors).toHaveBeenCalledWith('error'); | ||
}); | ||
}); | ||
|
||
describe('deleteCurationSet', () => { | ||
const confirmSpy = jest.spyOn(window, 'confirm'); | ||
|
||
beforeEach(() => { | ||
confirmSpy.mockImplementation(jest.fn(() => true)); | ||
}); | ||
|
||
it('should make an API call and show a success message', async () => { | ||
http.delete.mockReturnValueOnce(Promise.resolve({})); | ||
mount(); | ||
jest.spyOn(CurationsLogic.actions, 'loadCurations'); | ||
|
||
CurationsLogic.actions.deleteCurationSet('some-curation-id'); | ||
expect(clearFlashMessages).toHaveBeenCalled(); | ||
await nextTick(); | ||
|
||
expect(http.delete).toHaveBeenCalledWith( | ||
'/api/app_search/engines/some-engine/curations/some-curation-id' | ||
); | ||
expect(CurationsLogic.actions.loadCurations).toHaveBeenCalled(); | ||
expect(setSuccessMessage).toHaveBeenCalledWith('Successfully removed curation.'); | ||
}); | ||
|
||
it('handles errors', async () => { | ||
http.delete.mockReturnValueOnce(Promise.reject('error')); | ||
mount(); | ||
|
||
CurationsLogic.actions.deleteCurationSet('some-curation-id'); | ||
expect(clearFlashMessages).toHaveBeenCalled(); | ||
await nextTick(); | ||
|
||
expect(flashAPIErrors).toHaveBeenCalledWith('error'); | ||
}); | ||
|
||
it('does nothing if the user cancels the confirmation prompt', async () => { | ||
confirmSpy.mockImplementationOnce(() => false); | ||
mount(); | ||
|
||
CurationsLogic.actions.deleteCurationSet('some-curation-id'); | ||
expect(clearFlashMessages).toHaveBeenCalled(); | ||
await nextTick(); | ||
|
||
expect(http.delete).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.