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 expectations for sorting behavior in Calendar Index Pages

Aaron Contreras1446cfc44807
diff --git a/modules/calendar/spec/features/calendars_index_spec.rb b/modules/calendar/spec/features/calendars_index_spec.rb
index 851e4b7767c..cbb62ceed56 100644
--- a/modules/calendar/spec/features/calendars_index_spec.rb
+++ b/modules/calendar/spec/features/calendars_index_spec.rb
@@ -30,12 +30,15 @@ require 'spec_helper'
require_relative '../support/pages/calendar'
RSpec.describe 'Calendars', 'index', :js, :with_cuprite do
+ # The order the Projects are created in is important. By naming `project` alphanumerically
+ # after `other_project`, we can ensure that subsequent specs that assert sorting is
+ # correct for the right reasons (sorting by Project name and not id)
shared_let(:project) do
- create(:project, enabled_module_names: %w[work_package_tracking calendar_view])
+ create(:project, name: 'Project 2', enabled_module_names: %w[work_package_tracking calendar_view])
end
shared_let(:other_project) do
- create(:project, enabled_module_names: %w[work_package_tracking calendar_view])
+ create(:project, name: 'Project 1', enabled_module_names: %w[work_package_tracking calendar_view])
end
shared_let(:user) do
@@ -135,6 +138,43 @@ RSpec.describe 'Calendars', 'index', :js, :with_cuprite do
calendars_page.expect_no_delete_button(q)
end
end
+
+ describe 'sorting' do
+ before do
+ # Name ASC is the default sort order for Calendars
+ # We can assert the initial sort by expecting the order is
+ # 1. `query`
+ # 2. `other_query`
+ # upon page load
+ calendars_page.expect_views_listed_in_order(query, other_query)
+ end
+
+ it 'allows sorting by "Name", "Project" and "Created On"' do
+ aggregate_failures 'Sorting by Name' do
+ calendars_page.click_to_sort_by('Name')
+ calendars_page.expect_views_listed_in_order(other_query,
+ query)
+ end
+
+ aggregate_failures 'Sorting by Project' do
+ calendars_page.click_to_sort_by('Project')
+ calendars_page.expect_views_listed_in_order(other_query,
+ query)
+ calendars_page.click_to_sort_by('Project')
+ calendars_page.expect_views_listed_in_order(query,
+ other_query)
+ end
+
+ aggregate_failures 'Sorting by Created On' do
+ calendars_page.click_to_sort_by('Created on')
+ calendars_page.expect_views_listed_in_order(query,
+ other_query)
+ calendars_page.click_to_sort_by('Created on')
+ calendars_page.expect_views_listed_in_order(other_query,
+ query)
+ end
+ end
+ end
end
context 'with another user with limited access' do
diff --git a/modules/calendar/spec/support/pages/calendar.rb b/modules/calendar/spec/support/pages/calendar.rb
index ddf5dd75e55..f52501f1066 100644
--- a/modules/calendar/spec/support/pages/calendar.rb
+++ b/modules/calendar/spec/support/pages/calendar.rb
@@ -174,5 +174,19 @@ module Pages
def expect_view_not_visible(query)
expect(page).not_to have_selector 'td', text: query.name
end
+
+ def click_to_sort_by(header_name)
+ within '.generic-table thead' do
+ click_link header_name
+ end
+ end
+
+ def expect_views_listed_in_order(*queries)
+ within '.generic-table tbody' do
+ listed_view_names = all('tr td.name').map(&:text)
+
+ expect(listed_view_names).to eq(queries.map(&:name))
+ end
+ end
end
end