From 44a25271f1caa0cc1281e0353c363e8e965bfd63 Mon Sep 17 00:00:00 2001 From: cpradio Date: Wed, 3 Sep 2014 06:51:52 -0400 Subject: [PATCH] FIX: Remove additional search code related to the up/down navigation Removed additional search code that was related to the up/down navigation and their related tests. https://meta.discourse.org/t/magic-search-code-for-keyboard-shortcuts/19563 --- .../discourse/controllers/search.js.es6 | 18 ------- .../controllers/search-test.js.es6 | 51 ------------------- 2 files changed, 69 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/search.js.es6 b/app/assets/javascripts/discourse/controllers/search.js.es6 index 65805bde9..fe33c69dd 100644 --- a/app/assets/javascripts/discourse/controllers/search.js.es6 +++ b/app/assets/javascripts/discourse/controllers/search.js.es6 @@ -133,23 +133,5 @@ export default Em.Controller.extend(Discourse.Presence, { cancelTypeFilter: function() { this.set('typeFilter', null); - }, - - moveUp: function() { - if (this.get('selectedIndex') === 0) return; - this.set('selectedIndex', this.get('selectedIndex') - 1); - }, - - moveDown: function() { - if (this.get('resultCount') === (this.get('selectedIndex') + 1)) return; - this.set('selectedIndex', this.get('selectedIndex') + 1); - }, - - select: function() { - if (this.get('loading')) return; - var href = this.get('urls')[this.get("selectedIndex")]; - if (href) { - Discourse.URL.routeTo(href); - } } }); diff --git a/test/javascripts/controllers/search-test.js.es6 b/test/javascripts/controllers/search-test.js.es6 index d5c56dc92..2439beaee 100644 --- a/test/javascripts/controllers/search-test.js.es6 +++ b/test/javascripts/controllers/search-test.js.es6 @@ -128,57 +128,6 @@ test("keyboard navigation", function() { }); equal(controller.get("selectedIndex"), 0, "initially the first item is selected"); - - controller.moveUp(); - equal(controller.get("selectedIndex"), 0, "you can't move up above the first item"); - - controller.moveDown(); - equal(controller.get("selectedIndex"), 1, "you can go down from the first item"); - - controller.moveDown(); - equal(controller.get("selectedIndex"), 2, "you can go down from the middle item"); - - controller.moveDown(); - equal(controller.get("selectedIndex"), 2, "you can't go down below the last item"); - - controller.moveUp(); - equal(controller.get("selectedIndex"), 1, "you can go up from the last item"); - - controller.moveUp(); - equal(controller.get("selectedIndex"), 0, "you can go up from the middle item"); -}); - -test("selecting a highlighted item", function() { - sandbox.stub(Discourse.URL, "routeTo"); - - var controller = this.subject(); - Ember.run(function() { - controller.set("term", "ab"); - - searcherStub.resolve( - { - type: "user", - posts: [], - categories: [], - topics: [], - users: [{username: 'bob'}], - grouped_search_result: {}, - } - ); - }); - - Ember.run(function() { - controller.set("selectedIndex", 0); - }); - controller.select(); - ok(Discourse.URL.routeTo.calledWith("/users/bob"), "when selected item has url, a redirect is fired"); - - Discourse.URL.routeTo.reset(); - Ember.run(function() { - controller.set("loading", true); - }); - controller.select(); - ok(!Discourse.URL.routeTo.called, "when loading flag is set to true, there is no redirect"); }); test("search query / the flow of the search", function() {