Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…7493) * Suffixing field names with colon. * Adding test cases. Co-authored-by: Dennis Oelkers <dennis@graylog.com>
- Loading branch information
1 parent
3df5bfd
commit f6251bf
Showing
2 changed files
with
51 additions
and
2 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
49 changes: 49 additions & 0 deletions
49
...og2-web-interface/src/views/components/searchbar/completions/FieldNameCompletion.test.jsx
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,49 @@ | ||
// @flow strict | ||
import { StoreMock as MockStore } from 'helpers/mocking'; | ||
import asMock from 'helpers/mocking/AsMock'; | ||
import { FieldTypesStore } from 'views/stores/FieldTypesStore'; | ||
|
||
import FieldNameCompletion from './FieldNameCompletion'; | ||
|
||
jest.mock('views/stores/FieldTypesStore', () => ({ | ||
FieldTypesStore: MockStore( | ||
'listen', | ||
['getInitialState', jest.fn(() => ({ all: [], queryFields: { get: () => [] } }))], | ||
), | ||
})); | ||
|
||
const _createField = name => ({ name, type: { type: 'string' } }); | ||
const dummyFields = ['source', 'message', 'timestamp'].map(_createField); | ||
|
||
const _createQueryFields = fields => ({ get: () => fields }); | ||
const _createFieldTypesStoreState = fields => ({ all: fields, queryFields: _createQueryFields(fields) }); | ||
|
||
describe('FieldNameCompletion', () => { | ||
beforeEach(() => { | ||
asMock(FieldTypesStore.getInitialState).mockReturnValue(_createFieldTypesStoreState(dummyFields)); | ||
}); | ||
it('returns empty list if inputs are empty', () => { | ||
asMock(FieldTypesStore.getInitialState).mockReturnValue(_createFieldTypesStoreState([])); | ||
|
||
const completer = new FieldNameCompletion(); | ||
expect(completer.getCompletions(null, null, '')).toEqual([]); | ||
}); | ||
|
||
it('returns matching fields if prefix is present in one field name', () => { | ||
const completer = new FieldNameCompletion(); | ||
expect(completer.getCompletions(null, null, 'mess').map(result => result.name)) | ||
.toEqual(['message']); | ||
}); | ||
|
||
it('returns matching fields if prefix is present in at least one field name', () => { | ||
const completer = new FieldNameCompletion(); | ||
expect(completer.getCompletions(null, null, 'e').map(result => result.name)) | ||
.toEqual(['source', 'message', 'timestamp']); | ||
}); | ||
|
||
it('suffixes matching fields with colon', () => { | ||
const completer = new FieldNameCompletion(); | ||
expect(completer.getCompletions(null, null, 'e').map(result => result.value)) | ||
.toEqual(['source:', 'message:', 'timestamp:']); | ||
}); | ||
}); |