Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Jan 12, 2018
1 parent fe95929 commit 7defe9b
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 898 deletions.
108 changes: 108 additions & 0 deletions test/y2partitioner/setup_errors_presenter_test.rb
@@ -0,0 +1,108 @@
#!/usr/bin/env rspec
# encoding: utf-8

# Copyright (c) [2018] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require_relative "test_helper"
require "y2storage"
require "y2partitioner/setup_errors_presenter"

describe Y2Partitioner::SetupErrorsPresenter do
using Y2Storage::Refinements::SizeCasts

let(:setup_checker) { instance_double(Y2Storage::SetupChecker) }

before do
Y2Storage::StorageManager.create_test_instance
allow(setup_checker).to receive(:boot_errors).and_return(boot_errors)
allow(setup_checker).to receive(:product_errors).and_return(product_errors)
end

subject { described_class.new(setup_checker) }

let(:boot_errors) { [] }

let(:product_errors) { [] }

describe "#to_html" do
context "when there is no error" do
let(:boot_errors) { [] }
let(:product_errors) { [] }

it "returns nil" do
expect(subject.to_html).to be_nil
end
end

context "when there are errors" do
let(:boot_error1) { instance_double(Y2Storage::SetupError, message: "boot error 1") }
let(:boot_error2) { instance_double(Y2Storage::SetupError, message: "boot error 2") }
let(:product_error1) { instance_double(Y2Storage::SetupError, message: "product error 1") }
let(:product_error2) { instance_double(Y2Storage::SetupError, message: "product error 2") }
let(:product_error3) { instance_double(Y2Storage::SetupError, message: "product error 3") }

let(:boot_errors) { [boot_error1, boot_error2] }
let(:product_errors) { [product_error1, product_error2, product_error3] }

it "contains a message for each error" do
expect(subject.to_html.scan(/<li>/).size).to eq(5)
end

context "and there are boot errors" do
let(:boot_errors) { [boot_error1] }
let(:product_errors) { [] }

it "contains a general error message for boot errors" do
expect(subject.to_html).to match(/could not load/)
end

it "does not contain a general error message for product errors" do
expect(subject.to_html).to_not match(/could not work/)
end
end

context "and there are product errors" do
let(:boot_errors) { [] }
let(:product_errors) { [product_error1] }

it "contains a general error message for product errors" do
expect(subject.to_html).to match(/could not work/)
end

it "does not contain a general error message for boot errors" do
expect(subject.to_html).to_not match(/could not load/)
end
end

context "and there are boot and product errors" do
let(:boot_errors) { [boot_error1] }
let(:product_errors) { [product_error1] }

it "contains a general error message for boot errors" do
expect(subject.to_html).to match(/could not load/)
end

it "contains a general error message for product errors" do
expect(subject.to_html).to match(/could not work/)
end
end
end
end
end
4 changes: 2 additions & 2 deletions test/y2partitioner/widgets/overview_test.rb
Expand Up @@ -187,15 +187,15 @@
allow(Y2Storage::SetupChecker).to receive(:new).and_return(checker)
allow(checker).to receive(:valid?).and_return(valid_setup)

allow(Y2Storage::SetupErrorsPresenter).to receive(:new).and_return(presenter)
allow(Y2Partitioner::SetupErrorsPresenter).to receive(:new).and_return(presenter)
allow(presenter).to receive(:to_html).and_return("html representation")

allow(Yast2::Popup).to receive(:show).and_return(user_input)
end

let(:checker) { instance_double(Y2Storage::SetupChecker) }

let(:presenter) { instance_double(Y2Storage::SetupErrorsPresenter) }
let(:presenter) { instance_double(Y2Partitioner::SetupErrorsPresenter) }

let(:valid_setup) { nil }

Expand Down
24 changes: 24 additions & 0 deletions test/y2storage/boot_requirements_errors_test.rb
Expand Up @@ -29,6 +29,30 @@

include_context "boot requirements"

describe "#valid?" do
let(:architecture) { :x86 }

before do
allow(checker).to receive(:errors).and_return(errors)
end

context "when there are setup errors" do
let(:errors) { [instance_double(Y2Storage::SetupError)] }

it "returns false" do
expect(checker.valid?).to eq(false)
end
end

context "when there are no setup errors" do
let(:errors) { [] }

it "returns true" do
expect(checker.valid?).to eq(true)
end
end
end

describe "#errors" do
RSpec.shared_examples "missing boot partition" do
it "contains an error for missing boot partition" do
Expand Down

0 comments on commit 7defe9b

Please sign in to comment.