1<!doctype html> 2<!-- 3@license 4Copyright (c) 2016 The Polymer Project Authors. All rights reserved. 5This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt 6The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 7The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 8Code distributed by Google as part of the polymer project is also 9subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt 10--> 11 12<html> 13<head> 14 <title>app-route 0bserver Test</title> 15 16 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> 17 <script src="../../web-component-tester/browser.js"></script> 18 19 <link rel="import" href="../../polymer/polymer.html"> 20 <link rel="import" href="./observer-tester.html"> 21 22</head> 23<body> 24 25 <test-fixture id="observer_app"> 26 <template> 27 <observer-tester id="testel"></observer-tester> 28 </template> 29 </test-fixture> 30 <script> 31 'use strict'; 32 function setLocation(url) { 33 window.history.pushState({}, '', url); 34 Polymer.Base.fire('location-changed', {}, { node: window }); 35 } 36 37 38 suite('observe app-route active changes', function(){ 39 var originalLocation; 40 var sandbox, el; 41 setup(function(){ 42 originalLocation = window.location.href; 43 sandbox = sinon.sandbox.create(); 44 el = fixture('observer_app'); 45 }); 46 teardown(function(){ 47 sandbox.restore(); 48 window.history.replaceState({}, '', originalLocation); 49 }); 50 51 test('observer should fire when route selected', function(){ 52 sandbox.spy(el,'checkActive'); 53 setLocation('/report/1000'); 54 expect(el.checkActive).to.have.been.called.once; 55 expect(el.checkActive).to.have.been.calledWith(true); 56 }); 57 test('observer should fire when route deselected',function(){ 58 setLocation('/report/1000'); 59 sandbox.spy(el,'checkActive'); 60 setLocation('/menu'); 61 expect(el.checkActive).to.have.been.called.once; 62 expect(el.checkActive).to.have.been.calledWith(false); 63 }); 64 }); 65 </script> 66</body> 67 68