# frozen_string_literal: true require 'spec_helper' RSpec.describe FormHelper do include Devise::Test::ControllerHelpers describe '#dropdown_max_select' do context "with the :limit_reviewer_and_assignee_size feature flag on" do it 'correctly returns the max amount of reviewers or assignees to allow' do max = MergeRequest::MAX_NUMBER_OF_ASSIGNEES_OR_REVIEWERS expect(helper.dropdown_max_select({})) .to eq(max) expect(helper.dropdown_max_select({ 'max-select'.to_sym => 5 })) .to eq(5) expect(helper.dropdown_max_select({ 'max-select'.to_sym => max + 5 })) .to eq(max) end end context "with the :limit_reviewer_and_assignee_size feature flag off" do before do stub_feature_flags(limit_reviewer_and_assignee_size: false) end it 'correctly returns the max amount of reviewers or assignees to allow' do expect(helper.dropdown_max_select({})) .to eq(nil) expect(helper.dropdown_max_select({ 'max-select'.to_sym => 5 })) .to eq(5) expect(helper.dropdown_max_select({ 'max-select'.to_sym => 120 })) .to eq(120) end end end describe '#reviewers_dropdown_options' do let(:merge_request) { build(:merge_request) } context "with the :limit_reviewer_and_assignee_size feature flag on" do context "with multiple reviewers" do it 'correctly returns the max amount of reviewers or assignees to allow' do allow(helper).to receive(:merge_request_supports_multiple_reviewers?).and_return(true) expect(helper.reviewers_dropdown_options(merge_request)[:data][:'max-select']) .to eq(MergeRequest::MAX_NUMBER_OF_ASSIGNEES_OR_REVIEWERS) end end context "with only 1 reviewer" do it 'correctly returns the max amount of reviewers or assignees to allow' do expect(helper.reviewers_dropdown_options(merge_request)[:data][:'max-select']) .to eq(1) end end end context "with the :limit_reviewer_and_assignee_size feature flag off" do before do stub_feature_flags(limit_reviewer_and_assignee_size: false) end context "with multiple reviewers" do it 'correctly returns the max amount of reviewers or assignees to allow' do allow(helper).to receive(:merge_request_supports_multiple_reviewers?).and_return(true) expect(helper.reviewers_dropdown_options(merge_request)[:data][:'max-select']) .to eq(nil) end end context "with only 1 reviewer" do it 'correctly returns the max amount of reviewers or assignees to allow' do expect(helper.reviewers_dropdown_options(merge_request)[:data][:'max-select']) .to eq(1) end end end end describe 'form_errors' do it 'returns nil when model has no errors' do model = double(errors: []) expect(helper.form_errors(model)).to be_nil end it 'renders an appropriately styled alert div' do model = double(errors: errors_stub('Error 1')) expect(helper.form_errors(model)) .to include( '