@@ -789,6 +789,104 @@ def parse(string)
789789 end
790790 end
791791
792+ describe "#probe" do
793+ before do
794+ allow ( subject ) . to receive ( :SystemChanged )
795+ allow ( subject ) . to receive ( :ProgressChanged )
796+ allow ( subject ) . to receive ( :ProgressFinished )
797+
798+ allow ( backend ) . to receive ( :activated? ) . and_return activated
799+ allow ( backend ) . to receive ( :probe )
800+ end
801+
802+ let ( :activated ) { true }
803+
804+ it "triggers a new probing" do
805+ expect ( backend ) . to receive ( :probe )
806+ subject . probe
807+ end
808+
809+ context "when storage devices are already activated" do
810+ it "does not activate devices" do
811+ expect ( backend ) . to_not receive ( :activate )
812+ subject . probe
813+ end
814+ end
815+
816+ context "when storage devices are not yet activated" do
817+ let ( :activated ) { false }
818+
819+ it "activates the devices" do
820+ expect ( backend ) . to receive ( :activate )
821+ subject . probe
822+ end
823+ end
824+
825+ context "when no storage configuration has been set" do
826+ it "does not calculate a new proposal" do
827+ expect ( backend ) . to_not receive ( :configure )
828+ subject . probe
829+ end
830+
831+ it "does not emit a ProposalChanged signal" do
832+ expect ( subject ) . to_not receive ( :ProposalChanged )
833+ subject . probe
834+ end
835+
836+ it "emits signals for SystemChanged, ProgressChanged and ProgressFinished" do
837+ expect ( subject ) . to receive ( :SystemChanged ) do |system_str |
838+ system = parse ( system_str )
839+ device = system [ :devices ] . first
840+ expect ( device [ :name ] ) . to eq "/dev/sda"
841+ expect ( system [ :availableDrives ] ) . to eq [ device [ :sid ] ]
842+ end
843+ expect ( subject ) . to receive ( :ProgressChanged ) . with ( /storage configuration/i )
844+ expect ( subject ) . to receive ( :ProgressFinished )
845+
846+ subject . probe
847+ end
848+ end
849+
850+ context "when a storage configuration was previously set" do
851+ before do
852+ allow ( proposal ) . to receive ( :storage_json ) . and_return config_json . to_json
853+ allow ( subject ) . to receive ( :ProposalChanged )
854+ allow ( backend ) . to receive ( :configure )
855+ end
856+
857+ let ( :config_json ) do
858+ {
859+ storage : {
860+ drives : [
861+ {
862+ partitions : [ { generate : "defaults" } ]
863+ }
864+ ]
865+ }
866+ }
867+ end
868+
869+ it "re-calculates the proposal" do
870+ expect ( backend ) . to receive ( :configure ) . with ( config_json )
871+ subject . probe
872+ end
873+
874+ it "emits signals for ProposalChanged, SystemChanged, ProgressChanged and ProgressFinished" do
875+ expect ( subject ) . to receive ( :SystemChanged ) do |system_str |
876+ system = parse ( system_str )
877+ device = system [ :devices ] . first
878+ expect ( device [ :name ] ) . to eq "/dev/sda"
879+ expect ( system [ :availableDrives ] ) . to eq [ device [ :sid ] ]
880+ end
881+ expect ( subject ) . to receive ( :ProposalChanged )
882+ expect ( subject ) . to receive ( :ProgressChanged ) . with ( /storage configuration/i )
883+ expect ( subject ) . to receive ( :ProgressFinished )
884+
885+ subject . probe
886+ end
887+ end
888+ end
889+
792890 describe "#recover_issues" do
793891 context "if no proposal has been calculated" do
794892 it "returns an empty array" do
0 commit comments