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

graph_spec.rb « projects « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9b0803e4b0c07942c1dedfc8c0f2bf76b5c83523 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Project Graph', :js, feature_category: :groups_and_projects do
  let(:user) { create(:user, :no_super_sidebar) }
  let(:project) { create(:project, :repository, namespace: user.namespace) }
  let(:branch_name) { 'master' }

  before do
    ::Projects::DetectRepositoryLanguagesService.new(project, user).execute

    project.add_maintainer(user)

    sign_in(user)
  end

  shared_examples 'page should have commits graphs' do
    it 'renders commits' do
      expect(page).to have_content("Commit statistics for #{branch_name}")
      expect(page).to have_content('Commits per day of month')
    end
  end

  context 'commits graph' do
    before do
      visit commits_project_graph_path(project, 'master')
    end

    it_behaves_like 'page should have commits graphs'
  end

  context 'languages graph' do
    before do
      visit languages_project_graph_path(project, 'master')
    end

    it_behaves_like 'page should have commits graphs'
  end

  context 'charts graph' do
    before do
      visit charts_project_graph_path(project, 'master')
    end

    it_behaves_like 'page should have commits graphs'
  end

  context 'chart graph with HTML escaped branch name' do
    let(:branch_name) { '<h1>evil</h1>' }

    before do
      project.repository.create_branch(branch_name)

      visit charts_project_graph_path(project, branch_name)
    end

    it_behaves_like 'page should have commits graphs'

    it 'HTML escapes branch name' do
      expect(page.body).to include("Commit statistics for <strong>#{ERB::Util.html_escape(branch_name)}</strong>")
      expect(page.find('.gl-new-dropdown-button-text')['innerHTML']).to include(ERB::Util.html_escape(branch_name))
    end
  end

  context 'charts graph ref switcher' do
    it 'switches ref to branch' do
      ref_name = 'add-pdf-file'
      visit charts_project_graph_path(project, 'master')

      # Not a huge fan of using a HTML (CSS) selectors here as any change of them will cause a failed test
      ref_selector = find('.ref-selector .gl-new-dropdown-toggle')
      scroll_to(ref_selector)
      ref_selector.click

      page.within '.gl-new-dropdown-contents' do
        dropdown_branch_item = find('li', text: 'add-pdf-file')
        scroll_to(dropdown_branch_item)
        dropdown_branch_item.click
      end

      scroll_to(find('.tree-ref-header'), align: :center)
      expect(page).to have_selector '.gl-new-dropdown-toggle', text: ref_name
      page.within '.tree-ref-header' do
        expect(page).to have_selector('h4', text: ref_name)
      end
    end
  end

  context 'when CI enabled' do
    before do
      project.enable_ci

      visit ci_project_graph_path(project, 'master')
    end

    it 'renders CI graphs' do
      expect(page).to have_content 'Overall'
      expect(page).to have_content 'Last week'
      expect(page).to have_content 'Last month'
      expect(page).to have_content 'Last year'
      expect(page).to have_content 'Pipeline durations for the last 30 commits'
    end
  end
end