|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +#-- copyright |
| 4 | +# OpenProject is an open source project management software. |
| 5 | +# Copyright (C) the OpenProject GmbH |
| 6 | +# |
| 7 | +# This program is free software; you can redistribute it and/or |
| 8 | +# modify it under the terms of the GNU General Public License version 3. |
| 9 | +# |
| 10 | +# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
| 11 | +# Copyright (C) 2006-2013 Jean-Philippe Lang |
| 12 | +# Copyright (C) 2010-2013 the ChiliProject Team |
| 13 | +# |
| 14 | +# This program is free software; you can redistribute it and/or |
| 15 | +# modify it under the terms of the GNU General Public License |
| 16 | +# as published by the Free Software Foundation; either version 2 |
| 17 | +# of the License, or (at your option) any later version. |
| 18 | +# |
| 19 | +# This program is distributed in the hope that it will be useful, |
| 20 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | +# GNU General Public License for more details. |
| 23 | +# |
| 24 | +# You should have received a copy of the GNU General Public License |
| 25 | +# along with this program; if not, write to the Free Software |
| 26 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 27 | +# |
| 28 | +# See COPYRIGHT and LICENSE files for more details. |
| 29 | +#++ |
| 30 | + |
| 31 | +require "rails_helper" |
| 32 | + |
| 33 | +RSpec.describe Documents::Admin::DocumentTypes::IndexComponent, type: :component do |
| 34 | + subject(:rendered_component) do |
| 35 | + with_controller_class(Documents::Admin::Settings::DocumentTypesController) do |
| 36 | + with_request_url("/admin/settings/document_types") do |
| 37 | + render_inline(described_class.new(enumerations: document_types)) |
| 38 | + end |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + let(:document_types) { DocumentType.order(:position) } |
| 43 | + |
| 44 | + context "with document types" do |
| 45 | + let!(:note_type) { create(:document_type, name: "Note", position: 1) } |
| 46 | + let!(:report_type) { create(:document_type, name: "Report", position: 2) } |
| 47 | + |
| 48 | + it "renders the document types in a border box list with preserved controls and drag-and-drop data" do |
| 49 | + expect(rendered_component).to have_css(".Box.op-border-box-list") |
| 50 | + expect(rendered_component).to have_css(".Box[data-generic-drag-and-drop-target='container']") |
| 51 | + expect(rendered_component).to have_css(".Box[data-target-container-accessor=':scope > ul']") |
| 52 | + expect(rendered_component).to have_css(".Box[data-target-allowed-drag-type='enumeration']") |
| 53 | + |
| 54 | + expect(rendered_component).to have_css("[data-test-selector='admin-document-types-subheader']") |
| 55 | + expect(rendered_component).to have_css("[data-test-selector='add-document-type-button']") |
| 56 | + expect(rendered_component).to have_css("h3", text: I18n.t("documents.index_page.type")) |
| 57 | + expect(rendered_component).to have_css(".Counter", text: "2") |
| 58 | + |
| 59 | + rows = rendered_component.css(".Box-row[data-draggable-type='enumeration']") |
| 60 | + expect(rows.size).to eq(2) |
| 61 | + |
| 62 | + expect(rendered_component).to have_css( |
| 63 | + ".Box-row[data-test-selector='document-type-row-#{note_type.id}']" \ |
| 64 | + "[data-draggable-id='#{note_type.id}']" \ |
| 65 | + "[data-draggable-type='enumeration']" \ |
| 66 | + "[data-drop-url$='/admin/settings/document_types/#{note_type.id}/move']", |
| 67 | + text: "Note" |
| 68 | + ) |
| 69 | + expect(rendered_component).to have_css( |
| 70 | + ".Box-row[data-test-selector='document-type-row-#{report_type.id}']" \ |
| 71 | + "[data-draggable-id='#{report_type.id}']" \ |
| 72 | + "[data-draggable-type='enumeration']" \ |
| 73 | + "[data-drop-url$='/admin/settings/document_types/#{report_type.id}/move']", |
| 74 | + text: "Report" |
| 75 | + ) |
| 76 | + end |
| 77 | + end |
| 78 | + |
| 79 | + context "without document types" do |
| 80 | + it "renders the existing empty result text as a border box list row" do |
| 81 | + expect(rendered_component).to have_css(".Box.op-border-box-list") |
| 82 | + expect(rendered_component).to have_css(".Box-row", text: I18n.t(:no_results_title_text)) |
| 83 | + end |
| 84 | + end |
| 85 | +end |
0 commit comments