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

describe 'Issue Boards', feature: true, js: true do
  include WaitForVueResource

6
  let(:user)         { create(:user) }
7
  let(:user2)        { create(:user) }
8 9 10 11 12 13
  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') }
14
  let!(:issue1)      { create(:labeled_issue, project: project, assignees: [user], milestone: milestone, labels: [development], relative_position: 2) }
P
Phil Hughes 已提交
15
  let!(:issue2)      { create(:labeled_issue, project: project, labels: [development, stretch], relative_position: 1) }
16 17
  let(:board)        { create(:board, project: project) }
  let!(:list)        { create(:list, board: board, label: development, position: 0) }
P
Phil Hughes 已提交
18
  let(:card) { first('.board').first('.card') }
P
Phil Hughes 已提交
19 20

  before do
P
Phil Hughes 已提交
21 22
    Timecop.freeze

P
Phil Hughes 已提交
23 24 25 26
    project.team << [user, :master]

    login_as(user)

P
Phil Hughes 已提交
27
    visit namespace_project_board_path(project.namespace, project, board)
P
Phil Hughes 已提交
28 29 30
    wait_for_vue_resource
  end

P
Phil Hughes 已提交
31 32 33 34
  after do
    Timecop.return
  end

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

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

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

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

P
Phil Hughes 已提交
46
    click_card(card)
P
Phil Hughes 已提交
47 48 49 50 51

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

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

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

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

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

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

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

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

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

P
Phil Hughes 已提交
77 78
    wait_for_vue_resource

P
Phil Hughes 已提交
79 80 81 82 83
    page.within(first('.board')) do
      expect(page).to have_selector('.card', count: 1)
    end
  end

P
Phil Hughes 已提交
84 85
  context 'assignee' do
    it 'updates the issues assignee' do
P
Phil Hughes 已提交
86
      click_card(card)
P
Phil Hughes 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

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

        wait_for_ajax

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

          wait_for_vue_resource
        end

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

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

    it 'removes the assignee' do
P
Phil Hughes 已提交
106 107
      card_two = first('.board').find('.card:nth-child(2)')
      click_card(card_two)
P
Phil Hughes 已提交
108 109 110 111 112 113 114 115 116 117

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

        wait_for_ajax

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

118 119 120
        find('.dropdown-menu-toggle').click
        wait_for_vue_resource

P
Phil Hughes 已提交
121 122 123
        expect(page).to have_content('No assignee')
      end

P
Phil Hughes 已提交
124
      expect(card_two).not_to have_selector('.avatar')
P
Phil Hughes 已提交
125 126 127
    end

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

130 131 132
      page.within(find('.assignee')) do
        expect(page).to have_content('No assignee')

133
        click_button 'assign yourself'
P
Phil Hughes 已提交
134 135 136 137 138 139

        wait_for_vue_resource

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

P
Phil Hughes 已提交
140
      expect(card).to have_selector('.avatar')
P
Phil Hughes 已提交
141
    end
142

143
    it 'updates assignee dropdown' do
P
Phil Hughes 已提交
144
      click_card(card)
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

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

        wait_for_ajax

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

          wait_for_vue_resource
        end

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

      page.within(first('.board')) do
        find('.card:nth-child(2)').click
      end

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

167
        expect(page).to have_selector('.is-active')
168 169
      end
    end
P
Phil Hughes 已提交
170 171 172 173
  end

  context 'milestone' do
    it 'adds a milestone' do
P
Phil Hughes 已提交
174
      click_card(card)
P
Phil Hughes 已提交
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191

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

        wait_for_ajax

        click_link milestone.title

        wait_for_vue_resource

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

    it 'removes a milestone' do
P
Phil Hughes 已提交
192
      click_card(card)
P
Phil Hughes 已提交
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211

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

        wait_for_ajax

        click_link "No Milestone"

        wait_for_vue_resource

        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 已提交
212
      click_card(card)
P
Phil Hughes 已提交
213 214 215 216

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

P
Phil Hughes 已提交
217
        click_button Date.today.day
P
Phil Hughes 已提交
218 219 220 221 222 223 224 225 226 227

        wait_for_vue_resource

        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 已提交
228
      click_card(card)
P
Phil Hughes 已提交
229 230 231 232 233 234

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

        wait_for_ajax

235
        click_link bug.title
P
Phil Hughes 已提交
236 237 238 239 240 241

        wait_for_vue_resource

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

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

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

    it 'adds a multiple labels' do
P
Phil Hughes 已提交
252
      click_card(card)
P
Phil Hughes 已提交
253 254 255 256 257 258

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

        wait_for_ajax

259 260
        click_link bug.title
        click_link regression.title
P
Phil Hughes 已提交
261 262 263 264 265 266

        wait_for_vue_resource

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

        page.within('.value') do
267 268 269
          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 已提交
270 271 272
        end
      end

P
Phil Hughes 已提交
273 274 275
      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 已提交
276 277 278
    end

    it 'removes a label' do
P
Phil Hughes 已提交
279
      click_card(card)
P
Phil Hughes 已提交
280 281 282 283 284 285

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

        wait_for_ajax

286
        click_link stretch.title
P
Phil Hughes 已提交
287 288 289 290 291 292

        wait_for_vue_resource

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

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

P
Phil Hughes 已提交
298 299
      expect(card).not_to have_selector('.label')
      expect(card).not_to have_content(stretch.title)
P
Phil Hughes 已提交
300 301
    end
  end
302 303 304

  context 'subscription' do
    it 'changes issue subscription' do
P
Phil Hughes 已提交
305
      click_card(card)
306 307 308

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

  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 已提交
325
    Timeout.timeout(0.5) do
P
Phil Hughes 已提交
326 327 328
      loop until evaluate_script('$(".right-sidebar").outerWidth()') == 290
    end
  end
P
Phil Hughes 已提交
329
end