2015-12-31 18:33:35 -05:00
|
|
|
# frozen_string_literal: true
|
2015-04-09 14:14:05 -04:00
|
|
|
require_relative 'helper'
|
2017-05-01 13:47:51 -04:00
|
|
|
require 'sidekiq/web'
|
2015-04-09 14:14:05 -04:00
|
|
|
|
2018-12-03 16:24:37 -05:00
|
|
|
class TestWebHelpers < Minitest::Test
|
2015-04-09 14:14:05 -04:00
|
|
|
|
|
|
|
class Helpers
|
|
|
|
include Sidekiq::WebHelpers
|
|
|
|
|
|
|
|
def initialize(params={})
|
|
|
|
@thehash = default.merge(params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def request
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def settings
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def locales
|
|
|
|
['web/locales']
|
|
|
|
end
|
|
|
|
|
|
|
|
def env
|
|
|
|
@thehash
|
|
|
|
end
|
|
|
|
|
|
|
|
def default
|
|
|
|
{
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_locale_determination
|
|
|
|
obj = Helpers.new
|
|
|
|
assert_equal 'en', obj.locale
|
|
|
|
|
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4,ru;q=0.2')
|
|
|
|
assert_equal 'fr', obj.locale
|
|
|
|
|
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4,ru;q=0.2')
|
|
|
|
assert_equal 'zh-cn', obj.locale
|
2015-05-15 15:02:57 -04:00
|
|
|
|
2017-05-01 13:47:51 -04:00
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'en-US,sv-SE;q=0.8,sv;q=0.6,en;q=0.4')
|
|
|
|
assert_equal 'en', obj.locale
|
|
|
|
|
2015-10-04 14:47:28 -04:00
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'nb-NO,nb;q=0.2')
|
|
|
|
assert_equal 'nb', obj.locale
|
|
|
|
|
2017-05-01 13:47:51 -04:00
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'en-us')
|
|
|
|
assert_equal 'en', obj.locale
|
|
|
|
|
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'sv-se')
|
|
|
|
assert_equal 'sv', obj.locale
|
|
|
|
|
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4')
|
|
|
|
assert_equal 'pt-br', obj.locale
|
|
|
|
|
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4')
|
|
|
|
assert_equal 'pt', obj.locale
|
|
|
|
|
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'pt-br')
|
|
|
|
assert_equal 'pt-br', obj.locale
|
|
|
|
|
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'pt-pt')
|
|
|
|
assert_equal 'pt', obj.locale
|
|
|
|
|
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'pt')
|
|
|
|
assert_equal 'pt', obj.locale
|
|
|
|
|
2015-05-15 15:02:57 -04:00
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'en-us; *')
|
|
|
|
assert_equal 'en', obj.locale
|
|
|
|
|
2017-05-01 13:47:51 -04:00
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.8')
|
|
|
|
assert_equal 'en', obj.locale
|
|
|
|
|
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'en-GB,en-US;q=0.8,en;q=0.6')
|
|
|
|
assert_equal 'en', obj.locale
|
|
|
|
|
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'ru,en')
|
|
|
|
assert_equal 'ru', obj.locale
|
|
|
|
|
2015-05-15 15:02:57 -04:00
|
|
|
obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => '*')
|
|
|
|
assert_equal 'en', obj.locale
|
2015-04-09 14:14:05 -04:00
|
|
|
end
|
2017-05-01 13:47:51 -04:00
|
|
|
|
|
|
|
def test_available_locales
|
|
|
|
obj = Helpers.new
|
|
|
|
expected = %w(
|
|
|
|
ar cs da de el en es fa fr he hi it ja
|
2017-12-18 04:50:19 -05:00
|
|
|
ko nb nl pl pt pt-br ru sv ta uk ur
|
2017-05-01 13:47:51 -04:00
|
|
|
zh-cn zh-tw
|
|
|
|
)
|
2017-12-18 04:50:19 -05:00
|
|
|
assert_equal expected, obj.available_locales.sort
|
2017-05-01 13:47:51 -04:00
|
|
|
end
|
2015-04-09 14:14:05 -04:00
|
|
|
end
|