Test todos_count_format helper at the correct level to improve speed
Instead of an integration test that creates 101 Todo records to test a simple view helper, just unit test the helper.
This commit is contained in:
parent
b16730fc83
commit
f2dee8e855
4 changed files with 14 additions and 29 deletions
|
@ -47,11 +47,6 @@ class Dashboard::TodosController < Dashboard::ApplicationController
|
||||||
render json: todos_counts
|
render json: todos_counts
|
||||||
end
|
end
|
||||||
|
|
||||||
# Used in TodosHelper also
|
|
||||||
def self.todos_count_format(count)
|
|
||||||
count >= 100 ? '99+' : count
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_todos
|
def find_todos
|
||||||
|
|
|
@ -4,7 +4,7 @@ module TodosHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def todos_count_format(count)
|
def todos_count_format(count)
|
||||||
count > 99 ? '99+' : count
|
count > 99 ? '99+' : count.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def todos_done_count
|
def todos_done_count
|
||||||
|
|
|
@ -333,29 +333,6 @@ describe 'Dashboard Todos', feature: true do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'User have large number of todos' do
|
|
||||||
before do
|
|
||||||
create_list(:todo, 101, :mentioned, user: user, project: project, target: issue, author: author)
|
|
||||||
|
|
||||||
login_as(user)
|
|
||||||
visit dashboard_todos_path
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'shows 99+ for count >= 100 in notification' do
|
|
||||||
expect(page).to have_selector('.todos-count', text: '99+')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'shows exact number in To do tab' do
|
|
||||||
expect(page).to have_selector('.todos-pending .badge', text: '101')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'shows exact number for count < 100' do
|
|
||||||
3.times { first('.js-done-todo').click }
|
|
||||||
|
|
||||||
expect(page).to have_selector('.todos-count', text: '98')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'User has a Build Failed todo' do
|
context 'User has a Build Failed todo' do
|
||||||
let!(:todo) { create(:todo, :build_failed, user: user, project: project, author: author) }
|
let!(:todo) { create(:todo, :build_failed, user: user, project: project, author: author) }
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,19 @@
|
||||||
require "spec_helper"
|
require "spec_helper"
|
||||||
|
|
||||||
describe TodosHelper do
|
describe TodosHelper do
|
||||||
|
describe '#todos_count_format' do
|
||||||
|
it 'shows fuzzy count for 100 or more items' do
|
||||||
|
expect(helper.todos_count_format(100)).to eq '99+'
|
||||||
|
expect(helper.todos_count_format(1000)).to eq '99+'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'shows exact count for 99 or fewer items' do
|
||||||
|
expect(helper.todos_count_format(99)).to eq '99'
|
||||||
|
expect(helper.todos_count_format(50)).to eq '50'
|
||||||
|
expect(helper.todos_count_format(1)).to eq '1'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#todo_projects_options' do
|
describe '#todo_projects_options' do
|
||||||
let(:projects) { create_list(:empty_project, 3) }
|
let(:projects) { create_list(:empty_project, 3) }
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
|
|
Loading…
Reference in a new issue