|
| 1 | +# frozen_string_literal: true |
| 2 | + |
1 | 3 | require "test_helper"
|
| 4 | +require "support/phlex_component_test_case" |
2 | 5 |
|
3 | 6 | module Pages
|
4 | 7 | module Groups
|
5 |
| - class ComponentTest < ActiveSupport::TestCase |
6 |
| - include Phlex::Testing::ViewHelper |
7 |
| - |
8 |
| - setup do |
9 |
| - @databases_group = groups(:databases) |
10 |
| - @dev_env_group = groups(:dev_env) |
| 8 | + class ComponentTest < PhlexComponentTestCase |
| 9 | + test "renders group with stimulus attributes" do |
| 10 | + group = Group.new(title: "Test Group", behavior_type: "generic_checkbox") |
| 11 | + group.stubs(:stimulus_attributes).returns({ |
| 12 | + controller: "rails-flag-checkbox", |
| 13 | + "rails-flag-checkbox-generated-output-outlet": "#rails-flags" |
| 14 | + }) |
| 15 | + group.stubs(:sub_groups).returns([]) |
| 16 | + |
| 17 | + component = Component.new(group: group) |
| 18 | + html = component.render_in(view_context) |
| 19 | + |
| 20 | + assert_includes html, 'data-controller="rails-flag-checkbox"' |
| 21 | + assert_includes html, 'data-rails-flag-checkbox-generated-output-outlet="#rails-flags"' |
11 | 22 | end
|
12 | 23 |
|
13 |
| - test "renders database choice group with correct stimulus attributes" do |
14 |
| - component = Component.new(group: @databases_group) |
15 |
| - |
16 |
| - Pages::Groups::SubGroups::Elements::RadioButton::Component.any_instance |
17 |
| - .stubs(:image_tag) |
18 |
| - .returns("image_tag_stub") |
| 24 | + private |
19 | 25 |
|
20 |
| - html = render(component) |
21 |
| - |
22 |
| - assert_includes html, 'data-controller="radio-button-choice"' |
23 |
| - assert_includes html, 'data-radio-button-choice-generated-output-outlet="#database-choice"' |
24 |
| - assert_includes html, 'data-output-prefix="-d"' |
| 26 | + def view_context |
| 27 | + controller.view_context |
25 | 28 | end
|
26 | 29 |
|
27 |
| - test "renders generic checkbox group with correct stimulus attributes" do |
28 |
| - @dev_env_group.update!(behavior_type: "generic_checkbox") |
29 |
| - component = Component.new(group: @dev_env_group) |
30 |
| - |
31 |
| - html = render(component) |
32 |
| - |
33 |
| - assert_includes html, 'data-controller="check-box"' |
34 |
| - assert_includes html, 'data-check-box-generated-output-outlet="#rails-flags"' |
| 30 | + def controller |
| 31 | + @controller ||= ApplicationController.new.tap do |c| |
| 32 | + c.request = ActionDispatch::TestRequest.create |
| 33 | + c.response = ActionDispatch::TestResponse.new |
| 34 | + end |
35 | 35 | end
|
36 | 36 | end
|
37 | 37 | end
|
|
0 commit comments