move_service_spec.rb 3.34 KB
Newer Older
1 2 3 4 5 6
require 'spec_helper'

describe Boards::Lists::MoveService, services: true do
  describe '#execute' do
    let(:project) { create(:project_with_board) }
    let(:board)   { project.board }
7 8 9 10 11 12 13

    let!(:backlog)     { create(:backlog_list, board: board) }
    let!(:planning)    { create(:label_list,   board: board, position: 1) }
    let!(:development) { create(:label_list,   board: board, position: 2) }
    let!(:review)      { create(:label_list,   board: board, position: 3) }
    let!(:staging)     { create(:label_list,   board: board, position: 4) }
    let!(:done)        { create(:done_list,    board: board) }
14

15 16
    context 'when list type is set to label' do
      it 'keeps position of lists when new position is nil' do
17
        service = described_class.new(project, { list_id: planning.id, position: nil })
18 19 20

        service.execute

21
        expect(current_list_positions).to eq [1, 2, 3, 4]
22 23 24
      end

      it 'keeps position of lists when new positon is equal to old position' do
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
        service = described_class.new(project, { list_id: planning.id, position: 1 })

        service.execute

        expect(current_list_positions).to eq [1, 2, 3, 4]
      end

      it 'keeps position of lists when new positon is negative' do
        service = described_class.new(project, { list_id: planning.id, position: -1 })

        service.execute

        expect(current_list_positions).to eq [1, 2, 3, 4]
      end

      it 'keeps position of lists when new positon is greater than number of labels lists' do
        service = described_class.new(project, { list_id: planning.id, position: 6 })
42 43 44

        service.execute

45
        expect(current_list_positions).to eq [1, 2, 3, 4]
46 47
      end

48 49
      it 'increments position of intermediate lists when new positon is equal to first position' do
        service = described_class.new(project, { list_id: staging.id, position: 1 })
50 51 52

        service.execute

53
        expect(current_list_positions).to eq [2, 3, 4, 1]
54 55
      end

56 57
      it 'decrements position of intermediate lists when new positon is equal to last position' do
        service = described_class.new(project, { list_id: planning.id, position: 4 })
58 59 60

        service.execute

61
        expect(current_list_positions).to eq [4, 1, 2, 3]
62
      end
63

64
      it 'decrements position of intermediate lists when new position is greater than old position' do
65
        service = described_class.new(project, { list_id: planning.id, position: 3 })
66 67 68

        service.execute

69
        expect(current_list_positions).to eq [3, 1, 2, 4]
70 71
      end

72 73
      it 'increments position of intermediate lists when new position is lower than old position' do
        service = described_class.new(project, { list_id: staging.id, position: 2 })
74 75 76

        service.execute

77
        expect(current_list_positions).to eq [1, 3, 4, 2]
78
      end
79 80
    end

81
    it 'keeps position of lists when list type is backlog' do
82
      service = described_class.new(project, { list_id: backlog.id, position: 2 })
83 84 85

      service.execute

86
      expect(current_list_positions).to eq [1, 2, 3, 4]
87 88
    end

89
    it 'keeps position of lists when list type is done' do
90
      service = described_class.new(project, { list_id: done.id, position: 2 })
91 92 93

      service.execute

94
      expect(current_list_positions).to eq [1, 2, 3, 4]
95 96
    end
  end
97

98 99
  def current_list_positions
    [planning, development, review, staging].map { |list| list.reload.position }
100
  end
101
end