Commit dfb0e258 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Moves the modal data to a helper

Adds a helper method for the remove modal
data, adds additional specs.
parent 4e88386b
# frozen_string_literal: true
module Groups
module SettingsHelper
include GroupsHelper
def group_settings_confirm_modal_data(group, remove_form_id = nil)
base_data = { remove_form_id: remove_form_id, button_text: _('Remove group'), testid: 'remove-group-button' }
base_data.merge!({ disabled: group.paid?.to_s, confirm_danger_message: remove_group_message(group), phrase: group.full_path })
end
end
end
Groups::SettingsHelper.prepend_mod_with('Groups::SettingsHelper')
- remove_form_id = local_assigns.fetch(:remove_form_id, nil)
- confirm_modal_data = { "remove_form_id" => remove_form_id, "disabled" => group.paid?.to_s, "button-text" => _('Remove group'), "confirm-danger-message" => remove_group_message(group), phrase: group.full_path, 'testid' => 'remove-group-button' }
- if group.paid?
.gl-alert.gl-alert-info.gl-mb-5{ data: { testid: 'group-has-linked-subscription-alert' } }
......@@ -7,4 +6,4 @@
.gl-alert-body
= html_escape(_("This group can't be removed because it is linked to a subscription. To remove this group, %{linkStart}link the subscription%{linkEnd} with a different group.")) % { linkStart: "<a href=\"#{help_page_path('subscriptions/index', anchor: 'change-the-linked-namespace')}\">".html_safe, linkEnd: '</a>'.html_safe }
.js-confirm-danger{ data: confirm_modal_data }
.js-confirm-danger{ data: group_settings_confirm_modal_data(group, remove_form_id) }
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::SettingsHelper do
include GroupsHelper
let_it_be(:group) { create(:group, path: "foo") }
describe('#group_settings_confirm_modal_data') do
using RSpec::Parameterized::TableSyntax
fake_form_id = "fake_form_id"
where(:is_paid, :is_button_disabled, :form_value_id) do
true | "true" | nil
true | "true" | fake_form_id
false | "false" | nil
false | "false" | fake_form_id
end
with_them do
it "returns expected parameters" do
allow(group).to receive(:paid?).and_return(is_paid)
expected = helper.group_settings_confirm_modal_data(group, form_value_id)
expect(expected).to eq({
button_text: "Remove group",
confirm_danger_message: remove_group_message(group),
remove_form_id: form_value_id,
phrase: group.full_path,
testid: "remove-group-button",
disabled: is_button_disabled
})
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment