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

[#52147] add feature specs for action menu

Tobias Dillmann9c26b601f2a4
diff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rb
index b0bbfa035cb..742d23cca18 100644
--- a/spec/features/projects/projects_index_spec.rb
+++ b/spec/features/projects/projects_index_spec.rb
@@ -1484,4 +1484,123 @@ RSpec.describe "Projects index page", :js, :with_cuprite, with_settings: { login
projects_page.expect_columns("Name", "Created on", "Status")
end
end
+
+ context "when using the action menu", with_settings: { enabled_projects_columns: %w[created_at name project_status] } do
+ before do
+ login_as(admin)
+ visit projects_path
+ end
+
+ describe "moving a column" do
+ it "moves the selected column one place to the left and right" do
+ projects_page.expect_columns_in_order("Created on", "Name", "Status")
+
+ # Move "Name" column to the left
+ projects_page.click_table_header_to_open_action_menu("Name")
+ projects_page.move_column_via_action_menu("Name", direction: :left)
+ wait_for_reload
+
+ # Name was moved left?
+ projects_page.expect_columns_in_order("Name", "Created on", "Status")
+
+ # Now move it back to the right once
+ projects_page.click_table_header_to_open_action_menu("Name")
+ projects_page.move_column_via_action_menu("Name", direction: :right)
+ wait_for_reload
+
+ # Original position should have been restored
+ projects_page.expect_columns_in_order("Created on", "Name", "Status")
+
+ # Looking at the leftmost column
+ projects_page.click_table_header_to_open_action_menu("created_at")
+ projects_page.within("#menu-created_at-overlay") do
+ # It should allow us to move the column right
+ expect(page)
+ .to have_css("a[data-test-selector='created_at-move-col-right']", text: I18n.t(:label_move_column_right))
+
+ # It should not allow us to move the column further left
+ expect(page)
+ .to have_no_css("a[data-test-selector='created_at-move-col-left']", text: I18n.t(:label_move_column_left))
+ end
+
+ # Looking at the rightmost column
+ projects_page.click_table_header_to_open_action_menu("project_status")
+ projects_page.within("#menu-project_status-overlay") do
+ # It should allow us to move the column further left
+ expect(page)
+ .to have_css("a[data-test-selector='project_status-move-col-left']", text: I18n.t(:label_move_column_left))
+
+ # It should not allow us to move the column right
+ expect(page)
+ .to have_no_css("a[data-test-selector='project_status-move-col-right']", text: I18n.t(:label_move_column_right))
+ end
+ end
+ end
+
+ describe "removing a column" do
+ it "removes the column from the table view" do
+ projects_page.expect_columns_in_order("Created on", "Name", "Status")
+
+ # Remove "Name" column
+ projects_page.click_table_header_to_open_action_menu("Name")
+ projects_page.remove_column_via_action_menu("Name")
+ wait_for_reload
+
+ # Name was removed
+ projects_page.expect_columns_in_order("Created on", "Status")
+
+ # Remove "Status" column, too
+ projects_page.click_table_header_to_open_action_menu("project_status")
+ projects_page.remove_column_via_action_menu("project_status")
+ wait_for_reload
+
+ # It was removed
+ projects_page.expect_columns_in_order("Created on")
+ end
+ end
+
+ describe "adding a column" do
+ it "opens the configure view dialog" do
+ projects_page.click_table_header_to_open_action_menu("Name")
+ projects_page.click_add_column_in_action_menu("Name")
+
+ # Configure view dialog was opened
+ expect(page).to have_css("#op-project-list-configure-dialog")
+ end
+ end
+
+ describe "filtering by column",
+ with_settings: { enabled_projects_columns: %w[created_at identifier project_status] } do
+ it "adds the filter for a selected column" do
+ projects_page.click_table_header_to_open_action_menu("created_at")
+ projects_page.expect_filter_option_in_action_menu("created_at")
+ projects_page.filter_by_column_via_action_menu("created_at")
+
+ # Filter component is visible
+ expect(page).to have_select("add_filter_select")
+ # Filter for column is visible and can now be specified by the user
+ expect(page).to have_css(".advanced-filters--filter-name[for='created_at']")
+ end
+
+ it "adds the filter for a selected column that has a different filter mapped to its column" do
+ projects_page.click_table_header_to_open_action_menu("project_status")
+ projects_page.expect_filter_option_in_action_menu("project_status")
+ projects_page.filter_by_column_via_action_menu("project_status")
+
+ # Filter component is visible
+ expect(page).to have_select("add_filter_select")
+ # Filter for column is visible. Note that the filter name is different from the column attribute!
+ expect(page).to have_css(".advanced-filters--filter-name[for='project_status_code']")
+ end
+
+ it "does not offer to filter if the column has no associated filter" do
+ # There is no filter mapping for the identifier column: we should not get the option to filter by it
+ projects_page.click_table_header_to_open_action_menu("identifier")
+ projects_page.expect_no_filter_option_in_action_menu("identifier")
+
+ # Filters have not been activated and are therefore not visible
+ expect(page).to have_no_select("add_filter_select")
+ end
+ end
+ end
end
diff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rb
index 465a71cb249..925a4beef8b 100644
--- a/spec/support/pages/projects/index.rb
+++ b/spec/support/pages/projects/index.rb
@@ -198,6 +198,11 @@ module Pages
end
end
+ def expect_columns_in_order(*column_names)
+ columns = page.find_all("#project-table th .Button-label")
+ expect(column_names.map(&:upcase)).to eq(columns.map { |c| c.text.upcase })
+ end
+
def expect_no_columns(*column_names)
column_names.each do |column_name|
expect(page).to have_no_css("th", text: column_name.upcase)
@@ -482,6 +487,33 @@ module Pages
find(".generic-table--sort-header a[data-test-selector='#{column_name.downcase}-sort-#{direction}']").click
end
+ def move_column_via_action_menu(column_name, direction:)
+ raise ArgumentError, "direction should be :left or :right" unless %i[left right].include?(direction)
+
+ find(".generic-table--sort-header a[data-test-selector='#{column_name.downcase}-move-col-#{direction}']").click
+ end
+
+ def remove_column_via_action_menu(column_name)
+ find(".generic-table--sort-header a[data-test-selector='#{column_name.downcase}-remove-column']").click
+ end
+
+ def click_add_column_in_action_menu(column_name)
+ find(".generic-table--sort-header a[data-test-selector='#{column_name.downcase}-add-column']").click
+ end
+
+ def expect_filter_option_in_action_menu(column_name)
+ expect(page).to have_css("[data-test-selector='#{column_name.downcase}-filter-by']",
+ text: I18n.t(:label_filter_by))
+ end
+
+ def expect_no_filter_option_in_action_menu(column_name)
+ expect(page).to have_no_css("[data-test-selector='#{column_name.downcase}-filter-by']")
+ end
+
+ def filter_by_column_via_action_menu(column_name)
+ page.find("[data-test-selector='#{column_name.downcase}-filter-by']", text: I18n.t(:label_filter_by)).click
+ end
+
def expect_sort_order_via_table_header(column_name, direction:)
raise ArgumentError, "direction should be :asc or :desc" unless %i[asc desc].include?(direction)