-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display warning text when progress calculation changes
There is also a new helper to display HTML content in forms.
- Loading branch information
Showing
9 changed files
with
178 additions
and
99 deletions.
There are no files selected for viewing
44 changes: 0 additions & 44 deletions
44
app/forms/admin/settings/progress_tracking/progress_calculation_mode_form.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
module OpenProject | ||
module Forms | ||
module Dsl | ||
class HtmlContentInput < Primer::Forms::Dsl::Input | ||
def initialize(**system_arguments, &html_block) | ||
@html_block = html_block | ||
|
||
super(**system_arguments) | ||
end | ||
|
||
def to_component | ||
HtmlContent.new(&@html_block) | ||
end | ||
|
||
def type | ||
:html_content | ||
end | ||
|
||
def name = nil | ||
def form_control? = false | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= rendered_html_content %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Primer | ||
module OpenProject | ||
module Forms | ||
# :nodoc: | ||
class HtmlContent < Primer::Forms::BaseComponent | ||
def initialize(&html_block) | ||
super() | ||
@html_block = html_block | ||
end | ||
|
||
def rendered_html_content | ||
@view_context.capture do | ||
@view_context.instance_exec(&@html_block) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#-- 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 "Progress tracking admin page", :cuprite, :js, | ||
with_flag: { percent_complete_edition: true } do | ||
include ActionView::Helpers::SanitizeHelper | ||
include Toasts::Expectations | ||
|
||
shared_let(:admin) { create(:admin) } | ||
|
||
it "displays a warning when changing progress calculation mode" do | ||
Setting.work_package_done_ratio = "field" | ||
login_as(admin) | ||
visit admin_settings_progress_tracking_path | ||
|
||
# change from work-based to status-based | ||
expect(page).to have_field("Work-based", checked: true) | ||
expect(page).to have_field("Status-based", checked: false) | ||
|
||
find(:radio_button, "Status-based").click | ||
|
||
expected_warning_text = | ||
I18n.t("js.admin.work_packages_settings.warning_progress_calculation_mode_change_from_field_to_status_html") | ||
expected_warning_text = strip_tags(expected_warning_text)[..80] # take only the beginning of the text | ||
expect(page).to have_text(expected_warning_text) | ||
|
||
click_on "Save" | ||
expect_and_dismiss_toaster(message: "Successful update.") | ||
expect(Setting.find_by(name: "work_package_done_ratio").value).to eq("status") | ||
|
||
# now change from status-based to work-based | ||
expect(page).to have_field("Work-based", checked: false) | ||
expect(page).to have_field("Status-based", checked: true) | ||
|
||
find(:radio_button, "Work-based").click | ||
expected_warning_text = | ||
I18n.t("js.admin.work_packages_settings.warning_progress_calculation_mode_change_from_status_to_field_html") | ||
expected_warning_text = strip_tags(expected_warning_text)[..80] # take only the beginning of the text | ||
expect(page).to have_text(expected_warning_text) | ||
|
||
click_on "Save" | ||
expect_and_dismiss_toaster(message: "Successful update.") | ||
expect(Setting.find_by(name: "work_package_done_ratio").value).to eq("field") | ||
end | ||
end |