Commit 5c882acd05b914f2af75bcf78856d50a91773c2c
1 parent
d75dc8ae
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
site_tour: fix step sequence for groups
Showing
2 changed files
with
40 additions
and
7 deletions
Show diff stats
plugins/site_tour/test/unit/site_tour_plugin_test.rb
| @@ -38,4 +38,36 @@ class SiteTourPluginTest < ActionView::TestCase | @@ -38,4 +38,36 @@ class SiteTourPluginTest < ActionView::TestCase | ||
| 38 | assert_no_tag_in_string instance_exec(&plugin.body_ending), :tag => "script" | 38 | assert_no_tag_in_string instance_exec(&plugin.body_ending), :tag => "script" |
| 39 | end | 39 | end |
| 40 | 40 | ||
| 41 | + should 'render javascript tag with tooltip actions and group triggers' do | ||
| 42 | + expects(:language).returns('en').at_least_once | ||
| 43 | + | ||
| 44 | + settings = Noosfero::Plugin::Settings.new(Environment.default, SiteTourPlugin) | ||
| 45 | + settings.actions = [{:language => 'en', :group_name => 'test', :selector => 'body', :description => 'Test'}] | ||
| 46 | + settings.group_triggers = [{:group_name => 'test', :selector => 'body', :event => 'click'}] | ||
| 47 | + settings.save! | ||
| 48 | + | ||
| 49 | + expects(:environment).returns(Environment.default) | ||
| 50 | + body_ending = instance_exec(&plugin.body_ending) | ||
| 51 | + assert_match /siteTourPlugin\.add\('test', 'body', 'Test', 1\);/, body_ending | ||
| 52 | + assert_match /siteTourPlugin\.addGroupTrigger\('test', 'body', 'click'\);/, body_ending | ||
| 53 | + end | ||
| 54 | + | ||
| 55 | + should 'start each tooltip group with the correct step order' do | ||
| 56 | + expects(:language).returns('en').at_least_once | ||
| 57 | + | ||
| 58 | + settings = Noosfero::Plugin::Settings.new(Environment.default, SiteTourPlugin) | ||
| 59 | + settings.actions = [ | ||
| 60 | + {:language => 'en', :group_name => 'test_a', :selector => 'body', :description => 'Test A1'}, | ||
| 61 | + {:language => 'en', :group_name => 'test_a', :selector => 'body', :description => 'Test A2'}, | ||
| 62 | + {:language => 'en', :group_name => 'test_b', :selector => 'body', :description => 'Test B1'}, | ||
| 63 | + ] | ||
| 64 | + settings.save! | ||
| 65 | + | ||
| 66 | + expects(:environment).returns(Environment.default) | ||
| 67 | + body_ending = instance_exec(&plugin.body_ending) | ||
| 68 | + assert_match /siteTourPlugin\.add\('test_a', 'body', 'Test A1', 1\);/, body_ending | ||
| 69 | + assert_match /siteTourPlugin\.add\('test_a', 'body', 'Test A2', 2\);/, body_ending | ||
| 70 | + assert_match /siteTourPlugin\.add\('test_b', 'body', 'Test B1', 1\);/, body_ending | ||
| 71 | + end | ||
| 72 | + | ||
| 41 | end | 73 | end |
plugins/site_tour/views/tour_actions.html.erb
| @@ -4,14 +4,15 @@ | @@ -4,14 +4,15 @@ | ||
| 4 | <% if actions.present? %> | 4 | <% if actions.present? %> |
| 5 | <script> | 5 | <script> |
| 6 | jQuery( document ).ready(function( $ ) { | 6 | jQuery( document ).ready(function( $ ) { |
| 7 | - <% actions.each_with_index do |action, index| %> | ||
| 8 | - <%= "siteTourPlugin.add('#{j action[:group_name]}', '#{j action[:selector]}', '#{j action[:description]}', #{index + 1});" %> | ||
| 9 | - <% end %> | ||
| 10 | - | ||
| 11 | - <% (group_triggers||[]).each_with_index do |group, index| %> | ||
| 12 | - <%= "siteTourPlugin.addGroupTrigger('#{j group[:group_name]}', '#{j group[:selector]}', '#{j group[:event]}');" %> | ||
| 13 | - <% end %> | 7 | + <% actions.group_by {|h| h[:group_name]}.each do |group, group_actions| %> |
| 8 | + <% group_actions.each_with_index do |action, index| %> | ||
| 9 | + <%= "siteTourPlugin.add('#{j action[:group_name]}', '#{j action[:selector]}', '#{j action[:description]}', #{index + 1});" %> | ||
| 10 | + <% end %> | ||
| 11 | + <% end %> | ||
| 14 | 12 | ||
| 13 | + <% (group_triggers||[]).each_with_index do |group, index| %> | ||
| 14 | + <%= "siteTourPlugin.addGroupTrigger('#{j group[:group_name]}', '#{j group[:selector]}', '#{j group[:event]}');" %> | ||
| 15 | + <% end %> | ||
| 15 | }); | 16 | }); |
| 16 | </script> | 17 | </script> |
| 17 | <% end %> | 18 | <% end %> |