Commit 319b151e authored by Eulyeon Ko's avatar Eulyeon Ko Committed by David O'Regan

Apply reviewer suggestions

- Use let_it_be over let for performance
- Remove repeated, unnecessary code
parent 13065180
...@@ -8,19 +8,20 @@ require 'spec_helper' ...@@ -8,19 +8,20 @@ require 'spec_helper'
RSpec.describe 'Issue Boards', :js do RSpec.describe 'Issue Boards', :js do
include BoardHelpers include BoardHelpers
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:user2) { create(:user) } let_it_be(:user2) { create(:user) }
let(:group) { create(:group) } let_it_be(:group) { create(:group) }
let(:project) { create(:project, :public, group: group) } let_it_be(:project) { create(:project, :public, group: group) }
let!(:milestone) { create(:milestone, project: project) } let_it_be(:milestone) { create(:milestone, project: project) }
let!(:development) { create(:label, project: project, name: 'Development') } let_it_be(:development) { create(:label, project: project, name: 'Development') }
let!(:stretch) { create(:label, project: project, name: 'Stretch') } let_it_be(:stretch) { create(:label, project: project, name: 'Stretch') }
let!(:issue1) { create(:labeled_issue, project: project, assignees: [user], milestone: milestone, labels: [development], weight: 3, relative_position: 2) } let_it_be(:issue1) { create(:labeled_issue, project: project, assignees: [user], milestone: milestone, labels: [development], weight: 3, relative_position: 2) }
let!(:issue2) { create(:labeled_issue, project: project, labels: [development, stretch], relative_position: 1) } let_it_be(:issue2) { create(:labeled_issue, project: project, labels: [development, stretch], relative_position: 1) }
let!(:scoped_label_1) { create(:label, project: project, name: 'Scoped1::Label1') } let_it_be(:board) { create(:board, project: project) }
let!(:scoped_label_2) { create(:label, project: project, name: 'Scoped2::Label2') } let_it_be(:list) { create(:list, board: board, label: development, position: 0) }
let(:board) { create(:board, project: project) } let_it_be(:scoped_label_1) { create(:label, project: project, name: 'Scoped1::Label1') }
let!(:list) { create(:list, board: board, label: development, position: 0) } let_it_be(:scoped_label_2) { create(:label, project: project, name: 'Scoped2::Label2') }
let(:card1) { find('.board:nth-child(2)').find('.board-card:nth-child(2)') } let(:card1) { find('.board:nth-child(2)').find('.board-card:nth-child(2)') }
let(:card2) { find('.board:nth-child(2)').find('.board-card:nth-child(1)') } let(:card2) { find('.board:nth-child(2)').find('.board-card:nth-child(1)') }
...@@ -79,9 +80,11 @@ RSpec.describe 'Issue Boards', :js do ...@@ -79,9 +80,11 @@ RSpec.describe 'Issue Boards', :js do
click_button('Apply') click_button('Apply')
wait_for_requests wait_for_requests
aggregate_failures do
expect(page).to have_link(nil, title: user.name) expect(page).to have_link(nil, title: user.name)
expect(page).to have_link(nil, title: assignee) expect(page).to have_link(nil, title: assignee)
end end
end
expect(card1.all('.avatar').length).to eq(2) expect(card1.all('.avatar').length).to eq(2)
end end
...@@ -91,14 +94,12 @@ RSpec.describe 'Issue Boards', :js do ...@@ -91,14 +94,12 @@ RSpec.describe 'Issue Boards', :js do
page.within('.assignee') do page.within('.assignee') do
click_button('Edit') click_button('Edit')
wait_for_requests
page.within('.dropdown-menu-user') do page.within('.dropdown-menu-user') do
find('[data-testid="unassign"]').click find('[data-testid="unassign"]').click
end end
click_button('Apply') click_button('Apply')
wait_for_requests
expect(page).to have_content('None') expect(page).to have_content('None')
end end
...@@ -109,9 +110,7 @@ RSpec.describe 'Issue Boards', :js do ...@@ -109,9 +110,7 @@ RSpec.describe 'Issue Boards', :js do
it 'assignees to current user' do it 'assignees to current user' do
click_card(card2) click_card(card2)
wait_for_requests page.within('.assignee') do
page.within(find('.assignee')) do
expect(page).to have_content('None') expect(page).to have_content('None')
click_button 'assign yourself' click_button 'assign yourself'
...@@ -143,9 +142,7 @@ RSpec.describe 'Issue Boards', :js do ...@@ -143,9 +142,7 @@ RSpec.describe 'Issue Boards', :js do
expect(page).to have_content(assignee) expect(page).to have_content(assignee)
end end
page.within(find('.board:nth-child(2)')) do click_card(card1)
find('.board-card:nth-child(2)').click
end
page.within('.assignee') do page.within('.assignee') do
click_button('Edit') click_button('Edit')
...@@ -167,7 +164,6 @@ RSpec.describe 'Issue Boards', :js do ...@@ -167,7 +164,6 @@ RSpec.describe 'Issue Boards', :js do
context 'when the issue is not associated with an epic' do context 'when the issue is not associated with an epic' do
it 'displays `None` for value of epic' do it 'displays `None` for value of epic' do
click_card(card1) click_card(card1)
wait_for_requests
expect(find('.js-epic-label').text).to have_content('None') expect(find('.js-epic-label').text).to have_content('None')
end end
...@@ -180,16 +176,14 @@ RSpec.describe 'Issue Boards', :js do ...@@ -180,16 +176,14 @@ RSpec.describe 'Issue Boards', :js do
it 'displays name of epic and links to it' do it 'displays name of epic and links to it' do
click_card(card1) click_card(card1)
wait_for_requests
expect(find('.js-epic-label')).to have_link(epic1.title, href: epic_path(epic1)) expect(find('.js-epic-label')).to have_link(epic1.title, href: epic_path(epic1))
end end
it 'updates the epic associated with the issue' do it 'updates the epic associated with the issue' do
click_card(card1) click_card(card1)
wait_for_requests
page.within(find('.js-epic-block')) do page.within('.js-epic-block') do
page.find('.sidebar-dropdown-toggle').click page.find('.sidebar-dropdown-toggle').click
wait_for_requests wait_for_requests
...@@ -201,10 +195,8 @@ RSpec.describe 'Issue Boards', :js do ...@@ -201,10 +195,8 @@ RSpec.describe 'Issue Boards', :js do
# Ensure that boards_store is also updated the epic associated with the issue. # Ensure that boards_store is also updated the epic associated with the issue.
click_card(card1) click_card(card1)
wait_for_requests
click_card(card1) click_card(card1)
wait_for_requests
expect(find('.js-epic-label')).to have_content(epic2.title) expect(find('.js-epic-label')).to have_content(epic2.title)
end end
...@@ -214,14 +206,12 @@ RSpec.describe 'Issue Boards', :js do ...@@ -214,14 +206,12 @@ RSpec.describe 'Issue Boards', :js do
context 'weight' do context 'weight' do
it 'displays weight async' do it 'displays weight async' do
click_card(card1) click_card(card1)
wait_for_requests
expect(find('.js-weight-weight-label').text).to have_content(issue1.weight) expect(find('.js-weight-weight-label').text).to have_content(issue1.weight)
end end
it 'updates weight in sidebar to 1' do it 'updates weight in sidebar to 1' do
click_card(card1) click_card(card1)
wait_for_requests
page.within '.weight' do page.within '.weight' do
click_link 'Edit' click_link 'Edit'
...@@ -237,18 +227,14 @@ RSpec.describe 'Issue Boards', :js do ...@@ -237,18 +227,14 @@ RSpec.describe 'Issue Boards', :js do
wait_for_requests wait_for_requests
click_card(card1) click_card(card1)
wait_for_requests
page.within '.weight' do page.within '.weight .value' do
page.within '.value' do
expect(page).to have_content '1' expect(page).to have_content '1'
end end
end end
end
it 'updates weight in sidebar to no weight' do it 'updates weight in sidebar to no weight' do
click_card(card1) click_card(card1)
wait_for_requests
page.within '.weight' do page.within '.weight' do
click_link 'remove weight' click_link 'remove weight'
...@@ -263,14 +249,11 @@ RSpec.describe 'Issue Boards', :js do ...@@ -263,14 +249,11 @@ RSpec.describe 'Issue Boards', :js do
wait_for_requests wait_for_requests
click_card(card1) click_card(card1)
wait_for_requests
page.within '.weight' do page.within '.weight .value' do
page.within '.value' do
expect(page).to have_content 'None' expect(page).to have_content 'None'
end end
end end
end
context 'unlicensed' do context 'unlicensed' do
before do before do
...@@ -281,7 +264,6 @@ RSpec.describe 'Issue Boards', :js do ...@@ -281,7 +264,6 @@ RSpec.describe 'Issue Boards', :js do
it 'hides weight' do it 'hides weight' do
click_card(card1) click_card(card1)
wait_for_requests
expect(page).not_to have_selector('.js-weight-weight-label') expect(page).not_to have_selector('.js-weight-weight-label')
end end
...@@ -315,6 +297,7 @@ RSpec.describe 'Issue Boards', :js do ...@@ -315,6 +297,7 @@ RSpec.describe 'Issue Boards', :js do
find('.dropdown-menu-close-icon').click find('.dropdown-menu-close-icon').click
page.within('.value') do page.within('.value') do
aggregate_failures do
expect(page).to have_selector('.gl-label-scoped', count: 2) expect(page).to have_selector('.gl-label-scoped', count: 2)
expect(page).to have_content(scoped_label_1.scoped_label_key) expect(page).to have_content(scoped_label_1.scoped_label_key)
expect(page).to have_content(scoped_label_1.scoped_label_value) expect(page).to have_content(scoped_label_1.scoped_label_value)
...@@ -323,10 +306,10 @@ RSpec.describe 'Issue Boards', :js do ...@@ -323,10 +306,10 @@ RSpec.describe 'Issue Boards', :js do
end end
end end
end end
end
context 'with scoped label assigned' do context 'with scoped label assigned' do
let!(:issue3) { create(:labeled_issue, project: project, labels: [development, scoped_label_1, scoped_label_2], relative_position: 3) } let!(:issue3) { create(:labeled_issue, project: project, labels: [development, scoped_label_1, scoped_label_2], relative_position: 3) }
let(:board) { create(:board, project: project) }
let(:card3) { find('.board:nth-child(2)').find('.board-card:nth-child(1)') } let(:card3) { find('.board:nth-child(2)').find('.board-card:nth-child(1)') }
before do before do
...@@ -351,13 +334,16 @@ RSpec.describe 'Issue Boards', :js do ...@@ -351,13 +334,16 @@ RSpec.describe 'Issue Boards', :js do
find('.dropdown-menu-close-icon').click find('.dropdown-menu-close-icon').click
page.within('.value') do page.within('.value') do
aggregate_failures do
expect(page).to have_selector('.gl-label-scoped', count: 1) expect(page).to have_selector('.gl-label-scoped', count: 1)
expect(page).not_to have_content(scoped_label_1.scoped_label_value) expect(page).not_to have_content(scoped_label_1.scoped_label_value)
expect(page).to have_content(scoped_label_2.scoped_label_key) expect(page).to have_content(scoped_label_2.scoped_label_key)
expect(page).to have_content(scoped_label_2.scoped_label_value) expect(page).to have_content(scoped_label_2.scoped_label_value)
end end
end end
end
aggregate_failures do
expect(card3).to have_selector('.gl-label-scoped', count: 1) expect(card3).to have_selector('.gl-label-scoped', count: 1)
expect(card3).not_to have_content(scoped_label_1.scoped_label_key) expect(card3).not_to have_content(scoped_label_1.scoped_label_key)
expect(card3).not_to have_content(scoped_label_1.scoped_label_value) expect(card3).not_to have_content(scoped_label_1.scoped_label_value)
...@@ -366,6 +352,7 @@ RSpec.describe 'Issue Boards', :js do ...@@ -366,6 +352,7 @@ RSpec.describe 'Issue Boards', :js do
end end
end end
end end
end
context 'when opening sidebars' do context 'when opening sidebars' do
let(:settings_button) { find('.js-board-settings-button') } let(:settings_button) { find('.js-board-settings-button') }
......
This diff is collapsed.
...@@ -4,6 +4,7 @@ module BoardHelpers ...@@ -4,6 +4,7 @@ module BoardHelpers
def click_card(card) def click_card(card)
within card do within card do
first('.board-card-number').click first('.board-card-number').click
wait_for_requests
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment