Skip to content

Commit

Permalink
[#52147] add feature specs for action menu
Browse files Browse the repository at this point in the history
  • Loading branch information
EinLama committed Oct 16, 2024
1 parent 1891443 commit 0a0df25
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 0 deletions.
119 changes: 119 additions & 0 deletions spec/features/projects/projects_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1484,4 +1484,123 @@ def load_and_open_filters(user)
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
32 changes: 32 additions & 0 deletions spec/support/pages/projects/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ def expect_columns(*column_names)
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)
Expand Down Expand Up @@ -482,6 +487,33 @@ def sort_via_action_menu(column_name, direction:)
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)

Expand Down

0 comments on commit 0a0df25

Please sign in to comment.