BigW Consortium Gitlab

issue_sidebar_spec.rb 5.24 KB
Newer Older
1 2 3
require 'rails_helper'

feature 'Issue Sidebar', feature: true do
4
  include MobileHelpers
5

6 7
  let(:group) { create(:group, :nested) }
  let(:project) { create(:project, :public, namespace: group) }
8 9
  let(:issue) { create(:issue, project: project) }
  let!(:user) { create(:user)}
10
  let!(:label) { create(:label, project: project, title: 'bug') }
11 12 13 14 15

  before do
    login_as(user)
  end

16 17 18 19 20 21 22 23 24 25
  context 'assignee', js: true do
    let(:user2) { create(:user) }
    let(:issue2) { create(:issue, project: project, author: user2) }

    before do
      project.team << [user, :developer]
      visit_issue(project, issue2)

      find('.block.assignee .edit-link').click

26
      wait_for_requests
27 28 29 30 31 32 33 34 35 36 37 38 39
    end

    it 'shows author in assignee dropdown' do
      page.within '.dropdown-menu-user' do
        expect(page).to have_content(user2.name)
      end
    end

    it 'shows author when filtering assignee dropdown' do
      page.within '.dropdown-menu-user' do
        find('.dropdown-input-field').native.send_keys user2.name
        sleep 1 # Required to wait for end of input delay

40
        wait_for_requests
41 42 43 44

        expect(page).to have_content(user2.name)
      end
    end
45 46 47 48 49 50

    it 'assigns yourself' do
      find('.block.assignee .dropdown-menu-toggle').click

      click_button 'assign yourself'

51
      wait_for_requests
52 53 54 55 56 57 58 59

      find('.block.assignee .edit-link').click

      page.within '.dropdown-menu-user' do
        expect(page.find('.dropdown-header')).to be_visible
        expect(page.find('.dropdown-menu-user-link.is-active')).to have_content(user.name)
      end
    end
Clement Ho committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

    it 'keeps your filtered term after filtering and dismissing the dropdown' do
      find('.dropdown-input-field').native.send_keys user2.name

      wait_for_requests

      page.within '.dropdown-menu-user' do
        expect(page).not_to have_content 'Unassigned'
        click_link user2.name
      end

      find('.js-right-sidebar').click
      find('.block.assignee .edit-link').click

      expect(page.all('.dropdown-menu-user li').length).to eq(1)
      expect(find('.dropdown-input-field').value).to eq(user2.name)
    end
77 78
  end

79 80 81 82 83 84
  context 'as a allowed user' do
    before do
      project.team << [user, :developer]
      visit_issue(project, issue)
    end

85 86 87 88 89 90
    context 'sidebar', js: true do
      it 'changes size when the screen size is smaller' do
        sidebar_selector = 'aside.right-sidebar.right-sidebar-collapsed'
        # Resize the window
        resize_screen_sm
        # Make sure the sidebar is collapsed
91
        find(sidebar_selector)
92 93
        expect(page).to have_css(sidebar_selector)
        # Once is collapsed let's open the sidebard and reload
94
        open_issue_sidebar
95
        refresh
96
        find(sidebar_selector)
97 98 99
        expect(page).to have_css(sidebar_selector)
        # Restore the window size as it was including the sidebar
        restore_window_size
100
        open_issue_sidebar
101 102 103
      end
    end

104 105
    context 'editing issue labels', js: true do
      before do
106 107
        page.within('.block.labels') do
          find('.edit-link').click
108 109
        end
      end
110

111 112
      it 'shows option to create a new label' do
        page.within('.block.labels') do
113 114 115 116
          expect(page).to have_content 'Create new'
        end
      end

117 118 119 120 121 122
      context 'creating a new label', js: true do
        before do
          page.within('.block.labels') do
            click_link 'Create new'
          end
        end
123

124 125 126 127
        it 'shows dropdown switches to "create label" section' do
          page.within('.block.labels') do
            expect(page).to have_content 'Create new label'
          end
128 129
        end

130 131 132 133 134 135 136 137 138 139 140
        it 'adds new label' do
          page.within('.block.labels') do
            fill_in 'new_label_name', with: 'wontfix'
            page.find(".suggest-colors a", match: :first).click
            click_button 'Create'

            page.within('.dropdown-page-one') do
              expect(page).to have_content 'wontfix'
            end
          end
        end
141

142 143 144 145 146
        it 'shows error message if label title is taken' do
          page.within('.block.labels') do
            fill_in 'new_label_name', with: label.title
            page.find('.suggest-colors a', match: :first).click
            click_button 'Create'
147

148 149 150
            page.within('.dropdown-page-two') do
              expect(page).to have_content 'Title has already been taken'
            end
151 152 153 154 155 156
          end
        end
      end
    end
  end

157 158 159 160 161 162 163 164 165 166 167 168 169 170
  context 'as a allowed mobile user', js: true do
    before do
      project.team << [user, :developer]
      resize_screen_xs
      visit_issue(project, issue)
    end

    context 'mobile sidebar' do
      it 'collapses the sidebar for small screens' do
        expect(page).not_to have_css('aside.right-sidebar.right-sidebar-collapsed')
      end
    end
  end

171 172 173 174 175 176 177 178 179 180 181 182 183 184
  context 'as a guest' do
    before do
      project.team << [user, :guest]
      visit_issue(project, issue)
    end

    it 'does not have a option to edit labels' do
      expect(page).not_to have_selector('.block.labels .edit-link')
    end
  end

  def visit_issue(project, issue)
    visit namespace_project_issue_path(project.namespace, project, issue)
  end
185 186

  def open_issue_sidebar
187
    find('aside.right-sidebar.right-sidebar-collapsed .js-sidebar-toggle').trigger('click')
188
    find('aside.right-sidebar.right-sidebar-expanded')
189
  end
190
end