{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/comments/27953023","id":27953023,"diff_hunk":"@@ -285,145 +194,372 @@ define([\n     });\n \n \n-    describe('SearchListView', function () {\n+    describe('SearchRouter', function () {\n \n         beforeEach(function () {\n-            setFixtures(\n-                '<section id=\"courseware-search-results\" data-course-name=\"Test Course\"></section>' +\n-                '<section id=\"course-content\"></section>'\n-            );\n+            this.router = new SearchRouter();\n+            this.onSearch = jasmine.createSpy('onSearch');\n+            this.router.on('search', this.onSearch);\n+        });\n \n+        it ('has a search route', function () {\n+            expect(this.router.routes['search/:query']).toEqual('search');\n+        });\n+\n+        it ('triggers a search event', function () {\n+            var query = 'mercury';\n+            this.router.search(query);\n+            expect(this.onSearch).toHaveBeenCalledWith(query);\n+        });\n+\n+    });\n+\n+\n+    describe('SearchItemView', function () {\n+\n+        function beforeEachHelper(SearchItemView) {\n             TemplateHelpers.installTemplates([\n-                'templates/courseware_search/search_item',\n-                'templates/courseware_search/search_item_seq',\n-                'templates/courseware_search/search_list',\n-                'templates/courseware_search/search_loading',\n-                'templates/courseware_search/search_error'\n+                'templates/search/course_search_item',\n+                'templates/search/dashboard_search_item'\n             ]);\n \n-            var MockCollection = Backbone.Collection.extend({\n-                hasNextPage: function (){}\n+            this.model = new SearchResult({\n+                location: ['section', 'subsection', 'unit'],\n+                content_type: 'Video',\n+                course_name: 'Course Name',\n+                excerpt: 'A short excerpt.',\n+                url: 'path/to/content'\n             });\n-            this.collection = new MockCollection();\n \n-            // spy on these methods before they are bound to events\n-            spyOn(SearchListView.prototype, 'render').andCallThrough();\n-            spyOn(SearchListView.prototype, 'renderNext').andCallThrough();\n-            spyOn(SearchListView.prototype, 'showErrorMessage').andCallThrough();\n+            this.seqModel = new SearchResult({\n+                location: ['section', 'subsection'],\n+                content_type: 'Sequence',\n+                course_name: 'Course Name',\n+                excerpt: 'A short excerpt.',\n+                url: 'path/to/content'\n+            });\n \n-            this.listView = new SearchListView({ collection: this.collection });\n+            this.item = new SearchItemView({ model: this.model });\n+            this.item.render();\n+            this.seqItem = new SearchItemView({ model: this.seqModel });\n+            this.seqItem.render();\n+        }\n+\n+        function rendersItem() {\n+            expect(this.item.$el).toHaveAttr('role', 'region');\n+            expect(this.item.$el).toHaveAttr('aria-label', 'search result');\n+            expect(this.item.$el).toContain('a[href=\"' + this.model.get('url') + '\"]');\n+            expect(this.item.$el.find('.sri-type')).toContainHtml(this.model.get('content_type'));\n+            expect(this.item.$el.find('.sri-excerpt')).toContainHtml(this.model.get('excerpt'));\n+            expect(this.item.$el.find('.sri-location')).toContainHtml('section ▸ subsection ▸ unit');\n+        }\n+\n+        function rendersSequentialItem() {\n+            expect(this.seqItem.$el).toHaveAttr('role', 'region');\n+            expect(this.seqItem.$el).toHaveAttr('aria-label', 'search result');\n+            expect(this.seqItem.$el).toContain('a[href=\"' + this.seqModel.get('url') + '\"]');\n+            expect(this.seqItem.$el.find('.sri-type')).toBeEmpty();\n+            expect(this.seqItem.$el.find('.sri-excerpt')).toBeEmpty();\n+            expect(this.seqItem.$el.find('.sri-location')).toContainHtml('section ▸ subsection');\n+        }\n+\n+        function logsSearchItemViewEvent() {\n+            this.model.collection = new SearchCollection([this.model], { course_id: 'edx101' });\n+            this.item.render();\n+            // Mock the redirect call\n+            spyOn(this.item, 'redirect').andCallFake( function() {} );\n+            spyOn(Logger, 'log').andReturn($.Deferred().resolve());\n+            var link = this.item.$el.find('a');\n+            expect(link.length).toBe(1);\n+            link.trigger('click');\n+            expect(this.item.redirect).toHaveBeenCalled();\n+        }\n+\n+        describe('CourseSearchItemView', function () {\n+            beforeEach(function () {\n+                beforeEachHelper.call(this, CourseSearchItemView);\n+            });\n+            it('renders items correctly', rendersItem);\n+            it('renders Sequence items correctly', rendersSequentialItem);\n+            it('logs view event', logsSearchItemViewEvent);\n         });\n \n-        it('shows loading message', function () {\n-            this.listView.showLoadingMessage();\n-            expect($('#course-content')).toBeHidden();\n-            expect(this.listView.$el).toBeVisible();\n-            expect(this.listView.$el).not.toBeEmpty();\n+        describe('DashSearchItemView', function () {\n+            beforeEach(function () {\n+                beforeEachHelper.call(this, DashSearchItemView);\n+            });\n+            it('renders items correctly', rendersItem);\n+            it('renders Sequence items correctly', rendersSequentialItem);\n+            it('displays course name in breadcrumbs', function () {\n+                expect(this.seqItem.$el.find('.sri-course-name')).toContainHtml(this.model.get('course_name'));\n+            });\n+            it('logs view event', logsSearchItemViewEvent);\n         });\n \n-        it('shows error message', function () {\n-            this.listView.showErrorMessage();\n-            expect($('#course-content')).toBeHidden();\n-            expect(this.listView.$el).toBeVisible();\n-            expect(this.listView.$el).not.toBeEmpty();\n+    });\n+\n+\n+    describe('SearchForm', function () {\n+\n+        function trimsInputString() {\n+            var term = '    search string  ';\n+            $('.search-field').val(term);\n+            $('form').trigger('submit');\n+            expect(this.onSearch).toHaveBeenCalledWith($.trim(term));\n+        }\n+\n+        function doesSearch() {\n+            var term = '  search string  ';\n+            $('.search-field').val(term);\n+            this.form.doSearch(term);\n+            expect(this.onSearch).toHaveBeenCalledWith($.trim(term));\n+            expect($('.search-field').val()).toEqual(term);\n+            expect($('.search-field')).toHaveClass('is-active');\n+            expect($('.search-button')).toBeHidden();\n+            expect($('.cancel-button')).toBeVisible();\n+        }\n+\n+        function triggersSearchEvent() {\n+            var term = 'search string';\n+            $('.search-field').val(term);\n+            $('form').trigger('submit');\n+            expect(this.onSearch).toHaveBeenCalledWith(term);\n+        }\n+\n+        function changesToActiveState() {\n+            var term = 'search string';\n+            $('.search-field').val(term);\n+            $('form').trigger('submit');\n+            expect($('.search-field')).toHaveClass('is-active');\n+            expect($('.search-button')).toBeHidden();\n+            expect($('.cancel-button')).toBeVisible();\n+        }\n+\n+        function clearsSearchOnCancel() {\n+            $('.search-field').val('search string');\n+            $('.cancel-button').trigger('click');\n+            expect($('.search-field')).not.toHaveClass('is-active');\n+            expect($('.search-button')).toBeVisible();\n+            expect($('.cancel-button')).toBeHidden();\n+            expect($('.search-field')).toHaveValue('');\n+        }\n+\n+        function clearsSearchOnEmpty() {\n+            $('.search-field').val('');\n+            $('form').trigger('submit');\n+            expect(this.onClear).toHaveBeenCalled();\n+            expect($('.search-field')).not.toHaveClass('is-active');\n+            expect($('.cancel-button')).toBeHidden();\n+            expect($('.search-button')).toBeVisible();\n+        }\n+\n+        describe('CourseSearchForm', function () {\n+            beforeEach(function () {\n+                loadFixtures('js/fixtures/search/course_search_form.html');\n+                this.form = new CourseSearchForm();\n+                this.onClear = jasmine.createSpy('onClear');","path":"lms/static/js/spec/search/search_spec.js","position":428,"original_position":421,"commit_id":"8621f4f6a3f7014a7e50627a854dd99ead8f65ce","original_commit_id":"2b5683363c1ec5c500203e1b75abf5bfcf780ded","user":{"login":"dino-cikatic","id":7403820,"avatar_url":"https://avatars.githubusercontent.com/u/7403820?v=3","gravatar_id":"","url":"https://api.github.com/users/dino-cikatic","html_url":"https://github.com/dino-cikatic","followers_url":"https://api.github.com/users/dino-cikatic/followers","following_url":"https://api.github.com/users/dino-cikatic/following{/other_user}","gists_url":"https://api.github.com/users/dino-cikatic/gists{/gist_id}","starred_url":"https://api.github.com/users/dino-cikatic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dino-cikatic/subscriptions","organizations_url":"https://api.github.com/users/dino-cikatic/orgs","repos_url":"https://api.github.com/users/dino-cikatic/repos","events_url":"https://api.github.com/users/dino-cikatic/events{/privacy}","received_events_url":"https://api.github.com/users/dino-cikatic/received_events","type":"User","site_admin":false},"body":"Upon taking a better look you are right. You can't spyOn collection event handlers that are attached from you view init. ","created_at":"2015-04-08T08:57:50Z","updated_at":"2015-04-08T08:57:50Z","html_url":"https://github.com/edx/edx-platform/pull/7522#discussion_r27953023","pull_request_url":"https://api.github.com/repos/edx/edx-platform/pulls/7522","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments/27953023"},"html":{"href":"https://github.com/edx/edx-platform/pull/7522#discussion_r27953023"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/7522"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/7522","id":32251463,"html_url":"https://github.com/edx/edx-platform/pull/7522","diff_url":"https://github.com/edx/edx-platform/pull/7522.diff","patch_url":"https://github.com/edx/edx-platform/pull/7522.patch","issue_url":"https://api.github.com/repos/edx/edx-platform/issues/7522","number":7522,"state":"open","locked":false,"title":"Feature/dashboard search","user":{"login":"martynjames","id":675165,"avatar_url":"https://avatars.githubusercontent.com/u/675165?v=3","gravatar_id":"","url":"https://api.github.com/users/martynjames","html_url":"https://github.com/martynjames","followers_url":"https://api.github.com/users/martynjames/followers","following_url":"https://api.github.com/users/martynjames/following{/other_user}","gists_url":"https://api.github.com/users/martynjames/gists{/gist_id}","starred_url":"https://api.github.com/users/martynjames/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martynjames/subscriptions","organizations_url":"https://api.github.com/users/martynjames/orgs","repos_url":"https://api.github.com/users/martynjames/repos","events_url":"https://api.github.com/users/martynjames/events{/privacy}","received_events_url":"https://api.github.com/users/martynjames/received_events","type":"User","site_admin":false},"body":"Creating for review purposes","created_at":"2015-03-30T18:05:51Z","updated_at":"2015-04-08T08:57:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e98c265e491ad9065e5efd20b92692f80c0ec320","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-platform/pulls/7522/commits","review_comments_url":"https://api.github.com/repos/edx/edx-platform/pulls/7522/comments","review_comment_url":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-platform/issues/7522/comments","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/8621f4f6a3f7014a7e50627a854dd99ead8f65ce","head":{"label":"edx:feature/dashboard-search","ref":"feature/dashboard-search","sha":"8621f4f6a3f7014a7e50627a854dd99ead8f65ce","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":10391073,"name":"edx-platform","full_name":"edx/edx-platform","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-platform","description":"Open edX, the edX platform that powers http://edx.org","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","created_at":"2013-05-30T20:20:38Z","updated_at":"2015-04-07T22:04:58Z","pushed_at":"2015-04-08T07:54:38Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://openedx.org/","size":1876948,"stargazers_count":1850,"watchers_count":1850,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1047,"mirror_url":null,"open_issues_count":152,"forks":1047,"open_issues":152,"watchers":1850,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"e469e4da9ee2782b4483f16eb3ec0949da0394a2","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":10391073,"name":"edx-platform","full_name":"edx/edx-platform","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-platform","description":"Open edX, the edX platform that powers http://edx.org","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","created_at":"2013-05-30T20:20:38Z","updated_at":"2015-04-07T22:04:58Z","pushed_at":"2015-04-08T07:54:38Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://openedx.org/","size":1876948,"stargazers_count":1850,"watchers_count":1850,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1047,"mirror_url":null,"open_issues_count":152,"forks":1047,"open_issues":152,"watchers":1850,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/7522"},"html":{"href":"https://github.com/edx/edx-platform/pull/7522"},"issue":{"href":"https://api.github.com/repos/edx/edx-platform/issues/7522"},"comments":{"href":"https://api.github.com/repos/edx/edx-platform/issues/7522/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/7522/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/7522/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-platform/statuses/8621f4f6a3f7014a7e50627a854dd99ead8f65ce"}}}}