generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Style calculators constructor show page (#984)
* Style show page * Fix formatting * Added calculation service helper test * Added change color logic * fix dynamic colors adding * Change calculation_service logic * Fix calculation_service_helper test * Change constructor calculatior description partial * Added space * Change constructor calculator description partial * Added comment * Fix image and added alt I18n and change calculation result partial * Code formatting
- Loading branch information
1 parent
0537196
commit 679ae88
Showing
11 changed files
with
147 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 21 additions & 13 deletions
34
app/views/calculators/partials/_calculation_results.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
<h2 class="mt-4 text-2xl font-bold text-white underline">Calculation Results</h2> | ||
<div class="mt-2 space-y-2 text-white"> | ||
<% results.each do |result| %> | ||
<div class="flex gap-2 text-lg font-medium"> | ||
<h3> | ||
<%= result[:label] %> | ||
</h3> | ||
= | ||
<p> | ||
<%= result[:result] %> | ||
</p> | ||
</div> | ||
<% end %> | ||
<%# TODO: Delete this and use user provided value%> | ||
<% formula_image = "money_to_spent_2.png" %> | ||
|
||
<div class="calculation-results rounded jumbotron jumbotron-fluid position-relative"> | ||
<h2 class="pt-6 text-2xl font-semibold text-center dynamic-text-color">Calculation Results</h2> | ||
<div class="jumbotron calculation-results result main-result-container result-container"> | ||
<% results.each do |result| %> | ||
<div> | ||
<%= image_tag "#{formula_image}", class: "img-margin", alt: "icon" %> | ||
<p class="dynamic-text-color"> | ||
<%= result[:result] %> | ||
</p> | ||
<p class="text-2xl dynamic-text-color"> | ||
<%= result[:unit] %> | ||
</p> | ||
<p class="diapers-font-text"> | ||
<%= result[:label] %> | ||
</p> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> |
8 changes: 8 additions & 0 deletions
8
app/views/calculators/partials/show/_constructor_calculator_description.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<%# TODO: Delete this if %> | ||
<% if false %> | ||
<section class="description-section"> | ||
<div class="description-block"> | ||
<%# TODO: ADD text here %> | ||
</div> | ||
</section> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,40 @@ | ||
<div class="container place-items-center"> | ||
<h1 class="text-4xl font-bold">Calculator <%= @calculator.name %></h1><br> | ||
<%# TODO: Delete this and use user provided value %> | ||
<% color = "#088F8F" %> | ||
<%= form_with url: calculate_calculator_path(@calculator) do |form| %> | ||
<% @calculator.fields.each do |field| %> | ||
<div class="space-y-4 form-inputs"> | ||
<h1><%= form.label field.var_name, field.label %></h1> | ||
<% if field.kind == 'number' %> | ||
<%= form.number_field "inputs[#{field.var_name}]", placeholder: field.label %> | ||
<% else %> | ||
<%= form.select "inputs[#{field.var_name}]", options_from_collection_for_select(field.categories, :price, :name) %> | ||
<% end %> | ||
</div><br> | ||
<%# TODO: Delete this and use user provided value %> | ||
<% calculator_image = "scales.png" %> | ||
|
||
<div style="--calculator-color: <%= color %>"> | ||
<div class="rounded jumbotron jumbotron-fluid position-relative"> | ||
<h1 class="pt-6 text-2xl font-semibold text-center font-sans dynamic-text-color">Calculator <%= @calculator.name %> <%= @text %></h1> | ||
<div class="flex-wrap d-flex justify-content-around calculator_wrap ms-5"> | ||
|
||
<%= form_with html: { class: "simple_form_calculator"}, url: calculate_calculator_path(@calculator) do |form| %> | ||
<div class="flex-item flex-column"> | ||
<% @calculator.fields.each do |field| %> | ||
<div class="pb-2 input_lable"><%= form.label field.var_name, field.label %></div> | ||
<% if field.kind == 'number' %> | ||
<div class="flex-row rounded flex-item w-100 age_wrapper form_fild"> | ||
<%= form.number_field "inputs[#{field.var_name}]", | ||
placeholder: field.label, | ||
class: "required rounded w-100 calculator-field" | ||
%> | ||
</div> | ||
<% else %> | ||
<%= form.select "inputs[#{field.var_name}]", | ||
options_from_collection_for_select(field.categories, :price, :name), | ||
{}, | ||
class: "flex-row rounded flex-item w-100 form_fild calculator-field" %> | ||
<% end %> | ||
<% end %> | ||
<%= form.submit "Calculate", class: "btn-nonito result-btn dynamic-background-color" %> | ||
</div> | ||
<% end %> | ||
<div class="mt-6 form-actions"> | ||
<%= form.submit "Calculate", class: "bg-blue-500 text-white font-semibold px-4 py-2 rounded hover:bg-blue-700" %> | ||
<%= image_tag calculator_image, class: "scales_img", alt: t(".image_alt") %> | ||
</div> | ||
<% end %> | ||
</div> | ||
|
||
<%= turbo_frame_tag "calc-results" %> | ||
</div> | ||
|
||
<%= render "calculators/partials/show/constructor_calculator_description" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
spec/helpers/calculators/calculation_service_helper_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Calculators::CalculationService, type: :helper do | ||
let(:calculator) { instance_double("Calculator", formulas: formulas) } | ||
let(:formulas) do | ||
[ | ||
Formula.new(en_label: "Addition", en_unit: "units", uk_label: "Додавання", uk_unit: "одиниці", expression: "x + y"), | ||
Formula.new(en_label: "Multiplication", en_unit: "units", uk_label: "Множення", uk_unit: "одиниці", expression: "x * y") | ||
] | ||
end | ||
let(:inputs) { ActionController::Parameters.new({ x: 5, y: 3 }) } | ||
|
||
before do | ||
allow_any_instance_of(ApplicationHelper).to receive(:current_locale?).with(:en).and_return(locale_en) | ||
end | ||
|
||
describe "#perform" do | ||
subject do | ||
I18n.with_locale(locale_en ? :en : :uk) do | ||
described_class.new(calculator, inputs).perform | ||
end | ||
end | ||
|
||
context "when locale is English" do | ||
let(:locale_en) { true } | ||
|
||
it "returns results with English labels and units" do | ||
expect(subject).to eq([ | ||
{ label: "Addition", result: 8, unit: "units" }, | ||
{ label: "Multiplication", result: 15, unit: "units" } | ||
]) | ||
end | ||
end | ||
|
||
context "when locale is Ukrainian" do | ||
let(:locale_en) { false } | ||
|
||
it "returns results with Ukrainian labels and units" do | ||
expect(subject).to eq([ | ||
{ label: "Додавання", result: 8, unit: "одиниці" }, | ||
{ label: "Множення", result: 15, unit: "одиниці" } | ||
]) | ||
end | ||
end | ||
end | ||
end |