diff options
| author | Teddy Wing | 2017-06-08 11:36:03 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-06-08 11:36:03 +0200 |
| commit | c3d752af1ed040f64cd7cbfb964c2c5d5d8f7cde (patch) | |
| tree | 4f1b2fda6aa3d0195cbef9935b095ef4434b1468 /spec | |
| parent | 212d1f740b17ae89b69603a3f1964351a38b86f6 (diff) | |
| download | chouette-core-c3d752af1ed040f64cd7cbfb964c2c5d5d8f7cde.tar.bz2 | |
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
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/helpers/table_builder_helper_spec.rb | 120 |
1 files changed, 120 insertions, 0 deletions
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 +<table class="table has-filter has-search"> + <thead> + <tr> + <th> + <div class="checkbox"><input type="checkbox" name="0" id="0" value="all" /><label for="0"></label></div> + </th> + <th><a href="/workbenches/1?direction=desc&q%5Barchived_at_not_null%5D=1&q%5Barchived_at_null%5D=1&sort=name">Nom<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/workbenches/1?direction=desc&q%5Barchived_at_not_null%5D=1&q%5Barchived_at_null%5D=1&sort=status">Etat<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/workbenches/1?direction=desc&q%5Barchived_at_not_null%5D=1&q%5Barchived_at_null%5D=1&sort=organisation">Organisation<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/workbenches/1?direction=desc&q%5Barchived_at_not_null%5D=1&q%5Barchived_at_null%5D=1&sort=validity_period">Période de validité englobante<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/workbenches/1?direction=desc&q%5Barchived_at_not_null%5D=1&q%5Barchived_at_null%5D=1&sort=lines">Lignes<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/workbenches/1?direction=desc&q%5Barchived_at_not_null%5D=1&q%5Barchived_at_null%5D=1&sort=created_at">Créé le<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/workbenches/1?direction=desc&q%5Barchived_at_not_null%5D=1&q%5Barchived_at_null%5D=1&sort=updated_at">Edité le<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th><a href="/workbenches/1?direction=desc&q%5Barchived_at_not_null%5D=1&q%5Barchived_at_null%5D=1&sort=published_at">Intégré le<span class="orderers"><span class="fa fa-sort-asc active"></span><span class="fa fa-sort-desc "></span></span></a></th> + <th></th> + </tr> + </thead> + <tbody> + <tr> + <td> + <div class="checkbox"><input type="checkbox" name="4" id="4" value="4" /><label for="4"></label></div> + </td> + <td title="Voir"><a href="/referentials/4">Referential Yanis Gaillard</a></td> + <td> + <div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>En préparation</span></div> + </td> + <td>STIF</td> + <td>01/05/2017 > 31/08/2017</td> + <td>1</td> + <td>02/05/2017</td> + <td>02/05/2017</td> + <td></td> + <td class="actions"> + <div class="btn-group"> + <div class="btn dropdown-toggle" data-toggle="dropdown"><span class="fa fa-cog"></span></div> + <ul class="dropdown-menu"> + <li><a href="/referentials/4">Consulter</a></li> + <li><a href="/referentials/4/edit">Editer</a></li> + <li><a rel="nofollow" data-method="put" href="/referentials/4/archive">Conserver</a></li> + <li class="delete-action"><a data-confirm="Etes-vous sûr(e) de vouloir effectuer cette action ?" rel="nofollow" data-method="delete" href="/referentials/4"><span class="fa fa-trash"></span>Supprimer</a></li> + </ul> + </div> + </td> + </tr> + <tr> + <td> + <div class="checkbox"><input type="checkbox" name="3" id="3" value="3" /><label for="3"></label></div> + </td> + <td title="Voir"><a href="/referentials/3">Test Referential 2017.04.25</a></td> + <td> + <div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>En préparation</span></div> + </td> + <td>STIF</td> + <td>25/04/2017 > 25/05/2022</td> + <td>6</td> + <td>25/04/2017</td> + <td>25/04/2017</td> + <td></td> + <td class="actions"> + <div class="btn-group"> + <div class="btn dropdown-toggle" data-toggle="dropdown"><span class="fa fa-cog"></span></div> + <ul class="dropdown-menu"> + <li><a href="/referentials/3">Consulter</a></li> + <li><a href="/referentials/3/edit">Editer</a></li> + <li><a rel="nofollow" data-method="put" href="/referentials/3/archive">Conserver</a></li> + <li class="delete-action"><a data-confirm="Etes-vous sûr(e) de vouloir effectuer cette action ?" rel="nofollow" data-method="delete" href="/referentials/3"><span class="fa fa-trash"></span>Supprimer</a></li> + </ul> + </div> + </td> + </tr> + </tbody> +</table> + HTML +# <div class="select_toolbox noselect"> +# <ul> +# <li class="st_action"><a data-path="/workbenches/1/referentials" data-confirm="Etes-vous sûr(e) de vouloir effectuer cette action ?" title="Supprimer" rel="nofollow" data-method="delete" href="#"><span class="fa fa-trash"></span></a></li> +# </ul><span class="info-msg"><span>0</span> élément(s) sélectionné(s)</span> +# </div> + + minified_expected = expected.gsub(/^\s+/, '').gsub("\n", '') + + expect(helper.table_builder_2( + workbenches, + { :name => 'name', + :status => Proc.new {|w| w.archived? ? ("<div class='td-block'><span class='fa fa-archive'></span><span>Conservé</span></div>").html_safe : ("<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>En préparation</span></div>").html_safe}, + :status => Proc.new {|w| ("<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>En préparation</span></div>").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 |
