Added unit tests for loc drop generation and consumption.
This commit is contained in:
parent
8815c095d8
commit
ba4b69baf2
3 changed files with 71 additions and 0 deletions
BIN
test/fixtures/consume_loc_drop.zip
vendored
Normal file
BIN
test/fixtures/consume_loc_drop.zip
vendored
Normal file
Binary file not shown.
27
test/test_consume_loc_drop.rb
Normal file
27
test/test_consume_loc_drop.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'command_test_case'
|
||||
|
||||
class TestConsumeLocDrop < CommandTestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
options = {}
|
||||
options[:input_path] = fixture 'consume_loc_drop.zip'
|
||||
options[:output_path] = @output_path
|
||||
options[:format] = 'apple'
|
||||
|
||||
@twine_file = build_twine_file 'en', 'es' do
|
||||
add_section 'Section' do
|
||||
add_row key1: 'value1'
|
||||
end
|
||||
end
|
||||
|
||||
@runner = Twine::Runner.new(nil, options, @twine_file)
|
||||
end
|
||||
|
||||
def test_consumes_zip_file
|
||||
@runner.consume_loc_drop
|
||||
|
||||
assert @twine_file.strings_map['key1'].translations['en'], 'value1-english'
|
||||
assert @twine_file.strings_map['key1'].translations['es'], 'value1-spanish'
|
||||
end
|
||||
end
|
44
test/test_generate_loc_drop.rb
Normal file
44
test/test_generate_loc_drop.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
require 'command_test_case'
|
||||
|
||||
class TestGenerateLocDrop < CommandTestCase
|
||||
def setup
|
||||
super
|
||||
|
||||
options = {}
|
||||
options[:output_path] = @output_path
|
||||
options[:format] = 'apple'
|
||||
|
||||
@twine_file = build_twine_file 'en', 'fr' do
|
||||
add_section 'Section' do
|
||||
add_row key: 'value'
|
||||
end
|
||||
end
|
||||
|
||||
@runner = Twine::Runner.new(nil, options, @twine_file)
|
||||
end
|
||||
|
||||
def test_generates_zip_file
|
||||
@runner.generate_loc_drop
|
||||
|
||||
assert File.exists?(@output_path), "language folder should not be created"
|
||||
end
|
||||
|
||||
def test_zip_file_structure
|
||||
@runner.generate_loc_drop
|
||||
|
||||
names = []
|
||||
Zip::File.open(@output_path) do |zipfile|
|
||||
zipfile.each do |entry|
|
||||
names << entry.name
|
||||
end
|
||||
end
|
||||
assert_equal ['Locales/', 'Locales/en.strings', 'Locales/fr.strings'], names
|
||||
end
|
||||
|
||||
def test_uses_formatter
|
||||
formatter = prepare_mock_formatter Twine::Formatters::Apple
|
||||
formatter.expects(:write_file).twice.with() { |path, lang| FileUtils.touch path }
|
||||
|
||||
@runner.generate_loc_drop
|
||||
end
|
||||
end
|
Reference in a new issue