|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
| 3 | +# See also `gp_update_metadata_source_spec.rb` for the iOS counterpart and an |
| 4 | +# annotated spec. |
| 5 | +# |
| 6 | +# The fact that we have an Android and iOS differentiation is not ideal and |
| 7 | +# something we hope to address in an upcoming refactor/rewrite. |
3 | 8 | describe Fastlane::Actions::AnUpdateMetadataSourceAction do |
4 | 9 | it 'updates any block in a given .po file with the values from the given sources' do |
5 | 10 | Dir.mktmpdir do |dir| |
6 | | - # 1: Create a dummy .po file to use as input. |
7 | 11 | output_path = File.join(dir, 'output.po') |
8 | 12 | dummy_text = <<~PO |
9 | 13 | msgctxt "release_note_0122" |
|
21 | 25 | PO |
22 | 26 | File.write(output_path, dummy_text) |
23 | 27 |
|
24 | | - # 2: Create source files with value to insert in the .po |
25 | 28 | release_notes_path = File.join(dir, 'release_notes.txt') |
26 | 29 | File.write(release_notes_path, "- release notes\n- more release notes") |
27 | 30 | file_1_path = File.join(dir, '1.txt') |
28 | 31 | File.write(file_1_path, 'value 1') |
29 | 32 | file_2_path = File.join(dir, '2.txt') |
30 | 33 | File.write(file_2_path, 'value 2') |
31 | | - file_3_path = File.join(dir, '3.txt') |
32 | | - File.write(file_3_path, 'value 3') |
33 | 34 |
|
34 | 35 | described_class.run( |
35 | 36 | po_file_path: output_path, |
36 | 37 | release_version: '1.23', |
37 | 38 | source_files: { |
38 | 39 | release_note: release_notes_path, |
39 | 40 | key1: file_1_path, |
40 | | - key2: file_2_path, |
41 | | - key3: file_3_path # This is not in the input .po and won't be added |
| 41 | + key2: file_2_path |
42 | 42 | } |
43 | 43 | ) |
44 | 44 |
|
45 | | - # 3: Assert given .po has been updated as expected |
46 | | - # |
47 | | - # Notice: |
48 | | - # |
49 | | - # - The new line after each block is added by the conversion |
50 | | - # - That there's no new line between release_note_0122 and key1, because |
51 | | - # the notes are copied as they are with no extra manipulation |
52 | | - # - The key3 source is not part of the output because was not in the |
53 | | - # original .po input |
54 | 45 | expected = <<~PO |
55 | 46 | msgctxt "release_note_0123" |
56 | 47 | msgid "" |
|
109 | 100 | expect(File.read(output_path)).to eq(expected) |
110 | 101 | end |
111 | 102 | end |
| 103 | + |
| 104 | + it 'adds entries passed as input even if not part of the original `.po` file' do |
| 105 | + pending 'this currently fails and will be addressed as part of the upcoming refactor/rewrite of the functionality' |
| 106 | + Dir.mktmpdir do |dir| |
| 107 | + output_path = File.join(dir, 'output.po') |
| 108 | + dummy_text = <<~PO |
| 109 | + msgctxt "key1" |
| 110 | + msgid "this value should change" |
| 111 | + msgstr "" |
| 112 | + PO |
| 113 | + File.write(output_path, dummy_text) |
| 114 | + |
| 115 | + # 2: Create source files with value to insert in the .po |
| 116 | + file_1_path = File.join(dir, '1.txt') |
| 117 | + File.write(file_1_path, 'value 1') |
| 118 | + file_2_path = File.join(dir, '2.txt') |
| 119 | + File.write(file_2_path, 'value 2') |
| 120 | + |
| 121 | + described_class.run( |
| 122 | + po_file_path: output_path, |
| 123 | + source_files: { |
| 124 | + key1: file_1_path, |
| 125 | + key2: file_2_path |
| 126 | + } |
| 127 | + ) |
| 128 | + |
| 129 | + expected = <<~PO |
| 130 | + msgctxt "key1" |
| 131 | + msgid "value 1" |
| 132 | + msgstr "" |
| 133 | +
|
| 134 | + msgctxt "key2" |
| 135 | + msgid "value 2" |
| 136 | + msgstr "" |
| 137 | +
|
| 138 | + PO |
| 139 | + expect(File.read(output_path)).to eq(expected) |
| 140 | + end |
| 141 | + end |
112 | 142 | end |
0 commit comments