|
| 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 My::Notifications::ShowPageComponent, type: :component do |
| 34 | + let(:user) { create(:user) } |
| 35 | + # create(:user) already seeds the global (project-less) notification setting. |
| 36 | + let(:global_setting) { user.notification_settings.find_by!(project: nil) } |
| 37 | + |
| 38 | + subject(:rendered_component) do |
| 39 | + with_request_url("/my/notifications") do |
| 40 | + render_inline( |
| 41 | + described_class.new( |
| 42 | + user:, |
| 43 | + global_notification_setting: global_setting, |
| 44 | + update_participating_url: { action: "update_participating" }, |
| 45 | + update_non_participating_url: { action: "update_non_participating" }, |
| 46 | + update_date_alerts_url: { action: "update_date_alerts" }, |
| 47 | + new_project_settings_url: "/my/project_notifications/new", |
| 48 | + edit_project_settings_url: ->(project_id) { "/my/project_notifications/#{project_id}/edit" }, |
| 49 | + project_setting_url: ->(project_id) { "/my/project_notifications/#{project_id}" } |
| 50 | + ) |
| 51 | + ) |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + context "with project-specific settings" do |
| 56 | + let(:project) { create(:project) } |
| 57 | + let!(:project_setting) { create(:notification_setting, user:, project:) } |
| 58 | + |
| 59 | + it "renders the list header and the add-project action", :aggregate_failures do |
| 60 | + expect(rendered_component).to have_css(".Box-header") do |header| |
| 61 | + expect(header).to have_heading(I18n.t("my_account.notifications.project_specific_settings.list_header")) |
| 62 | + end |
| 63 | + expect(rendered_component).to have_link( |
| 64 | + I18n.t("my_account.notifications.project_specific_settings.add_button"), |
| 65 | + href: "/my/project_notifications/new" |
| 66 | + ) |
| 67 | + end |
| 68 | + |
| 69 | + it "renders a row per project-specific setting with an edit/delete actions menu", :aggregate_failures do |
| 70 | + expect(rendered_component).to have_css(".Box-row", text: project.name) do |row| |
| 71 | + expect(row).to have_button(accessible_name: I18n.t(:label_open_menu)) |
| 72 | + expect(row).to have_link(I18n.t(:button_edit), href: "/my/project_notifications/#{project.id}/edit") |
| 73 | + expect(row).to have_link(I18n.t(:button_delete), href: "/my/project_notifications/#{project.id}") |
| 74 | + end |
| 75 | + end |
| 76 | + end |
| 77 | + |
| 78 | + context "without project-specific settings" do |
| 79 | + it_behaves_like "rendering Blank Slate", |
| 80 | + heading: I18n.t(:label_nothing_display) |
| 81 | + end |
| 82 | +end |
0 commit comments