dropdown_label_spec.rb 7.3 KB
Newer Older
C
Clement Ho 已提交
1 2 3 4 5 6 7 8 9 10 11
require 'rails_helper'

describe 'Dropdown label', js: true, feature: true do
  include WaitForAjax

  let!(:project) { create(:empty_project) }
  let!(:user) { create(:user) }
  let!(:bug_label) { create(:label, project: project, title: 'bug') }
  let!(:uppercase_label) { create(:label, project: project, title: 'BUG') }
  let!(:two_words_label) { create(:label, project: project, title: 'High Priority') }
  let!(:wont_fix_label) { create(:label, project: project, title: 'Won"t Fix') }
C
Clement Ho 已提交
12
  let!(:wont_fix_single_label) { create(:label, project: project, title: 'Won\'t Fix') }
C
Clement Ho 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
  let!(:special_label) { create(:label, project: project, title: '!@#$%^+&*()')}
  let!(:long_label) { create(:label, project: project, title: 'this is a very long title this is a very long title this is a very long title this is a very long title this is a very long title')}
  let(:filtered_search) { find('.filtered-search') }
  let(:js_dropdown_label) { '#js-dropdown-label' }

  def send_keys_to_filtered_search(input)
    input.split("").each do |i|
      filtered_search.send_keys(i)
      sleep 3
      wait_for_ajax
      sleep 3
    end
  end

  def dropdown_label_size
    page.all('#js-dropdown-label .filter-dropdown .filter-dropdown-item').size
  end

  def click_label(text)
    find('#js-dropdown-label .filter-dropdown .filter-dropdown-item', text: text).click
  end

  before do
    project.team << [user, :master]
    login_as(user)
    create(:issue, project: project)

    visit namespace_project_issues_path(project.namespace, project)
  end

  describe 'behavior' do
    it 'opens when the search bar has label:' do
      filtered_search.set('label:')
C
Clement Ho 已提交
46

C
Clement Ho 已提交
47 48 49 50 51
      expect(page).to have_css(js_dropdown_label, visible: true)
    end

    it 'closes when the search bar is unfocused' do
      find('body').click()
C
Clement Ho 已提交
52

C
Clement Ho 已提交
53 54 55 56 57
      expect(page).to have_css(js_dropdown_label, visible: false)
    end

    it 'should show loading indicator when opened' do
      filtered_search.set('label:')
C
Clement Ho 已提交
58

C
Clement Ho 已提交
59 60 61 62 63
      expect(page).to have_css('#js-dropdown-label .filter-dropdown-loading', visible: true)
    end

    it 'should hide loading indicator when loaded' do
      send_keys_to_filtered_search('label:')
C
Clement Ho 已提交
64

C
Clement Ho 已提交
65 66 67 68 69
      expect(page).not_to have_css('#js-dropdown-label .filter-dropdown-loading')
    end

    it 'should load all the labels when opened' do
      send_keys_to_filtered_search('label:')
C
Clement Ho 已提交
70

C
Clement Ho 已提交
71 72 73 74 75 76
      expect(dropdown_label_size).to be > 0
    end
  end

  describe 'filtering' do
    before do
C
Clement Ho 已提交
77
      filtered_search.set('label')
C
Clement Ho 已提交
78 79 80
    end

    it 'filters by name' do
C
Clement Ho 已提交
81
      send_keys_to_filtered_search(':b')
C
Clement Ho 已提交
82

C
Clement Ho 已提交
83 84 85 86
      expect(dropdown_label_size).to eq(2)
    end

    it 'filters by case insensitive name' do
C
Clement Ho 已提交
87
      send_keys_to_filtered_search(':B')
C
Clement Ho 已提交
88

C
Clement Ho 已提交
89 90 91 92
      expect(dropdown_label_size).to eq(2)
    end

    it 'filters by name with symbol' do
C
Clement Ho 已提交
93
      send_keys_to_filtered_search(':~bu')
C
Clement Ho 已提交
94

C
Clement Ho 已提交
95 96 97 98
      expect(dropdown_label_size).to eq(2)
    end

    it 'filters by case insensitive name with symbol' do
C
Clement Ho 已提交
99
      send_keys_to_filtered_search(':~BU')
C
Clement Ho 已提交
100

C
Clement Ho 已提交
101 102 103
      expect(dropdown_label_size).to eq(2)
    end

C
Clement Ho 已提交
104 105
    it 'filters by multiple words' do
      send_keys_to_filtered_search(':Hig')
C
Clement Ho 已提交
106

C
Clement Ho 已提交
107 108 109 110 111
      expect(dropdown_label_size).to eq(1)
    end

    it 'filters by multiple words with symbol' do
      send_keys_to_filtered_search(':~Hig')
C
Clement Ho 已提交
112

C
Clement Ho 已提交
113 114 115
      expect(dropdown_label_size).to eq(1)
    end

C
Clement Ho 已提交
116 117
    it 'filters by multiple words containing single quotes' do
      send_keys_to_filtered_search(':won\'t')
C
Clement Ho 已提交
118

C
Clement Ho 已提交
119 120 121
      expect(dropdown_label_size).to eq(1)
    end

C
Clement Ho 已提交
122 123
    it 'filters by multiple words containing single quotes with symbol' do
      send_keys_to_filtered_search(':~won\'t')
C
Clement Ho 已提交
124

C
Clement Ho 已提交
125 126 127
      expect(dropdown_label_size).to eq(1)
    end

C
Clement Ho 已提交
128 129
    it 'filters by multiple words containing double quotes' do
      send_keys_to_filtered_search(':won"t')
C
Clement Ho 已提交
130

C
Clement Ho 已提交
131 132 133
      expect(dropdown_label_size).to eq(1)
    end

C
Clement Ho 已提交
134 135
    it 'filters by multiple words containing double quotes with symbol' do
      send_keys_to_filtered_search(':~won"t')
C
Clement Ho 已提交
136

C
Clement Ho 已提交
137 138 139 140
      expect(dropdown_label_size).to eq(1)
    end

    it 'filters by special characters' do
C
Clement Ho 已提交
141
      send_keys_to_filtered_search(':^+')
C
Clement Ho 已提交
142

C
Clement Ho 已提交
143 144 145 146
      expect(dropdown_label_size).to eq(1)
    end

    it 'filters by special characters with symbol' do
C
Clement Ho 已提交
147
      send_keys_to_filtered_search(':~^+')
C
Clement Ho 已提交
148

C
Clement Ho 已提交
149 150 151 152 153 154 155 156 157 158 159
      expect(dropdown_label_size).to eq(1)
    end
  end

  describe 'selecting from dropdown' do
    before do
      filtered_search.set('label:')
    end

    it 'fills in the label name when the label has not been filled' do
      click_label(bug_label.title)
C
Clement Ho 已提交
160

C
Clement Ho 已提交
161
      expect(page).to have_css(js_dropdown_label, visible: false)
162
      expect(filtered_search.value).to eq("label:~#{bug_label.title} ")
C
Clement Ho 已提交
163 164 165 166 167
    end

    it 'fills in the label name when the label is partially filled' do
      send_keys_to_filtered_search('bu')
      click_label(bug_label.title)
C
Clement Ho 已提交
168

C
Clement Ho 已提交
169
      expect(page).to have_css(js_dropdown_label, visible: false)
170
      expect(filtered_search.value).to eq("label:~#{bug_label.title} ")
C
Clement Ho 已提交
171 172 173 174
    end

    it 'fills in the label name that contains multiple words' do
      click_label(two_words_label.title)
C
Clement Ho 已提交
175

C
Clement Ho 已提交
176
      expect(page).to have_css(js_dropdown_label, visible: false)
177
      expect(filtered_search.value).to eq("label:~\"#{two_words_label.title}\" ")
C
Clement Ho 已提交
178 179 180 181
    end

    it 'fills in the label name that contains multiple words and is very long' do
      click_label(long_label.title)
C
Clement Ho 已提交
182

C
Clement Ho 已提交
183
      expect(page).to have_css(js_dropdown_label, visible: false)
184
      expect(filtered_search.value).to eq("label:~\"#{long_label.title}\" ")
C
Clement Ho 已提交
185 186 187 188
    end

    it 'fills in the label name that contains double quotes' do
      click_label(wont_fix_label.title)
C
Clement Ho 已提交
189

C
Clement Ho 已提交
190
      expect(page).to have_css(js_dropdown_label, visible: false)
191
      expect(filtered_search.value).to eq("label:~'#{wont_fix_label.title}' ")
C
Clement Ho 已提交
192 193 194 195
    end

    it 'fills in the label name with the correct capitalization' do
      click_label(uppercase_label.title)
C
Clement Ho 已提交
196

C
Clement Ho 已提交
197
      expect(page).to have_css(js_dropdown_label, visible: false)
198
      expect(filtered_search.value).to eq("label:~#{uppercase_label.title} ")
C
Clement Ho 已提交
199 200 201 202
    end

    it 'fills in the label name with special characters' do
      click_label(special_label.title)
C
Clement Ho 已提交
203

C
Clement Ho 已提交
204
      expect(page).to have_css(js_dropdown_label, visible: false)
205
      expect(filtered_search.value).to eq("label:~#{special_label.title} ")
C
Clement Ho 已提交
206 207 208
    end

    it 'selects `no label`' do
C
Clement Ho 已提交
209
      find('#js-dropdown-label .filter-dropdown-item', text: 'No Label').click
C
Clement Ho 已提交
210

C
Clement Ho 已提交
211
      expect(page).to have_css(js_dropdown_label, visible: false)
212
      expect(filtered_search.value).to eq("label:none ")
C
Clement Ho 已提交
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
    end
  end

  describe 'input has existing content' do
    it 'opens label dropdown with existing search term' do
      filtered_search.set('searchTerm label:')
      expect(page).to have_css(js_dropdown_label, visible: true)
    end

    it 'opens label dropdown with existing author' do
      filtered_search.set('author:@person label:')
      expect(page).to have_css(js_dropdown_label, visible: true)
    end

    it 'opens label dropdown with existing assignee' do
      filtered_search.set('assignee:@person label:')
      expect(page).to have_css(js_dropdown_label, visible: true)
    end

    it 'opens label dropdown with existing label' do
      filtered_search.set('label:~urgent label:')
      expect(page).to have_css(js_dropdown_label, visible: true)
    end

    it 'opens label dropdown with existing milestone' do
      filtered_search.set('milestone:%v2.0 label:')
      expect(page).to have_css(js_dropdown_label, visible: true)
    end
  end
end