Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/services/boards/lists_move_service_shared_examples.rb')
-rw-r--r--spec/support/shared_examples/services/boards/lists_move_service_shared_examples.rb120
1 files changed, 64 insertions, 56 deletions
diff --git a/spec/support/shared_examples/services/boards/lists_move_service_shared_examples.rb b/spec/support/shared_examples/services/boards/lists_move_service_shared_examples.rb
index bf84b912610..97d0bae3552 100644
--- a/spec/support/shared_examples/services/boards/lists_move_service_shared_examples.rb
+++ b/spec/support/shared_examples/services/boards/lists_move_service_shared_examples.rb
@@ -1,95 +1,103 @@
# frozen_string_literal: true
RSpec.shared_examples 'lists move service' do
- let!(:planning) { create(:list, board: board, position: 0) }
- let!(:development) { create(:list, board: board, position: 1) }
- let!(:review) { create(:list, board: board, position: 2) }
- let!(:staging) { create(:list, board: board, position: 3) }
- let!(:closed) { create(:closed_list, board: board) }
+ shared_examples 'correct movement behavior' do
+ context 'when list type is set to label' do
+ it 'does not reorder lists when new position is nil' do
+ service = described_class.new(parent, user, position: nil)
- context 'when list type is set to label' do
- it 'keeps position of lists when new position is nil' do
- service = described_class.new(parent, user, position: nil)
+ service.execute(planning)
- service.execute(planning)
+ expect(ordered_lists).to eq([planning, development, review, staging])
+ end
- expect(current_list_positions).to eq [0, 1, 2, 3]
- end
-
- it 'keeps position of lists when new position is equal to old position' do
- service = described_class.new(parent, user, position: planning.position)
+ it 'does not reorder lists when new position is equal to old position' do
+ service = described_class.new(parent, user, position: planning.position)
- service.execute(planning)
+ service.execute(planning)
- expect(current_list_positions).to eq [0, 1, 2, 3]
- end
+ expect(ordered_lists).to eq([planning, development, review, staging])
+ end
- it 'keeps position of lists when new position is negative' do
- service = described_class.new(parent, user, position: -1)
+ it 'does not reorder lists when new position is negative' do
+ service = described_class.new(parent, user, position: -1)
- service.execute(planning)
+ service.execute(planning)
- expect(current_list_positions).to eq [0, 1, 2, 3]
- end
+ expect(ordered_lists).to eq([planning, development, review, staging])
+ end
- it 'keeps position of lists when new position is equal to number of labels lists' do
- service = described_class.new(parent, user, position: board.lists.label.size)
+ it 'does not reorder lists when new position is bigger then last position' do
+ service = described_class.new(parent, user, position: ordered_lists.last.position + 1)
- service.execute(planning)
+ service.execute(planning)
- expect(current_list_positions).to eq [0, 1, 2, 3]
- end
+ expect(ordered_lists).to eq([planning, development, review, staging])
+ end
- it 'keeps position of lists when new position is greater than number of labels lists' do
- service = described_class.new(parent, user, position: board.lists.label.size + 1)
+ it 'moves the list to the first position when new position is equal to first position' do
+ service = described_class.new(parent, user, position: 0)
- service.execute(planning)
+ service.execute(staging)
- expect(current_list_positions).to eq [0, 1, 2, 3]
- end
+ expect(ordered_lists).to eq([staging, planning, development, review])
+ end
- it 'increments position of intermediate lists when new position is equal to first position' do
- service = described_class.new(parent, user, position: 0)
+ it 'moves the list to the last position when new position is equal to last position' do
+ service = described_class.new(parent, user, position: board.lists.label.last.position)
- service.execute(staging)
+ service.execute(planning)
- expect(current_list_positions).to eq [1, 2, 3, 0]
- end
+ expect(ordered_lists).to eq([development, review, staging, planning])
+ end
- it 'decrements position of intermediate lists when new position is equal to last position' do
- service = described_class.new(parent, user, position: board.lists.label.last.position)
+ it 'moves the list to the correct position when new position is greater than old position (third list)' do
+ service = described_class.new(parent, user, position: review.position)
- service.execute(planning)
+ service.execute(planning)
- expect(current_list_positions).to eq [3, 0, 1, 2]
- end
+ expect(ordered_lists).to eq([development, review, planning, staging])
+ end
- it 'decrements position of intermediate lists when new position is greater than old position' do
- service = described_class.new(parent, user, position: 2)
+ it 'moves the list to the correct position when new position is lower than old position (second list)' do
+ service = described_class.new(parent, user, position: development.position)
- service.execute(planning)
+ service.execute(staging)
- expect(current_list_positions).to eq [2, 0, 1, 3]
+ expect(ordered_lists).to eq([planning, staging, development, review])
+ end
end
- it 'increments position of intermediate lists when new position is lower than old position' do
- service = described_class.new(parent, user, position: 1)
+ it 'keeps position of lists when list type is closed' do
+ service = described_class.new(parent, user, position: 2)
- service.execute(staging)
+ service.execute(closed)
- expect(current_list_positions).to eq [0, 2, 3, 1]
+ expect(ordered_lists).to eq([planning, development, review, staging])
end
end
- it 'keeps position of lists when list type is closed' do
- service = described_class.new(parent, user, position: 2)
+ context 'with complete position sequence' do
+ let!(:planning) { create(:list, board: board, position: 0) }
+ let!(:development) { create(:list, board: board, position: 1) }
+ let!(:review) { create(:list, board: board, position: 2) }
+ let!(:staging) { create(:list, board: board, position: 3) }
+ let!(:closed) { create(:closed_list, board: board) }
+
+ it_behaves_like 'correct movement behavior'
+ end
- service.execute(closed)
+ context 'with corrupted position sequence' do
+ let!(:planning) { create(:list, board: board, position: 0) }
+ let!(:staging) { create(:list, board: board, position: 6) }
+ let!(:development) { create(:list, board: board, position: 1) }
+ let!(:review) { create(:list, board: board, position: 4) }
+ let!(:closed) { create(:closed_list, board: board) }
- expect(current_list_positions).to eq [0, 1, 2, 3]
+ it_behaves_like 'correct movement behavior'
end
- def current_list_positions
- [planning, development, review, staging].map { |list| list.reload.position }
+ def ordered_lists
+ board.lists.where.not(position: nil)
end
end