Skip to content

Commit

Permalink
Corrected tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergei Tsoganov authored and Sergei Tsoganov committed Dec 19, 2023
1 parent 851ceee commit 908d415
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
23 changes: 8 additions & 15 deletions app/helpers/stats_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,24 @@ module StatsHelper
def market_share_distribution_chart(search_params)
url = market_share_distribution_data_path(search: search_params)
title = t('stats.market_share.distribution.chart_title',
date: title_period(search_params[:start_date],
search_params[:end_date]))
date: title_period(search_params[:end_date]))
tag.div(nil, data: chart_data_params(url: url, title: title, type: __method__.to_s)) do
tag.div(preloader, class: 'pie_chart')
end
end

# rubocop:disable Metrics/MethodLength
def market_share_growth_rate_chart(search_params)
url = market_share_growth_rate_data_path(search: search_params)
title = t('stats.market_share.growth_rate.chart_title',
date: title_period(search_params[:start_date],
search_params[:end_date]))
date: title_period(search_params[:end_date]))
subtitle = t('stats.market_share.growth_rate.chart_subtitle',
date: title_period(search_params[:compare_to_start_date],
search_params[:compare_to_end_date]))
date: title_period(search_params[:compare_to_end_date]))
tag.div(nil, data: chart_data_params(url: url, title: title, type: __method__.to_s,
subtitle: subtitle,
translations: date_translations(search_params))) do
data_type_radio_buttons + tag.div(preloader, class: 'bar_chart')
end
end
# rubocop:enable Metrics/MethodLength

private

Expand All @@ -46,16 +41,14 @@ def data_type_radio_buttons(tags: [])
end
end

def title_period(start_date, end_date, period: '')
period += "#{translate_date(to_date(start_date))} - " if start_date.present?
period += translate_date(to_date(end_date, end_date: true)).to_s
def title_period(end_date, period: '')
period += translate_date(to_date(end_date)).to_s

period
end

def to_date(month_year, end_date: false)
def to_date(month_year)
parsed_date = Date.strptime(month_year, '%m.%y')
return parsed_date unless end_date

current_date = Time.zone.today

Expand All @@ -82,8 +75,8 @@ def chart_data_params(url:, title:, type:, subtitle: nil, translations: {})
end

def date_translations(params, dates: {})
end_date = to_date(params[:end_date], end_date: true)
compare_to_end_date = to_date(params[:compare_to_end_date], end_date: true)
end_date = to_date(params[:end_date])
compare_to_end_date = to_date(params[:compare_to_end_date])
dates[params[:end_date]] = translate_date(end_date)
dates[params[:compare_to_end_date]] = translate_date(compare_to_end_date)

Expand Down
4 changes: 1 addition & 3 deletions spec/features/managing_stats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
visit market_share_path
expect(page).to have_content('Stats')

page.fill_in 'search_start_date', with: '01.22'
page.fill_in 'search_end_date', with: '09.22'

click_button('Filter')
expect(page).to have_current_path(/search\[start_date\]=01.22/)
expect(page).to have_current_path(/search\[end_date\]=09.22/)
end
end

Expand All @@ -38,7 +37,6 @@
visit market_share_path(type: 'distribution')
expect(page).to have_content('Stats')

page.fill_in 'search_start_date', with: '01.22'
page.fill_in 'search_end_date', with: '09.22'

click_link('Download CSV')
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 908d415

Please sign in to comment.