github.com/jancarloviray/community@v0.41.1-0.20170124221257-33a66c87cf2f/app/tests/helpers/wait-to-appear.js (about) 1 // Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved. 2 // 3 // This software (Documize Community Edition) is licensed under 4 // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html 5 // 6 // You can operate outside the AGPL restrictions by purchasing 7 // Documize Enterprise Edition and obtaining a commercial license 8 // by contacting <sales@documize.com>. 9 // 10 // https://documize.com 11 12 import Ember from 'ember'; 13 14 function isVisible(selector) { 15 return $(selector).length > 0; 16 } 17 18 function checkVisibility(selector, interval, resolve, visibility) { 19 if (isVisible(selector) === visibility) { 20 resolve($(selector)); 21 } else { 22 Ember.run.later(null, function () { 23 checkVisibility(selector, interval, resolve, visibility); 24 }, interval); 25 } 26 } 27 28 export default Ember.Test.registerAsyncHelper('waitToAppear', function (app, selector, interval = 200) { 29 return new Ember.RSVP.Promise(function (resolve) { 30 checkVisibility(selector, interval, resolve, true); 31 }); 32 });