[chore] add unit tests to new dsl input

This commit is contained in:
Eric Schubert
2026-06-04 13:17:31 +02:00
committed by Alexander Brandon Coles
parent 2c574f623e
commit 0be3025f64
2 changed files with 77 additions and 0 deletions
@@ -279,6 +279,14 @@ RSpec.describe Primer::OpenProject::Forms::Dsl::InputMethods, type: :forms do
it_behaves_like "supporting help texts"
end
describe "#filterable_tree_view" do
let(:field_group) { form_dsl.filterable_tree_view(name:, **options) }
include_examples "input class", Primer::OpenProject::Forms::Dsl::FilterableTreeViewInput
# TODO: Should the filterable tree view support a label?
# it_behaves_like "supporting help texts"
end
describe "#segmented_control" do
let(:field_group) do
form_dsl.segmented_control(name:, label:, value: "a", items: [{ value: "a", label: "A" }], **options)
@@ -0,0 +1,69 @@
# frozen_string_literal: true
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
#++
#
require "spec_helper"
RSpec.describe Primer::OpenProject::Forms::FilterableTreeView, type: :forms do
include ViewComponent::TestHelpers
describe "rendering" do
let(:params) { {} }
let(:model) { build_stubbed(:comment) }
def render_form
render_in_view_context(model, params) do |model, params|
primer_form_with(url: "/foo", model:) do |f|
render_inline_form(f) do |form|
form.filterable_tree_view(name: :ingredients, **params) do |tree|
tree.with_leaf(select_variant: :multiple, label: "flour")
tree.with_leaf(select_variant: :multiple, label: "sugar")
tree.with_leaf(select_variant: :multiple, label: "eggs")
end
end
end
end
end
subject(:rendered_form) do
render_form
page
end
it "renders the filterable-tree-view" do
expect(rendered_form).to have_element :"filterable-tree-view"
end
it "renders the leafs", :aggregate_failures do
expect(rendered_form).to have_element(:li, class: "TreeViewItem", role: "none", text: "flour")
expect(rendered_form).to have_element(:li, class: "TreeViewItem", role: "none", text: "sugar")
expect(rendered_form).to have_element(:li, class: "TreeViewItem", role: "none", text: "eggs")
end
end
end