diff --git a/spec/helpers/todos_helper_spec.rb b/spec/helpers/todos_helper_spec.rb index 2780e5ff1dbe488ed607b81dc2848fcf2d7915b2..c0330d824ea6d4f1509aabdbf1db498e6e542d53 100644 --- a/spec/helpers/todos_helper_spec.rb +++ b/spec/helpers/todos_helper_spec.rb @@ -163,4 +163,61 @@ RSpec.describe TodosHelper do expect(design_option).to include(text: 'Design') end end + + describe '#todo_target_state_pill' do + subject { helper.todo_target_state_pill(todo) } + + shared_examples 'a rendered state pill' do |atrr| + it 'returns expected html' do + html = "<span class=\"target-status\"><span class=\"status-box status-box-#{atrr[:type]}-#{atrr[:state].dasherize}\">#{atrr[:state].capitalize}</span></span>" + expect(subject).to eql(html) + end + end + + shared_examples 'no state pill' do + specify { expect(subject).to eq(nil) } + end + + context 'merge request todo' do + let(:todo) { create(:todo, target: create(:merge_request)) } + + it_behaves_like 'no state pill' + + context 'merged MR' do + before do + todo.target.update!(state: 'merged') + end + + it_behaves_like 'a rendered state pill', type: 'mr', state: 'merged' + end + end + + context 'issue todo' do + let(:todo) { create(:todo, target: issue) } + + it_behaves_like 'no state pill' + + context 'closed issue' do + before do + todo.target.update!(state: 'closed') + end + + it_behaves_like 'a rendered state pill', type: 'issue', state: 'closed' + end + end + + context 'alert todo' do + let(:todo) { alert_todo } + + it_behaves_like 'no state pill' + + context 'resolved alert' do + before do + todo.target.resolve! + end + + it_behaves_like 'a rendered state pill', type: 'alert', state: 'resolved' + end + end + end end