|
@@ -857,6 +857,133 @@ describe('SmartSearchBar', function () {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ describe('cursorSearchTerm', function () {
|
|
|
+ it('selects the correct free text word', async function () {
|
|
|
+ jest.useRealTimers();
|
|
|
+
|
|
|
+ const props = {
|
|
|
+ query: '',
|
|
|
+ organization,
|
|
|
+ location,
|
|
|
+ supportedTags,
|
|
|
+ };
|
|
|
+ const smartSearchBar = mountWithTheme(<SmartSearchBar {...props} />, options);
|
|
|
+ const searchBar = smartSearchBar.instance();
|
|
|
+ const textarea = smartSearchBar.find('textarea');
|
|
|
+
|
|
|
+ textarea.simulate('focus');
|
|
|
+ mockCursorPosition(searchBar, 6);
|
|
|
+ textarea.simulate('change', {target: {value: 'typ testest err'}});
|
|
|
+ await tick();
|
|
|
+
|
|
|
+ // Expect the correct search term to be selected
|
|
|
+ const cursorSearchTerm = searchBar.cursorSearchTerm;
|
|
|
+ expect(cursorSearchTerm.searchTerm).toEqual('testest');
|
|
|
+ expect(cursorSearchTerm.start).toBe(4);
|
|
|
+ expect(cursorSearchTerm.end).toBe(11);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('selects the correct free text word (last word)', async function () {
|
|
|
+ jest.useRealTimers();
|
|
|
+
|
|
|
+ const props = {
|
|
|
+ query: '',
|
|
|
+ organization,
|
|
|
+ location,
|
|
|
+ supportedTags,
|
|
|
+ };
|
|
|
+ const smartSearchBar = mountWithTheme(<SmartSearchBar {...props} />, options);
|
|
|
+ const searchBar = smartSearchBar.instance();
|
|
|
+ const textarea = smartSearchBar.find('textarea');
|
|
|
+
|
|
|
+ textarea.simulate('focus');
|
|
|
+ mockCursorPosition(searchBar, 15);
|
|
|
+ textarea.simulate('change', {target: {value: 'typ testest err'}});
|
|
|
+ await tick();
|
|
|
+
|
|
|
+ // Expect the correct search term to be selected
|
|
|
+ const cursorSearchTerm = searchBar.cursorSearchTerm;
|
|
|
+ expect(cursorSearchTerm.searchTerm).toEqual('err');
|
|
|
+ expect(cursorSearchTerm.start).toBe(15);
|
|
|
+ expect(cursorSearchTerm.end).toBe(18);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('selects the correct free text word (first word)', async function () {
|
|
|
+ jest.useRealTimers();
|
|
|
+
|
|
|
+ const props = {
|
|
|
+ query: '',
|
|
|
+ organization,
|
|
|
+ location,
|
|
|
+ supportedTags,
|
|
|
+ };
|
|
|
+ const smartSearchBar = mountWithTheme(<SmartSearchBar {...props} />, options);
|
|
|
+ const searchBar = smartSearchBar.instance();
|
|
|
+ const textarea = smartSearchBar.find('textarea');
|
|
|
+
|
|
|
+ textarea.simulate('focus');
|
|
|
+ mockCursorPosition(searchBar, 1);
|
|
|
+ textarea.simulate('change', {target: {value: 'typ testest err'}});
|
|
|
+ await tick();
|
|
|
+
|
|
|
+ // Expect the correct search term to be selected
|
|
|
+ const cursorSearchTerm = searchBar.cursorSearchTerm;
|
|
|
+ expect(cursorSearchTerm.searchTerm).toEqual('typ');
|
|
|
+ expect(cursorSearchTerm.start).toBe(0);
|
|
|
+ expect(cursorSearchTerm.end).toBe(3);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('search term location correctly selects key of filter token', async function () {
|
|
|
+ jest.useRealTimers();
|
|
|
+
|
|
|
+ const props = {
|
|
|
+ query: '',
|
|
|
+ organization,
|
|
|
+ location,
|
|
|
+ supportedTags,
|
|
|
+ };
|
|
|
+ const smartSearchBar = mountWithTheme(<SmartSearchBar {...props} />, options);
|
|
|
+ const searchBar = smartSearchBar.instance();
|
|
|
+ const textarea = smartSearchBar.find('textarea');
|
|
|
+
|
|
|
+ textarea.simulate('focus');
|
|
|
+ mockCursorPosition(searchBar, 6);
|
|
|
+ textarea.simulate('change', {target: {value: 'typ device:123'}});
|
|
|
+ await tick();
|
|
|
+
|
|
|
+ // Expect the correct search term to be selected
|
|
|
+ const cursorSearchTerm = searchBar.cursorSearchTerm;
|
|
|
+ expect(cursorSearchTerm.searchTerm).toEqual('device');
|
|
|
+ expect(cursorSearchTerm.start).toBe(4);
|
|
|
+ expect(cursorSearchTerm.end).toBe(10);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('search term location correctly selects value of filter token', async function () {
|
|
|
+ jest.useRealTimers();
|
|
|
+
|
|
|
+ const props = {
|
|
|
+ query: '',
|
|
|
+ organization,
|
|
|
+ location,
|
|
|
+ supportedTags,
|
|
|
+ };
|
|
|
+ const smartSearchBar = mountWithTheme(<SmartSearchBar {...props} />, options);
|
|
|
+ const searchBar = smartSearchBar.instance();
|
|
|
+ const textarea = smartSearchBar.find('textarea');
|
|
|
+
|
|
|
+ textarea.simulate('focus');
|
|
|
+ mockCursorPosition(searchBar, 11);
|
|
|
+ textarea.simulate('change', {target: {value: 'typ device:123'}});
|
|
|
+ await tick();
|
|
|
+
|
|
|
+ // Expect the correct search term to be selected
|
|
|
+ const cursorSearchTerm = searchBar.cursorSearchTerm;
|
|
|
+ expect(cursorSearchTerm.searchTerm).toEqual('123');
|
|
|
+ expect(cursorSearchTerm.start).toBe(11);
|
|
|
+ expect(cursorSearchTerm.end).toBe(14);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
describe('onAutoComplete()', function () {
|
|
|
it('completes terms from the list', function () {
|
|
|
const props = {
|
|
@@ -916,7 +1043,8 @@ describe('SmartSearchBar', function () {
|
|
|
);
|
|
|
});
|
|
|
|
|
|
- it('keeps the negation operator is present', function () {
|
|
|
+ it('keeps the negation operator present', async function () {
|
|
|
+ jest.useRealTimers();
|
|
|
const props = {
|
|
|
query: '',
|
|
|
organization,
|
|
@@ -927,8 +1055,15 @@ describe('SmartSearchBar', function () {
|
|
|
const searchBar = smartSearchBar.instance();
|
|
|
const textarea = smartSearchBar.find('textarea');
|
|
|
// start typing part of the tag prefixed by the negation operator!
|
|
|
+ textarea.simulate('focus');
|
|
|
textarea.simulate('change', {target: {value: 'event.type:error !ti'}});
|
|
|
mockCursorPosition(searchBar, 20);
|
|
|
+ await tick();
|
|
|
+ // Expect the correct search term to be selected
|
|
|
+ const cursorSearchTerm = searchBar.cursorSearchTerm;
|
|
|
+ expect(cursorSearchTerm.searchTerm).toEqual('ti');
|
|
|
+ expect(cursorSearchTerm.start).toBe(18);
|
|
|
+ expect(cursorSearchTerm.end).toBe(20);
|
|
|
// use autocompletion to do the rest
|
|
|
searchBar.onAutoComplete('title:', {});
|
|
|
expect(searchBar.state.query).toEqual('event.type:error !title:');
|
|
@@ -1138,6 +1273,33 @@ describe('SmartSearchBar', function () {
|
|
|
);
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ it('replaces the correct word', async function () {
|
|
|
+ const props = {
|
|
|
+ query: '',
|
|
|
+ organization,
|
|
|
+ location,
|
|
|
+ supportedTags,
|
|
|
+ };
|
|
|
+ const smartSearchBar = mountWithTheme(<SmartSearchBar {...props} />, options);
|
|
|
+ const searchBar = smartSearchBar.instance();
|
|
|
+ const textarea = smartSearchBar.find('textarea');
|
|
|
+
|
|
|
+ textarea.simulate('focus');
|
|
|
+ mockCursorPosition(searchBar, 4);
|
|
|
+ textarea.simulate('change', {target: {value: 'typ ti err'}});
|
|
|
+
|
|
|
+ await tick();
|
|
|
+
|
|
|
+ // Expect the correct search term to be selected
|
|
|
+ const cursorSearchTerm = searchBar.cursorSearchTerm;
|
|
|
+ expect(cursorSearchTerm.searchTerm).toEqual('ti');
|
|
|
+ expect(cursorSearchTerm.start).toBe(4);
|
|
|
+ expect(cursorSearchTerm.end).toBe(6);
|
|
|
+ // use autocompletion to do the rest
|
|
|
+ searchBar.onAutoComplete('title:', {});
|
|
|
+ expect(searchBar.state.query).toEqual('typ title: err');
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
describe('Invalid field state', () => {
|