-
Notifications
You must be signed in to change notification settings - Fork 894
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add loading indicator and counter to query result (#8212)
* add loading indicator and counter to query result Signed-off-by: abbyhu2000 <[email protected]> * Changeset file for PR #8212 created/updated * add unit tests Signed-off-by: abbyhu2000 <[email protected]> * address comments Signed-off-by: abbyhu2000 <[email protected]> * update snapshot Signed-off-by: abbyhu2000 <[email protected]> --------- Signed-off-by: abbyhu2000 <[email protected]> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> (cherry picked from commit 27ba36c) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1f9ec15
commit d9373d8
Showing
5 changed files
with
252 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
feat: | ||
- Add loading indicator and counter to query result ([#8212](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8212)) |
62 changes: 62 additions & 0 deletions
62
...a/public/query/query_string/language_service/lib/__snapshots__/query_result.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
109 changes: 109 additions & 0 deletions
109
src/plugins/data/public/query/query_string/language_service/lib/query_result.test.tsx
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,109 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { mountWithIntl, shallowWithIntl } from 'test_utils/enzyme_helpers'; | ||
import { QueryResult } from './query_result'; | ||
|
||
enum ResultStatus { | ||
UNINITIALIZED = 'uninitialized', | ||
LOADING = 'loading', // initial data load | ||
READY = 'ready', // results came back | ||
NO_RESULTS = 'none', // no results came back | ||
ERROR = 'error', // error occurred | ||
} | ||
|
||
describe('Query Result', () => { | ||
it('shows loading status', () => { | ||
const props = { | ||
queryStatus: { | ||
status: ResultStatus.LOADING, | ||
startTime: Number.NEGATIVE_INFINITY, | ||
}, | ||
}; | ||
const component = shallowWithIntl(<QueryResult {...props} />); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
it('shows ready status with complete message', () => { | ||
const props = { | ||
queryStatus: { | ||
status: ResultStatus.READY, | ||
startTime: new Date().getTime(), | ||
}, | ||
}; | ||
const component = mountWithIntl(<QueryResult {...props} />); | ||
const loadingIndicator = component.find(`[data-test-subj="queryResultLoading"]`); | ||
expect(loadingIndicator.exists()).toBeFalsy(); | ||
expect(component.find('EuiText').text()).toEqual('Completed'); | ||
}); | ||
|
||
it('shows ready status with complete in miliseconds message', () => { | ||
const props = { | ||
queryStatus: { | ||
status: ResultStatus.READY, | ||
startTime: new Date().getTime(), | ||
elapsedMs: 500, | ||
}, | ||
}; | ||
const component = mountWithIntl(<QueryResult {...props} />); | ||
expect(component.find('EuiText').text()).toEqual('Completed in 500 ms'); | ||
}); | ||
|
||
it('shows ready status with complete in seconds message', () => { | ||
const props = { | ||
queryStatus: { | ||
status: ResultStatus.READY, | ||
startTime: new Date().getTime(), | ||
elapsedMs: 2000, | ||
}, | ||
}; | ||
const component = mountWithIntl(<QueryResult {...props} />); | ||
expect(component.find('EuiText').text()).toEqual('Completed in 2.0 s'); | ||
}); | ||
|
||
it('shows ready status with split seconds', () => { | ||
const props = { | ||
queryStatus: { | ||
status: ResultStatus.READY, | ||
startTime: new Date().getTime(), | ||
elapsedMs: 2700, | ||
}, | ||
}; | ||
const component = mountWithIntl(<QueryResult {...props} />); | ||
expect(component.find('EuiText').text()).toEqual('Completed in 2.7 s'); | ||
}); | ||
|
||
it('show error status with error message', () => { | ||
const props = { | ||
queryStatus: { | ||
status: ResultStatus.ERROR, | ||
body: { | ||
error: { | ||
reason: 'error reason', | ||
details: 'error details', | ||
}, | ||
statusCode: 400, | ||
}, | ||
}, | ||
}; | ||
const component = shallowWithIntl(<QueryResult {...props} />); | ||
expect(component.find(`[data-test-subj="queryResultError"]`).text()).toMatchInlineSnapshot( | ||
`"<EuiPopover />"` | ||
); | ||
component.find(`[data-test-subj="queryResultError"]`).simulate('click'); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
it('returns null when error body is empty', () => { | ||
const props = { | ||
queryStatus: { | ||
status: ResultStatus.ERROR, | ||
}, | ||
}; | ||
const component = shallowWithIntl(<QueryResult {...props} />); | ||
expect(component).toEqual({}); | ||
}); | ||
}); |
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