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

Make `match_table` work regardless of the order of the work packages

Christophe Bliarda89cfa43211e
diff --git a/spec/support/table_helpers.rb b/spec/support/table_helpers.rb
index e4597d06e14..7819e5c8fa0 100644
--- a/spec/support/table_helpers.rb
+++ b/spec/support/table_helpers.rb
@@ -36,6 +36,7 @@ RSpec.configure do |config|
match do |actual_work_packages|
expected_data = TableHelpers::TableData.for(expected)
actual_data = TableHelpers::TableData.from_work_packages(actual_work_packages, expected_data.columns)
+ actual_data.order_like!(expected_data)
representer = TableHelpers::TableRepresenter.new(tables_data: [expected_data, actual_data],
columns: expected_data.columns)
diff --git a/spec/support/table_helpers/table_data.rb b/spec/support/table_helpers/table_data.rb
index 0659f89280f..59186d3463a 100644
--- a/spec/support/table_helpers/table_data.rb
+++ b/spec/support/table_helpers/table_data.rb
@@ -83,6 +83,15 @@ module TableHelpers
Table.new(work_packages_by_identifier)
end
+ def order_like!(other_table)
+ ordered_identifiers = other_table.work_package_identifiers
+ extra_identifiers = work_package_identifiers - ordered_identifiers
+ @work_packages_data = work_packages_data
+ .index_by { _1[:identifier] }
+ .values_at(*(ordered_identifiers + extra_identifiers))
+ .compact
+ end
+
class Factory
attr_reader :table_data, :work_packages_by_identifier
diff --git a/spec/support_spec/table_helpers/table_data_spec.rb b/spec/support_spec/table_helpers/table_data_spec.rb
index 0fbecea1677..f6ffe858194 100644
--- a/spec/support_spec/table_helpers/table_data_spec.rb
+++ b/spec/support_spec/table_helpers/table_data_spec.rb
@@ -145,5 +145,69 @@ module TableHelpers
.not_to raise_error
end
end
+
+ describe "#order_like" do
+ it "orders the table data like the given table" do
+ table_representation = <<~TABLE
+ | subject | remaining work |
+ | work package | 3h |
+ | another one | |
+ TABLE
+ table_data = described_class.for(table_representation)
+
+ other_table_representation = <<~TABLE
+ | subject | remaining work |
+ | another one | |
+ | work package | 3h |
+ TABLE
+ other_table_data = described_class.for(other_table_representation)
+ expect(table_data.work_package_identifiers).to eq(%i[work_package another_one])
+
+ table_data.order_like!(other_table_data)
+ expect(table_data.work_package_identifiers).to eq(%i[another_one work_package])
+ end
+
+ it "ignores unknown rows from the given table" do
+ table_representation = <<~TABLE
+ | subject | remaining work |
+ | work package | 3h |
+ | another one | |
+ TABLE
+ table_data = described_class.for(table_representation)
+
+ other_table_representation = <<~TABLE
+ | subject | remaining work |
+ | another one | |
+ | work package | 3h |
+ | unknown one | |
+ TABLE
+ other_table_data = described_class.for(other_table_representation)
+ expect(table_data.work_package_identifiers).to eq(%i[work_package another_one])
+
+ table_data.order_like!(other_table_data)
+ expect(table_data.work_package_identifiers).to eq(%i[another_one work_package])
+ end
+
+ it "appends to the bottom the rows missing in the given table" do
+ table_representation = <<~TABLE
+ | subject | remaining work |
+ | work package | 3h |
+ | extra one | |
+ | another one | |
+ TABLE
+ table_data = described_class.for(table_representation)
+
+ other_table_representation = <<~TABLE
+ | subject | remaining work |
+ | another one | |
+ | work package | 3h |
+ TABLE
+ other_table_data = described_class.for(other_table_representation)
+ expect(table_data.work_package_identifiers).to eq(%i[work_package extra_one another_one])
+
+ table_data.order_like!(other_table_data)
+ expect(table_data.work_package_identifiers).to eq(%i[another_one work_package extra_one])
+ end
+ end
end
end