mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* Fix field stats not loaded without time field * Add integration test for API * Add unit test for API call * Correct typo in comment
This commit is contained in:
parent
6f0ed422cf
commit
8b8e258a89
3 changed files with 45 additions and 5 deletions
|
@ -90,6 +90,24 @@ describe('IndexPattern Field Item', () => {
|
|||
} as unknown) as FieldFormatsStart;
|
||||
});
|
||||
|
||||
it('should request field stats without a time field, if the index pattern has none', async () => {
|
||||
indexPattern.timeFieldName = undefined;
|
||||
core.http.post.mockImplementationOnce(() => {
|
||||
return Promise.resolve({});
|
||||
});
|
||||
const wrapper = mountWithIntl(<FieldItem {...defaultProps} />);
|
||||
wrapper.find('[data-test-subj="lnsFieldListPanelField-bytes"]').simulate('click');
|
||||
|
||||
expect(core.http.post).toHaveBeenCalledWith(
|
||||
'/api/lens/index_stats/my-fake-index-pattern/field',
|
||||
expect.anything()
|
||||
);
|
||||
// Function argument types not detected correctly (https://github.com/microsoft/TypeScript/issues/26591)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const { body } = (core.http.post.mock.calls[0] as any)[1];
|
||||
expect(JSON.parse(body)).not.toHaveProperty('timeFieldName');
|
||||
});
|
||||
|
||||
it('should request field stats every time the button is clicked', async () => {
|
||||
let resolveFunction: (arg: unknown) => void;
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ export async function initFieldsRoute(setup: CoreSetup) {
|
|||
dslQuery: schema.object({}, { allowUnknowns: true }),
|
||||
fromDate: schema.string(),
|
||||
toDate: schema.string(),
|
||||
timeFieldName: schema.string(),
|
||||
timeFieldName: schema.maybe(schema.string()),
|
||||
field: schema.object(
|
||||
{
|
||||
name: schema.string(),
|
||||
|
@ -46,9 +46,8 @@ export async function initFieldsRoute(setup: CoreSetup) {
|
|||
const { fromDate, toDate, timeFieldName, field, dslQuery } = req.body;
|
||||
|
||||
try {
|
||||
const query = {
|
||||
bool: {
|
||||
filter: [
|
||||
const filter = timeFieldName
|
||||
? [
|
||||
{
|
||||
range: {
|
||||
[timeFieldName]: {
|
||||
|
@ -58,7 +57,12 @@ export async function initFieldsRoute(setup: CoreSetup) {
|
|||
},
|
||||
},
|
||||
dslQuery,
|
||||
],
|
||||
]
|
||||
: [dslQuery];
|
||||
|
||||
const query = {
|
||||
bool: {
|
||||
filter,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -47,6 +47,24 @@ export default ({ getService }: FtrProviderContext) => {
|
|||
.expect(404);
|
||||
});
|
||||
|
||||
it('should also work without specifying a time field', async () => {
|
||||
const { body } = await supertest
|
||||
.post('/api/lens/index_stats/logstash-2015.09.22/field')
|
||||
.set(COMMON_HEADERS)
|
||||
.send({
|
||||
dslQuery: { match_all: {} },
|
||||
fromDate: TEST_START_TIME,
|
||||
toDate: TEST_END_TIME,
|
||||
field: {
|
||||
name: 'bytes',
|
||||
type: 'number',
|
||||
},
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
expect(body).to.have.property('totalDocuments', 4633);
|
||||
});
|
||||
|
||||
it('should return an auto histogram for numbers and top values', async () => {
|
||||
const { body } = await supertest
|
||||
.post('/api/lens/index_stats/logstash-2015.09.22/field')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue