diff --git a/app/assets/javascripts/discourse/components/search-advanced-options.js.es6 b/app/assets/javascripts/discourse/components/search-advanced-options.js.es6 index b45f54b5306..4d154491b5f 100644 --- a/app/assets/javascripts/discourse/components/search-advanced-options.js.es6 +++ b/app/assets/javascripts/discourse/components/search-advanced-options.js.es6 @@ -60,7 +60,7 @@ export default Em.Component.extend({ this.setProperties({ searchedTerms: { username: '', - category: null, + category: '', group: [], badge: [], tags: [], @@ -167,21 +167,21 @@ export default Em.Component.extend({ const userInput = Discourse.Category.findBySlug(subcategories[1], subcategories[0]); if ((!existingInput && userInput) || (existingInput && userInput && existingInput.id !== userInput.id)) - this.set('searchedTerms.category', userInput.id); + this.set('searchedTerms.category', [userInput]); } else if (isNaN(subcategories)) { const userInput = Discourse.Category.findSingleBySlug(subcategories[0]); if ((!existingInput && userInput) || (existingInput && userInput && existingInput.id !== userInput.id)) - this.set('searchedTerms.category', userInput.id); + this.set('searchedTerms.category', [userInput]); } else { const userInput = Discourse.Category.findById(subcategories[0]); if ((!existingInput && userInput) || (existingInput && userInput && existingInput.id !== userInput.id)) - this.set('searchedTerms.category', userInput.id); + this.set('searchedTerms.category', [userInput]); } } else - this.set('searchedTerms.category', null); + this.set('searchedTerms.category', ''); }, setSearchedTermValueForGroup() { @@ -278,16 +278,16 @@ export default Em.Component.extend({ @observes('searchedTerms.category') updateSearchTermForCategory() { const match = this.filterBlocks(REGEXP_CATEGORY_PREFIX); - const categoryFilter = Discourse.Category.findById(this.get('searchedTerms.category')); + const categoryFilter = this.get('searchedTerms.category'); let searchTerm = this.get('searchTerm') || ''; const slugCategoryMatches = (match.length !== 0) ? match[0].match(REGEXP_CATEGORY_SLUG) : null; const idCategoryMatches = (match.length !== 0) ? match[0].match(REGEXP_CATEGORY_ID) : null; - if (categoryFilter && categoryFilter.length !== 0) { - const id = categoryFilter.id; - const slug = categoryFilter.slug; - if (categoryFilter && categoryFilter.parentCategory) { - const parentSlug = categoryFilter.parentCategory.slug; + if (categoryFilter && categoryFilter[0]) { + const id = categoryFilter[0].id; + const slug = categoryFilter[0].slug; + if (categoryFilter[0].parentCategory) { + const parentSlug = categoryFilter[0].parentCategory.slug; if (slugCategoryMatches) searchTerm = searchTerm.replace(slugCategoryMatches[0], `#${parentSlug}:${slug}`); else if (idCategoryMatches) @@ -296,7 +296,7 @@ export default Em.Component.extend({ searchTerm += ` #${parentSlug}:${slug}`; this.set('searchTerm', searchTerm.trim()); - } else if (categoryFilter) { + } else { if (slugCategoryMatches) searchTerm = searchTerm.replace(slugCategoryMatches[0], `#${slug}`); else if (idCategoryMatches) diff --git a/app/assets/javascripts/discourse/templates/components/search-advanced-options.hbs b/app/assets/javascripts/discourse/templates/components/search-advanced-options.hbs index 554a2d689cf..21322e0f3d9 100644 --- a/app/assets/javascripts/discourse/templates/components/search-advanced-options.hbs +++ b/app/assets/javascripts/discourse/templates/components/search-advanced-options.hbs @@ -13,7 +13,7 @@
- {{category-chooser value=searchedTerms.category}} + {{category-selector categories=searchedTerms.category single="true"}}
diff --git a/test/javascripts/acceptance/search-full-test.js.es6 b/test/javascripts/acceptance/search-full-test.js.es6 index 29d863912d7..9804e6db072 100644 --- a/test/javascripts/acceptance/search-full-test.js.es6 +++ b/test/javascripts/acceptance/search-full-test.js.es6 @@ -76,7 +76,7 @@ test("validate population of advanced search", assert => { andThen(() => { assert.ok(exists('.search-advanced-options span:contains("admin")'), 'has "admin" pre-populated'); - assert.ok(exists('.search-advanced-options .category-combobox .select2-choice .select2-chosen:contains("bug")'), 'has "bug" pre-populated'); + assert.ok(exists('.search-advanced-options .badge-category:contains("bug")'), 'has "bug" pre-populated'); //assert.ok(exists('.search-advanced-options span:contains("moderators")'), 'has "moderators" pre-populated'); //assert.ok(exists('.search-advanced-options span:contains("Reader")'), 'has "Reader" pre-populated'); assert.ok(exists('.search-advanced-options .tag-chooser .tag-monkey'), 'has "monkey" pre-populated'); @@ -118,11 +118,13 @@ test("update category through advanced search ui", assert => { visit("/search"); fillIn('.search input.full-page-search', 'none'); click('.search-advanced-btn'); - selectDropdown('.search-advanced-options .category-combobox', 4); - click('.search-advanced-options'); // need to click off the combobox for the search-term to get updated + fillIn('.search-advanced-options .category-selector', 'faq'); + click('.search-advanced-options .category-selector'); + keyEvent('.search-advanced-options .category-selector', 'keydown', 8); + keyEvent('.search-advanced-options .category-selector', 'keydown', 9); andThen(() => { - assert.ok(exists('.search-advanced-options .category-combobox .select2-choice .select2-chosen:contains("faq")'), 'has "faq" populated'); + assert.ok(exists('.search-advanced-options .badge-category:contains("faq")'), 'has "faq" populated'); assert.equal(find('.search input.full-page-search').val(), "none #faq", 'has updated search term to "none #faq"'); }); });