Skip to content

Commit

Permalink
added i18n extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Jun 19, 2018
1 parent 4449c95 commit 159b65e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gem 'bundler', '~> 1.16'
gem 'rake', '~> 10.0'
gem 'minitest', '~> 5.0'
gem 'rack'
gem 'i18n'
gem 'slim'
gem 'haml'
gem 'benchmark-ips'
Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ DEPENDENCIES
bundler (~> 1.16)
github-pages
haml
i18n
kalibera
memory_profiler
minitest (~> 5.0)
Expand Down
10 changes: 8 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ require "rubocop/rake_task"
Rake::TestTask.new(:test_common) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList.new.include("test/**/*_test.rb").exclude('test/**/items_test.rb')
t.test_files = FileList.new.include("test/**/*_test.rb").exclude('test/**/i18n_test.rb', 'test/**/items_test.rb')
end

Rake::TestTask.new(:test_extra_i18n) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList['test/**/i18n_test.rb']
end

Rake::TestTask.new(:test_extra_items) do |t|
Expand All @@ -19,7 +25,7 @@ Rake::TestTask.new(:test_extra_items) do |t|
t.test_files = FileList['test/**/items_test.rb']
end

task :test => [:test_common, :test_extra_items]
task :test => [:test_common, :test_extra_items, :test_extra_i18n]

RuboCop::RakeTask.new(:rubocop) do |t|
t.options = `git ls-files -z`.split("\x0") # limit rubocop to the files in the repo
Expand Down
43 changes: 43 additions & 0 deletions test/pagy/extras/i18n_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require_relative '../../test_helper'
require 'i18n'
require 'pagy/extras/i18n'

SingleCov.covered!

describe Pagy::Frontend do

let(:frontend) { TestView.new }

describe "#pagy_t" do
def test_data
assert_equal "&lsaquo;&nbsp;Prev", Pagy::Frontend::I18N_DATA['pagy']['nav']['prev']
assert_equal "&hellip;", Pagy::Frontend::I18N_DATA['pagy']['nav']['gap']
end

def test_translation
assert_equal "&lsaquo;&nbsp;Prev", frontend.pagy_t('pagy.nav.prev')

assert_equal "items", frontend.pagy_t('pagy.info.item_name', count: 0)
assert_equal "item", frontend.pagy_t('pagy.info.item_name', count: 1)
assert_equal "items", frontend.pagy_t('pagy.info.item_name', count: 10)

end

def test_missing
assert_equal 'translation missing: en.pagy.nav.not_here', frontend.pagy_t('pagy.nav.not_here')
end

def test_render_info_no_118n_key
pagy = Pagy.new count: 0
assert_equal "No items found", frontend.pagy_info(pagy)
pagy = Pagy.new count: 1
assert_equal "Displaying <b>1</b> item", frontend.pagy_info(pagy)
pagy = Pagy.new count: 13
assert_equal "Displaying <b>all 13</b> items", frontend.pagy_info(pagy)
pagy = Pagy.new count: 100, page: 3
assert_equal "Displaying items <b>41-60</b> of <b>100</b> in total", frontend.pagy_info(pagy)
end

end

end

0 comments on commit 159b65e

Please sign in to comment.