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

index.html.haml_spec.rb « tags « projects « views « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 01e8d23fb9fe899aae88f78edc572de3d312cf84 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'projects/tags/index.html.haml' do
  let_it_be(:project)  { create(:project, :repository) }
  let_it_be(:git_tag)  { project.repository.tags.last }
  let_it_be(:release)  do
    create(:release, project: project, sha: git_tag.target_commit.sha, tag: 'v1.1.0')
  end

  let(:pipeline) { create(:ci_pipeline, :success, project: project, ref: git_tag.name, sha: release.sha) }

  before do
    assign(:project, project)
    assign(:repository, project.repository)
    assign(:releases, project.releases)
    assign(:tags, Kaminari.paginate_array(tags).page(0))
    assign(:tags_pipelines, { git_tag.name => pipeline })

    allow(view).to receive(:current_ref).and_return('master')
    allow(view).to receive(:current_user).and_return(project.namespace.owner)
  end

  context 'when tag is associated with a release' do
    context 'when name does not contain a backslash' do
      it 'renders a link to the release page' do
        render
        expect(rendered).to have_link(release.name, href: project_release_path(project, release))
      end
    end

    context 'when name contains backslash' do
      let_it_be(:release) { create(:release, project: project, tag: 'test/v1') }

      before_all do
        project.repository.add_tag(project.owner, 'test/v1', project.default_branch_or_main)
        project.repository.expire_tags_cache

        project.releases.reload

        assign(:tags, Kaminari.paginate_array(tags).page(0))
      end

      it 'renders a link to the release page with backslash escaped' do
        render
        expect(rendered).to have_link(release.name, href: project_release_path(project, release))
      end
    end
  end

  context 'when the most recent build for a tag has artifacts' do
    let!(:build) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }

    it 'renders the Artifacts section in the download list' do
      render
      expect(rendered).to have_selector('li', text: 'Artifacts')
    end

    it 'renders artifact download links' do
      render
      expect(rendered).to have_link(href: latest_succeeded_project_artifacts_path(project, "#{pipeline.ref}/download", job: 'test'))
    end
  end

  context 'when the most recent build for a tag has expired artifacts' do
    let!(:build) { create(:ci_build, :success, :expired, :artifacts, pipeline: pipeline) }

    it 'does not render the Artifacts section in the download list' do
      render
      expect(rendered).not_to have_selector('li', text: 'Artifacts')
    end

    it 'does not render artifact download links' do
      render
      expect(rendered).not_to have_link(href: latest_succeeded_project_artifacts_path(project, "#{pipeline.ref}/download", job: 'test'))
    end
  end

  context 'build stats' do
    let(:tag) { 'v1.0.0' }
    let(:page) { Capybara::Node::Simple.new(rendered) }

    it 'shows build status or placeholder when pipelines present' do
      create(:ci_pipeline,
        project: project,
        ref: tag,
        sha: project.commit(tag).sha,
        status: :success)
      assign(:tag_pipeline_statuses, Ci::CommitStatusesFinder.new(project, project.repository, project.namespace.owner, tags).execute)

      render

      expect(page.find('.tags .content-list li', text: tag)).to have_css '.gl-badge .ci-status-icon-success'
      expect(page.all('.tags .content-list li')).to all(have_css('svg.s16'))
    end

    it 'shows no build status or placeholder when no pipelines present' do
      render

      expect(page.all('.tags .content-list li')).not_to have_css 'svg.s16'
    end

    it 'shows no build status or placeholder when pipelines are private' do
      project.project_feature.update!(builds_access_level: ProjectFeature::PRIVATE)
      assign(:tag_pipeline_statuses, Ci::CommitStatusesFinder.new(project, project.repository, build(:user), tags).execute)

      render

      expect(page.all('.tags .content-list li')).not_to have_css 'svg.s16'
    end
  end

  context 'when Gitaly is unavailable' do
    it 'renders an error' do
      assign(:tags_loading_error, GRPC::Unavailable.new)

      content = render

      expect(content).to include("Unable to load tags")
      expect(content).to include(
        "The git server, Gitaly, is not available at this time. Please contact your administrator."
      )
    end
  end

  def tags
    project.repository.tags
  end
end