Skip to content

Commit 53e1733

Browse files
committed
Update Admin to have firstname and lastname fields
Update the address handling logic in the admin components and tests for 'firstname' and 'lastname' fields, instead of using a single 'name' field.
1 parent b2bd848 commit 53e1733

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

admin/app/components/solidus_admin/ui/forms/address/component.html.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
>
55
<div class="<%= stimulus_id %>--address-form flex flex-wrap gap-4 pb-4">
66
<%= render component("ui/forms/field").text_field(@name, :name, object: @address) %>
7+
<%= render component("ui/forms/field").text_field(@name, :firstname, object: @address) %>
8+
<%= render component("ui/forms/field").text_field(@name, :lastname, object: @address) %>
9+
<% if Spree::Config[:company] %>
10+
<%= render component("ui/forms/field").text_field(@name, :company, object: @address) %>
11+
<% end %>
712
<%= render component("ui/forms/field").text_field(@name, :address1, object: @address) %>
813
<%= render component("ui/forms/field").text_field(@name, :address2, object: @address) %>
914
<div class="flex gap-4 w-full">

admin/spec/features/orders/show_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252

5353
within("dialog") do
5454
fill_in "Name", with: "John Doe"
55+
fill_in "First Name", with: "John"
56+
fill_in "Last Name", with: "Doe"
5557
fill_in "Street Address", with: "1 John Doe Street"
5658
fill_in "Street Address (cont'd)", with: "Apartment 2"
5759
fill_in "City", with: "John Doe City"
@@ -78,6 +80,8 @@
7880

7981
within("dialog") do
8082
fill_in "Name", with: "Jane Doe"
83+
fill_in "First Name", with: "Jane"
84+
fill_in "Last Name", with: "Doe"
8185
fill_in "Street Address", with: "1 Jane Doe Street"
8286
fill_in "Street Address (cont'd)", with: "Apartment 3"
8387
fill_in "City", with: "Jane Doe City"

admin/spec/features/users_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,28 +129,32 @@
129129
# Invalid submission
130130
within("form.ship_address") do
131131
fill_in "Name", with: ""
132+
fill_in "First Name", with: ""
132133
fill_in "Street Address", with: ""
133134
click_on "Update"
134135
end
135-
expect(page).to have_content("can't be blank").twice
136+
expect(page).to have_content("can't be blank").thrice
136137

137138
# Valid submission
138139
within("form.bill_address") do
139140
fill_in "Name", with: "Galadriel"
141+
fill_in "First Name", with: "Galadriel"
140142
click_on "Update"
141143
end
142144
expect(page).to have_content("Billing Address has been successfully updated.")
143145

144146
# Valid submission
145147
within("form.ship_address") do
146148
fill_in "Name", with: "Elrond"
149+
fill_in "First Name", with: "Elrond"
147150
click_on "Update"
148151
end
149152
expect(page).to have_content("Shipping Address has been successfully updated.")
150153

151154
# Cancel submission
152155
within("form.bill_address") do
153156
fill_in "Name", with: "Smeagol"
157+
fill_in "First Name", with: "Smeagol"
154158
click_on "Cancel"
155159
end
156160
expect(page).to have_content("Users / customer@example.com / Addresses")
@@ -159,6 +163,8 @@
159163
# The address forms weirdly only have values rather than actual text on the page.
160164
expect(page).to have_field("user[bill_address_attributes][name]", with: "Galadriel")
161165
expect(page).to have_field("user[ship_address_attributes][name]", with: "Elrond")
166+
expect(page).to have_field("user[bill_address_attributes][firstname]", with: "Galadriel")
167+
expect(page).to have_field("user[ship_address_attributes][firstname]", with: "Elrond")
162168
end
163169
end
164170

admin/spec/requests/solidus_admin/users_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
user: {
1313
bill_address_attributes: {
1414
name: address.name,
15+
firstname: address.firstname,
16+
lastname: address.lastname,
1517
address1: address.address1,
1618
address2: address.address2,
1719
city: address.city,

0 commit comments

Comments
 (0)