PageRenderTime 51ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/features/issues/filtered_search/visual_tokens_spec.rb

https://gitlab.com/certik/gitlab-ce
Ruby | 356 lines | 274 code | 82 blank | 0 comment | 0 complexity | facdb655a2b3482e32ae867e06b7a06e MD5 | raw file
  1. require 'rails_helper'
  2. describe 'Visual tokens', js: true do
  3. include FilteredSearchHelpers
  4. include WaitForRequests
  5. let!(:project) { create(:project) }
  6. let!(:user) { create(:user, name: 'administrator', username: 'root') }
  7. let!(:user_rock) { create(:user, name: 'The Rock', username: 'rock') }
  8. let!(:milestone_nine) { create(:milestone, title: '9.0', project: project) }
  9. let!(:milestone_ten) { create(:milestone, title: '10.0', project: project) }
  10. let!(:label) { create(:label, project: project, title: 'abc') }
  11. let!(:cc_label) { create(:label, project: project, title: 'Community Contribution') }
  12. let(:filtered_search) { find('.filtered-search') }
  13. let(:filter_author_dropdown) { find("#js-dropdown-author .filter-dropdown") }
  14. let(:filter_assignee_dropdown) { find("#js-dropdown-assignee .filter-dropdown") }
  15. let(:filter_milestone_dropdown) { find("#js-dropdown-milestone .filter-dropdown") }
  16. let(:filter_label_dropdown) { find("#js-dropdown-label .filter-dropdown") }
  17. def is_input_focused
  18. page.evaluate_script("document.activeElement.classList.contains('filtered-search')")
  19. end
  20. before do
  21. project.add_user(user, :master)
  22. project.add_user(user_rock, :master)
  23. sign_in(user)
  24. create(:issue, project: project)
  25. page.driver.set_cookie('sidebar_collapsed', 'true')
  26. visit project_issues_path(project)
  27. end
  28. describe 'editing author token' do
  29. before do
  30. input_filtered_search('author:@root assignee:none', submit: false)
  31. first('.tokens-container .filtered-search-token').click
  32. end
  33. it 'opens author dropdown' do
  34. expect(page).to have_css('#js-dropdown-author', visible: true)
  35. end
  36. it 'makes value editable' do
  37. expect_filtered_search_input('@root')
  38. end
  39. it 'filters value' do
  40. filtered_search.send_keys(:backspace)
  41. expect(page).to have_css('#js-dropdown-author .filter-dropdown .filter-dropdown-item', count: 1)
  42. end
  43. it 'ends editing mode when document is clicked' do
  44. find('#content-body').click
  45. expect_filtered_search_input_empty
  46. expect(page).to have_css('#js-dropdown-author', visible: false)
  47. end
  48. it 'ends editing mode when scroll container is clicked' do
  49. find('.scroll-container').click
  50. expect_filtered_search_input_empty
  51. expect(page).to have_css('#js-dropdown-author', visible: false)
  52. end
  53. describe 'selecting different author from dropdown' do
  54. before do
  55. filter_author_dropdown.find('.filter-dropdown-item .dropdown-light-content', text: "@#{user_rock.username}").click
  56. end
  57. it 'changes value in visual token' do
  58. wait_for_requests
  59. expect(first('.tokens-container .filtered-search-token .value').text).to eq("#{user_rock.name}")
  60. end
  61. it 'moves input to the right' do
  62. expect(is_input_focused).to eq(true)
  63. end
  64. end
  65. end
  66. describe 'editing assignee token' do
  67. before do
  68. input_filtered_search('assignee:@root author:none', submit: false)
  69. first('.tokens-container .filtered-search-token').double_click
  70. end
  71. it 'opens assignee dropdown' do
  72. expect(page).to have_css('#js-dropdown-assignee', visible: true)
  73. end
  74. it 'makes value editable' do
  75. expect_filtered_search_input('@root')
  76. end
  77. it 'filters value' do
  78. filtered_search.send_keys(:backspace)
  79. expect(page).to have_css('#js-dropdown-assignee .filter-dropdown .filter-dropdown-item', count: 1)
  80. end
  81. it 'ends editing mode when document is clicked' do
  82. find('#content-body').click
  83. expect_filtered_search_input_empty
  84. expect(page).to have_css('#js-dropdown-assignee', visible: false)
  85. end
  86. it 'ends editing mode when scroll container is clicked' do
  87. find('.scroll-container').click
  88. expect_filtered_search_input_empty
  89. expect(page).to have_css('#js-dropdown-assignee', visible: false)
  90. end
  91. describe 'selecting static option from dropdown' do
  92. before do
  93. find("#js-dropdown-assignee").find('.filter-dropdown-item', text: 'No Assignee').click
  94. end
  95. it 'changes value in visual token' do
  96. expect(first('.tokens-container .filtered-search-token .value').text).to eq('none')
  97. end
  98. it 'moves input to the right' do
  99. expect(is_input_focused).to eq(true)
  100. end
  101. end
  102. end
  103. describe 'editing milestone token' do
  104. before do
  105. input_filtered_search('milestone:%10.0 author:none', submit: false)
  106. first('.tokens-container .filtered-search-token').click
  107. first('#js-dropdown-milestone .filter-dropdown .filter-dropdown-item')
  108. end
  109. it 'opens milestone dropdown' do
  110. expect(filter_milestone_dropdown.find('.filter-dropdown-item', text: milestone_ten.title)).to be_visible
  111. expect(filter_milestone_dropdown.find('.filter-dropdown-item', text: milestone_nine.title)).to be_visible
  112. expect(page).to have_css('#js-dropdown-milestone', visible: true)
  113. end
  114. it 'selects static option from dropdown' do
  115. find("#js-dropdown-milestone").find('.filter-dropdown-item', text: 'Upcoming').click
  116. expect(first('.tokens-container .filtered-search-token .value').text).to eq('upcoming')
  117. expect(is_input_focused).to eq(true)
  118. end
  119. it 'makes value editable' do
  120. expect_filtered_search_input('%10.0')
  121. end
  122. it 'filters value' do
  123. filtered_search.send_keys(:backspace)
  124. expect(page).to have_css('#js-dropdown-milestone .filter-dropdown .filter-dropdown-item', count: 1)
  125. end
  126. it 'ends editing mode when document is clicked' do
  127. find('#content-body').click
  128. expect_filtered_search_input_empty
  129. expect(page).to have_css('#js-dropdown-milestone', visible: false)
  130. end
  131. it 'ends editing mode when scroll container is clicked' do
  132. find('.scroll-container').click
  133. expect_filtered_search_input_empty
  134. expect(page).to have_css('#js-dropdown-milestone', visible: false)
  135. end
  136. end
  137. describe 'editing label token' do
  138. before do
  139. input_filtered_search("label:~#{label.title} author:none", submit: false)
  140. first('.tokens-container .filtered-search-token').double_click
  141. first('#js-dropdown-label .filter-dropdown .filter-dropdown-item')
  142. end
  143. it 'opens label dropdown' do
  144. expect(filter_label_dropdown.find('.filter-dropdown-item', text: label.title)).to be_visible
  145. expect(filter_label_dropdown.find('.filter-dropdown-item', text: cc_label.title)).to be_visible
  146. expect(page).to have_css('#js-dropdown-label', visible: true)
  147. end
  148. it 'selects option from dropdown' do
  149. expect(filter_label_dropdown.find('.filter-dropdown-item', text: label.title)).to be_visible
  150. expect(filter_label_dropdown.find('.filter-dropdown-item', text: cc_label.title)).to be_visible
  151. find("#js-dropdown-label").find('.filter-dropdown-item', text: cc_label.title).click
  152. expect(first('.tokens-container .filtered-search-token .value').text).to eq("~\"#{cc_label.title}\"")
  153. expect(is_input_focused).to eq(true)
  154. end
  155. it 'makes value editable' do
  156. expect_filtered_search_input("~#{label.title}")
  157. end
  158. it 'filters value' do
  159. expect(filter_label_dropdown.find('.filter-dropdown-item', text: label.title)).to be_visible
  160. expect(filter_label_dropdown.find('.filter-dropdown-item', text: cc_label.title)).to be_visible
  161. filtered_search.send_keys(:backspace)
  162. filter_label_dropdown.find('.filter-dropdown-item')
  163. expect(page.all('#js-dropdown-label .filter-dropdown .filter-dropdown-item').size).to eq(1)
  164. end
  165. it 'ends editing mode when document is clicked' do
  166. find('#content-body').click
  167. expect_filtered_search_input_empty
  168. expect(page).to have_css('#js-dropdown-label', visible: false)
  169. end
  170. it 'ends editing mode when scroll container is clicked' do
  171. find('.scroll-container').click
  172. expect_filtered_search_input_empty
  173. expect(page).to have_css('#js-dropdown-label', visible: false)
  174. end
  175. end
  176. describe 'editing multiple tokens' do
  177. before do
  178. input_filtered_search('author:@root assignee:none', submit: false)
  179. first('.tokens-container .filtered-search-token').double_click
  180. end
  181. it 'opens author dropdown' do
  182. expect(page).to have_css('#js-dropdown-author', visible: true)
  183. end
  184. it 'opens assignee dropdown' do
  185. find('.tokens-container .filtered-search-token', text: 'Assignee').double_click
  186. expect(page).to have_css('#js-dropdown-assignee', visible: true)
  187. end
  188. end
  189. describe 'editing a search term while editing another filter token' do
  190. before do
  191. input_filtered_search('author assignee:', submit: false)
  192. first('.tokens-container .filtered-search-term').double_click
  193. end
  194. it 'opens hint dropdown' do
  195. expect(page).to have_css('#js-dropdown-hint', visible: true)
  196. end
  197. it 'opens author dropdown' do
  198. find('#js-dropdown-hint .filter-dropdown .filter-dropdown-item', text: 'author').click
  199. expect(page).to have_css('#js-dropdown-author', visible: true)
  200. end
  201. end
  202. describe 'add new token after editing existing token' do
  203. before do
  204. input_filtered_search('author:@root assignee:none', submit: false)
  205. first('.tokens-container .filtered-search-token').double_click
  206. filtered_search.send_keys(' ')
  207. end
  208. describe 'opens dropdowns' do
  209. it 'opens hint dropdown' do
  210. expect(page).to have_css('#js-dropdown-hint', visible: true)
  211. end
  212. it 'opens author dropdown' do
  213. filtered_search.send_keys('author:')
  214. expect(page).to have_css('#js-dropdown-author', visible: true)
  215. end
  216. it 'opens assignee dropdown' do
  217. filtered_search.send_keys('assignee:')
  218. expect(page).to have_css('#js-dropdown-assignee', visible: true)
  219. end
  220. it 'opens milestone dropdown' do
  221. filtered_search.send_keys('milestone:')
  222. expect(page).to have_css('#js-dropdown-milestone', visible: true)
  223. end
  224. it 'opens label dropdown' do
  225. filtered_search.send_keys('label:')
  226. expect(page).to have_css('#js-dropdown-label', visible: true)
  227. end
  228. end
  229. describe 'creates visual tokens' do
  230. it 'creates author token' do
  231. filtered_search.send_keys('author:@thomas ')
  232. token = page.all('.tokens-container .filtered-search-token')[1]
  233. expect(token.find('.name').text).to eq('Author')
  234. expect(token.find('.value').text).to eq('@thomas')
  235. end
  236. it 'creates assignee token' do
  237. filtered_search.send_keys('assignee:@thomas ')
  238. token = page.all('.tokens-container .filtered-search-token')[1]
  239. expect(token.find('.name').text).to eq('Assignee')
  240. expect(token.find('.value').text).to eq('@thomas')
  241. end
  242. it 'creates milestone token' do
  243. filtered_search.send_keys('milestone:none ')
  244. token = page.all('.tokens-container .filtered-search-token')[1]
  245. expect(token.find('.name').text).to eq('Milestone')
  246. expect(token.find('.value').text).to eq('none')
  247. end
  248. it 'creates label token' do
  249. filtered_search.send_keys('label:~Backend ')
  250. token = page.all('.tokens-container .filtered-search-token')[1]
  251. expect(token.find('.name').text).to eq('Label')
  252. expect(token.find('.value').text).to eq('~Backend')
  253. end
  254. end
  255. it 'does not tokenize incomplete token' do
  256. filtered_search.send_keys('author:')
  257. find('body').click
  258. token = page.all('.tokens-container .js-visual-token')[1]
  259. expect_filtered_search_input_empty
  260. expect(token.find('.name').text).to eq('Author')
  261. end
  262. end
  263. describe 'search using incomplete visual tokens' do
  264. before do
  265. input_filtered_search('author:@root assignee:none', extra_space: false)
  266. end
  267. it 'tokenizes the search term to complete visual token' do
  268. expect_tokens([
  269. author_token(user.name),
  270. assignee_token('none')
  271. ])
  272. end
  273. end
  274. end