From c3d752af1ed040f64cd7cbfb964c2c5d5d8f7cde Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 8 Jun 2017 11:36:03 +0200 Subject: Add in-progress `TableBuilderHelper` (WIP) Porting `table_builder` code over from `NewapplicationHelper`. The code is very much in progress and incomplete. Only decided to commit it now because I keep making changes and want to have those tracked so I don't lose anything. A lot of the original is commented out and the initial test I wrote doesn't pass. The test also doesn't use the proper data, I just copied it from the website's output. Anyway, this is sort of the starting point. Refs #3479 --- spec/helpers/table_builder_helper_spec.rb | 120 ++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 spec/helpers/table_builder_helper_spec.rb (limited to 'spec') diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb new file mode 100644 index 000000000..e9d1afed3 --- /dev/null +++ b/spec/helpers/table_builder_helper_spec.rb @@ -0,0 +1,120 @@ +require 'spec_helper' + +describe TableBuilderHelper, type: :helper do + describe "#table_builder_2" do + it "builds a table" do + workbenches = [ + build_stubbed(:referential) + ] + + expected = <<-HTML + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + HTML +#
+# 0 élément(s) sélectionné(s) +#
+ + minified_expected = expected.gsub(/^\s+/, '').gsub("\n", '') + + expect(helper.table_builder_2( + workbenches, + { :name => 'name', + :status => Proc.new {|w| w.archived? ? ("
Conservé
").html_safe : ("
En préparation
").html_safe}, + :status => Proc.new {|w| ("
En préparation
").html_safe}, + :organisation => Proc.new {|w| w.organisation.name}, + :validity_period => Proc.new {|w| w.validity_period.nil? ? '-' : t('validity_range', debut: l(w.try(:validity_period).try(:begin), format: :short), end: l(w.try(:validity_period).try(:end), format: :short))}, + :lines => Proc.new {|w| w.lines.count}, + :created_at => Proc.new {|w| l(w.created_at, format: :short)}, + :updated_at => Proc.new {|w| l(w.updated_at, format: :short)}, + :published_at => ''}, + links: [:show, :edit, :archive, :unarchive, :delete], + cls: 'table has-filter has-search' + )).to eq(minified_expected) + end + end +end + + +# Replace table builder on workspaces#show page +# Make the builder work without a `current_referential` so we can actually test it +# Make a way to define a column as non-sortable. By default, columns will be sortable. Unless sortable==false and no columns should be sortable. +# +# +# TODO: +# - Finish writing workbench test +# - Port some code over to the new table builder +# - Ask Jean-Paul if there's anything he wishes could be changed or improved about the existing table builder +# - Thing that Jean-Paul didn't like was the link generation -- cgit v1.2.3