Skip to content

Commit

Permalink
feat: Implement editable cell component with button interactions and …
Browse files Browse the repository at this point in the history
…update tests for button selectors
  • Loading branch information
joshsadam committed Dec 18, 2024
1 parent a7f3030 commit f21976b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
29 changes: 29 additions & 0 deletions app/components/samples/editable_cell.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<td id="<%= dom_id(@sample, @field) %>" class="relative" role="gridcell">
<%= form_with(
url: editable_namespace_project_sample_metadata_field_path(
@sample.project.namespace.parent,
@sample.project,
@sample
),
method: :get,
class: "w-full"
) do |form| %>

<%= form.hidden_field :field, value: @field %>
<%= form.hidden_field :format, value: "turbo_stream" %>

<button
type="submit"
class="
w-full p-4 text-left cursor-pointer hover:bg-slate-50 focus:outline-none
dark:hover:bg-slate-600
"
aria-label="<%= t(:".aria_label", value: @sample.metadata[@field]) %> value"
<%= "autofocus" if @autofocus %>
>
<span class="block truncate">
<%= @sample.metadata[@field] || "" %>
</span>
</button>
<% end %>
</td>
29 changes: 0 additions & 29 deletions app/components/samples/editable_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,6 @@ module Samples
class EditableCell < Component
with_collection_parameter :field

erb_template <<~ERB
<td id="<%= dom_id(@sample, @field) %>"
class="relative"
role="gridcell">
<%= form_with(
url: editable_namespace_project_sample_metadata_field_path(
@sample.project.namespace.parent,
@sample.project,
@sample
),
method: :get,
class: "w-full"
) do |form| %>
<%= form.hidden_field :field, value: @field %>
<%= form.hidden_field :format, value: "turbo_stream" %>
<button type="submit"
class="w-full p-4 text-left cursor-pointer hover:bg-slate-50 focus:ring-4 focus:outline-none focus:ring-primary-200 dark:hover:bg-slate-600 dark:focus:ring-primary-700"
aria-label="<%= t(:".aria_label", value: @sample.metadata[@field]) %> value"
<%= "autofocus" if @autofocus %>>
<span class="block truncate">
<%= @sample.metadata[@field] || "" %>
</span>
</button>
<% end %>
</td>
ERB

def initialize(field:, sample:, autofocus: false)
@sample = sample
@field = field
Expand Down
12 changes: 6 additions & 6 deletions test/system/groups/samples_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,16 +391,16 @@ def retrieve_puids
assert_selector 'table thead tr th', count: 9
within('table tbody tr:first-child') do
assert_text @sample30.name
assert_selector 'td:nth-child(7) input[value="value1"]'
assert_selector 'td:nth-child(8) input[value="value2"]'
assert_selector 'td:nth-child(9) input[type="submit"]'
assert_selector 'td:nth-child(7) button', text: 'value1'
assert_selector 'td:nth-child(8) button', text: 'value2'
assert_selector 'td:nth-child(9) button', text: ''
end

within('table tbody tr:nth-child(3)') do
assert_text @sample28.name
assert_selector 'td:nth-child(7) input[type="submit"]'
assert_selector 'td:nth-child(8) input[type="submit"]'
assert_selector 'td:nth-child(9) input[value="unique_value"]'
assert_selector 'td:nth-child(7) button', text: ''
assert_selector 'td:nth-child(8) button', text: ''
assert_selector 'td:nth-child(9) button', text: 'unique_value'
end

find('label', text: I18n.t('projects.samples.shared.metadata_toggle.label')).click
Expand Down
4 changes: 2 additions & 2 deletions test/system/projects/samples_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,8 @@ class SamplesTest < ApplicationSystemTestCase
assert_selector '#samples-table table thead tr th', count: 8
within('#samples-table table tbody tr:first-child') do
assert_text @sample3.name
assert_selector 'td input[type="submit"][value="value1"]'
assert_selector 'td input[type="submit"][value="value2"]'
assert_selector 'td button', text: 'value1'
assert_selector 'td button', text: 'value2'
end
find('label', text: I18n.t('projects.samples.shared.metadata_toggle.label')).click
assert_selector '#samples-table table thead tr th', count: 6
Expand Down

0 comments on commit f21976b

Please sign in to comment.