Stop query from executing if predicate is empty
If user types a query in the search bar with incomplete predicate then we do not
execute the query if it is one of the pre-defined ones.
Bug: Issue 7083
Change-Id: I5b29caf3a025f8b0282185133e18de1b6f21c859
(cherry picked from commit 098e93f397)
			
			
This commit is contained in:
		
				
					committed by
					
						
						Paladox none
					
				
			
			
				
	
			
			
			
						parent
						
							9e3f442ff2
						
					
				
				
					commit
					528f411261
				
			@@ -91,7 +91,7 @@
 | 
			
		||||
 | 
			
		||||
  // All of the ops, with corresponding negations.
 | 
			
		||||
  const SEARCH_OPERATORS_WITH_NEGATIONS =
 | 
			
		||||
      SEARCH_OPERATORS.concat(SEARCH_OPERATORS.map(op => `-${op}`));
 | 
			
		||||
    SEARCH_OPERATORS.concat(SEARCH_OPERATORS.map(op => `-${op}`));
 | 
			
		||||
 | 
			
		||||
  const MAX_AUTOCOMPLETE_RESULTS = 10;
 | 
			
		||||
 | 
			
		||||
@@ -185,7 +185,16 @@
 | 
			
		||||
      } else {
 | 
			
		||||
        target.blur();
 | 
			
		||||
      }
 | 
			
		||||
      if (this._inputVal) {
 | 
			
		||||
      const trimmedInput = this._inputVal && this._inputVal.trim();
 | 
			
		||||
      if (trimmedInput) {
 | 
			
		||||
        const predefinedOpOnlyQuery = SEARCH_OPERATORS_WITH_NEGATIONS.some(
 | 
			
		||||
            op => {
 | 
			
		||||
              return op.endsWith(':') && op === trimmedInput;
 | 
			
		||||
            }
 | 
			
		||||
        );
 | 
			
		||||
        if (predefinedOpOnlyQuery) {
 | 
			
		||||
          return;
 | 
			
		||||
        }
 | 
			
		||||
        this.dispatchEvent(new CustomEvent('handle-search', {
 | 
			
		||||
          detail: {inputVal: this._inputVal},
 | 
			
		||||
        }));
 | 
			
		||||
 
 | 
			
		||||
@@ -91,6 +91,42 @@ limitations under the License.
 | 
			
		||||
      assert.isFalse(searchSpy.called);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Predefined query op with no predication doesnt trigger nav', () => {
 | 
			
		||||
      const searchSpy = sandbox.spy();
 | 
			
		||||
      element.addEventListener('handle-search', searchSpy);
 | 
			
		||||
      element.value = 'added:';
 | 
			
		||||
      MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
 | 
			
		||||
          null, 'enter');
 | 
			
		||||
      assert.isFalse(searchSpy.called);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('predefined predicate query triggers nav', () => {
 | 
			
		||||
      const searchSpy = sandbox.spy();
 | 
			
		||||
      element.addEventListener('handle-search', searchSpy);
 | 
			
		||||
      element.value = 'age:1week';
 | 
			
		||||
      MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
 | 
			
		||||
          null, 'enter');
 | 
			
		||||
      assert.isTrue(searchSpy.called);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('undefined predicate query triggers nav', () => {
 | 
			
		||||
      const searchSpy = sandbox.spy();
 | 
			
		||||
      element.addEventListener('handle-search', searchSpy);
 | 
			
		||||
      element.value = 'random:1week';
 | 
			
		||||
      MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
 | 
			
		||||
          null, 'enter');
 | 
			
		||||
      assert.isTrue(searchSpy.called);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('empty undefined predicate query triggers nav', () => {
 | 
			
		||||
      const searchSpy = sandbox.spy();
 | 
			
		||||
      element.addEventListener('handle-search', searchSpy);
 | 
			
		||||
      element.value = 'random:';
 | 
			
		||||
      MockInteractions.pressAndReleaseKeyOn(element.$.searchInput.$.input, 13,
 | 
			
		||||
          null, 'enter');
 | 
			
		||||
      assert.isTrue(searchSpy.called);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('keyboard shortcuts', () => {
 | 
			
		||||
      const focusSpy = sandbox.spy(element.$.searchInput, 'focus');
 | 
			
		||||
      const selectAllSpy = sandbox.spy(element.$.searchInput, 'selectAll');
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user