Skip to content

Commit

Permalink
Maintenance: Stabilize ticket template test.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvuckovic committed May 2, 2023
1 parent db2d8e8 commit 2533afe
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
41 changes: 41 additions & 0 deletions spec/support/capybara/field_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,47 @@ def set_time_field_value(name, value)

find("div[data-name='#{name}'] .js-timepicker").fill_in with: value
end

# Check the field value of a form tokens field.
#
# @example
# check_tokens_field_value('tags', 'tag name')
# check_tokens_field_value('tags', %w[tag1 tag2 tag3)
#
def check_tokens_field_value(name, value, **find_options)
input_value = if value.is_a?(Array)
value.join(', ')
else
value
end

expect(find("input[name='#{name}']", visible: :all, **find_options).value).to eq(input_value)
end

# Set the field value of a form tokens field.
#
# @example
# set_tokens_field_value('tags', 'tag name')
# set_tokens_field_value('tags', %w[tag1 tag2 tag3])
#
def set_tokens_field_value(name, value, **find_options)
input_string = if value.is_a?(Array)
value.join(', ')
else
value
end

find("input[name='#{name}'] ~ input.token-input", **find_options).send_keys input_string, :tab

token_count = if value.is_a?(Array)
value.length
else
1
end

wait.until { find_all("input[name='#{name}'] ~ .token").length == token_count }
end

end

RSpec.configure do |config|
Expand Down
22 changes: 8 additions & 14 deletions spec/system/ticket/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,23 @@

shared_examples 'merging with existing tags in a dirty form' do
it 'merges with existing tags in a dirty form' do
find('input[name="tags"]', visible: :all)
set_input_field_value('tags', 'baz, qux, foo', visible: :all)
wait.until { find_all('.token').length == 3 }
set_tokens_field_value('tags', %w[baz qux foo])
use_template(template)
check_input_field_value('tags', "baz, qux, #{template_value}", visible: :all)
check_tokens_field_value('tags', ['baz', 'qux', *template_value.split(', ')])
end
end

shared_examples 'replacing tags in a clean form' do
it 'replaces tags in a clean form' do
use_template(template)
check_input_field_value('tags', template_value, visible: :all)
check_tokens_field_value('tags', template_value.split(', '), visible: :all)
end
end

shared_examples 'leaving tags empty in a clean form' do
it 'does nothing in a clean form' do
use_template(template)
check_input_field_value('tags', '', visible: :all)
check_tokens_field_value('tags', '')
end
end

Expand All @@ -121,11 +119,9 @@
it_behaves_like 'leaving tags empty in a clean form'

it 'removes existing tags in a dirty form' do
find('input[name="tags"]', visible: :all)
set_input_field_value('tags', 'foo, bar, baz, qux', visible: :all)
wait.until { find_all('.token').length == 4 }
set_tokens_field_value('tags', %w[foo bar baz qux])
use_template(template)
check_input_field_value('tags', 'baz, qux', visible: :all)
check_tokens_field_value('tags', %w[baz qux])
end
end

Expand All @@ -144,11 +140,9 @@
it_behaves_like 'leaving tags empty in a clean form'

it 'leaves existing tags untouched in a dirty form' do
find('input[name="tags"]', visible: :all)
set_input_field_value('tags', 'baz, qux', visible: :all)
wait.until { find_all('.token').length == 2 }
set_tokens_field_value('tags', %w[baz qux])
use_template(template)
check_input_field_value('tags', 'baz, qux', visible: :all)
check_tokens_field_value('tags', %w[baz qux])
end
end
end
Expand Down

0 comments on commit 2533afe

Please sign in to comment.