Skip to content

Commit

Permalink
Add tests to prefixed select2 component
Browse files Browse the repository at this point in the history
  • Loading branch information
malchua committed Dec 20, 2024
1 parent f990196 commit 2eb7ab3
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions test/components/viral/form/prefixed/select2_component_test.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
# frozen_string_literal: true

require 'test_helper'
require 'application_system_test_case'

module Viral
module Form
module Prefixed
class Select2ComponentTest < ViewComponent::TestCase
def test_component_renders_something_useful
# assert_equal(
# %(<span>Hello, components!</span>),
# render_inline(Viral::Form::Prefixed::Select2Component.new(message: "Hello, components!")).css("span").to_html
# )
class Select2ComponentTest < ApplicationSystemTestCase
test 'default' do
visit '/rails/view_components/viral_form_prefixed_select2_component/default'
assert_selector 'input[type="hidden"][name="user"]', visible: :hidden, count: 1
assert_no_selector 'input[type="submit"][disabled="disabled"]'

find('input#select2-input[type="text"]').click
assert_selector 'div[data-viral--select2-target="dropdown"]', visible: :visible
assert_selector 'ul[data-viral--select2-target="scroller"] li', count: 11

find('li button[data-viral--select2-primary-param="User 1"]').click
assert_selector 'input[type="hidden"][name="user"][value="1"]', visible: :hidden, count: 1
assert_no_selector 'input[type="submit"][disabled="disabled"]'
assert_selector 'input[type="submit"]', count: 1

find('input#select2-input[type="text"]').send_keys :backspace
assert_selector 'input[type="submit"][disabled="disabled"]', count: 1
find('input#select2-input[type="text"]').send_keys '22'
find('input#select2-input[type="text"]').send_keys :enter
assert_selector 'input[type="hidden"][name="user"][value="22"]', visible: :hidden, count: 1
assert_no_selector 'input[type="submit"][disabled="disabled"]'
assert_selector 'input[type="submit"]', count: 1
end
end
end
Expand Down

0 comments on commit 2eb7ab3

Please sign in to comment.