sidebar_spec.rb 7.4 KB
Newer Older
P
Phil Hughes 已提交
1 2 3
require 'rails_helper'

describe 'Issue Boards', feature: true, js: true do
4
  let(:user)         { create(:user) }
5
  let(:user2)        { create(:user) }
6 7 8 9 10 11
  let(:project)      { create(:empty_project, :public) }
  let!(:milestone)   { create(:milestone, project: project) }
  let!(:development) { create(:label, project: project, name: 'Development') }
  let!(:bug)         { create(:label, project: project, name: 'Bug') }
  let!(:regression)  { create(:label, project: project, name: 'Regression') }
  let!(:stretch)     { create(:label, project: project, name: 'Stretch') }
12
  let!(:issue1)      { create(:labeled_issue, project: project, assignees: [user], milestone: milestone, labels: [development], relative_position: 2) }
P
Phil Hughes 已提交
13
  let!(:issue2)      { create(:labeled_issue, project: project, labels: [development, stretch], relative_position: 1) }
14 15
  let(:board)        { create(:board, project: project) }
  let!(:list)        { create(:list, board: board, label: development, position: 0) }
P
Phil Hughes 已提交
16
  let(:card) { find('.board:nth-child(2)').first('.card') }
P
Phil Hughes 已提交
17 18

  before do
P
Phil Hughes 已提交
19 20
    Timecop.freeze

P
Phil Hughes 已提交
21 22
    project.team << [user, :master]

23
    gitlab_sign_in(user)
P
Phil Hughes 已提交
24

P
Phil Hughes 已提交
25
    visit namespace_project_board_path(project.namespace, project, board)
26
    wait_for_requests
P
Phil Hughes 已提交
27 28
  end

P
Phil Hughes 已提交
29 30 31 32
  after do
    Timecop.return
  end

P
Phil Hughes 已提交
33
  it 'shows sidebar when clicking issue' do
P
Phil Hughes 已提交
34
    click_card(card)
P
Phil Hughes 已提交
35 36 37 38 39

    expect(page).to have_selector('.issue-boards-sidebar')
  end

  it 'closes sidebar when clicking issue' do
P
Phil Hughes 已提交
40
    click_card(card)
P
Phil Hughes 已提交
41 42 43

    expect(page).to have_selector('.issue-boards-sidebar')

P
Phil Hughes 已提交
44
    click_card(card)
P
Phil Hughes 已提交
45 46 47 48 49

    expect(page).not_to have_selector('.issue-boards-sidebar')
  end

  it 'closes sidebar when clicking close button' do
P
Phil Hughes 已提交
50
    click_card(card)
P
Phil Hughes 已提交
51 52 53

    expect(page).to have_selector('.issue-boards-sidebar')

54
    find('.gutter-toggle').trigger('click')
P
Phil Hughes 已提交
55 56 57 58 59

    expect(page).not_to have_selector('.issue-boards-sidebar')
  end

  it 'shows issue details when sidebar is open' do
P
Phil Hughes 已提交
60
    click_card(card)
P
Phil Hughes 已提交
61 62

    page.within('.issue-boards-sidebar') do
63 64
      expect(page).to have_content(issue2.title)
      expect(page).to have_content(issue2.to_reference)
P
Phil Hughes 已提交
65 66 67
    end
  end

P
Phil Hughes 已提交
68 69
  it 'removes card from board when clicking ' do
    click_card(card)
P
Phil Hughes 已提交
70 71 72 73 74

    page.within('.issue-boards-sidebar') do
      click_button 'Remove from board'
    end

75
    wait_for_requests
P
Phil Hughes 已提交
76

P
Phil Hughes 已提交
77
    page.within(find('.board:nth-child(2)')) do
P
Phil Hughes 已提交
78 79 80 81
      expect(page).to have_selector('.card', count: 1)
    end
  end

P
Phil Hughes 已提交
82 83
  context 'assignee' do
    it 'updates the issues assignee' do
P
Phil Hughes 已提交
84
      click_card(card)
P
Phil Hughes 已提交
85 86 87 88

      page.within('.assignee') do
        click_link 'Edit'

89
        wait_for_requests
P
Phil Hughes 已提交
90 91 92 93

        page.within('.dropdown-menu-user') do
          click_link user.name

94
          wait_for_requests
P
Phil Hughes 已提交
95 96 97 98 99
        end

        expect(page).to have_content(user.name)
      end

P
Phil Hughes 已提交
100
      expect(card).to have_selector('.avatar')
P
Phil Hughes 已提交
101 102 103
    end

    it 'removes the assignee' do
P
Phil Hughes 已提交
104
      card_two = find('.board:nth-child(2)').find('.card:nth-child(2)')
P
Phil Hughes 已提交
105
      click_card(card_two)
P
Phil Hughes 已提交
106 107 108 109

      page.within('.assignee') do
        click_link 'Edit'

110
        wait_for_requests
P
Phil Hughes 已提交
111 112 113 114 115

        page.within('.dropdown-menu-user') do
          click_link 'Unassigned'
        end

116
        wait_for_requests
117

P
Phil Hughes 已提交
118 119 120
        expect(page).to have_content('No assignee')
      end

P
Phil Hughes 已提交
121
      expect(card_two).not_to have_selector('.avatar')
P
Phil Hughes 已提交
122 123 124
    end

    it 'assignees to current user' do
P
Phil Hughes 已提交
125
      click_card(card)
P
Phil Hughes 已提交
126

127 128 129
      page.within(find('.assignee')) do
        expect(page).to have_content('No assignee')

130
        click_button 'assign yourself'
P
Phil Hughes 已提交
131

132
        wait_for_requests
P
Phil Hughes 已提交
133 134 135 136

        expect(page).to have_content(user.name)
      end

P
Phil Hughes 已提交
137
      expect(card).to have_selector('.avatar')
P
Phil Hughes 已提交
138
    end
139

140
    it 'updates assignee dropdown' do
P
Phil Hughes 已提交
141
      click_card(card)
142 143 144 145

      page.within('.assignee') do
        click_link 'Edit'

146
        wait_for_requests
147 148 149 150

        page.within('.dropdown-menu-user') do
          click_link user.name

151
          wait_for_requests
152 153 154 155 156
        end

        expect(page).to have_content(user.name)
      end

P
Phil Hughes 已提交
157
      page.within(find('.board:nth-child(2)')) do
158
        find('.card:nth-child(2)').trigger('click')
159 160 161 162
      end

      page.within('.assignee') do
        click_link 'Edit'
163

164
        expect(find('.dropdown-menu')).to have_selector('.is-active')
165 166
      end
    end
P
Phil Hughes 已提交
167 168 169 170
  end

  context 'milestone' do
    it 'adds a milestone' do
P
Phil Hughes 已提交
171
      click_card(card)
P
Phil Hughes 已提交
172 173 174 175

      page.within('.milestone') do
        click_link 'Edit'

176
        wait_for_requests
P
Phil Hughes 已提交
177 178 179

        click_link milestone.title

180
        wait_for_requests
P
Phil Hughes 已提交
181 182 183 184 185 186 187 188

        page.within('.value') do
          expect(page).to have_content(milestone.title)
        end
      end
    end

    it 'removes a milestone' do
P
Phil Hughes 已提交
189
      click_card(card)
P
Phil Hughes 已提交
190 191 192 193

      page.within('.milestone') do
        click_link 'Edit'

194
        wait_for_requests
P
Phil Hughes 已提交
195 196 197

        click_link "No Milestone"

198
        wait_for_requests
P
Phil Hughes 已提交
199 200 201 202 203 204 205 206 207 208

        page.within('.value') do
          expect(page).not_to have_content(milestone.title)
        end
      end
    end
  end

  context 'due date' do
    it 'updates due date' do
P
Phil Hughes 已提交
209
      click_card(card)
P
Phil Hughes 已提交
210 211 212 213

      page.within('.due_date') do
        click_link 'Edit'

P
Phil Hughes 已提交
214
        click_button Date.today.day
P
Phil Hughes 已提交
215

216
        wait_for_requests
P
Phil Hughes 已提交
217 218 219 220 221 222 223 224

        expect(page).to have_content(Date.today.to_s(:medium))
      end
    end
  end

  context 'labels' do
    it 'adds a single label' do
P
Phil Hughes 已提交
225
      click_card(card)
P
Phil Hughes 已提交
226 227 228 229

      page.within('.labels') do
        click_link 'Edit'

230
        wait_for_requests
P
Phil Hughes 已提交
231

232
        click_link bug.title
P
Phil Hughes 已提交
233

234
        wait_for_requests
P
Phil Hughes 已提交
235 236 237 238

        find('.dropdown-menu-close-icon').click

        page.within('.value') do
239 240
          expect(page).to have_selector('.label', count: 3)
          expect(page).to have_content(bug.title)
P
Phil Hughes 已提交
241 242 243
        end
      end

P
Phil Hughes 已提交
244 245
      expect(card).to have_selector('.label', count: 2)
      expect(card).to have_content(bug.title)
P
Phil Hughes 已提交
246 247 248
    end

    it 'adds a multiple labels' do
P
Phil Hughes 已提交
249
      click_card(card)
P
Phil Hughes 已提交
250 251 252 253

      page.within('.labels') do
        click_link 'Edit'

254
        wait_for_requests
P
Phil Hughes 已提交
255

256 257
        click_link bug.title
        click_link regression.title
P
Phil Hughes 已提交
258

259
        wait_for_requests
P
Phil Hughes 已提交
260 261 262 263

        find('.dropdown-menu-close-icon').click

        page.within('.value') do
264 265 266
          expect(page).to have_selector('.label', count: 4)
          expect(page).to have_content(bug.title)
          expect(page).to have_content(regression.title)
P
Phil Hughes 已提交
267 268 269
        end
      end

P
Phil Hughes 已提交
270 271 272
      expect(card).to have_selector('.label', count: 3)
      expect(card).to have_content(bug.title)
      expect(card).to have_content(regression.title)
P
Phil Hughes 已提交
273 274 275
    end

    it 'removes a label' do
P
Phil Hughes 已提交
276
      click_card(card)
P
Phil Hughes 已提交
277 278 279 280

      page.within('.labels') do
        click_link 'Edit'

281
        wait_for_requests
P
Phil Hughes 已提交
282

283
        click_link stretch.title
P
Phil Hughes 已提交
284

285
        wait_for_requests
P
Phil Hughes 已提交
286 287 288 289

        find('.dropdown-menu-close-icon').click

        page.within('.value') do
290 291
          expect(page).to have_selector('.label', count: 1)
          expect(page).not_to have_content(stretch.title)
P
Phil Hughes 已提交
292 293 294
        end
      end

P
Phil Hughes 已提交
295 296
      expect(card).not_to have_selector('.label')
      expect(card).not_to have_content(stretch.title)
P
Phil Hughes 已提交
297 298
    end
  end
299 300 301

  context 'subscription' do
    it 'changes issue subscription' do
P
Phil Hughes 已提交
302
      click_card(card)
303 304 305

      page.within('.subscription') do
        click_button 'Subscribe'
306
        wait_for_requests
307
        expect(page).to have_content("Unsubscribe")
308 309 310
      end
    end
  end
P
Phil Hughes 已提交
311 312 313 314 315 316 317 318 319 320 321

  def click_card(card)
    page.within(card) do
      first('.card-number').click
    end

    wait_for_sidebar
  end

  def wait_for_sidebar
    # loop until the CSS transition is complete
P
Phil Hughes 已提交
322
    Timeout.timeout(0.5) do
P
Phil Hughes 已提交
323 324 325
      loop until evaluate_script('$(".right-sidebar").outerWidth()') == 290
    end
  end
P
Phil Hughes 已提交
326
end