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

Update specs

Dombi Attila71bf959b237f
diff --git a/app/components/projects/index_sub_header_component.html.erb b/app/components/projects/index_sub_header_component.html.erb
index 788b67468f5..39e73f1f697 100644
--- a/app/components/projects/index_sub_header_component.html.erb
+++ b/app/components/projects/index_sub_header_component.html.erb
@@ -4,16 +4,16 @@
'filter--filters-form-perform-turbo-requests-value': true,
"application-target": "dynamic",
})) do |subheader|
- subheader.with_filter_input(name: "name-and-identifier",
- label: t('projects.index.search.label'),
- value: filter_input_value,
- placeholder: t('projects.index.search.placeholder'),
- leading_visual: {
- icon: :search,
- size: :small
- },
- show_clear_button: true,
- data: filter_input_data_attributes)
+ subheader.with_filter_input(name: "name_and_identifier",
+ label: t('projects.index.search.label'),
+ value: filter_input_value,
+ placeholder: t('projects.index.search.placeholder'),
+ leading_visual: {
+ icon: :search,
+ size: :small
+ },
+ show_clear_button: true,
+ data: filter_input_data_attributes)
subheader.with_filter_component do
render(Filter::FilterButtonComponent.new(query: @query, disabled: @disable_buttons))
diff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rb
index e239dd9562d..bc36edf58fb 100644
--- a/spec/features/projects/projects_index_spec.rb
+++ b/spec/features/projects/projects_index_spec.rb
@@ -39,7 +39,7 @@ RSpec.describe "Projects index page", :js, :with_cuprite, with_settings: { login
shared_let(:project) { create(:project, name: "Plain project", identifier: "plain-project") }
shared_let(:public_project) do
- create(:project, name: "Public project", identifier: "public-project", public: true) do |project|
+ create(:project, name: "Public Pr", identifier: "public-pr", public: true) do |project|
project.custom_field_values = { invisible_custom_field.id => "Secret CF" }
end
end
@@ -280,51 +280,51 @@ RSpec.describe "Projects index page", :js, :with_cuprite, with_settings: { login
expect(error_container["innerHTML"]).to include error_html
end
end
- end
- describe "project attributes visibility restrictions" do
- let(:user) do
- create(:user,
- member_with_roles: {
- development_project => create(:existing_project_role, permissions:),
- project => create(:existing_project_role)
- })
- end
+ context "for project attributes", with_ee: %i[custom_fields_in_projects_list] do
+ let(:user) do
+ create(:user,
+ member_with_roles: {
+ development_project => create(:existing_project_role, permissions:),
+ project => create(:existing_project_role)
+ })
+ end
- let!(:list_custom_field) do
- create(:list_project_custom_field, multi_value: true).tap do |cf|
- development_project.update(custom_field_values: { cf.id => [cf.value_of("A"), cf.value_of("B")] })
- project.update(custom_field_values: { cf.id => [cf.value_of("A"), cf.value_of("B")] })
+ let!(:list_custom_field) do
+ create(:list_project_custom_field, multi_value: true).tap do |cf|
+ development_project.update(custom_field_values: { cf.id => [cf.value_of("A"), cf.value_of("B")] })
+ project.update(custom_field_values: { cf.id => [cf.value_of("A"), cf.value_of("B")] })
+ end
end
- end
- before do
- login_as(user)
- projects_page.visit!
- end
+ before do
+ login_as(user)
+ projects_page.visit!
+ end
- context "with view_project_attributes permission" do
- let(:permissions) { %i(view_project_attributes) }
+ context "with view_project_attributes permission" do
+ let(:permissions) { %i(view_project_attributes) }
- it "can see the project attribute field value in the project list" do
- projects_page.set_columns(list_custom_field.name)
- projects_page.expect_columns(list_custom_field.name)
+ it "can see the project attribute field value in the project list" do
+ projects_page.set_columns(list_custom_field.name)
+ projects_page.expect_columns(list_custom_field.name)
- projects_page.within_row(development_project) do
- expect(page).to have_css("td.#{list_custom_field.column_name}", text: "A, B")
- end
+ projects_page.within_row(development_project) do
+ expect(page).to have_css("td.#{list_custom_field.column_name}", text: "A, B")
+ end
- projects_page.within_row(project) do
- expect(page).to have_css("td.#{list_custom_field.column_name}", text: "")
+ projects_page.within_row(project) do
+ expect(page).to have_css("td.#{list_custom_field.column_name}", text: "")
+ end
end
end
- end
- context "without view_project_attributes permission" do
- let(:permissions) { [] }
+ context "without view_project_attributes permission" do
+ let(:permissions) { [] }
- it "cannot see the project attribute field in the table configuration" do
- projects_page.expect_no_config_columns(list_custom_field.name)
+ it "cannot see the project attribute field in the table configuration" do
+ projects_page.expect_no_config_columns(list_custom_field.name)
+ end
end
end
end
@@ -399,16 +399,13 @@ RSpec.describe "Projects index page", :js, :with_cuprite, with_settings: { login
it "only shows the matching projects and filters" do
load_and_open_filters admin
- projects_page.set_filter("name_and_identifier",
- "Name or identifier",
- "contains",
- ["Plain"])
+ projects_page.filter_by_name_and_identifier("Plain")
# Filter is applied: Only the project that contains the the word "Plain" gets listed
projects_page.expect_projects_listed(project)
projects_page.expect_projects_not_listed(public_project)
# Filter form is visible and the filter is still set.
- expect(page).to have_css('li[filter-name="name_and_identifier"]')
+ expect(page).to have_field("name_and_identifier", with: "Plain")
end
end
@@ -420,10 +417,7 @@ RSpec.describe "Projects index page", :js, :with_cuprite, with_settings: { login
it "keeps applied filters, orders and columns" do
load_and_open_filters admin
- projects_page.set_filter("name_and_identifier",
- "Name or identifier",
- "doesn't contain",
- ["Plain"])
+ projects_page.filter_by_name_and_identifier("project")
wait_for_reload
@@ -439,8 +433,8 @@ RSpec.describe "Projects index page", :js, :with_cuprite, with_settings: { login
# Results should be filtered and ordered ASC by name and only the selected columns should be present
projects_page.expect_projects_listed(development_project)
- projects_page.expect_projects_not_listed(project, # as it is filtered out
- public_project) # as it is on the second page
+ projects_page.expect_projects_not_listed(public_project, # as it is filtered out
+ project) # as it is on the second page
projects_page.expect_columns("Name")
projects_page.expect_no_columns("Status")
expect(page).to have_text("Next") # as the result set is larger than 1
@@ -459,8 +453,8 @@ RSpec.describe "Projects index page", :js, :with_cuprite, with_settings: { login
projects_page.expect_current_page_number(2)
# On page 2 you should see the second page of the filtered set ordered ASC by name and only the selected columns exist
- projects_page.expect_projects_listed(public_project)
- projects_page.expect_projects_not_listed(project, # Filtered out
+ projects_page.expect_projects_listed(project)
+ projects_page.expect_projects_not_listed(public_project, # Filtered out
development_project) # Present on page 1
projects_page.expect_columns("Name")
projects_page.expect_no_columns("Status")
@@ -475,8 +469,8 @@ RSpec.describe "Projects index page", :js, :with_cuprite, with_settings: { login
projects_page.expect_current_page_number(1)
# The same filters should still be intact but the order should be DESC on name
- projects_page.expect_projects_listed(public_project)
- projects_page.expect_projects_not_listed(project, # Filtered out
+ projects_page.expect_projects_listed(project)
+ projects_page.expect_projects_not_listed(public_project, # Filtered out
development_project) # Present on page 2
projects_page.expect_total_pages(2) # Filters kept active, so there is no third page.
@@ -490,9 +484,9 @@ RSpec.describe "Projects index page", :js, :with_cuprite, with_settings: { login
# We should see page 1, resetting pagination, as it is a new filter, but keeping the DESC order on the project
# name
- projects_page.expect_projects_listed(public_project)
+ projects_page.expect_projects_listed(project)
projects_page.expect_projects_not_listed(development_project, # as it is on the second page
- project) # as it filtered out
+ public_project) # as it filtered out
projects_page.expect_total_pages(2) # as the result set is larger than 1
projects_page.expect_columns("Name")
projects_page.expect_no_columns("Status")
@@ -504,22 +498,17 @@ RSpec.describe "Projects index page", :js, :with_cuprite, with_settings: { login
load_and_open_filters admin
# Filter on model attribute 'name'
- projects_page.set_filter("name_and_identifier",
- "Name or identifier",
- "doesn't contain",
- ["Plain"])
+ projects_page.filter_by_name_and_identifier("Plain")
wait_for_reload
- projects_page.expect_projects_listed(development_project, public_project)
- projects_page.expect_projects_not_listed(project)
+ projects_page.expect_projects_listed(project)
+ projects_page.expect_projects_not_listed(development_project, public_project)
- # Filter on model attribute 'identifier'
projects_page.remove_filter("name_and_identifier")
+ projects_page.expect_projects_listed(project, development_project, public_project)
- projects_page.set_filter("name_and_identifier",
- "Name or identifier",
- "is",
- ["plain-project"])
+ # Filter on model attribute 'identifier'
+ projects_page.filter_by_name_and_identifier("plain-project")
wait_for_reload
projects_page.expect_projects_listed(project)
diff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rb
index 90cfa148635..b38aede0718 100644
--- a/spec/support/pages/projects/index.rb
+++ b/spec/support/pages/projects/index.rb
@@ -136,7 +136,11 @@ module Pages
end
def expect_filter_set(filter_name)
- expect(page).to have_css("li[data-filter-name='#{filter_name}']:not(.hidden)", visible: :hidden)
+ if filter_name == "name_and_identifier"
+ expect(page.find_by_id(filter_name).value).not_to be_empty
+ else
+ expect(page).to have_css("li[data-filter-name='#{filter_name}']:not(.hidden)", visible: :hidden)
+ end
end
def expect_filter_count(count)
@@ -203,18 +207,23 @@ module Pages
wait_for_reload
end
+ def filter_by_name_and_identifier(value)
+ set_name_and_identifier_filter([value])
+ wait_for_reload
+ end
+
def set_filter(name, human_name, human_operator = nil, values = [])
+ return unless values.any?
+
+ return set_name_and_identifier_filter(values) if name == "name_and_identifier"
+
select human_name, from: "add_filter_select"
selected_filter = page.find("li[data-filter-name='#{name}']")
select(human_operator, from: "operator") unless boolean_filter?(name)
within(selected_filter) do
- return unless values.any?
-
- if name == "name_and_identifier"
- set_name_and_identifier_filter(values)
- elsif boolean_filter?(name)
+ if boolean_filter?(name)
set_toggle_filter(values)
elsif name == "created_at"
select(human_operator, from: "operator")
@@ -227,7 +236,11 @@ module Pages
end
def remove_filter(name)
- page.find("li[data-filter-name='#{name}'] .filter_rem").click
+ if name == "name_and_identifier"
+ page.find_by_id(name).set("")
+ else
+ page.find("li[data-filter-name='#{name}'] .filter_rem").click
+ end
end
def set_toggle_filter(values)
@@ -246,7 +259,7 @@ module Pages
end
def set_name_and_identifier_filter(values)
- fill_in "value", with: values.first
+ fill_in "name_and_identifier", with: values.first
end
def set_created_at_filter(human_operator, values)