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

cherry_pick_spec.rb « commit « projects « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 489a90cc8fcd1525736bbaf535faca3455dfb041 (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
123
124
125
126
127
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Cherry-pick Commits', :js do
  let_it_be(:user) { create(:user) }
  let_it_be(:sha) { '7d3b0f7cff5f37573aea97cebfd5692ea1689924' }
  let!(:project) { create_default(:project, :repository, namespace: user.namespace) }
  let(:master_pickable_commit) { project.commit(sha) }

  before do
    sign_in(user)
  end

  context 'when clicking cherry-pick from the dropdown for a commit on pipelines tab' do
    it 'launches the modal form' do
      create(:ci_empty_pipeline, sha: sha)
      visit project_commit_path(project, master_pickable_commit.id)
      click_link 'Pipelines'

      open_modal

      page.within(modal_selector) do
        expect(page).to have_content('Cherry-pick this commit')
      end
    end
  end

  context 'when starting from the commit tab' do
    before do
      visit project_commit_path(project, master_pickable_commit.id)
    end

    context 'when cherry-picking a commit' do
      specify do
        cherry_pick_commit

        expect(page).to have_content('The commit has been successfully cherry-picked into master.')
      end
    end

    context 'when cherry-picking a merge commit' do
      specify do
        cherry_pick_commit

        expect(page).to have_content('The commit has been successfully cherry-picked into master.')
      end
    end

    context 'when cherry-picking a commit that was previously cherry-picked' do
      specify do
        cherry_pick_commit

        visit project_commit_path(project, master_pickable_commit.id)

        cherry_pick_commit

        expect(page).to have_content('Sorry, we cannot cherry-pick this commit automatically.')
      end
    end

    context 'when cherry-picking a commit in a new merge request' do
      specify do
        cherry_pick_commit(create_merge_request: true)

        expect(page).to have_content("The commit has been successfully cherry-picked into cherry-pick-#{master_pickable_commit.short_id}. You can now submit a merge request to get this change into the original branch.")
        expect(page).to have_content("From cherry-pick-#{master_pickable_commit.short_id} into master")
      end
    end

    context 'when I cherry-picking a commit from a different branch' do
      specify do
        open_modal

        page.within(modal_selector) do
          click_button 'master'
        end

        page.within("#{modal_selector} .dropdown-menu") do
          find('[data-testid="dropdown-search-box"]').set('feature')
          wait_for_requests
          click_button 'feature'
        end

        submit_cherry_pick

        expect(page).to have_content('The commit has been successfully cherry-picked into feature.')
      end
    end

    context 'when the project is archived' do
      let(:project) { create(:project, :repository, :archived, namespace: user.namespace) }

      it 'does not show the cherry-pick link' do
        open_dropdown

        expect(page).not_to have_text("Cherry-pick")
      end
    end
  end

  def cherry_pick_commit(create_merge_request: false)
    open_modal

    submit_cherry_pick(create_merge_request: create_merge_request)
  end

  def open_dropdown
    find('.header-action-buttons .dropdown').click
  end

  def open_modal
    open_dropdown
    find('[data-testid="cherry-pick-commit-link"]').click
  end

  def submit_cherry_pick(create_merge_request: false)
    page.within(modal_selector) do
      uncheck('create_merge_request') unless create_merge_request
      click_button('Cherry-pick')
    end
  end

  def modal_selector
    '[data-testid="modal-commit"]'
  end
end