From ba7f96fecc062f12117cb22d7ab023f2601703e8 Mon Sep 17 00:00:00 2001 From: bstepanovski Date: Wed, 15 Apr 2026 08:57:07 -0400 Subject: [PATCH] Add empty state message for balance warnings widget --- .../shared/_insufficient_balance.html.erb | 4 ++ apps/dashboard/config/locales/en-CA.yml | 1 + apps/dashboard/config/locales/en.yml | 1 + apps/dashboard/config/locales/fr-CA.yml | 1 + apps/dashboard/config/locales/ja_JP.yml | 1 + apps/dashboard/config/locales/zh-CN.yml | 1 + .../balance_warnings_views_test.rb | 46 +++++++++++++++++++ 7 files changed, 55 insertions(+) create mode 100644 apps/dashboard/test/integration/balance_warnings_views_test.rb diff --git a/apps/dashboard/app/views/shared/_insufficient_balance.html.erb b/apps/dashboard/app/views/shared/_insufficient_balance.html.erb index 00761f8f11..d143fd7042 100644 --- a/apps/dashboard/app/views/shared/_insufficient_balance.html.erb +++ b/apps/dashboard/app/views/shared/_insufficient_balance.html.erb @@ -13,4 +13,8 @@ <%- end -%> +<%- else -%> +
+ <%= t('dashboard.balance_no_warnings_html', threshold: Configuration.balance_threshold.to_i) %> +
<%- end -%> diff --git a/apps/dashboard/config/locales/en-CA.yml b/apps/dashboard/config/locales/en-CA.yml index 62f6b66e1b..ee1f2835fc 100644 --- a/apps/dashboard/config/locales/en-CA.yml +++ b/apps/dashboard/config/locales/en-CA.yml @@ -35,6 +35,7 @@ en-CA: back: Back balance_additional_message: Consider requesting additional %{balanace_units} balance_message: "%{units_balance} is %{value}" + balance_no_warnings_html: "No projects are within the %{threshold} day balance warning threshold." balance_reload_message_html: Reload page to see updated balance. Balances are updated daily.
Last update was %{last_update} balance_warning_prefix_html: "%{units_balance} warning for" batch_connect_apps_menu_title: Interactive Apps diff --git a/apps/dashboard/config/locales/en.yml b/apps/dashboard/config/locales/en.yml index 19478ee4ab..c393edfa62 100644 --- a/apps/dashboard/config/locales/en.yml +++ b/apps/dashboard/config/locales/en.yml @@ -36,6 +36,7 @@ en: back: Back balance_additional_message: Consider requesting additional %{balanace_units} balance_message: "%{units_balance} is %{value}" + balance_no_warnings_html: "No projects are within the %{threshold} day balance warning threshold." balance_reload_message_html: Reload page to see updated balance. Balances are updated daily.
Last update was %{last_update} balance_warning_prefix_html: "%{units_balance} warning for" batch_connect_apps_menu_title: Interactive Apps diff --git a/apps/dashboard/config/locales/fr-CA.yml b/apps/dashboard/config/locales/fr-CA.yml index b4b8a422aa..88ef34198b 100644 --- a/apps/dashboard/config/locales/fr-CA.yml +++ b/apps/dashboard/config/locales/fr-CA.yml @@ -35,6 +35,7 @@ fr-CA: back: Retour balance_additional_message: Envisagez de demander %{balanace_units} supplémentaires balance_message: "%{units_balance} est %{value}" + balance_no_warnings_html: "Aucun projet n’est dans le seuil d’avertissement de solde de %{threshold} jours." balance_reload_message_html: 'Rechargez la page pour voir le solde mis à jour. Les soldes sont mis à jour quotidiennement.
Dernière mise à jour : %{last_update}' balance_warning_prefix_html: "%{units_balance} avertissement pour" batch_connect_apps_menu_title: Applications interactives diff --git a/apps/dashboard/config/locales/ja_JP.yml b/apps/dashboard/config/locales/ja_JP.yml index 4c69d2f01f..977daa3d55 100644 --- a/apps/dashboard/config/locales/ja_JP.yml +++ b/apps/dashboard/config/locales/ja_JP.yml @@ -33,6 +33,7 @@ ja_JP: back: 戻る balance_additional_message: 追加の%{balanace_units}をリクエストすることを検討してください balance_message: "%{units_balance}は%{value}です" + balance_no_warnings_html: "%{threshold} 日の残高警告しきい値の範囲内にあるプロジェクトはありません。" balance_reload_message_html: ページを再読み込みして、更新された残高を確認してください。残高は毎日更新されます。
最終更新は %{last_update} でした。 balance_warning_prefix_html: "%{units_balance} の警告" batch_connect_apps_menu_title: インタラクティブアプリ diff --git a/apps/dashboard/config/locales/zh-CN.yml b/apps/dashboard/config/locales/zh-CN.yml index 1c64e6cd85..a76d9bd39c 100644 --- a/apps/dashboard/config/locales/zh-CN.yml +++ b/apps/dashboard/config/locales/zh-CN.yml @@ -34,6 +34,7 @@ zh-CN: back: 返回 balance_additional_message: 考虑申请额外的 %{balanace_units} balance_message: "%{units_balance} 是 %{value}" + balance_no_warnings_html: "没有项目处于 %{threshold} 天余额警告阈值范围内。" balance_reload_message_html: 重新加载页面以查看更新后的余额。 余额每天更新。
最后一次更新是 %{last_update} balance_warning_prefix_html: "%{units_balance} 警告" batch_connect_apps_menu_title: 交互式应用 diff --git a/apps/dashboard/test/integration/balance_warnings_views_test.rb b/apps/dashboard/test/integration/balance_warnings_views_test.rb new file mode 100644 index 0000000000..d752d9ca37 --- /dev/null +++ b/apps/dashboard/test/integration/balance_warnings_views_test.rb @@ -0,0 +1,46 @@ +require 'test_helper' + +class BalanceWarningsViewsTest < ActionDispatch::IntegrationTest + setup do + stub_user + stub_user_configuration({}) + end + + test 'shows informational message when there are no balance warnings' do + with_balance_file([{ project: 'PZS0708', user: 'me', value: 20 }]) do |path| + with_modified_env('OOD_BALANCE_PATH' => path, 'OOD_BALANCE_THRESHOLD' => '10') do + get '/' + assert_response :success + assert_select 'div.alert.alert-info.insufficient-balance' + end + end + end + + test 'shows danger alert when there is a balance warning' do + with_balance_file([{ project: 'PZS0708', user: 'me', value: 0 }]) do |path| + with_modified_env('OOD_BALANCE_PATH' => path, 'OOD_BALANCE_THRESHOLD' => '10') do + get '/' + assert_response :success + assert_select 'div.alert.alert-danger.insufficient-balance' + end + end + end + + private + + def with_balance_file(balances) + Tempfile.open(%w[balance .json]) do |f| + f.write( + { + version: 1, + timestamp: 1234567890, + config: { unit: 'RU', project_type: 'project' }, + balances: balances + }.to_json + ) + f.flush + + yield f.path + end + end +end \ No newline at end of file