From 36be4cd497a308672cc01bd175a0abfe68b0f767 Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Mon, 11 May 2015 18:07:58 -0700 Subject: [PATCH] fix(search): can search with a colon character Summary: Fixes T1127 For now, colons are taken literally. This means you can't type scoped searches. This will likely change when search gets re-designed Test Plan: SearchBar.cjsx got a test for this. The class needs more tests edgehill --test Reviewers: bengotow Reviewed By: bengotow Subscribers: mg Maniphest Tasks: T1127 Differential Revision: https://review.inboxapp.com/D1490 --- .../search-bar/lib/search-bar.cjsx | 17 +++-------------- .../search-bar/spec/search-bar-spec.cjsx | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 internal_packages/search-bar/spec/search-bar-spec.cjsx diff --git a/internal_packages/search-bar/lib/search-bar.cjsx b/internal_packages/search-bar/lib/search-bar.cjsx index a383f747e..a0b773c42 100644 --- a/internal_packages/search-bar/lib/search-bar.cjsx +++ b/internal_packages/search-bar/lib/search-bar.cjsx @@ -5,7 +5,6 @@ classNames = require 'classnames' SearchSuggestionStore = require './search-suggestion-store' _ = require 'underscore-plus' - class SearchBar extends React.Component @displayName = 'SearchBar' @@ -97,20 +96,11 @@ class SearchBar extends React.Component if key == "all" str += val else - str += "#{key}:#{val}" + str += val _stringToQuery: (str) => return [] unless str - - # note: right now this only works if there's one term. In the future, - # we'll make this whole search input a tokenizing field - [a,b] = str.split(':') - term = {} - if b - term[a] = b - else - term["all"] = a - [term] + return [all: str] _onValueChange: (event) => Actions.searchQueryChanged(@_stringToQuery(event.target.value)) @@ -148,5 +138,4 @@ class SearchBar extends React.Component suggestions: SearchSuggestionStore.suggestions() committedQuery: SearchSuggestionStore.committedQuery() - -module.exports = SearchBar \ No newline at end of file +module.exports = SearchBar diff --git a/internal_packages/search-bar/spec/search-bar-spec.cjsx b/internal_packages/search-bar/spec/search-bar-spec.cjsx new file mode 100644 index 000000000..6fb6315c9 --- /dev/null +++ b/internal_packages/search-bar/spec/search-bar-spec.cjsx @@ -0,0 +1,19 @@ +React = require 'react' +ReactTestUtils = React.addons.TestUtils + +{Actions} = require 'inbox-exports' + +SearchBar = require '../lib/search-bar' +SearchSuggestionStore = require '../lib/search-suggestion-store.coffee' + +describe 'SearchBar', -> + beforeEach -> + @searchBar = ReactTestUtils.renderIntoDocument() + input = ReactTestUtils.findRenderedDOMComponentWithTag(@searchBar, "input") + @input = React.findDOMNode(input) + + it 'supports search queries with a colon character', -> + spyOn(Actions, "searchQueryChanged") + test = "::Hello: World::" + ReactTestUtils.Simulate.change @input, target: value: test + expect(Actions.searchQueryChanged).toHaveBeenCalledWith [all: test]