From 5aba3471fea4ab86bae1f270edeb49e53b085e9a Mon Sep 17 00:00:00 2001 From: Jonathan Abbett Date: Thu, 5 Jan 2017 13:43:48 -0500 Subject: [PATCH] Feature: Automatically skip steps with missing attachTo elements, resolves #6 --- .gitignore | 4 ++++ app/views/application/_abraham.html.erb | 4 ++++ lib/abraham/version.rb | 2 +- test/dummy/config/tours/dashboard/home.en.yml | 6 ++++++ test/dummy/config/tours/dashboard/home.es.yml | 6 ++++++ test/dummy/db/development.sqlite3 | Bin 40960 -> 0 bytes test/dummy/db/test.sqlite3 | Bin 40960 -> 0 bytes .../controllers/dashboard_controller_test.rb | 3 +++ 8 files changed, 24 insertions(+), 1 deletion(-) delete mode 100644 test/dummy/db/development.sqlite3 delete mode 100644 test/dummy/db/test.sqlite3 diff --git a/.gitignore b/.gitignore index 6cbbd99..5e2f246 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/app/views/application/_abraham.html.erb b/app/views/application/_abraham.html.erb index 9b34c20..dea6365 100644 --- a/app/views/application/_abraham.html.erb +++ b/app/views/application/_abraham.html.erb @@ -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 %> diff --git a/lib/abraham/version.rb b/lib/abraham/version.rb index c05f56d..a5c6429 100644 --- a/lib/abraham/version.rb +++ b/lib/abraham/version.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true module Abraham - VERSION = '1.1.1' + VERSION = '1.2' end diff --git a/test/dummy/config/tours/dashboard/home.en.yml b/test/dummy/config/tours/dashboard/home.en.yml index 34c8cfc..0de045a 100644 --- a/test/dummy/config/tours/dashboard/home.en.yml +++ b/test/dummy/config/tours/dashboard/home.en.yml @@ -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: diff --git a/test/dummy/config/tours/dashboard/home.es.yml b/test/dummy/config/tours/dashboard/home.es.yml index ff645c0..7077862 100644 --- a/test/dummy/config/tours/dashboard/home.es.yml +++ b/test/dummy/config/tours/dashboard/home.es.yml @@ -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: diff --git a/test/dummy/db/development.sqlite3 b/test/dummy/db/development.sqlite3 deleted file mode 100644 index 2b24f4f03e066049f6035b27d2f23cbd201ec613..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 40960 zcmeI*&2QUe90zc}Bu>+Ic_ySOr!p%QV$qf~j}zzZG7LmjMVG$N3aT9}FL|~Yl6Z66 zY6x-YChq$qxNw0p9Jp}eUzj*?fFW^#0|&-|$4OrtJ1HI7fo5MTah>O}fB8KhKd$uD zFMWS&-S(Jz*KvE6rxu0Ff+z}asj46d3;aFL-^Y`}7h=aB_)jsgJZ*77$o(9@ME(|% z^FIjWCiy1yM(WSS=Zjx1CKqg8gb4x=fB*y_009U<00RF_;BYCKNPn;*9vXJP%^nVC zrgg`)I#$o@*aOdTZ8k8SzPW$DZF#J1T3)1j{+;cHvC~l3n(sC~R5Rxal2JFBY9o9IyxbtltWMOdMsgW4yiIP($lp>svi`gKwFA^kzJfUReRL6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0=Ti7zBVUwT-s{P=J1 z1^<}#l4virzeYMm1P=iSKmY;|fB*y_009U<00I#BL^00Izz00bZa0SG_<0uUHCfyua%hy|Yvq~dC#d;O2~|8W}#$QJ?- zfB*y_009U<00Izz00c%yVEF3(;nx3K_y4~k+MChI8<9c)0uX=z1Rwwb2tWV=5P$## zATUhes1nNrcMKSYao+ecx0KHY_x~&M;vd)l!`x5@0SG_<0uX=z1Rwwb2tWV=5Evza zWATjIfBoND|9?TW7o(I1Vub(%AOHafKmY;|fB*y_009V$gTOb+#L3T0le>G4@3~d( z3c+il|9=5y7nk!(XBU^UStA!+(^~(3N3?h2;D#I_009U<00Izz00bZa0SG_<0%IaD L8$YS`d~Wa_z)x&s diff --git a/test/dummy/test/controllers/dashboard_controller_test.rb b/test/dummy/test/controllers/dashboard_controller_test.rb index 183c6e5..c684713 100644 --- a/test/dummy/test/controllers/dashboard_controller_test.rb +++ b/test/dummy/test/controllers/dashboard_controller_test.rb @@ -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'"