summaryrefslogtreecommitdiff
path: root/spec/features/projects/view_on_env_spec.rb
blob: f6a640b90b4947881a9568c058cc5caf1fb1c614 (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
require 'spec_helper'

describe 'View on environment', js: true do
  let(:branch_name) { 'feature' }
  let(:file_path) { 'files/ruby/feature.rb' }
  let(:project) { create(:project, :repository) }
  let(:user) { project.creator }

  before do
    project.add_master(user)
  end

  context 'when the branch has a route map' do
    let(:route_map) do
      <<-MAP.strip_heredoc
      - source: /files/(.*)\\..*/
        public: '\\1'
      MAP
    end

    before do
      Files::CreateService.new(
        project,
        user,
        start_branch: branch_name,
        branch_name: branch_name,
        commit_message: "Add .gitlab/route-map.yml",
        file_path: '.gitlab/route-map.yml',
        file_content: route_map
      ).execute

      # Update the file so that we still have a commit that will have a file on the environment
      Files::UpdateService.new(
        project,
        user,
        start_branch: branch_name,
        branch_name: branch_name,
        commit_message: "Update feature",
        file_path: file_path,
        file_content: "# Noop"
      ).execute
    end

    context 'and an active deployment' do
      let(:sha) { project.commit(branch_name).sha }
      let(:environment) { create(:environment, project: project, name: 'review/feature', external_url: 'http://feature.review.example.com') }
      let!(:deployment) { create(:deployment, environment: environment, ref: branch_name, sha: sha) }

      context 'when visiting the diff of a merge request for the branch' do
        let(:merge_request) { create(:merge_request, :simple, source_project: project, source_branch: branch_name) }

        before do
          gitlab_sign_in(user)

          visit diffs_namespace_project_merge_request_path(project.namespace, project, merge_request)

          wait_for_requests
        end

        it 'has a "View on env" button' do
          within '.diffs' do
            expect(page).to have_link('View on feature.review.example.com', href: 'http://feature.review.example.com/ruby/feature')
          end
        end
      end

      context 'when visiting a comparison for the branch' do
        before do
          gitlab_sign_in(user)

          visit namespace_project_compare_path(project.namespace, project, from: 'master', to: branch_name)

          wait_for_requests
        end

        it 'has a "View on env" button' do
          expect(page).to have_link('View on feature.review.example.com', href: 'http://feature.review.example.com/ruby/feature')
        end
      end

      context 'when visiting a comparison for the commit' do
        before do
          gitlab_sign_in(user)

          visit namespace_project_compare_path(project.namespace, project, from: 'master', to: sha)

          wait_for_requests
        end

        it 'has a "View on env" button' do
          expect(page).to have_link('View on feature.review.example.com', href: 'http://feature.review.example.com/ruby/feature')
        end
      end

      context 'when visiting a blob on the branch' do
        before do
          gitlab_sign_in(user)

          visit namespace_project_blob_path(project.namespace, project, File.join(branch_name, file_path))

          wait_for_requests
        end

        it 'has a "View on env" button' do
          expect(page).to have_link('View on feature.review.example.com', href: 'http://feature.review.example.com/ruby/feature')
        end
      end

      context 'when visiting a blob on the commit' do
        before do
          gitlab_sign_in(user)

          visit namespace_project_blob_path(project.namespace, project, File.join(sha, file_path))

          wait_for_requests
        end

        it 'has a "View on env" button' do
          expect(page).to have_link('View on feature.review.example.com', href: 'http://feature.review.example.com/ruby/feature')
        end
      end

      context 'when visiting the commit' do
        before do
          gitlab_sign_in(user)

          visit namespace_project_commit_path(project.namespace, project, sha)

          wait_for_requests
        end

        it 'has a "View on env" button' do
          expect(page).to have_link('View on feature.review.example.com', href: 'http://feature.review.example.com/ruby/feature')
        end
      end
    end
  end
end