From 908d415729ed891dc4d74fa88245f0ac56550a34 Mon Sep 17 00:00:00 2001 From: Sergei Tsoganov Date: Tue, 19 Dec 2023 11:06:36 +0200 Subject: [PATCH] Corrected tests --- app/helpers/stats_helper.rb | 23 +++++++------------ spec/features/managing_stats_spec.rb | 4 +--- .../distribution_data-auth-fail.yml | 2 +- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/app/helpers/stats_helper.rb b/app/helpers/stats_helper.rb index 1aee576e..ed40a68e 100644 --- a/app/helpers/stats_helper.rb +++ b/app/helpers/stats_helper.rb @@ -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 @@ -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 @@ -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) diff --git a/spec/features/managing_stats_spec.rb b/spec/features/managing_stats_spec.rb index 47c8c336..3dba46d7 100644 --- a/spec/features/managing_stats_spec.rb +++ b/spec/features/managing_stats_spec.rb @@ -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 @@ -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') diff --git a/spec/fixtures/vcr_cassettes/controllers/stats/market_share_controller/distribution_data-auth-fail.yml b/spec/fixtures/vcr_cassettes/controllers/stats/market_share_controller/distribution_data-auth-fail.yml index cbf63d5c..1368e7c3 100644 --- a/spec/fixtures/vcr_cassettes/controllers/stats/market_share_controller/distribution_data-auth-fail.yml +++ b/spec/fixtures/vcr_cassettes/controllers/stats/market_share_controller/distribution_data-auth-fail.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: http://registry:3000/repp/v1/stats/market_share_distribution?q%5Bend_date%5D=09.22&q%5Bstart_date%5D=01.22 + uri: http://registry:3000/repp/v1/stats/market_share_distribution?q%5Bend_date%5D=09.22 body: encoding: US-ASCII string: ''