1: -module(translate_SUITE).
    2: -compile([export_all, nowarn_export_all]).
    3: -include_lib("eunit/include/eunit.hrl").
    4: 
    5: all() ->
    6:     [
    7:      test_english_translation,
    8:      test_polish_translation,
    9:      test_portuguese_translation
   10:     ].
   11: 
   12: 
   13: end_per_testcase(_, _C) ->
   14:     mongoose_config:erase_opts().
   15: 
   16: test_english_translation(_Config) ->
   17:     %% given
   18:     given_default_language(<<"en">>),
   19:     given_loaded_translations(),
   20: 
   21:     %% then
   22:     ?assertEqual(<<"cat">>, translate:translate(<<"en">>, <<"cat">>)),
   23:     ?assertEqual(<<"dog">>, translate:translate(<<"en-us">>, <<"dog">>)),
   24:     ?assertEqual(<<"rabbit">>, translate:translate(<<"en-br">>, <<"rabbit">>)),
   25:     ?assertEqual(<<"kangaroo">>, translate:translate(<<"en-au">>, <<"kangaroo">>)),
   26:     ?assertEqual(<<"wombat">>, translate:translate(<<"klingon">>, <<"wombat">>)),
   27: 
   28:     %% tear down mocks
   29:     meck:unload(),
   30:     ok.
   31: 
   32: test_polish_translation(_Config) ->
   33:     %% given
   34:     given_default_language(<<"pl">>),
   35:     given_loaded_translations(),
   36: 
   37:     ?assertEqual(<<"Dodaj nowe">>, translate:translate(<<"pl">>, <<"Add New">>)),
   38:     %% check if the languages in the form of en-us are handled correctly in case
   39:     %% of other languages
   40:     ?assertEqual(<<"Dodaj nowe">>, translate:translate(<<"pl-gr">>, <<"Add New">>)),
   41:     %% not existing key is not translated
   42:     ?assertEqual(<<"undef_test">>, translate:translate(<<"pl">>, <<"undef_test">>)),
   43:     %% in case of non-existing languege it will chouuse polish tranlation
   44:     ?assertEqual(<<"Dodaj nowe">>, translate:translate(<<"klingon">>, <<"Add New">>)),
   45: 
   46:     ok.
   47: 
   48: test_portuguese_translation(_Config)->
   49:     %% given
   50:     given_default_language(<<"pt">>),
   51:     given_loaded_translations(),
   52: 
   53:     ?assertEqual(<<"Adicionar usuário"/utf8>>, translate:translate(<<"pt-br">>, <<"Add User">>)),
   54:     %% check brasilian
   55:     ?assertEqual(<<"Adicionar utilizador"/utf8>>, translate:translate(<<"pt">>, <<"Add User">>)),
   56: 
   57:     ok.
   58: 
   59: given_loaded_translations() ->
   60:     translate:start().
   61: 
   62: given_default_language(Language) ->
   63:     mongoose_config:set_opts(#{language => Language}).