Skip to content

Commit a69208e

Browse files
author
Jens Schmidt
committed
Fix log time datetime fields
1 parent 30e3f5d commit a69208e

6 files changed

Lines changed: 62 additions & 16 deletions

File tree

app/views/brews/_form.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
</div>
3535
<% end %>
3636

37-
<%= render "brews/occurred_at_field", form: %>
38-
3937
<% if brew.quick_drip? %>
4038
<%= render "brews/quick_drip_form_fields", form:, brew: %>
4139
<% else %>
@@ -47,5 +45,7 @@
4745
hide_brew_field: %>
4846
<% end %>
4947

48+
<%= render "brews/occurred_at_field", form: %>
49+
5050
<%= form.submit submit_label, class: "rounded-2xl bg-[var(--rn-coffee)] px-5 py-3 text-sm font-extrabold text-[#fff8e8] shadow-lg hover:opacity-90" %>
5151
<% end %>

app/views/brews/_occurred_at_field.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<h2 class="text-sm font-extrabold uppercase tracking-[0.08em] text-rn-muted"><%= t("brews.form.sections.log_time") %></h2>
33
<div class="mt-3 min-w-0 overflow-hidden">
44
<%= form.label :occurred_at, t("brews.form.occurred_at"), class: "block text-sm font-bold text-rn-muted" %>
5-
<%= form.datetime_local_field :occurred_at, required: true, class: "mt-1 block min-w-0 max-w-full w-full rounded-2xl border border-rn-line bg-[var(--rn-canvas)] px-3 py-3 text-rn-ink shadow-sm focus:border-[var(--rn-accent-strong)] focus:outline-none rn-datetime-input" %>
5+
<%= form.datetime_local_field :occurred_at, required: true, step: 1, class: "mt-1 block min-w-0 max-w-full w-full rounded-2xl border border-rn-line bg-[var(--rn-canvas)] px-3 py-3 text-rn-ink shadow-sm focus:border-[var(--rn-accent-strong)] focus:outline-none rn-datetime-input" %>
66
</div>
77
</section>

app/views/external_coffees/_form.html.erb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@
2929
<%= form.text_field :drink_size, class: input_class %>
3030
</div>
3131

32-
<div data-testid="external-coffee-occurred-at-field" class="min-w-0 overflow-hidden">
33-
<%= form.label :occurred_at, t(".occurred_at"), class: label_class %>
34-
<%= form.datetime_local_field :occurred_at, required: true, class: "#{input_class} rn-datetime-input" %>
35-
</div>
36-
3732
<div class="min-w-0">
3833
<%= form.label :price, t(".price"), class: label_class %>
3934
<div class="mt-1 grid grid-cols-[minmax(0,1fr)_5rem] gap-2">
@@ -148,5 +143,14 @@
148143
section_class:,
149144
section_title_class: %>
150145

146+
<section class="<%= section_class %>">
147+
<h2 class="<%= section_title_class %>"><%= t(".sections.log_time") %></h2>
148+
149+
<div data-testid="external-coffee-occurred-at-field" class="min-w-0 overflow-hidden">
150+
<%= form.label :occurred_at, t(".occurred_at"), class: label_class %>
151+
<%= form.datetime_local_field :occurred_at, required: true, step: 1, class: "#{input_class} rn-datetime-input" %>
152+
</div>
153+
</section>
154+
151155
<%= form.submit submit_label, class: "rounded-2xl bg-[var(--rn-coffee)] px-5 py-3 text-sm font-extrabold text-[#fff8e8] shadow-lg hover:opacity-90" %>
152156
<% end %>

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ en:
591591
rating: "Rating"
592592
sections:
593593
drink: "Drink"
594+
log_time: "Log time"
594595
notes: "Notes and photos"
595596
place: "Place"
596597
taste: "Taste"

test/controllers/brews_controller_test.rb

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,32 @@ class BrewsControllerTest < ActionDispatch::IntegrationTest
3030
assert_select "input[name=?][value=?]", "brew[preinfusion_seconds]", "5"
3131
assert_select "input[name=?][value=?]", "brew[first_drip_seconds]", "8", count: 0
3232
assert_select "input[name=?][value=?][checked]", "brew[rating]", "4", count: 0
33-
assert_select "input[type=datetime-local][name=?][required=required]", "brew[occurred_at]"
33+
assert_select "input[type=datetime-local][name=?][required=required][step=?]", "brew[occurred_at]", "1"
3434
assert_select "textarea[name=?]", "brew[notes]", text: ""
3535
assert_select "input[type=checkbox][name=?][value=?][checked]", "brew[preparation_tool_ids][]", preparation_tools(:wdt).id.to_s
3636
assert_select "input[type=checkbox][name=?][value=?]", "brew[preparation_tool_ids][]", preparation_tools(:puck_screen).id.to_s
3737
assert_select "input[type=checkbox][name=?][value=?]", "brew[preparation_tool_ids][]", preparation_tools(:other_workspace_tool).id.to_s, count: 0
3838
assert_select "input[type=file][name=?][multiple=multiple]", "brew[photos][]"
3939
end
4040

41+
test "new places brew log time at the end of the form" do
42+
sign_in_as(users(:one))
43+
44+
get new_brew_path
45+
46+
assert_response :success
47+
form_body = Nokogiri::HTML(response.body).at_css("form[action='#{brews_path}']").inner_html
48+
log_time_index = form_body.index('data-section="log-time"')
49+
record_links_index = form_body.index('data-testid="record-links-fields"')
50+
submit_index = form_body.index('type="submit"')
51+
52+
assert_not_nil log_time_index
53+
assert_not_nil record_links_index
54+
assert_not_nil submit_index
55+
assert_operator log_time_index, :>, record_links_index
56+
assert_operator log_time_index, :<, submit_index
57+
end
58+
4159
test "new falls back to household last brew defaults for a user without household brews" do
4260
user = users(:two)
4361
user.update!(active_workspace: workspaces(:household))
@@ -113,7 +131,7 @@ class BrewsControllerTest < ActionDispatch::IntegrationTest
113131
get new_brew_path(method: "quick_drip")
114132

115133
assert_response :success
116-
assert_select "input[type=datetime-local][name=?][required=required]", "brew[occurred_at]"
134+
assert_select "input[type=datetime-local][name=?][required=required][step=?]", "brew[occurred_at]", "1"
117135
assert_select "input[name=?][autofocus]", "brew[machine_cups]"
118136
assert_select "input[type=text][inputmode=decimal][name=?]", "brew[machine_cups]"
119137
assert_select "input[type=text][inputmode=decimal][name=?]", "brew[coffee_spoons]"
@@ -666,14 +684,19 @@ class BrewsControllerTest < ActionDispatch::IntegrationTest
666684
test "writer can update brew log time and inventory adjustment time" do
667685
sign_in_as(users(:one))
668686
brew = brews(:morning_espresso)
669-
new_time = Time.zone.local(2026, 5, 27, 10, 15, 0)
687+
new_time = Time.zone.local(2026, 5, 27, 10, 15, 28)
688+
689+
get edit_brew_path(brew)
690+
691+
assert_response :success
692+
assert_select "input[type=datetime-local][name=?][required=required][step=?]", "brew[occurred_at]", "1"
670693

671694
patch brew_path(brew), params: {
672695
brew: {
673696
bean_id: brew.bean.id,
674697
grinder_id: brew.grinder.id,
675698
machine_id: brew.machine.id,
676-
occurred_at: "2026-05-27T10:15",
699+
occurred_at: "2026-05-27T10:15:28",
677700
bean_weight_grams: brew.bean_weight_grams.to_s,
678701
ground_weight_grams: brew.ground_weight_grams.to_s,
679702
dose_grams: brew.dose_grams.to_s,

test/controllers/external_coffees_controller_test.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,32 @@ class ExternalCoffeesControllerTest < ActionDispatch::IntegrationTest
2020
assert_select "input[name=?]", "external_coffee[place_name]"
2121
assert_select "input[name=?]", "external_coffee[price]"
2222
assert_select "[data-testid=external-coffee-occurred-at-field].overflow-hidden"
23-
assert_select "input[type=datetime-local][name=?].rn-datetime-input.min-w-0.max-w-full", "external_coffee[occurred_at]"
23+
assert_select "input[type=datetime-local][name=?][step=?].rn-datetime-input.min-w-0.max-w-full", "external_coffee[occurred_at]", "1"
2424
assert_select "textarea[name=?]", "external_coffee[notes]"
2525
assert_select "textarea[name=?]", "external_coffee[public_note]"
2626
assert_select "input[type=file][name=?][multiple=multiple][data-testid=photo-upload-input]", "external_coffee[photos][]"
2727
assert_select "input[type=hidden][name=?]", "external_coffee[photos][]", count: 0
2828
assert_select "[data-controller=external-coffee-location][data-insecure-message]"
2929
end
3030

31+
test "new places external coffee log time at the end of the form" do
32+
sign_in_as(users(:one))
33+
34+
get new_external_coffee_path
35+
36+
assert_response :success
37+
form_body = Nokogiri::HTML(response.body).at_css("form[action='#{external_coffees_path}']").inner_html
38+
log_time_index = form_body.index('data-testid="external-coffee-occurred-at-field"')
39+
record_links_index = form_body.index('data-testid="record-links-fields"')
40+
submit_index = form_body.index('type="submit"')
41+
42+
assert_not_nil log_time_index
43+
assert_not_nil record_links_index
44+
assert_not_nil submit_index
45+
assert_operator log_time_index, :>, record_links_index
46+
assert_operator log_time_index, :<, submit_index
47+
end
48+
3149
test "new renders external taste and rating as styled choices" do
3250
sign_in_as(users(:one))
3351

@@ -124,18 +142,18 @@ class ExternalCoffeesControllerTest < ActionDispatch::IntegrationTest
124142
get edit_external_coffee_path(coffee)
125143

126144
assert_response :success
127-
assert_select "input[type=datetime-local][name=?][required=required]", "external_coffee[occurred_at]"
145+
assert_select "input[type=datetime-local][name=?][required=required][step=?]", "external_coffee[occurred_at]", "1"
128146

129147
patch external_coffee_path(coffee), params: {
130148
external_coffee: {
131149
drink_type: "Americano",
132-
occurred_at: "2026-06-08T14:45",
150+
occurred_at: "2026-06-08T14:45:28",
133151
currency: "EUR"
134152
}
135153
}
136154

137155
assert_redirected_to external_coffee_path(coffee)
138-
assert_equal Time.zone.local(2026, 6, 8, 14, 45, 0), coffee.reload.occurred_at
156+
assert_equal Time.zone.local(2026, 6, 8, 14, 45, 28), coffee.reload.occurred_at
139157
end
140158

141159
test "show hero card renders brand mark identity images footer timestamp bean rating and symbol price" do

0 commit comments

Comments
 (0)