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

move_spec.rb « design_management « mutations « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 27b5259c56b621dd1b12c08b6342f5103a6acd73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# frozen_string_literal: true
require "spec_helper"

RSpec.describe "moving designs", feature_category: :design_management do
  include GraphqlHelpers
  include DesignManagementTestHelpers

  let_it_be(:issue) { create(:issue) }
  let_it_be(:designs) { create_list(:design, 3, :with_versions, :with_relative_position, issue: issue) }
  let_it_be(:developer) { create(:user, developer_projects: [issue.project]) }

  let(:user) { developer }

  let(:current_design) { designs.first }
  let(:previous_design) { designs.second }
  let(:next_design) { designs.third }
  let(:mutation_name) { :design_management_move }

  let(:mutation) do
    input = {
      id: current_design.to_global_id.to_s,
      previous: previous_design&.to_global_id&.to_s,
      next: next_design&.to_global_id&.to_s
    }.compact

    graphql_mutation(mutation_name, input, <<~FIELDS)
    errors
    designCollection {
      designs {
        nodes {
          filename
        }
      }
    }
    FIELDS
  end

  let(:move_designs) { post_graphql_mutation(mutation, current_user: user) }
  let(:mutation_response) { graphql_mutation_response(mutation_name) }

  before do
    enable_design_management
    designs.each(&:reset)
    issue.reset
  end

  shared_examples 'a successful move' do
    it 'does not error, and reports the current order' do
      move_designs

      expect(graphql_errors).not_to be_present

      expect(mutation_response).to eq(
        'errors' => [],
        'designCollection' => {
          'designs' => {
            'nodes' => new_order.map { |d| { 'filename' => d.filename } }
          }
        }
      )
    end
  end

  context 'the user is not allowed to move designs' do
    let(:user) { create(:user) }

    it 'returns an error' do
      move_designs

      expect(graphql_errors).to be_present
    end
  end

  context 'the neighbors do not have positions' do
    let!(:previous_design) { create(:design, :with_versions, issue: issue) }
    let!(:next_design) { create(:design, :with_versions, issue: issue) }

    let(:new_order) do
      [
        designs.second,
        designs.third,
        previous_design, current_design, next_design
      ]
    end

    it_behaves_like 'a successful move'

    it 'maintains the correct order in the presence of other unpositioned designs' do
      other_design = create(:design, :with_versions, issue: issue)

      move_designs
      moved_designs = mutation_response.dig('designCollection', 'designs', 'nodes')

      expect(moved_designs.map { |d| d['filename'] })
        .to eq([*new_order.map(&:filename), other_design.filename])
    end
  end

  context 'moving a design between two others' do
    let(:new_order) { [designs.second, designs.first, designs.third] }

    it_behaves_like 'a successful move'
  end

  context 'moving a design to the start' do
    let(:current_design) { designs.last }
    let(:next_design) { designs.first }
    let(:previous_design) { nil }
    let(:new_order) { [designs.last, designs.first, designs.second] }

    it_behaves_like 'a successful move'
  end

  context 'moving a design to the end' do
    let(:current_design) { designs.first }
    let(:next_design) { nil }
    let(:previous_design) { designs.last }
    let(:new_order) { [designs.second, designs.third, designs.first] }

    it_behaves_like 'a successful move'
  end
end