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 feature specs for changing project status

Wieland Lindenthal28400781a531
diff --git a/modules/dashboards/spec/features/project_status_spec.rb b/modules/dashboards/spec/features/project_status_spec.rb
index 168c4b53acc..6b293d89b24 100644
--- a/modules/dashboards/spec/features/project_status_spec.rb
+++ b/modules/dashboards/spec/features/project_status_spec.rb
@@ -35,37 +35,118 @@ describe 'Project status widget on dashboard', type: :feature, js: true do
let!(:project_status) do
FactoryBot.create :project_status
end
+
let(:permissions) do
%i[view_dashboards manage_dashboards]
end
+
+ let(:editing_permissions) do
+ %i[view_dashboards
+ manage_dashboards
+ edit_project]
+ end
+
let(:user) do
FactoryBot.create(:user,
member_in_project: project,
member_with_permissions: permissions)
end
- let(:dashboard) do
+ let(:editing_user) do
+ FactoryBot.create(:user,
+ member_in_project: project,
+ member_with_permissions: editing_permissions)
+ end
+
+ let(:dashboard_page) do
Pages::Dashboard.new(project)
end
- before do
- login_as user
+ def add_project_status_widget
+ dashboard_page.visit!
+ dashboard_page.add_widget(1, 1, :within, "Project status")
+
+ sleep(0.1)
+ end
+
+ context 'without editing permissions' do
+ before do
+ login_as user
+ add_project_status_widget
+ end
+
+ it 'can add the widget, but not edit the status' do
+ # As the user lacks the manage_public_queries and save_queries permission, no other widget is present
+ status_widget = Components::Grids::GridArea.new('.grid--area.-widgeted:nth-of-type(1)')
+
+ within(status_widget.area) do
+ # The description is visible
+ expect(page)
+ .to have_content('ON TRACK')
+
+ expect(page)
+ .to have_content(project_status.explanation)
- dashboard.visit!
+ # The status selector does not open
+ field = EditField.new(dashboard_page, 'status')
+ field.activate! expect_open: false
+
+ # The explanation is not editable
+ field = TextEditorField.new(dashboard_page, 'statusExplanation')
+ field.activate! expect_open: false
+ end
+ end
end
- it 'can add the widget and see the status' do
- # within top-right area, add an additional widget
- dashboard.add_widget(1, 1, :within, 'Project status')
+ context 'with editing permissions' do
+ before do
+ login_as editing_user
+ add_project_status_widget
+ end
+
+ it 'can edit the status and its explanation' do
+ # As the user lacks the manage_public_queries and save_queries permission, no other widget is present
+ status_widget = Components::Grids::GridArea.new('.grid--area.-widgeted:nth-of-type(1)')
+
+ within(status_widget.area) do
+ # Open status selector
+ field = ProjectStatusField.new(dashboard_page, 'status')
+ field.activate!
+ sleep(0.1)
+
+ # Change the value
+ field.set_to('AT RISK')
+
+ # The edit field is toggled and the value saved.
+ expect(page).to have_content('AT RISK')
+ expect(page).to have_selector(field.selector)
+ expect(page).not_to have_selector(field.input_selector)
+
+ # Unset the project status
+ field.activate!
+ sleep(0.1)
+ field.set_to('NOT SET')
+
+ # The edit field is toggled and the value saved.
+ expect(page).to have_content('NOT SET')
+ expect(page).to have_selector(field.selector)
+ expect(page).not_to have_selector(field.input_selector)
- status_widget = Components::Grids::GridArea.new('.grid--area.-widgeted:nth-of-type(1)')
+ # Open explanation field
+ field = TextEditorField.new dashboard_page, 'statusExplanation'
+ field.activate!
+ sleep(0.1)
- within status_widget.area do
- expect(page)
- .to have_content project_status.explanation
+ # Change the value
+ field.expect_value(project_status.explanation)
+ field.set_value 'A completely new explanation which is super cool.'
+ field.save!
- expect(page)
- .to have_content 'ON TRACK'
+ # The edit field is toggled and the value saved.
+ expect(page).to have_content('A completely new explanation which is super cool.')
+ expect(page).to have_selector(field.selector)
+ expect(page).not_to have_selector(field.input_selector)
+ end
end
end
end
diff --git a/spec/support/edit_fields/project_status_field.rb b/spec/support/edit_fields/project_status_field.rb
new file mode 100644
index 00000000000..928c83980dd
--- /dev/null
+++ b/spec/support/edit_fields/project_status_field.rb
@@ -0,0 +1,17 @@
+require_relative './edit_field'
+
+class ProjectStatusField < EditField
+ include ::Components::NgSelectAutocompleteHelpers
+
+ def input_selector
+ '.ng-select.project-status'
+ end
+
+ def field_type
+ input_selector
+ end
+
+ def set_to(status_name)
+ page.find('.ng-input input').set("#{status_name}\n")
+ end
+end