1+ var FuncUnit = require ( 'funcunit' ) ;
12var localStorage = require ( './local-storage' ) ;
23var PageModel = require ( './page-model' ) ;
34var QUnit = require ( 'steal-qunit' ) ;
45var searchMap = require ( '../doc/searchMap.json' ) ;
56var stache = require ( 'can-stache' ) ;
7+ var utils = require ( './utils' ) ;
68var ViewModel = require ( './sidebar.viewmodel' ) ;
79
810require ( './sidebar' ) ;
@@ -159,7 +161,7 @@ QUnit.test('Correct page is selected after “asynchonously” setting the searc
159161 var vm = new ViewModel ( { selectedPageName : 'about' } ) ;
160162 vm . searchMap = searchMap ;
161163 var fragment = renderer ( vm ) ;
162- var currentPage = fragment . querySelector ( '.current ' ) ;
164+ var currentPage = fragment . querySelector ( '[selected-in-sidebar] ' ) ;
163165 assert . ok ( currentPage , 'page is selected when searchMap is provided' ) ;
164166 var currentPageTitle = currentPage . querySelector ( 'a' ) . textContent . trim ( ) ;
165167 assert . strictEqual ( 'About' , currentPageTitle , 'correct page is selected' ) ;
@@ -173,7 +175,7 @@ QUnit.test('When an item is selected, its children should be shown', function(as
173175 firstLink . click ( ) ;
174176 var firstLinkParent = firstLink . parentElement ;
175177 var firstLinkParentChildrenLinks = firstLinkParent . querySelectorAll ( 'li' ) ;
176- assert . ok ( firstLinkParent . classList . contains ( 'current ') , 'has current class ' ) ;
178+ assert . ok ( firstLinkParent . hasAttribute ( 'selected-in-sidebar ') , 'has selected-in-sidebar attribute ' ) ;
177179 assert . ok ( firstLinkParent . classList . contains ( 'expanded' ) , 'has expanded class' ) ;
178180 assert . ok ( firstLinkParentChildrenLinks . length > 0 , 'has children' ) ;
179181} ) ;
@@ -197,3 +199,37 @@ QUnit.test('When a child item is selected, it should still be visible', function
197199 assert . ok ( firstLinkParent . classList . contains ( 'expanded' ) , 'parent has expanded class' ) ;
198200 assert . ok ( firstLinkParentChildrenLinks . length > 0 , 'parent has children' ) ;
199201} ) ;
202+
203+ QUnit . test ( 'Sidebar scrolls to selected items' , function ( assert ) {
204+ var done = assert . async ( 1 ) ;
205+
206+ var timeout = 20000 ;
207+ var timeoutID = setTimeout ( function ( ) {
208+ assert . notOk ( true , 'Test took longer than ' + timeout + 'ms; test timed out.' ) ;
209+ } , timeout ) ;
210+
211+ // Open the demo page in a new window
212+ FuncUnit . open ( '../sidebar/demo.html' , function ( ) {
213+
214+ // Set the height & width of FuncUnit’s iframe
215+ FuncUnit . frame . height = 200 ;
216+ FuncUnit . frame . width = 600 ;
217+
218+ // Select the can-ajax page
219+ FuncUnit ( '.go-to-can-ajax' ) . click ( ) ;
220+
221+ // Check to make sure the element is visible
222+ FuncUnit ( '[selected-in-sidebar]' ) . wait ( function ( ) {
223+ var element = this [ 0 ] ;
224+ if ( ! element ) {
225+ return false ;
226+ }
227+ var rect = element . getBoundingClientRect ( ) ;
228+ return utils . rectIntersectsWithWindow ( rect , FuncUnit . win ) ;
229+ } , function ( ) {
230+ clearTimeout ( timeoutID ) ;
231+ assert . ok ( true , 'did scroll to selected element' ) ;
232+ done ( ) ;
233+ } ) ;
234+ } ) ;
235+ } ) ;
0 commit comments