Commit c0a7eb38 authored by Stan Hu's avatar Stan Hu

Refactor boards_spec.rb to avoid code duplication

Originally created to address #21197, but !6224 solved the intermittent spec
failures.
parent d38499b3
...@@ -94,15 +94,8 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -94,15 +94,8 @@ describe 'Issue Boards', feature: true, js: true do
end end
it 'shows issues in lists' do it 'shows issues in lists' do
page.within(find('.board:nth-child(2)')) do wait_for_board_cards(2, 2)
expect(page.find('.board-header')).to have_content('2') wait_for_board_cards(3, 2)
expect(page).to have_selector('.card', count: 2)
end
page.within(find('.board:nth-child(3)')) do
expect(page.find('.board-header')).to have_content('2')
expect(page).to have_selector('.card', count: 2)
end
end end
it 'shows confidential issues with icon' do it 'shows confidential issues with icon' do
...@@ -203,37 +196,33 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -203,37 +196,33 @@ describe 'Issue Boards', feature: true, js: true do
context 'backlog' do context 'backlog' do
it 'shows issues in backlog with no labels' do it 'shows issues in backlog with no labels' do
page.within(find('.board', match: :first)) do wait_for_board_cards(1, 6)
expect(page.find('.board-header')).to have_content('6')
expect(page).to have_selector('.card', count: 6)
end
end end
it 'moves issue from backlog into list' do it 'moves issue from backlog into list' do
drag_to(list_to_index: 1) drag_to(list_to_index: 1)
page.within(find('.board', match: :first)) do
expect(page.find('.board-header')).to have_content('5')
expect(page).to have_selector('.card', count: 5)
end
wait_for_vue_resource wait_for_vue_resource
wait_for_board_cards(1, 5)
page.within(find('.board:nth-child(2)')) do wait_for_board_cards(2, 3)
expect(page.find('.board-header')).to have_content('3')
expect(page).to have_selector('.card', count: 3)
end
end end
end end
context 'done' do context 'done' do
it 'shows list of done issues' do it 'shows list of done issues' do
expect(find('.board:nth-child(4)')).to have_selector('.card', count: 1) wait_for_board_cards(4, 1)
wait_for_ajax
end end
it 'moves issue to done' do it 'moves issue to done' do
drag_to(list_from_index: 0, list_to_index: 3) drag_to(list_from_index: 0, list_to_index: 3)
wait_for_board_cards(1, 5)
wait_for_board_cards(2, 2)
wait_for_board_cards(3, 2)
wait_for_board_cards(4, 2)
expect(find('.board:nth-child(1)')).not_to have_content(issue9.title)
expect(find('.board:nth-child(4)')).to have_selector('.card', count: 2) expect(find('.board:nth-child(4)')).to have_selector('.card', count: 2)
expect(find('.board:nth-child(4)')).to have_content(issue9.title) expect(find('.board:nth-child(4)')).to have_content(issue9.title)
expect(find('.board:nth-child(4)')).not_to have_content(planning.title) expect(find('.board:nth-child(4)')).not_to have_content(planning.title)
...@@ -242,8 +231,12 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -242,8 +231,12 @@ describe 'Issue Boards', feature: true, js: true do
it 'removes all of the same issue to done' do it 'removes all of the same issue to done' do
drag_to(list_from_index: 1, list_to_index: 3) drag_to(list_from_index: 1, list_to_index: 3)
expect(find('.board:nth-child(2)')).to have_selector('.card', count: 1) wait_for_board_cards(1, 6)
expect(find('.board:nth-child(3)')).to have_selector('.card', count: 1) wait_for_board_cards(2, 1)
wait_for_board_cards(3, 1)
wait_for_board_cards(4, 2)
expect(find('.board:nth-child(2)')).not_to have_content(issue6.title)
expect(find('.board:nth-child(4)')).to have_content(issue6.title) expect(find('.board:nth-child(4)')).to have_content(issue6.title)
expect(find('.board:nth-child(4)')).not_to have_content(planning.title) expect(find('.board:nth-child(4)')).not_to have_content(planning.title)
end end
...@@ -253,6 +246,11 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -253,6 +246,11 @@ describe 'Issue Boards', feature: true, js: true do
it 'changes position of list' do it 'changes position of list' do
drag_to(list_from_index: 1, list_to_index: 2, selector: '.board-header') drag_to(list_from_index: 1, list_to_index: 2, selector: '.board-header')
wait_for_board_cards(1, 6)
wait_for_board_cards(2, 2)
wait_for_board_cards(3, 2)
wait_for_board_cards(4, 1)
expect(find('.board:nth-child(2)')).to have_content(development.title) expect(find('.board:nth-child(2)')).to have_content(development.title)
expect(find('.board:nth-child(2)')).to have_content(planning.title) expect(find('.board:nth-child(2)')).to have_content(planning.title)
end end
...@@ -260,8 +258,11 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -260,8 +258,11 @@ describe 'Issue Boards', feature: true, js: true do
it 'issue moves between lists' do it 'issue moves between lists' do
drag_to(list_from_index: 1, card_index: 1, list_to_index: 2) drag_to(list_from_index: 1, card_index: 1, list_to_index: 2)
expect(find('.board:nth-child(2)')).to have_selector('.card', count: 1) wait_for_board_cards(1, 6)
expect(find('.board:nth-child(3)')).to have_selector('.card', count: 3) wait_for_board_cards(2, 1)
wait_for_board_cards(3, 3)
wait_for_board_cards(4, 1)
expect(find('.board:nth-child(3)')).to have_content(issue6.title) expect(find('.board:nth-child(3)')).to have_content(issue6.title)
expect(find('.board:nth-child(3)').all('.card').last).not_to have_content(development.title) expect(find('.board:nth-child(3)').all('.card').last).not_to have_content(development.title)
end end
...@@ -269,8 +270,11 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -269,8 +270,11 @@ describe 'Issue Boards', feature: true, js: true do
it 'issue moves between lists' do it 'issue moves between lists' do
drag_to(list_from_index: 2, list_to_index: 1) drag_to(list_from_index: 2, list_to_index: 1)
expect(find('.board:nth-child(2)')).to have_selector('.card', count: 3) wait_for_board_cards(1, 6)
expect(find('.board:nth-child(3)')).to have_selector('.card', count: 1) wait_for_board_cards(2, 3)
wait_for_board_cards(3, 1)
wait_for_board_cards(4, 1)
expect(find('.board:nth-child(2)')).to have_content(issue7.title) expect(find('.board:nth-child(2)')).to have_content(issue7.title)
expect(find('.board:nth-child(2)').all('.card').first).not_to have_content(planning.title) expect(find('.board:nth-child(2)').all('.card').first).not_to have_content(planning.title)
end end
...@@ -278,8 +282,12 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -278,8 +282,12 @@ describe 'Issue Boards', feature: true, js: true do
it 'issue moves from done' do it 'issue moves from done' do
drag_to(list_from_index: 3, list_to_index: 1) drag_to(list_from_index: 3, list_to_index: 1)
expect(find('.board:nth-child(2)')).to have_selector('.card', count: 3)
expect(find('.board:nth-child(2)')).to have_content(issue8.title) expect(find('.board:nth-child(2)')).to have_content(issue8.title)
wait_for_board_cards(1, 6)
wait_for_board_cards(2, 3)
wait_for_board_cards(3, 2)
wait_for_board_cards(4, 0)
end end
context 'issue card' do context 'issue card' do
...@@ -342,10 +350,7 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -342,10 +350,7 @@ describe 'Issue Boards', feature: true, js: true do
end end
it 'moves issues from backlog into new list' do it 'moves issues from backlog into new list' do
page.within(find('.board', match: :first)) do wait_for_board_cards(1, 6)
expect(page.find('.board-header')).to have_content('6')
expect(page).to have_selector('.card', count: 6)
end
click_button 'Create new list' click_button 'Create new list'
wait_for_ajax wait_for_ajax
...@@ -356,10 +361,7 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -356,10 +361,7 @@ describe 'Issue Boards', feature: true, js: true do
wait_for_vue_resource wait_for_vue_resource
page.within(find('.board', match: :first)) do wait_for_board_cards(1, 5)
expect(page.find('.board-header')).to have_content('5')
expect(page).to have_selector('.card', count: 5)
end
end end
end end
end end
...@@ -379,16 +381,8 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -379,16 +381,8 @@ describe 'Issue Boards', feature: true, js: true do
end end
wait_for_vue_resource wait_for_vue_resource
wait_for_board_cards(1, 1)
page.within(find('.board', match: :first)) do wait_for_empty_boards((2..4))
expect(page.find('.board-header')).to have_content('1')
expect(page).to have_selector('.card', count: 1)
end
page.within(find('.board:nth-child(2)')) do
expect(page.find('.board-header')).to have_content('0')
expect(page).to have_selector('.card', count: 0)
end
end end
it 'filters by assignee' do it 'filters by assignee' do
...@@ -406,15 +400,8 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -406,15 +400,8 @@ describe 'Issue Boards', feature: true, js: true do
wait_for_vue_resource wait_for_vue_resource
page.within(find('.board', match: :first)) do wait_for_board_cards(1, 1)
expect(page.find('.board-header')).to have_content('1') wait_for_empty_boards((2..4))
expect(page).to have_selector('.card', count: 1)
end
page.within(find('.board:nth-child(2)')) do
expect(page.find('.board-header')).to have_content('0')
expect(page).to have_selector('.card', count: 0)
end
end end
it 'filters by milestone' do it 'filters by milestone' do
...@@ -431,16 +418,10 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -431,16 +418,10 @@ describe 'Issue Boards', feature: true, js: true do
end end
wait_for_vue_resource wait_for_vue_resource
wait_for_board_cards(1, 0)
page.within(find('.board', match: :first)) do wait_for_board_cards(2, 1)
expect(page.find('.board-header')).to have_content('0') wait_for_board_cards(3, 0)
expect(page).to have_selector('.card', count: 0) wait_for_board_cards(4, 0)
end
page.within(find('.board:nth-child(2)')) do
expect(page.find('.board-header')).to have_content('1')
expect(page).to have_selector('.card', count: 1)
end
end end
it 'filters by label' do it 'filters by label' do
...@@ -456,16 +437,8 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -456,16 +437,8 @@ describe 'Issue Boards', feature: true, js: true do
end end
wait_for_vue_resource wait_for_vue_resource
wait_for_board_cards(1, 1)
page.within(find('.board', match: :first)) do wait_for_empty_boards((2..4))
expect(page.find('.board-header')).to have_content('1')
expect(page).to have_selector('.card', count: 1)
end
page.within(find('.board:nth-child(2)')) do
expect(page.find('.board-header')).to have_content('0')
expect(page).to have_selector('.card', count: 0)
end
end end
it 'infinite scrolls list with label filter' do it 'infinite scrolls list with label filter' do
...@@ -519,15 +492,8 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -519,15 +492,8 @@ describe 'Issue Boards', feature: true, js: true do
wait_for_vue_resource wait_for_vue_resource
page.within(find('.board', match: :first)) do wait_for_board_cards(1, 1)
expect(page.find('.board-header')).to have_content('1') wait_for_empty_boards((2..4))
expect(page).to have_selector('.card', count: 1)
end
page.within(find('.board:nth-child(2)')) do
expect(page.find('.board-header')).to have_content('0')
expect(page).to have_selector('.card', count: 0)
end
end end
it 'filters by no label' do it 'filters by no label' do
...@@ -544,15 +510,10 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -544,15 +510,10 @@ describe 'Issue Boards', feature: true, js: true do
wait_for_vue_resource wait_for_vue_resource
page.within(find('.board', match: :first)) do wait_for_board_cards(1, 5)
expect(page.find('.board-header')).to have_content('5') wait_for_board_cards(2, 0)
expect(page).to have_selector('.card', count: 5) wait_for_board_cards(3, 0)
end wait_for_board_cards(4, 1)
page.within(find('.board:nth-child(2)')) do
expect(page.find('.board-header')).to have_content('0')
expect(page).to have_selector('.card', count: 0)
end
end end
it 'filters by clicking label button on issue' do it 'filters by clicking label button on issue' do
...@@ -565,15 +526,8 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -565,15 +526,8 @@ describe 'Issue Boards', feature: true, js: true do
wait_for_vue_resource wait_for_vue_resource
page.within(find('.board', match: :first)) do wait_for_board_cards(1, 1)
expect(page.find('.board-header')).to have_content('1') wait_for_empty_boards((2..4))
expect(page).to have_selector('.card', count: 1)
end
page.within(find('.board:nth-child(2)')) do
expect(page.find('.board-header')).to have_content('0')
expect(page).to have_selector('.card', count: 0)
end
page.within('.labels-filter') do page.within('.labels-filter') do
expect(find('.dropdown-toggle-text')).to have_content(bug.title) expect(find('.dropdown-toggle-text')).to have_content(bug.title)
...@@ -648,4 +602,17 @@ describe 'Issue Boards', feature: true, js: true do ...@@ -648,4 +602,17 @@ describe 'Issue Boards', feature: true, js: true do
wait_for_vue_resource wait_for_vue_resource
end end
def wait_for_board_cards(board_number, expected_cards)
page.within(find(".board:nth-child(#{board_number})")) do
expect(page.find('.board-header')).to have_content(expected_cards.to_s)
expect(page).to have_selector('.card', count: expected_cards)
end
end
def wait_for_empty_boards(board_numbers)
board_numbers.each do |board|
wait_for_board_cards(board, 0)
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