From 58e2cf164f565506b7c1725438e4eaf2a87f1bf1 Mon Sep 17 00:00:00 2001 From: Joanna Vigne Date: Mon, 17 Jul 2023 13:57:39 +0200 Subject: [PATCH] convert android translation mapper tests in sanitizer tests --- .../android_translation_mapper_test.rb | 58 ------------------- .../ios_to_android_sanitizer_test.rb | 26 +++++++++ 2 files changed, 26 insertions(+), 58 deletions(-) delete mode 100644 test/mappers/android_translation_mapper_test.rb diff --git a/test/mappers/android_translation_mapper_test.rb b/test/mappers/android_translation_mapper_test.rb deleted file mode 100644 index 9651cad..0000000 --- a/test/mappers/android_translation_mapper_test.rb +++ /dev/null @@ -1,58 +0,0 @@ -# frozen_string_literal: true -# require 'test_helper' - -# module AdLocalize -# module Mappers -# class AndroidTranslationMapperTest < TestCase -# setup do -# @translation = Entities::Translation.new( -# locale: 'fr', -# key: Entities::Key.new(label: 'password_specialchar_error'), -# value: "Caractères spéciaux autorisés : - / : ; ( ) € & @ . , ? ! ' [ ] { } # % ^ * + = _ | ~ < > $ £ ¥ ` ° \"", -# comment: "liste des caractères autorisés" -# ) -# @translation_percent_without_formatting = Entities::Translation.new( -# locale: 'fr', -# key: Entities::Key.new(label: 'non_escaped_percent'), -# value: "100%" -# ) -# @translation_percent_with_formatting = Entities::Translation.new( -# locale: 'fr', -# key: Entities::Key.new(label: 'non_escaped_percent'), -# value: "%1$@ %" -# ) -# end - -# test 'should map translation value for android' do -# android_view_model = AndroidTranslationMapper.new.map(translation: @translation) -# assert_equal @translation.key.label, android_view_model.label -# assert_nil android_view_model.key -# assert_equal( -# "\"Caractères spéciaux autorisés : - / : ; ( ) € \\& @ . , ? ! \\' [ ] { } # % ^ * + = _ | ~ \\< \\> $ £ ¥ ` ° \\"\"", -# android_view_model.value -# ) -# assert_equal @translation.comment, android_view_model.comment -# end - -# test 'should not escape "%" when not needed for android' do -# android_view_model = AndroidTranslationMapper.new.map(translation: @translation_percent_without_formatting) -# assert_equal @translation_percent_without_formatting.key.label, android_view_model.label -# assert_nil android_view_model.key -# assert_equal( -# "\"100%\"", -# android_view_model.value -# ) -# end - -# test 'should escape "%" when needed for android' do -# android_view_model = AndroidTranslationMapper.new.map(translation: @translation_percent_with_formatting) -# assert_equal @translation_percent_with_formatting.key.label, android_view_model.label -# assert_nil android_view_model.key -# assert_equal( -# "\"%1$s %%\"", -# android_view_model.value -# ) -# end -# end -# end -# end diff --git a/test/sanitizers/ios_to_android_sanitizer_test.rb b/test/sanitizers/ios_to_android_sanitizer_test.rb index fc76e8b..ddecf9e 100644 --- a/test/sanitizers/ios_to_android_sanitizer_test.rb +++ b/test/sanitizers/ios_to_android_sanitizer_test.rb @@ -4,6 +4,32 @@ module AdLocalize module Sanitizers class IOSToAndroidSanitizerTest < TestCase + test 'should not map nil value' do + assert_nil IOSToAndroidSanitizer.new.sanitize(value: nil) + end + + test 'should not map empty value' do + assert_nil IOSToAndroidSanitizer.new.sanitize(value: nil) + end + + test 'should map list of autorized characters for android' do + password_specialchar_error = "Caractères spéciaux autorisés : - / : ; ( ) € & @ . , ? ! ' [ ] { } # % ^ * + = _ | ~ < > $ £ ¥ ` ° \"" + sanitized_value = IOSToAndroidSanitizer.new.sanitize(value: password_specialchar_error) + expected_value = "\"Caractères spéciaux autorisés : - / : ; ( ) € \\& @ . , ? ! \\' [ ] { } # % ^ * + = _ | ~ \\< \\> $ £ ¥ ` ° \\"\"" + assert_equal expected_value, sanitized_value + end + + test 'should not escape "%" when not needed for android' do + percentage_value = "100%" + sanitized_value = IOSToAndroidSanitizer.new.sanitize(value: percentage_value) + assert_equal "\"100%\"", sanitized_value + end + + test 'should escape "%" when needed for android' do + formatted_string_value = "%1$@ %" + sanitized_value = IOSToAndroidSanitizer.new.sanitize(value: formatted_string_value) + assert_equal "\"%1$s %%\"", sanitized_value + end end end end