From 0be3025f644cf83cbaae1afeaa420e095e83bb88 Mon Sep 17 00:00:00 2001 From: Eric Schubert Date: Thu, 4 Jun 2026 13:17:31 +0200 Subject: [PATCH] [chore] add unit tests to new dsl input --- .../forms/dsl/input_methods_spec.rb | 8 +++ .../forms/filterable_tree_view_spec.rb | 69 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 spec/lib/primer/open_project/forms/filterable_tree_view_spec.rb diff --git a/spec/lib/primer/open_project/forms/dsl/input_methods_spec.rb b/spec/lib/primer/open_project/forms/dsl/input_methods_spec.rb index 597129b85e3..7879cc55872 100644 --- a/spec/lib/primer/open_project/forms/dsl/input_methods_spec.rb +++ b/spec/lib/primer/open_project/forms/dsl/input_methods_spec.rb @@ -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) diff --git a/spec/lib/primer/open_project/forms/filterable_tree_view_spec.rb b/spec/lib/primer/open_project/forms/filterable_tree_view_spec.rb new file mode 100644 index 00000000000..45ba32e4f2a --- /dev/null +++ b/spec/lib/primer/open_project/forms/filterable_tree_view_spec.rb @@ -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