File: value_streams_dashboard_shared_examples.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (170 lines) | stat: -rw-r--r-- 7,084 bytes parent folder | download
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# frozen_string_literal: true

RSpec.shared_examples 'renders usage overview metrics' do
  let(:usage_overview) { find_by_testid('panel-usage-overview') }

  it 'renders the metrics panel' do
    expect(usage_overview).to be_visible
    expect(usage_overview).to have_content format(_("Usage overview for the %{title}"), title: panel_title)
  end

  it 'renders each of the available metrics with the correct values' do
    within usage_overview do
      usage_overview_metrics.each do |id, name, value|
        stat = find_by_testid("usage-overview-metric-#{id}")
        expect(stat).to be_visible
        expect(stat).to have_content name
        expect(stat).to have_content value
      end
    end
  end
end

RSpec.shared_examples 'renders usage overview metrics with zero values' do
  it_behaves_like 'renders usage overview metrics'
end

RSpec.shared_examples 'renders usage overview metrics with empty values' do
  it_behaves_like 'renders usage overview metrics'
end

RSpec.shared_examples 'does not render usage overview metrics' do
  let(:usage_overview_testid) { "[data-testid='panel-usage-overview']" }

  it 'does not render the usage overview panel' do
    expect(page).not_to have_selector usage_overview_testid
  end
end

RSpec.shared_examples 'does not render usage overview background aggregation not enabled alert' do
  let(:vsd_background_aggregation_disabled_alert) { "[data-testid='vsd-background-aggregation-disabled-warning']" }

  it 'does not render background aggregation not enabled alert' do
    expect(page).not_to have_selector vsd_background_aggregation_disabled_alert
  end
end

RSpec.shared_examples 'renders metrics comparison tables' do
  let(:lifecycle_metrics_table) { find_by_testid('panel-vsd-lifecycle-metrics-table') }
  let(:dora_metrics_table) { find_by_testid('panel-vsd-dora-metrics-table') }
  let(:security_metrics_table) { find_by_testid('panel-vsd-security-metrics-table') }

  def expect_row_content(id, name, values)
    row = find_by_testid("dora-chart-metric-#{id}")

    expect(row).to be_visible
    expect(row).to have_content name
    expect(row).to have_content values
  end

  before do
    wait_for_all_requests
  end

  it 'renders the Lifecycle metrics table' do
    expect(lifecycle_metrics_table).to be_visible
    expect(lifecycle_metrics_table).to have_content format(_("Lifecycle metrics for the %{title}"), title: panel_title)
    [
      ['lead-time', _('Lead time'), '4.0 d 33.3% 2.0 d 50.0% -'],
      ['cycle-time', _('Cycle time'), '3.0 d 50.0% 1.0 d 66.7% -'],
      ['issues', _('Issues created'), '1 66.7% 2 100.0% -'],
      ['issues-completed', _('Issues closed'), '1 66.7% 2 100.0% -'],
      ['deploys', _('Deploys'), '10 25.0% 5 50.0% -'],
      ['merge-request-throughput', _('Merge request throughput'), '1 50.0% 3 200.0% -'],
      ['median-time-to-merge', _('Median time to merge'), '- - -']
    ].each do |id, name, values|
      expect_row_content(id, name, values)
    end
  end

  it 'renders the DORA metrics table' do
    expect(dora_metrics_table).to be_visible
    expect(dora_metrics_table).to have_content format(_("DORA metrics for the %{title}"), title: panel_title)
    [
      ['lead-time-for-changes', _('Lead time for changes'), '3.0 d 40.0% 1.0 d 66.7% 0.0 d'],
      ['time-to-restore-service', _('Time to restore service'), '3.0 d 57.1% 5.0 d 66.7% 0.0 d'],

      # The values of these metrics are dependent on the length of the month they are in. Due to the high
      # flake risk associated with them, we only validate the expected structure of the table row instead
      # of the actual metric values.
      ['deployment-frequency', _('Deployment frequency'), %r{ 0\.\d+/d \d+\.\d% 0\.\d+/d \d+\.\d% 0\.0/d}],
      ['change-failure-rate', _('Change failure rate'), %r{0\.0% \d+\.\d% \d+\.\d% \d+\.\d% \d+\.\d%}]
    ].each do |id, name, values|
      expect_row_content(id, name, values)
    end
  end

  it 'renders the Security metrics table' do
    expect(security_metrics_table).to be_visible
    expect(security_metrics_table).to have_content format(_("Security metrics for the %{title}"), title: panel_title)
    [
      ['vulnerability-critical', _('Critical vulnerabilities over time'), '5 3 -'],
      ['vulnerability-high', _('High vulnerabilities over time'), '4 2 -']
    ].each do |id, name, values|
      expect_row_content(id, name, values)
    end
  end
end

RSpec.shared_examples 'renders dora performers score' do
  let(:dora_performers_score) { find_by_testid('panel-dora-performers-score') }
  let(:dora_performers_chart_title) { find_by_testid('dora-performers-score-chart-title') }

  it 'renders the dora performers score visualization' do
    expect(dora_performers_score).to be_visible

    expect(dora_performers_score).to have_content format(
      _("DORA performers score for the %{name} group (Last full calendar month)"),
      name: group.name
    )
    expect(dora_performers_chart_title).to have_content _("Total projects (3) with DORA metrics")
  end
end

RSpec.shared_examples 'VSD renders as an analytics dashboard' do
  let(:dashboard_list_item_testid) { "[data-testid='dashboard-list-item']" }
  let(:feedback_survey) { find_by_testid('vsd-feedback-survey') }
  let(:vsd_background_aggregation_disabled_alert) { find_by_testid('vsd-background-aggregation-disabled-warning') }

  it 'renders VSD page correctly' do
    expect(find_by_testid('gridstack-grid')).to be_visible
    expect(page).not_to have_selector(dashboard_list_item_testid)
    expect(page).to have_content _('Value Streams Dashboard')
    expect(feedback_survey).to be_visible
    expect(feedback_survey).to have_content _("To help us improve the Value Stream Management Dashboard, " \
                                              "please share feedback about your experience in this survey.")
    expect(vsd_background_aggregation_disabled_alert).to be_visible

    expect(vsd_background_aggregation_disabled_alert).to have_content _('Background aggregation not enabled')
    expect(vsd_background_aggregation_disabled_alert).to have_content _("To see usage overview, you must enable " \
    "background aggregation.")
  end
end

RSpec.shared_examples 'renders contributor count' do
  let(:contributor_count) { find_by_testid('dora-chart-metric-contributor-count') }

  it 'renders the contributor count metric' do
    expect(contributor_count).to be_visible
  end
end

RSpec.shared_examples 'does not render contributor count' do
  let(:contributor_count_testid) { "[data-testid='dora-chart-metric-contributor-count']" }

  it 'does not render the contributor count metric' do
    expect(page).not_to have_selector contributor_count_testid
  end
end

RSpec.shared_examples 'has value streams dashboard link' do
  it 'renders the value streams dashboard link' do
    dashboard_items = page.all(dashboard_list_item_testid)

    first_dashboard = dashboard_items[0]

    expect(dashboard_items.length).to eq(1)
    expect(first_dashboard).to have_content _('Value Streams Dashboard')
    expect(first_dashboard).to have_selector dashboard_by_gitlab_testid
  end
end