BigW Consortium Gitlab

file_spec.rb 2.03 KB
Newer Older
1 2 3 4 5 6 7 8
require 'spec_helper'

feature 'Artifact file', :js, feature: true do
  let(:project) { create(:project, :public) }
  let(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.sha, ref: 'master') }
  let(:build) { create(:ci_build, :artifacts, pipeline: pipeline) }

  def visit_file(path)
9 10 11 12 13
    visit file_path(path)
  end

  def file_path(path)
    file_namespace_project_job_artifacts_path(project.namespace, project, build, path)
14 15 16 17 18 19
  end

  context 'Text file' do
    before do
      visit_file('other_artifacts_0.1.2/doc_sample.txt')

20
      wait_for_requests
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    end

    it 'displays an error' do
      aggregate_failures do
        # shows an error message
        expect(page).to have_content('The source could not be displayed because it is stored as a job artifact. You can download it instead.')

        # does not show a viewer switcher
        expect(page).not_to have_selector('.js-blob-viewer-switcher')

        # does not show a copy button
        expect(page).not_to have_selector('.js-copy-blob-source-btn')

        # shows a download button
        expect(page).to have_link('Download')
      end
    end
  end

  context 'JPG file' do
    before do
42
      page.driver.browser.url_blacklist = []
43 44
      visit_file('rails_sample.jpg')

45
      wait_for_requests
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
    end

    it 'displays the blob' do
      aggregate_failures do
        # shows rendered image
        expect(page).to have_selector('.image_file img')

        # does not show a viewer switcher
        expect(page).not_to have_selector('.js-blob-viewer-switcher')

        # does not show a copy button
        expect(page).not_to have_selector('.js-copy-blob-source-btn')

        # shows a download button
        expect(page).to have_link('Download')
      end
    end
  end
64 65 66 67 68 69 70

  context 'when visiting old URL' do
    let(:file_url) do
      file_path('other_artifacts_0.1.2/doc_sample.txt')
    end

    before do
71
      visit file_url.sub('/-/jobs', '/builds')
72 73 74 75 76 77
    end

    it "redirects to new URL" do
      expect(page.current_path).to eq(file_url)
    end
  end
78
end