From 468f54360df9eda5a1c74f118551bf16c2be1db4 Mon Sep 17 00:00:00 2001 From: DanielVajnagi <82052651+DanielVajnagi@users.noreply.github.com> Date: Wed, 4 Dec 2024 10:28:53 +0200 Subject: [PATCH] Show page (#1001) * Show page * spec --- .../account/calculators_controller.rb | 2 +- app/views/account/calculators/show.html.erb | 58 ++++++++++++++++++- spec/requests/account/calculators_spec.rb | 11 ++++ 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/app/controllers/account/calculators_controller.rb b/app/controllers/account/calculators_controller.rb index 9a14436cf..beb21c3f4 100644 --- a/app/controllers/account/calculators_controller.rb +++ b/app/controllers/account/calculators_controller.rb @@ -10,7 +10,7 @@ def index end def show - # TODO: fill it + @calculator = resource end def new diff --git a/app/views/account/calculators/show.html.erb b/app/views/account/calculators/show.html.erb index 553e9b798..4ba438cfc 100644 --- a/app/views/account/calculators/show.html.erb +++ b/app/views/account/calculators/show.html.erb @@ -1 +1,57 @@ -<%= render "shared/under_construction" %> +
+ <%= link_to account_calculators_path, class: "back-arrow" do %> + <%= inline_svg "icons/arrow-left.svg", class: "z-1 mr-2 mb-0.5" %> + <%= t('buttons.back') %> + <% end %> + +
+ <%= t('.name') %>: +

<%= @calculator.name %>

+
+ +
+ <%= t('.slug') %>: +

<%= @calculator.slug %>

+
+ + +
+

<%= t('.fields') %>:

+ <% @calculator.fields.each do |field| %> +
+
+ <%= field.label %> + (<%= field.var_name %>)
+
+
+ <% end %> +
+ + +
+

<%= t('.formulas') %>:

+ <% @calculator.formulas.each do |formula| %> +
+
+ <%= formula.label %> + (<%= formula.expression %>)
+ <%= t('.unit') %>: + <%= formula.unit %> +
+
+ <% end %> +
+ +
+ <%= link_to t('.edit'), + edit_account_calculator_path(@calculator.slug, locale: I18n.locale), + class: "btn btn-green" %> + + <%= button_to account_calculator_path(@calculator.slug, locale: I18n.locale), + method: :delete, + data: { turbo_confirm: t('.confirm_delete') }, + class: "btn btn-danger" do %> + <%= t('.delete') %> + <% end %> +
+
\ No newline at end of file diff --git a/spec/requests/account/calculators_spec.rb b/spec/requests/account/calculators_spec.rb index c4f45a524..95f57150b 100644 --- a/spec/requests/account/calculators_spec.rb +++ b/spec/requests/account/calculators_spec.rb @@ -88,4 +88,15 @@ end end end + + describe "GET /account/calculators/:slug" do + it "renders the calculator's show page correctly" do + get account_calculator_path(calculator.slug, locale: locale) + + expect(response).to have_http_status(:ok) + expect(response).to render_template(:show) + expect(response.body).to include(calculator.en_name) + expect(response.body).to include(calculator.slug) + end + end end