Skip to content

Commit

Permalink
Feature: Automatically skip steps with missing attachTo elements, res…
Browse files Browse the repository at this point in the history
…olves #6
  • Loading branch information
Jonathan Abbett committed Jan 5, 2017
1 parent eac8e10 commit 5aba347
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ capybara-*.html
.rspec
/log
/tmp
/test/dummy/log
/test/dummy/tmp
/db/*.sqlite3
/db/*.sqlite3-journal
/test/dummy/db/*.sqlite3
/test/dummy/db/*.sqlite3-journal
/public/system
/coverage/
/spec/tmp
Expand Down
4 changes: 4 additions & 0 deletions app/views/application/_abraham.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
text: "<%= step['text'] %>",
<% if step.key?('attachTo') %>
attachTo: { element: "<%= step['attachTo']['element'] %>", on: "<%= step['attachTo']['placement'] %>" },
showOn: function() {
// Only display this step if its selector is present
return document.querySelector("<%= step['attachTo']['element'] %>") ? true : false
},
<% end %>
buttons: [
<% if index == 0 %>
Expand Down
2 changes: 1 addition & 1 deletion lib/abraham/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module Abraham
VERSION = '1.1.1'
VERSION = '1.2'
end
6 changes: 6 additions & 0 deletions test/dummy/config/tours/dashboard/home.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ intro:
title: "ENGLISH This step has a title"
text: "ENGLISH This intermediate step has some text"
3:
title: "ENGLISH A missing step"
text: "ENGLISH Refers to an element that won't exist on the page, should skip to 4"
attachTo:
element: "#i-dont-exist"
position: "right"
4:
title: "ENGLISH The final step"
text: "ENGLISH Some text here too, and it's attached to the right"
attachTo:
Expand Down
6 changes: 6 additions & 0 deletions test/dummy/config/tours/dashboard/home.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ intro:
title: "SPANISH This step has a title"
text: "This intermediate step has some text"
3:
title: "SPANISH A missing step"
text: "Refers to an element that won't exist on the page, should skip to 4"
attachTo:
element: "#i-dont-exist"
position: "right"
4:
title: "SPANISH The final step"
text: "Some text here too, and it's attached to the right"
attachTo:
Expand Down
Binary file removed test/dummy/db/development.sqlite3
Binary file not shown.
Binary file removed test/dummy/db/test.sqlite3
Binary file not shown.
3 changes: 3 additions & 0 deletions test/dummy/test/controllers/dashboard_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class DashboardControllerTest < ActionDispatch::IntegrationTest
assert element.text.include? 'step-1'
assert element.text.include? 'step-2'
assert element.text.include? 'step-3'
assert element.text.include? 'step-4'
# Generates a showOn option
assert element.text.include? 'showOn:'
# it will post the right completion information
assert element.text.include? "controller_name: 'dashboard'"
assert element.text.include? "action_name: 'home'"
Expand Down

0 comments on commit 5aba347

Please sign in to comment.