summaryrefslogtreecommitdiff
path: root/spec/javascripts
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2016-06-10 01:05:09 +0300
committerFatih Acet <acetfatih@gmail.com>2016-06-10 01:05:09 +0300
commite864bdf25b0082be8d0847fed6a2d16fe348ae59 (patch)
treed9ab18068a0a8b9f012fc02e2ff9f5004f73e994 /spec/javascripts
parent639347bad4909e3451d6f5617d6f79ae2e63e9aa (diff)
downloadgitlab-ce-e864bdf25b0082be8d0847fed6a2d16fe348ae59.tar.gz
Fix specs and add new tests.
Diffstat (limited to 'spec/javascripts')
-rw-r--r--spec/javascripts/search_autocomplete_spec.js.coffee104
1 files changed, 62 insertions, 42 deletions
diff --git a/spec/javascripts/search_autocomplete_spec.js.coffee b/spec/javascripts/search_autocomplete_spec.js.coffee
index 5212f5d223a..e77177783a7 100644
--- a/spec/javascripts/search_autocomplete_spec.js.coffee
+++ b/spec/javascripts/search_autocomplete_spec.js.coffee
@@ -13,18 +13,33 @@ window.gon.current_user_id = userId
dashboardIssuesPath = '/dashboard/issues'
dashboardMRsPath = '/dashboard/merge_requests'
-projectIssuesPath = "/gitlab-org/gitlab-ce/issues"
-projectMRsPath = "/gitlab-org/gitlab-ce/merge_requests"
+projectIssuesPath = '/gitlab-org/gitlab-ce/issues'
+projectMRsPath = '/gitlab-org/gitlab-ce/merge_requests'
+groupIssuesPath = '/groups/gitlab-org/issues'
+groupMRsPath = '/groups/gitlab-org/merge_requests'
projectName = 'GitLab Community Edition'
+groupName = 'Gitlab Org'
+
# Add required attributes to body before starting the test.
-addBodyAttributes = (page = 'groups') ->
+# section would be dashboard|group|project
+addBodyAttributes = (section = 'dashboard') ->
+
+ $body = $ 'body'
- $('body').removeAttr 'data-page'
- $('body').removeAttr 'data-project'
+ $body.removeAttr 'data-page'
+ $body.removeAttr 'data-project'
+ $body.removeAttr 'data-group'
- $('body').data 'page', "#{page}:show"
- $('body').data 'project', 'gitlab-ce'
+ switch section
+ when 'dashboard'
+ $body.data 'page', 'root:index'
+ when 'group'
+ $body.data 'page', 'groups:show'
+ $body.data 'group', 'gitlab-org'
+ when 'project'
+ $body.data 'page', 'projects:show'
+ $body.data 'project', 'gitlab-ce'
# Mock `gl` object in window for dashboard specific page. App code will need it.
@@ -47,7 +62,27 @@ mockProjectOptions = ->
projectName : projectName
-assertLinks = (list, a1, a2, a3, a4) ->
+mockGroupOptions = ->
+
+ window.gl or= {}
+ window.gl.groupOptions =
+ 'gitlab-org' :
+ issuesPath : groupIssuesPath
+ mrPath : groupMRsPath
+ projectName : groupName
+
+
+assertLinks = (list, issuesPath, mrsPath) ->
+
+ issuesAssignedToMeLink = "#{issuesPath}/?assignee_id=#{userId}"
+ issuesIHaveCreatedLink = "#{issuesPath}/?author_id=#{userId}"
+ mrsAssignedToMeLink = "#{mrsPath}/?assignee_id=#{userId}"
+ mrsIHaveCreatedLink = "#{mrsPath}/?author_id=#{userId}"
+
+ a1 = "a[href='#{issuesAssignedToMeLink}']"
+ a2 = "a[href='#{issuesIHaveCreatedLink}']"
+ a3 = "a[href='#{mrsAssignedToMeLink}']"
+ a4 = "a[href='#{mrsIHaveCreatedLink}']"
expect(list.find(a1).length).toBe 1
expect(list.find(a1).text()).toBe ' Issues assigned to me '
@@ -62,7 +97,6 @@ assertLinks = (list, a1, a2, a3, a4) ->
expect(list.find(a4).text()).toBe " Merge requests I've created "
-
describe 'Search autocomplete dropdown', ->
fixture.preload 'search_autocomplete.html'
@@ -77,53 +111,39 @@ describe 'Search autocomplete dropdown', ->
addBodyAttributes()
mockDashboardOptions()
-
- # Focus input to show dropdown list.
widget.searchInput.focus()
- w = widget.wrap.find '.dropdown-menu'
- l = w.find 'ul'
+ list = widget.wrap.find('.dropdown-menu').find 'ul'
+ assertLinks list, dashboardIssuesPath, dashboardMRsPath
- # # Expect dropdown and dropdown header
- expect(w.find('.dropdown-header').text()).toBe 'Go to in Dashboard'
- # Create links then assert link urls and inner texts
- issuesAssignedToMeLink = "#{dashboardIssuesPath}/?assignee_id=#{userId}"
- issuesIHaveCreatedLink = "#{dashboardIssuesPath}/?author_id=#{userId}"
- mrsAssignedToMeLink = "#{dashboardMRsPath}/?assignee_id=#{userId}"
- mrsIHaveCreatedLink = "#{dashboardMRsPath}/?author_id=#{userId}"
+ it 'should show Group specific dropdown menu', ->
- a1 = "a[href='#{issuesAssignedToMeLink}']"
- a2 = "a[href='#{issuesIHaveCreatedLink}']"
- a3 = "a[href='#{mrsAssignedToMeLink}']"
- a4 = "a[href='#{mrsIHaveCreatedLink}']"
+ addBodyAttributes 'group'
+ mockGroupOptions()
+ widget.searchInput.focus()
- assertLinks l, a1, a2, a3, a4
+ list = widget.wrap.find('.dropdown-menu').find 'ul'
+ assertLinks list, groupIssuesPath, groupMRsPath
it 'should show Project specific dropdown menu', ->
- addBodyAttributes 'projects'
+ addBodyAttributes 'project'
mockProjectOptions()
-
- # Focus input to show dropdown list.
widget.searchInput.focus()
- w = widget.wrap.find '.dropdown-menu'
- l = w.find 'ul'
+ list = widget.wrap.find('.dropdown-menu').find 'ul'
+ assertLinks list, projectIssuesPath, projectMRsPath
- # Expect dropdown and dropdown header
- expect(w.find('.dropdown-header').text()).toBe "Go to in #{projectName}"
- # Create links then verify link urls and inner texts
- issuesAssignedToMeLink = "#{projectIssuesPath}/?assignee_id=#{userId}"
- issuesIHaveCreatedLink = "#{projectIssuesPath}/?author_id=#{userId}"
- mrsAssignedToMeLink = "#{projectMRsPath}/?assignee_id=#{userId}"
- mrsIHaveCreatedLink = "#{projectMRsPath}/?author_id=#{userId}"
+ it 'should not show category related menu if there is text in the input', ->
- a1 = "a[href='#{issuesAssignedToMeLink}']"
- a2 = "a[href='#{issuesIHaveCreatedLink}']"
- a3 = "a[href='#{mrsAssignedToMeLink}']"
- a4 = "a[href='#{mrsIHaveCreatedLink}']"
+ addBodyAttributes 'project'
+ mockProjectOptions()
+ widget.searchInput.val 'help'
+ widget.searchInput.focus()
- assertLinks l, a1, a2, a3, a4
+ list = widget.wrap.find('.dropdown-menu').find 'ul'
+ link = "a[href='#{projectIssuesPath}/?assignee_id=#{userId}']"
+ expect(list.find(link).length).toBe 0