Skip to content

Commit

Permalink
Ask whether continue or not to not lose changes
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Oct 9, 2018
1 parent 73cb27e commit b27b031
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib/y2firewall/widgets/allowed_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ def help
)
end

def validate
return true if selected_services.empty?
# TRANSLATORS: popup question
msg = _("The selection of services will be lost if you leave without\n" \
"applying the changes.\n\nDo you really want to continue?\n")

Yast::Popup.YesNo(msg)
end

private

# @!attribute [r] known_services_table
Expand Down Expand Up @@ -128,6 +137,10 @@ def refresh_services
allowed_services_table.services = zone.services.clone
end

def selected_services
known_services_table.selected_services + allowed_services_table.selected_services
end

# Return a list of buttons to add/remove elements
#
# @return [Array<Yast::Term>] Buttons set UI terms
Expand Down
26 changes: 26 additions & 0 deletions test/lib/y2firewall/widgets/allowed_services_test.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@
.with(widget_id: "allowed:#{zone.name}").and_return(allowed_svcs_table)
end

describe "#validate" do
context "when no service has been selected" do
before do
allow(available_svcs_table).to receive(:selected_services).and_return([])
allow(allowed_svcs_table).to receive(:selected_services).and_return([])
end

it "returns true" do
expect(widget.validate).to eq(true)
end
end

context "when some service has been selected" do
it "warns the user about unsaved changed and ask for continuing" do
expect(Yast::Popup).to receive("YesNo").with(/Do you really want to continue/)
widget.validate
end

it "returns whether the user wanted to continue or not" do
expect(Yast::Popup).to receive("YesNo").and_return(false, true)
expect(widget.validate).to eq(false)
expect(widget.validate).to eq(true)
end
end
end

describe "#handle" do
context "when it receives an event to add a service" do
let(:event) { { "ID" => :add } }
Expand Down

0 comments on commit b27b031

Please sign in to comment.