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

editor_spec.rb « ci « projects « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: daf5ac61d7385ce0762ec5dba5dd5d7f6f6aeaed (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Pipeline Editor', :js do
  include Spec::Support::Helpers::Features::SourceEditorSpecHelpers

  let(:project) { create(:project_empty_repo, :public) }
  let(:user) { create(:user) }

  let(:default_branch) { 'main' }
  let(:other_branch) { 'test' }

  before do
    sign_in(user)
    project.add_developer(user)

    project.repository.create_file(user, project.ci_config_path_or_default, 'Default Content', message: 'Create CI file for main', branch_name: default_branch)
    project.repository.create_file(user, project.ci_config_path_or_default, 'Other Content', message: 'Create CI file for test', branch_name: other_branch)

    visit project_ci_pipeline_editor_path(project)
    wait_for_requests
  end

  it 'user sees the Pipeline Editor page' do
    expect(page).to have_content('Pipeline Editor')
  end

  describe 'Branch switcher' do
    def switch_to_branch(branch)
      find('[data-testid="branch-selector"]').click

      page.within '[data-testid="branch-selector"]' do
        click_button branch
        wait_for_requests
      end
    end

    it 'displays current branch' do
      page.within('[data-testid="branch-selector"]') do
        expect(page).to have_content(default_branch)
        expect(page).not_to have_content(other_branch)
      end
    end

    it 'displays updated current branch after switching branches' do
      switch_to_branch(other_branch)

      page.within('[data-testid="branch-selector"]') do
        expect(page).to have_content(other_branch)
        expect(page).not_to have_content(default_branch)
      end
    end

    it 'displays new branch as selected after commiting on a new branch' do
      find('#target-branch-field').set('new_branch', clear: :backspace)

      click_button 'Commit changes'

      page.within('[data-testid="branch-selector"]') do
        expect(page).to have_content('new_branch')
        expect(page).not_to have_content(default_branch)
      end
    end
  end

  describe 'Editor navigation' do
    context 'when no change is made' do
      it 'user can navigate away without a browser alert' do
        expect(page).to have_content('Pipeline Editor')

        click_link 'Pipelines'

        expect(page).not_to have_content('Pipeline Editor')
      end
    end

    context 'when a change is made' do
      before do
        click_button 'Collapse'

        page.within('#source-editor-') do
          find('textarea').send_keys '123'
          # It takes some time after sending keys for the vue
          # component to update
          sleep 1
        end
      end

      it 'user who tries to navigate away can cancel the action and keep their changes' do
        click_link 'Pipelines'

        page.driver.browser.switch_to.alert.dismiss

        expect(page).to have_content('Pipeline Editor')

        page.within('#source-editor-') do
          expect(page).to have_content('Default Content123')
        end
      end

      it 'user who tries to navigate away can confirm the action and discard their change' do
        click_link 'Pipelines'

        page.driver.browser.switch_to.alert.accept

        expect(page).not_to have_content('Pipeline Editor')
      end

      it 'user who creates a MR is taken to the merge request page without warnings' do
        expect(page).not_to have_content('New merge request')

        find_field('Target Branch').set 'new_branch'
        find_field('Start a new merge request with these changes').click

        click_button 'Commit changes'

        expect(page).not_to have_content('Pipeline Editor')
        expect(page).to have_content('New merge request')
      end
    end
  end

  describe 'Editor content' do
    it 'user can reset their CI configuration' do
      click_button 'Collapse'

      page.within('#source-editor-') do
        find('textarea').send_keys '123'
      end

      # It takes some time after sending keys for the reset
      # btn to register the changes inside the editor
      sleep 1
      click_button 'Reset'

      expect(page).to have_css('#reset-content')

      page.within('#reset-content') do
        click_button 'Reset file'
      end

      page.within('#source-editor-') do
        expect(page).to have_content('Default Content')
        expect(page).not_to have_content('Default Content123')
      end
    end

    it 'user can cancel reseting their CI configuration' do
      click_button 'Collapse'

      page.within('#source-editor-') do
        find('textarea').send_keys '123'
      end

      # It takes some time after sending keys for the reset
      # btn to register the changes inside the editor
      sleep 1
      click_button 'Reset'

      expect(page).to have_css('#reset-content')

      page.within('#reset-content') do
        click_button 'Cancel'
      end

      page.within('#source-editor-') do
        expect(page).to have_content('Default Content123')
      end
    end
  end
end