File: quick_actions_status_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 (102 lines) | stat: -rw-r--r-- 2,558 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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Notes::QuickActionsStatus, feature_category: :team_planning do
  let(:command_names) { %w[/assign /label] }
  let(:commands_only) { true }
  let(:status) { described_class.new(command_names: command_names, commands_only: commands_only) }

  describe '#add_message' do
    it 'adds a non-blank message to messages' do
      status.add_message('Test message')

      expect(status.messages).to eq(['Test message'])
    end

    it 'does not add a blank message' do
      status.add_message('')

      expect(status.messages).to be_empty
    end
  end

  describe '#add_error' do
    it 'adds an error message to error_messages' do
      status.add_error('Test error')

      expect(status.error_messages).to eq(['Test error'])
    end
  end

  describe '#commands_only?' do
    it 'returns the value of commands_only' do
      expect(status.commands_only?).to eq(commands_only)
    end
  end

  describe '#success?' do
    it 'returns true when there are no error messages' do
      expect(status.success?).to be true
    end

    it 'returns false when there are error messages' do
      status.add_error('Test error')

      expect(status.success?).to be false
    end
  end

  describe '#error?' do
    it 'returns false when there are no error messages' do
      expect(status.error?).to be false
    end

    it 'returns true when there are error messages' do
      status.add_error('Test error')

      expect(status.error?).to be true
    end
  end

  describe '#to_h' do
    context 'when there are no messages or errors' do
      it 'returns a hash with command_names and commands_only' do
        expect(status.to_h).to eq({
          command_names: command_names,
          commands_only: commands_only,
          messages: nil
        })
      end
    end

    context 'when there are messages' do
      before do
        status.add_message('Test message')
      end

      it 'includes messages in the hash' do
        expect(status.to_h).to eq({
          command_names: command_names,
          commands_only: commands_only,
          messages: ['Test message']
        })
      end
    end

    context 'when there are error messages' do
      before do
        status.add_error('Test error')
      end

      it 'includes error_messages in the hash' do
        expect(status.to_h).to eq({
          command_names: command_names,
          commands_only: commands_only,
          error_messages: ['Test error'],
          messages: nil
        })
      end
    end
  end
end