Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

3.7 KB
Raw Blame
# 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 "rails_helper"

RSpec.describe Projects::RowComponent, type: :component do
  include Rails.application.routes.url_helpers

  def render_component(...)
    render_inline(described_class.new(...))
  end

  let(:project) { build_stubbed(:project, name: "My Project No. 1", identifier: "myproject_no_1") }
  let(:table) do
    instance_double(Projects::TableComponent, columns: [Queries::Projects::Selects::Default.new(:name)],
                                              favorited_project_ids: [])
  end

  let(:user) { build_stubbed(:user) }

  current_user { user }

  subject(:rendered_component) do
    render_component(row: [project, 0], table:)
  end

  describe "Project Name" do
    it "renders the project name as a link" do
      expect(rendered_component).to have_css(
        "a[data-turbo='false'][href='/projects/myproject_no_1']",
        text: "My Project No. 1"
      )
    end
  end

  describe "Menu" do
    context "when the user has no project edit permissions" do
      it "renders a Primer ActionMenu (single variant)" do
        expect(subject).to have_element "action-menu", "data-select-variant": "none"
      end

      it "renders menu items", :aggregate_failures do
        expect(rendered_component).to have_menu do |menu|
          expect(menu).to have_selector :menuitem, count: 1
          expect(menu).to have_selector :menuitem, text: "Add to favorites"
        end
      end
    end

    context "when the user has project edit permissions" do
      let(:user) { build_stubbed(:admin) }

      it "renders a Primer ActionMenu (single variant)" do
        expect(subject).to have_element "action-menu", "data-select-variant": "none"
      end

      it "renders menu items", :aggregate_failures do
        expect(rendered_component).to have_menu do |menu|
          expect(menu).to have_selector :menuitem, count: 7
          expect(menu).to have_selector :menuitem, text: "New subproject"
          expect(menu).to have_selector :menuitem, text: "Project settings"
          expect(menu).to have_selector :menuitem, text: "Project activity"
          expect(menu).to have_selector :menuitem, text: "Add to favorites"
          expect(menu).to have_selector :menuitem, text: "Archive"
          expect(menu).to have_selector :menuitem, text: "Copy"
          expect(menu).to have_selector :menuitem, text: "Delete" do |link|
            expect(link[:href]).to eq confirm_destroy_project_path(project)
            expect(link[:"data-turbo-stream"]).to eq "true"
          end
        end
      end
    end
  end
end