From 78e22379dc304117d1718ff790026f678999131f Mon Sep 17 00:00:00 2001 From: zinyando Date: Fri, 3 Jun 2016 13:36:32 +0200 Subject: [PATCH] Add waitToDisappear helper and minor cleanup --- app/tests/helpers/start-app.js | 2 +- app/tests/helpers/stub-user-notification.js | 7 +++---- app/tests/helpers/wait-to-appear.js | 17 ++++++++------- app/tests/helpers/wait-to-disappear.js | 23 +++++++++++++++++++++ 4 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 app/tests/helpers/wait-to-disappear.js diff --git a/app/tests/helpers/start-app.js b/app/tests/helpers/start-app.js index 3c0d1486..024b70d1 100644 --- a/app/tests/helpers/start-app.js +++ b/app/tests/helpers/start-app.js @@ -4,8 +4,8 @@ import config from '../../config/environment'; import './stub-session'; import './stub-audit'; import './user-login'; -import './allow-anonymous-access'; import './wait-to-appear'; +import './wait-to-disappear'; import './stub-user-notification'; export default function startApp(attrs) { diff --git a/app/tests/helpers/stub-user-notification.js b/app/tests/helpers/stub-user-notification.js index 1e464340..255b8ffd 100644 --- a/app/tests/helpers/stub-user-notification.js +++ b/app/tests/helpers/stub-user-notification.js @@ -1,19 +1,18 @@ import Ember from 'ember'; -import miscUtil from 'documize/utils/misc'; const userNotification = Ember.Component.extend({ notifications: [], didInsertElement() { - // this.eventBus.subscribe('notifyUser', this, 'showNotification'); + this.eventBus.subscribe('notifyUser', this, 'notifyHandler'); }, willDestroyElement() { - // this.eventBus.unsubscribe('notifyUser'); + this.eventBus.unsubscribe('notifyUser'); }, showNotification(msg) { - // console.log(msg); + return msg; } }); diff --git a/app/tests/helpers/wait-to-appear.js b/app/tests/helpers/wait-to-appear.js index d700120d..16ec0054 100644 --- a/app/tests/helpers/wait-to-appear.js +++ b/app/tests/helpers/wait-to-appear.js @@ -5,14 +5,15 @@ function isVisible(selector) { } function checkVisibility(selector, interval, resolve, visibility) { - if (isVisible(selector) === visibility) { - resolve($(selector)); - } else { - console.log('waiting for visibility'); - Ember.run.later(null, function() { - checkVisibility(selector, interval, resolve, visibility); - }, interval); - } + if (isVisible(selector) === visibility) { + console.log("found in appear"); + resolve($(selector)); + } else { + Ember.run.later(null, function() { + console.log("waiting in appear"); + checkVisibility(selector, interval, resolve, visibility); + }, interval); + } } export default Ember.Test.registerAsyncHelper('waitToAppear', function(app, selector, interval = 200) { diff --git a/app/tests/helpers/wait-to-disappear.js b/app/tests/helpers/wait-to-disappear.js new file mode 100644 index 00000000..476c7373 --- /dev/null +++ b/app/tests/helpers/wait-to-disappear.js @@ -0,0 +1,23 @@ +import Ember from 'ember'; + +function isVisible(selector) { + return $(selector).length > 0; +} + +function checkVisibility(selector, interval, resolve, visibility) { + if (isVisible(selector) === visibility) { + console.log("found"); + resolve($(selector)); + } else { + Ember.run.later(null, function() { + console.log("waiting"); + checkVisibility(selector, interval, resolve, visibility); + }, interval); + } +} + +export default Ember.Test.registerAsyncHelper('waitToDisappear', function(app, selector, interval = 200) { + return new Ember.RSVP.Promise(function(resolve) { + checkVisibility(selector, interval, resolve, false); + }); +});