-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enterprise Search] Convert IndexingStatus to use logic for fetching #84710
Merged
scottybollinger
merged 8 commits into
elastic:master
from
scottybollinger:scottybollinger/indexing-status-logic
Dec 2, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c81c04e
Add IndexingStatusLogic
scottybollinger 887c195
Replace IndexingStatusFetcher with logic
scottybollinger 3d79dd3
Refactor out unnecessary conditional
scottybollinger a5efd2f
Misc styling - destructuring and typing
scottybollinger ec2b2c5
Misc styling - imports
scottybollinger d2f3a86
Remove div
scottybollinger 9a0095b
Refactor test
scottybollinger fa4f6e5
Replace method with string for statusPath
scottybollinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
64 changes: 0 additions & 64 deletions
64
.../enterprise_search/public/applications/shared/indexing_status/indexing_status_fetcher.tsx
This file was deleted.
Oops, something went wrong.
110 changes: 110 additions & 0 deletions
110
...nterprise_search/public/applications/shared/indexing_status/indexing_status_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,110 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { resetContext } from 'kea'; | ||
|
||
jest.mock('../http', () => ({ | ||
HttpLogic: { | ||
values: { http: { get: jest.fn() } }, | ||
}, | ||
})); | ||
import { HttpLogic } from '../http'; | ||
|
||
jest.mock('../flash_messages', () => ({ | ||
flashAPIErrors: jest.fn(), | ||
})); | ||
import { flashAPIErrors } from '../flash_messages'; | ||
|
||
import { IndexingStatusLogic } from './indexing_status_logic'; | ||
|
||
describe('IndexingStatusLogic', () => { | ||
let unmount: any; | ||
|
||
const mockStatusResponse = { | ||
percentageComplete: 50, | ||
numDocumentsWithErrors: 3, | ||
activeReindexJobId: 1, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
resetContext({}); | ||
unmount = IndexingStatusLogic.mount(); | ||
}); | ||
|
||
it('has expected default values', () => { | ||
expect(IndexingStatusLogic.values).toEqual({ | ||
percentageComplete: 100, | ||
numDocumentsWithErrors: 0, | ||
}); | ||
}); | ||
|
||
describe('setIndexingStatus', () => { | ||
it('sets reducers', () => { | ||
IndexingStatusLogic.actions.setIndexingStatus(mockStatusResponse); | ||
|
||
expect(IndexingStatusLogic.values.percentageComplete).toEqual( | ||
mockStatusResponse.percentageComplete | ||
); | ||
expect(IndexingStatusLogic.values.numDocumentsWithErrors).toEqual( | ||
mockStatusResponse.numDocumentsWithErrors | ||
); | ||
}); | ||
}); | ||
|
||
describe('fetchIndexingStatus', () => { | ||
jest.useFakeTimers(); | ||
const statusPath = '/api/workplace_search/path/123'; | ||
const onComplete = jest.fn(); | ||
const TIMEOUT = 3000; | ||
|
||
it('calls API and sets values', async () => { | ||
const setIndexingStatusSpy = jest.spyOn(IndexingStatusLogic.actions, 'setIndexingStatus'); | ||
const promise = Promise.resolve(mockStatusResponse); | ||
(HttpLogic.values.http.get as jest.Mock).mockReturnValue(promise); | ||
|
||
IndexingStatusLogic.actions.fetchIndexingStatus({ statusPath, onComplete }); | ||
jest.advanceTimersByTime(TIMEOUT); | ||
|
||
expect(HttpLogic.values.http.get).toHaveBeenCalledWith(statusPath); | ||
await promise; | ||
|
||
expect(setIndexingStatusSpy).toHaveBeenCalledWith(mockStatusResponse); | ||
}); | ||
|
||
it('handles error', async () => { | ||
const promise = Promise.reject('An error occured'); | ||
(HttpLogic.values.http.get as jest.Mock).mockReturnValue(promise); | ||
|
||
IndexingStatusLogic.actions.fetchIndexingStatus({ statusPath, onComplete }); | ||
jest.advanceTimersByTime(TIMEOUT); | ||
|
||
try { | ||
await promise; | ||
} catch { | ||
// Do nothing | ||
} | ||
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured'); | ||
}); | ||
|
||
it('handles indexing complete state', async () => { | ||
const promise = Promise.resolve({ ...mockStatusResponse, percentageComplete: 100 }); | ||
(HttpLogic.values.http.get as jest.Mock).mockReturnValue(promise); | ||
IndexingStatusLogic.actions.fetchIndexingStatus({ statusPath, onComplete }); | ||
jest.advanceTimersByTime(TIMEOUT); | ||
|
||
await promise; | ||
|
||
expect(clearInterval).toHaveBeenCalled(); | ||
expect(onComplete).toHaveBeenCalledWith(mockStatusResponse.numDocumentsWithErrors); | ||
}); | ||
|
||
it('handles unmounting', async () => { | ||
unmount(); | ||
expect(clearInterval).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
scottybollinger marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love how much easier this is to test w/o the render prop!! 🎉