File: single_stat_component_spec.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 (78 lines) | stat: -rw-r--r-- 1,840 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
# frozen_string_literal: true

require "spec_helper"

RSpec.describe Pajamas::SingleStatComponent, type: :component, feature_category: :shared do
  let(:title) { "Single Stat" }
  let(:stat_value) { "9,000" }
  let(:stat_value_testid) { nil }
  let(:title_icon) { nil }
  let(:unit) { nil }
  let(:meta_text) { nil }
  let(:variant) { :success }

  let(:params) do
    {
      title: title,
      title_icon: title_icon,
      stat_value_testid: stat_value_testid,
      stat_value: stat_value,
      unit: unit,
      meta_text: meta_text
    }.compact
  end

  before do
    render_inline(described_class.new(**params))
  end

  context "with default props" do
    it 'shows title' do
      expect(page).to have_css('[data-testid=title-text]', text: title)
    end

    it 'shows stat_value' do
      expect(page).to have_css('[data-testid=non-animated-value]', text: stat_value)
    end

    it 'does not show unit' do
      expect(page).not_to have_css('[data-testid=unit]')
    end

    it 'does not show meta badge' do
      expect(page).not_to have_css('[data-testid=meta-badge]')
    end
  end

  context 'with stat_value_testid' do
    let(:stat_value_testid) { 'foo' }

    it 'shows unique data-testid for stat_value' do
      expect(page).to have_css("[data-testid=#{stat_value_testid}]")
    end
  end

  context "with title_icon" do
    let(:title_icon) { :tanuki }

    it 'shows icon' do
      expect(page).to have_css('svg[data-testid=tanuki-icon]')
    end
  end

  context 'with unit' do
    let(:unit) { 'KB' }

    it 'shows unit' do
      expect(page).to have_css('[data-testid=unit]', text: unit)
    end
  end

  context 'with meta_text' do
    let(:meta_text) { "You're doing great!" }

    it 'shows badge with text' do
      expect(page).to have_css('[data-testid=meta-badge]', text: meta_text)
    end
  end
end