bard-tag_field 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99c36b23ef302095ac7b0c3994ac82027cc28df8efb1426097d67a639f735003
4
- data.tar.gz: badb540eb22db036f7ee1d6930e440cffec862ca008c06e8b57aebb01b86cf50
3
+ metadata.gz: 6f2e7769c2bbc3f424922811fb57fe48207c029af24b926b543550bcbdc525b5
4
+ data.tar.gz: 0f33799fff29c82c007553aa13df5f50ab4c96f271c689726d851e4e2d9b592e
5
5
  SHA512:
6
- metadata.gz: a0bdc6d674b71f7097dd8c6fa6f556f8a95dacd31560bcba2aed2dbb64a7cd94a22c71063e432b4d9f2e2e07b1b38fe2760fcced79a90cd7d9fb1c2935a9d123
7
- data.tar.gz: 85891e20dbc60abf1292f2d091e93ef28cdc824d1110d18d54cec747ad7e54747a8ef52a9991f31c84d5f09b5ce3c42261edf42915d12a50905028d6b0e6f928
6
+ metadata.gz: ec37d61083dd7f262bf358ed179b2a53d51df0e82cd0606746c5da0f1b2e77ee89a62222f27777de24b4308ee3b4f6924799f1238bf68b0402692105070487bf
7
+ data.tar.gz: c2856f864d7674102f7d679399959e19af91b96c44c933f24995332241ca2b70c0e84a426a5ecdcf593fd22aee374d8d40d802699c8f2b892a8871da84dd3863
@@ -0,0 +1,65 @@
1
+ class Chop::Form::TagField < Chop::Form::Field
2
+ def self.css_selector
3
+ "input-tag"
4
+ end
5
+
6
+ def matches?
7
+ field.tag_name == "input-tag"
8
+ end
9
+
10
+ def get_value
11
+ field.all("tag-option").map(&:text)
12
+ end
13
+
14
+ def diff_value
15
+ get_value.join(", ")
16
+ end
17
+ end
18
+
19
+ When "I fill in the {string} tag field with {string}" do |field, value|
20
+ find_input_tag_field(field).click
21
+ page.driver.browser.keyboard.type(value)
22
+ end
23
+
24
+ When "I remove {string} from the {string} tag field" do |value, field|
25
+ within find_input_tag_field(field) do
26
+ within find("tag-option", text: value).shadow_root do
27
+ find("button").trigger("click")
28
+ end
29
+ end
30
+ end
31
+
32
+ Then "I should see the following {string} tag field:" do |field, table|
33
+ tags = input_tag_value(find_input_tag_field(field))
34
+ table.diff! [tags]
35
+ end
36
+
37
+ Then "I should see an empty {string} tag field" do |field|
38
+ expect(find_input_tag_field(field)).to have_no_css("tag-option")
39
+ end
40
+
41
+ Then "I should see the following {string} available tag options:" do |field, table|
42
+ field = find_input_tag_field(field)
43
+ options = field.all("datalist option", visible: false).map { |e| e[:innerText] }
44
+ expect(options).to eq(table.raw.flatten)
45
+ end
46
+
47
+ Then "I should see the following {string} tag field autocomplete options:" do |field, table|
48
+ within find_input_tag_field(field).shadow_root do
49
+ expect(all("li").map(&:text)).to eq(table.raw.flatten)
50
+ end
51
+ end
52
+
53
+ def find_input_tag_field(label)
54
+ find("##{find("label", text: label)[:for]}")
55
+ end
56
+
57
+ def input_tag_value(field)
58
+ field.all("tag-option").map(&:text)
59
+ end
60
+
61
+ def input_tag_field actual, root, label: "Labels"
62
+ index = actual.index { |row| row.first == "Description" }
63
+ tags = input_tag_value(find_input_tag_field(label))
64
+ actual.insert index, [label, tags.join(", ")]
65
+ end
@@ -10,21 +10,15 @@ module Bard
10
10
  # Store choices for render_object_values method
11
11
  @choices = choices
12
12
 
13
- # Generate unique datalist ID if we have choices and no block
14
- datalist_id = nil
15
- if choices&.any? && !block
16
- datalist_id = "#{@options[:id]}_datalist"
17
- @options[:list] = datalist_id
18
- end
19
-
20
13
  result = @template_object.content_tag("input-tag", @options) do
21
- next block.call(@options) if block
22
- render_object_values
23
- end
14
+ content = block ? block.call(@options) : render_object_values
24
15
 
25
- # Add datalist after input-tag if we have choices and no block
26
- if choices&.any? && !block
27
- result += render_datalist(datalist_id, choices)
16
+ # Add nested anonymous datalist if we have choices, no block, and no external list specified
17
+ if choices&.any? && !block && !@options[:list]
18
+ content += render_datalist(nil, choices)
19
+ end
20
+
21
+ content
28
22
  end
29
23
 
30
24
  result
@@ -33,7 +27,10 @@ module Bard
33
27
  private
34
28
 
35
29
  def render_datalist(datalist_id, choices)
36
- @template_object.content_tag("datalist", id: datalist_id) do
30
+ # Use id attribute only if datalist_id is provided (for external datalist)
31
+ attributes = datalist_id ? { id: datalist_id } : {}
32
+
33
+ @template_object.content_tag("datalist", attributes) do
37
34
  choices.map do |choice|
38
35
  case choice
39
36
  when Array
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bard
4
4
  module TagField
5
- VERSION = "0.1.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard-tag_field
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
@@ -92,6 +92,7 @@ files:
92
92
  - gemfiles/rails_7.2.gemfile
93
93
  - gemfiles/rails_8.0.gemfile
94
94
  - lib/bard/tag_field.rb
95
+ - lib/bard/tag_field/cucumber.rb
95
96
  - lib/bard/tag_field/field.rb
96
97
  - lib/bard/tag_field/form_builder.rb
97
98
  - lib/bard/tag_field/version.rb