Skip to content

Commit

Permalink
add test for language switching
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Sep 7, 2017
1 parent 399bd88 commit 156e776
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
3 changes: 1 addition & 2 deletions language/src/lib/y2country/widgets/language_selection.rb
Expand Up @@ -79,8 +79,7 @@ def handle
Yast::Language.Set(value)
Yast::Language.languages = Yast::Language.RemoveSuffix(value)
@default = value
return nil unless @emit_event
return nil if Yast::Mode.config
return nil if !@emit_event || Yast::Mode.config

switch_language
:redraw
Expand Down
2 changes: 1 addition & 1 deletion language/test/Makefile.am
Expand Up @@ -7,7 +7,7 @@ TESTS = \
widgets/language_selection_test.rb

TEST_EXTENSIONS = .rb
RB_LOG_COMPILER = rspec
RB_LOG_COMPILER = rspec --format doc
VERBOSE = 1
EXTRA_DIST = $(TESTS)

73 changes: 69 additions & 4 deletions language/test/widgets/language_selection_test.rb
@@ -1,4 +1,4 @@
#!/usr/bin/env rspec
#!/usr/bin/env rspec --format doc

require_relative "../test_helper"
require "y2country/widgets/language_selection"
Expand All @@ -20,11 +20,62 @@
.with(:first_screen).and_return(LANGUAGE_ITEMS)
end

shared_examples "switch language" do |method|
before do
allow(Yast::Language).to receive(:SwitchToEnglishIfNeeded).and_return(false)
allow(Yast::Console).to receive(:SelectFont)
allow(Yast::Language).to receive(:language).and_return("cs_CZ")
# value have to be different otherwise it is skipped
allow(Yast::Language).to receive(:WfmSetLanguage)
allow(Yast::Language).to receive(:WfmSetGivenLanguage)
end

context "language needed to be switched to English" do
before do
allow(Yast::Language).to receive(:SwitchToEnglishIfNeeded).and_return(true)
end

it "switch language to english" do
expect(Yast::Language).to receive(:SwitchToEnglishIfNeeded).and_return(true)

subject.public_send(method)
end
end

context "language does not need to be switched to English" do
it "sets console font according to language" do
expect(Yast::Console).to receive(:SelectFont).with("cs_CZ")

subject.public_send(method)
end

it "sets WFM language according to selected language" do
expect(Yast::Language).to receive(:WfmSetLanguage)

subject.public_send(method)
end

context "selected langauge is nn_NO" do
before do
allow(Yast::Language).to receive(:language).and_return("nn_NO")
end

it "it sets WFM language to nb_NO instead" do
expect(Yast::Language).to receive(:WfmSetGivenLanguage).with("nb_NO")

subject.public_send(method)
end
end
end
end

it "enlists all available languages" do
expect(widget.items).to eq(LANGUAGES)
end

describe "#handle" do
let(:value) { "en_UK" }

before do
allow(Yast::Language).to receive(:language).and_return(default_language)
allow(widget).to receive(:value).and_return(value)
Expand All @@ -35,15 +86,12 @@

context "when language remains unchanged" do
let(:value) { default_language }

it "returns nil" do
expect(widget.handle).to eq(nil)
end
end

context "when language has been changed" do
let(:value) { "af_ZA" }

it "sets the new language" do
expect(Yast::Language).to receive(:Set).with(value)
expect(Yast::Language).to receive(:languages=).with(value)
Expand All @@ -55,12 +103,29 @@
widget.handle
end
end

context "when emit_event is set to true and Yast::Mode is not config" do
subject(:widget) { described_class.new(emit_event: true) }

include_examples "switch language", :handle

it "returns :redraw" do
expect(subject.handle).to eq :redraw
end
end
end

describe "#store" do
it "calls #handle method" do
expect(widget).to receive(:handle)
widget.store
end

context "when emit_event is set to false and Yast::Mode is not config" do
subject(:widget) { described_class.new(emit_event: false) }

include_examples "switch language", :store
end

end
end

0 comments on commit 156e776

Please sign in to comment.