1
0

languages_helper_spec.rb 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe LanguagesHelper do
  4. describe 'the SUPPORTED_LOCALES constant' do
  5. it 'includes all i18n locales' do
  6. expect(Set.new(described_class::SUPPORTED_LOCALES.keys + described_class::REGIONAL_LOCALE_NAMES.keys)).to include(*I18n.available_locales)
  7. end
  8. end
  9. describe 'native_locale_name' do
  10. context 'with a blank locale' do
  11. it 'defaults to a generic value' do
  12. expect(helper.native_locale_name(nil)).to eq(I18n.t('generic.none'))
  13. end
  14. end
  15. context 'with a locale of `und`' do
  16. it 'defaults to a generic value' do
  17. expect(helper.native_locale_name('und')).to eq(I18n.t('generic.none'))
  18. end
  19. end
  20. context 'with a supported locale' do
  21. it 'finds the human readable native name from a key' do
  22. expect(helper.native_locale_name(:de)).to eq('Deutsch')
  23. end
  24. end
  25. context 'with a regional locale' do
  26. it 'finds the human readable regional name from a key' do
  27. expect(helper.native_locale_name('en-GB')).to eq('English (British)')
  28. end
  29. end
  30. context 'with a non-existent locale' do
  31. it 'returns the supplied locale value' do
  32. expect(helper.native_locale_name(:xxx)).to eq(:xxx)
  33. end
  34. end
  35. end
  36. describe 'standard_locale_name' do
  37. context 'with a blank locale' do
  38. it 'defaults to a generic value' do
  39. expect(helper.standard_locale_name(nil)).to eq(I18n.t('generic.none'))
  40. end
  41. end
  42. context 'with a non-existent locale' do
  43. it 'returns the supplied locale value' do
  44. expect(helper.standard_locale_name(:xxx)).to eq(:xxx)
  45. end
  46. end
  47. context 'with a supported locale' do
  48. it 'finds the human readable standard name from a key' do
  49. expect(helper.standard_locale_name(:de)).to eq('German')
  50. end
  51. end
  52. end
  53. describe 'sorted_locales' do
  54. context 'when sorting with native name' do
  55. it 'returns Suomi after Gàidhlig' do
  56. expect(described_class.sorted_locale_keys(%w(fi gd))).to eq(%w(gd fi))
  57. end
  58. end
  59. context 'when sorting with diacritics' do
  60. it 'returns Íslensk before Suomi' do
  61. expect(described_class.sorted_locale_keys(%w(fi is))).to eq(%w(is fi))
  62. end
  63. end
  64. context 'when sorting with non-Latin' do
  65. it 'returns Suomi before Amharic' do
  66. expect(described_class.sorted_locale_keys(%w(am fi))).to eq(%w(fi am))
  67. end
  68. end
  69. context 'when sorting with local variants' do
  70. it 'returns variant in-line' do
  71. expect(described_class.sorted_locale_keys(%w(en eo en-GB))).to eq(%w(en en-GB eo))
  72. end
  73. end
  74. end
  75. end