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

Add test for inline editing of project custom fields

Henriette Dingerbfb23a271030
diff --git a/app/assets/stylesheets/content/_attributes_key_value.sass b/app/assets/stylesheets/content/_attributes_key_value.sass
index 593660fc65a..2addf04e60d 100644
--- a/app/assets/stylesheets/content/_attributes_key_value.sass
+++ b/app/assets/stylesheets/content/_attributes_key_value.sass
@@ -84,6 +84,7 @@
.attributes-map--key
@include text-shortener
font-weight: bold
+ line-height: 27px
.attributes-map.-minimal-keys &
max-width: 200px
diff --git a/frontend/src/app/modules/fields/openproject-fields.module.ts b/frontend/src/app/modules/fields/openproject-fields.module.ts
index c656c90ac99..c40cd82b45a 100644
--- a/frontend/src/app/modules/fields/openproject-fields.module.ts
+++ b/frontend/src/app/modules/fields/openproject-fields.module.ts
@@ -52,6 +52,7 @@ import {SelectAutocompleterRegisterService} from "core-app/modules/fields/edit/f
import {EditFormComponent} from "core-app/modules/fields/edit/edit-form/edit-form.component";
import {WorkPackageEditFieldComponent} from "core-app/modules/fields/edit/field-types/work-package-edit-field.component";
import {EditableAttributeFieldComponent} from "core-app/modules/fields/edit/field/editable-attribute-field.component";
+import {PortalCleanupService} from "core-app/modules/fields/display/display-portal/portal-cleanup.service";
@NgModule({
imports: [
@@ -69,6 +70,7 @@ import {EditableAttributeFieldComponent} from "core-app/modules/fields/edit/fiel
providers: [
EditingPortalService,
UserFieldPortalService,
+ PortalCleanupService,
DisplayFieldService,
EditFieldService,
SelectAutocompleterRegisterService,
diff --git a/modules/dashboards/spec/features/project_details_spec.rb b/modules/dashboards/spec/features/project_details_spec.rb
index 61db38a6911..2e3e4fc8155 100644
--- a/modules/dashboards/spec/features/project_details_spec.rb
+++ b/modules/dashboards/spec/features/project_details_spec.rb
@@ -64,6 +64,12 @@ describe 'Project details widget on dashboard', type: :feature, js: true do
manage_dashboards]
end
+ let(:editing_permissions) do
+ %i[view_dashboards
+ manage_dashboards
+ edit_project]
+ end
+
let(:role) do
FactoryBot.create(:role, permissions: permissions)
end
@@ -71,6 +77,13 @@ describe 'Project details widget on dashboard', type: :feature, js: true do
let(:user) do
FactoryBot.create(:user, member_in_project: project, member_through_role: role)
end
+ let(:second_user) do
+ FactoryBot.create(:user,
+ member_in_project: project,
+ member_with_permissions: editing_permissions,
+ firstname: 'Cool',
+ lastname: 'Guy')
+ end
let(:other_user) do
FactoryBot.create(:user)
end
@@ -78,37 +91,84 @@ describe 'Project details widget on dashboard', type: :feature, js: true do
Pages::Dashboard.new(project)
end
- before do
- login_as user
-
+ def add_project_details_widget
dashboard_page.visit!
- end
-
- it 'can add the widget and see the description in it' do
dashboard_page.add_widget(1, 1, :within, "Project details")
sleep(0.1)
+ end
+
+ def change_cf_value(cf, old_value, new_value)
+ # Open description field
+ cf.activate!
+ sleep(0.1)
+
+ # Change the value
+ cf.expect_value(old_value)
+ cf.set_value new_value
+ cf.save! unless cf.field_type === 'create-autocompleter'
+
+ # The edit field is toggled and the value saved.
+ expect(page).to have_content(new_value)
+ expect(page).to have_selector(cf.selector)
+ expect(page).not_to have_selector(cf.input_selector)
+ end
+
+ context 'without editing permissions' do
+ before do
+ login_as user
+ add_project_details_widget
+ end
+
+ it 'can add the widget, but not edit the custom fields' do
+ # As the user lacks the manage_public_queries and save_queries permission, no other widget is present
+ details_widget = Components::Grids::GridArea.new('.grid--area.-widgeted:nth-of-type(1)')
+
+ within(details_widget.area) do
+ # Expect values
+ expect(page)
+ .to have_content("#{int_cf.name}\n5")
+ expect(page)
+ .to have_content("#{bool_cf.name}\nyes")
+ expect(page)
+ .to have_content("#{version_cf.name}\n#{system_version.name}")
+ expect(page)
+ .to have_content("#{float_cf.name}\n4.5")
+ expect(page)
+ .to have_content("#{text_cf.name}\nSome long text")
+ expect(page)
+ .to have_content("#{string_cf.name}\nSome small text")
+ expect(page)
+ .to have_content("#{date_cf.name}\n#{Date.today.strftime('%m/%d/%Y')}")
+ expect(page)
+ .to have_content("#{user_cf.name}\n#{user.name.split.map(&:first).join}#{user.name}")
+
+ # The fields are not editable
+ field = EditField.new dashboard_page, "customField#{bool_cf.id}"
+ field.activate! expect_open: false
+ end
+ end
+ end
+
+ context 'with editing permissions' do
+ before do
+ user
+ login_as second_user
+ add_project_details_widget
+ end
+
+ it 'can edit the custom fields' do
+ int_field = EditField.new dashboard_page, "customField#{int_cf.id}"
+ change_cf_value int_field, "5", "3"
+
+ string_field = EditField.new dashboard_page, "customField#{string_cf.id}"
+ change_cf_value string_field, 'Some small text', 'Some new text'
+
+ text_field = TextEditorField.new dashboard_page, "customField#{text_cf.id}"
+ change_cf_value text_field, 'Some long text', 'Some very long text'
- # As the user lacks the manage_public_queries and save_queries permission, no other widget is present
- details_widget = Components::Grids::GridArea.new('.grid--area.-widgeted:nth-of-type(1)')
-
- within(details_widget.area) do
- expect(page)
- .to have_content("#{int_cf.name}\n5")
- expect(page)
- .to have_content("#{bool_cf.name}\nyes")
- expect(page)
- .to have_content("#{version_cf.name}\n#{system_version.name}")
- expect(page)
- .to have_content("#{float_cf.name}\n4.5")
- expect(page)
- .to have_content("#{text_cf.name}\nSome long text")
- expect(page)
- .to have_content("#{string_cf.name}\nSome small text")
- expect(page)
- .to have_content("#{date_cf.name}\n#{Date.today.strftime('%m/%d/%Y')}")
- expect(page)
- .to have_content("#{user_cf.name}\n#{user.name.split.map(&:first).join}#{user.name}")
+ user_field = SelectField.new dashboard_page, "customField#{user_cf.id}"
+ change_cf_value user_field, user.name, second_user.name
end
end
end
diff --git a/spec/features/custom_fields/multi_value_custom_field_spec.rb b/spec/features/custom_fields/multi_value_custom_field_spec.rb
index 42708c88abf..d2afe78f163 100644
--- a/spec/features/custom_fields/multi_value_custom_field_spec.rb
+++ b/spec/features/custom_fields/multi_value_custom_field_spec.rb
@@ -147,7 +147,7 @@ describe "multi select custom values", clear_cache: true, js: true do
# Open split view
split_view = wp_table.open_split_view work_package
- field = MultiSelectField.new(split_view.container, "customField#{custom_field.id}")
+ field = SelectField.new(split_view.container, "customField#{custom_field.id}")
field.activate!
field.unset_value "ham", true
diff --git a/spec/support/edit_fields/multi_select_field.rb b/spec/support/edit_fields/multi_select_field.rb
deleted file mode 100644
index 1cee1584adb..00000000000
--- a/spec/support/edit_fields/multi_select_field.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require_relative './edit_field'
-
-class MultiSelectField < EditField
-
- def multiselect?
- field_container.has_selector?('.inline-edit--toggle-multiselect .icon-minus2')
- end
-
- def expect_save_button(enabled: true)
- if enabled
- expect(field_container).to have_no_selector("#{control_link}[disabled]")
- else
- expect(field_container).to have_selector("#{control_link}[disabled]")
- end
- end
-
- def save!
- submit_by_click
- end
-
- def field_type
- 'create-autocompleter'
- end
-
- def control_link(action = :save)
- raise 'Invalid link' unless [:save, :cancel].include?(action)
- ".inplace-edit--control--#{action}"
- end
-end
diff --git a/spec/support/edit_fields/select_edit_field.rb b/spec/support/edit_fields/select_edit_field.rb
new file mode 100644
index 00000000000..efc00d5676f
--- /dev/null
+++ b/spec/support/edit_fields/select_edit_field.rb
@@ -0,0 +1,12 @@
+require_relative './edit_field'
+
+class SelectField < EditField
+ def expect_value(value)
+ input = context.find(input_selector + ' .ng-value-label')
+ expect(input.text).to eq(value)
+ end
+
+ def field_type
+ 'create-autocompleter'
+ end
+end