Skip to content
view_on_env_spec.rb 4.07 KiB
Newer Older
Douwe Maan's avatar
Douwe Maan committed
require 'spec_helper'

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

  before do
    project.add_maintainer(user)
Douwe Maan's avatar
Douwe Maan committed
  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,
Douwe Maan's avatar
Douwe Maan committed
        start_branch: branch_name,
        branch_name: branch_name,
Douwe Maan's avatar
Douwe Maan committed
        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,
Douwe Maan's avatar
Douwe Maan committed
        start_branch: branch_name,
        branch_name: branch_name,
Douwe Maan's avatar
Douwe Maan committed
        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, :success, environment: environment, ref: branch_name, sha: sha) }
Douwe Maan's avatar
Douwe Maan committed

      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
Douwe Maan's avatar
Douwe Maan committed

          visit diffs_project_merge_request_path(project, merge_request)
Douwe Maan's avatar
Douwe Maan committed

          wait_for_requests
Douwe Maan's avatar
Douwe Maan committed
        end

        it 'has a "View on env" button' do
          within '.diffs' do
            text = 'View on feature.review.example.com'
            url = 'http://feature.review.example.com/ruby/feature'
            expect(page).to have_selector("a[data-original-title='#{text}'][href='#{url}']")
Douwe Maan's avatar
Douwe Maan committed
          end
        end
      end

      context 'when visiting a comparison for the branch' do
        before do
Douwe Maan's avatar
Douwe Maan committed

          visit project_compare_path(project, from: 'master', to: branch_name)
Douwe Maan's avatar
Douwe Maan committed

          wait_for_requests
Douwe Maan's avatar
Douwe Maan committed
        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
Douwe Maan's avatar
Douwe Maan committed

          visit project_compare_path(project, from: 'master', to: sha)
Douwe Maan's avatar
Douwe Maan committed

          wait_for_requests
Douwe Maan's avatar
Douwe Maan committed
        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
Douwe Maan's avatar
Douwe Maan committed

          visit project_blob_path(project, File.join(branch_name, file_path))
Douwe Maan's avatar
Douwe Maan committed

Douwe Maan's avatar
Douwe Maan committed
        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
Douwe Maan's avatar
Douwe Maan committed

          visit project_blob_path(project, File.join(sha, file_path))
Douwe Maan's avatar
Douwe Maan committed

Douwe Maan's avatar
Douwe Maan committed
        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
Douwe Maan's avatar
Douwe Maan committed

          visit project_commit_path(project, sha)
Douwe Maan's avatar
Douwe Maan committed

Douwe Maan's avatar
Douwe Maan committed
        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