Skip to content

Commit 6c487aa

Browse files
committed
Add preliminary spec for .po generation Android action
1 parent ad7f3a3 commit 6c487aa

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ RSpec/FilePath:
132132
- 'spec/android_merge_translators_strings_spec.rb'
133133
- 'spec/android_version_helper_spec.rb'
134134
- 'spec/an_metadata_update_helper_spec.rb'
135+
- 'spec/an_update_metadata_source_spec.rb'
135136
- 'spec/configuration_spec.rb'
136137
- 'spec/configure_helper_spec.rb'
137138
- 'spec/encryption_helper_spec.rb'
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
require 'spec_helper'
2+
3+
describe Fastlane::Actions::AnUpdateMetadataSourceAction do
4+
it 'updates any block in a given .po file with the values from the given sources' do
5+
Dir.mktmpdir do |dir|
6+
# 1: Create a dummy .po file to use as input.
7+
output_path = File.join(dir, 'output.po')
8+
dummy_text = <<~PO
9+
msgctxt "release_note_0122"
10+
msgid "previous version notes required to have current one added"
11+
msgstr ""
12+
msgctxt "key1"
13+
msgid "this value should change"
14+
msgstr ""
15+
msgctxt "key2"
16+
msgid "this value should change"
17+
msgstr ""
18+
PO
19+
File.write(output_path, dummy_text)
20+
21+
# 2: Create source files with value to insert in the .po
22+
release_notes_path = File.join(dir, 'release_notes.txt')
23+
File.write(release_notes_path, "- release notes\n- more release notes")
24+
file_1_path = File.join(dir, '1.txt')
25+
File.write(file_1_path, 'value 1')
26+
file_2_path = File.join(dir, '2.txt')
27+
File.write(file_2_path, 'value 2')
28+
file_3_path = File.join(dir, '3.txt')
29+
File.write(file_3_path, 'value 3')
30+
31+
described_class.run(
32+
po_file_path: output_path,
33+
release_version: '1.23',
34+
source_files: {
35+
release_note: release_notes_path,
36+
key1: file_1_path,
37+
key2: file_2_path,
38+
key3: file_3_path # This is not in the input .po and won't be added
39+
}
40+
)
41+
42+
# 3: Assert given .po has been updated as expected
43+
#
44+
# Notice:
45+
#
46+
# - The new line after each block is added by the conversion
47+
# - That there's no new line between release_note_0122 and key1, because
48+
# the notes are copied as they are with no extra manipulation
49+
# - The key3 source is not part of the output because was not in the
50+
# original .po input
51+
expected = <<~PO
52+
msgctxt "release_note_0123"
53+
msgid ""
54+
"1.23:\\n"
55+
"- release notes\\n"
56+
"- more release notes\\n"
57+
msgstr ""
58+
59+
msgctxt "release_note_0122"
60+
msgid "previous version notes required to have current one added"
61+
msgstr ""
62+
msgctxt "key1"
63+
msgid "value 1"
64+
msgstr ""
65+
66+
msgctxt "key2"
67+
msgid "value 2"
68+
msgstr ""
69+
70+
PO
71+
expect(File.read(output_path)).to eq(expected)
72+
end
73+
end
74+
75+
it 'does not ignore the `whats_new` parameter' do
76+
pending 'this currently fails; in the long run, we might consolidate whats_new with release_notes'
77+
78+
Dir.mktmpdir do |dir|
79+
output_path = File.join(dir, 'output.po')
80+
dummy_text = <<~PO
81+
msgctxt "v1.0-whats-new"
82+
msgid "this will not change"
83+
msgstr ""
84+
PO
85+
File.write(output_path, dummy_text)
86+
87+
whats_new_path = File.join(dir, 'whats_new.txt')
88+
File.write(whats_new_path, "- something new\n- something else new")
89+
90+
described_class.run(
91+
po_file_path: output_path,
92+
release_version: '1.23',
93+
source_files: {
94+
whats_new: whats_new_path
95+
}
96+
)
97+
98+
expected = <<~PO
99+
msgctxt "v1.23-whats-new"
100+
msgid ""
101+
"- something new\\n"
102+
"- something else new\\n"
103+
msgstr ""
104+
105+
PO
106+
expect(File.read(output_path)).to eq(expected)
107+
end
108+
end
109+
end

0 commit comments

Comments
 (0)