Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing #111

Open
nucleartide opened this issue Oct 17, 2016 · 11 comments
Open

Testing #111

nucleartide opened this issue Oct 17, 2016 · 11 comments

Comments

@nucleartide
Copy link

nucleartide commented Oct 17, 2016

Hey dude! First of all, this addon is great - I'm really liking the pretty default styles out of the box.

One question I have though: in acceptance tests, Ember waits for the run loop to clear before continuing. I notice that when I write an acceptance test for notifications, I have to wait clearDuration amount of time before my test continues. This slows down the test and is a little annoying.

It seems like these two methods are causing that to happen. So my resolution was to allow those methods to run, only if Ember isn't in test mode. (Using the Ember.testing flag would also work, instead of a having to manually toggle a variable on the service.)

Do you think it's a good idea to incorporate this change into ember-cli-notifications? Alternatively, I can simply extend the notifications service (as part of this recent change), and make the method overrides myself.

I'd love to hear what you think!

@ynnoj
Copy link
Contributor

ynnoj commented Oct 18, 2016

@nucleartide Hey man! Thanks for the interest in the add-on and your kind words 🙃

One area of the add-on that I am particularly keen to improve on is testing (see #91). I have little experience in writing tests, so I'd be more than happy to accept contributions that will improve this aspect of the add-on.

If you're interested in helping me make the add-on bulletproof, then fire away with the PRs 🚀

@nucleartide
Copy link
Author

Ah okay! I will fire away with the PRs should I run into problems. :)

@ynnoj ynnoj mentioned this issue Dec 5, 2016
@luketheobscure
Copy link

Was any progress made on this? Ran into the same issue. My current workaround is probably going to be to set setDefaultAutoClear to false during acceptance tests, and manually clearing out the notices as I go.

@nucleartide
Copy link
Author

my solution was to extend the notifications service, override methods involving the run loop, and remove calls to the run loop. but this was a long time ago.

hopefully that helps!

@ctcpip
Copy link

ctcpip commented Jul 18, 2017

This issue should get resolved in this addon, but in the meantime, here is my workaround: We check the environment variable to see if we are testing, and if so, set the auto clear duration to 0.

// controllers/application.js

import Ember from 'ember';
import ENV from 'myApp/config/environment';

export default Ember.Controller.extend({
  notifications: Ember.inject.service('notification-messages'),
  init: function () {

    const notifications = this.get('notifications');

    notifications.setDefaultAutoClear(true);

    if(ENV.environment === 'test') {
      notifications.setDefaultClearDuration(0);
    }

  }
});

@sbatson5
Copy link

That's a good workaround for clearing the images, but makes it hard if you want to actually test the notifications in an acceptance test. I had a defaults hash that I overwrite in test:
messageOptions: ENV.environment == 'test' ? {} : DEFAULT_OPTIONS,

Then wrote a helper that dismisses the notifications. That way the notifications stick around during the life of your test and you can test that the right messaging appears (if that's important to you).

@concertiv
Copy link

Even with setDefaultClearDuration at 0, the close animation slows down acceptance tests. I guess this is because removeNotification has a hard-coded 500ms delay? https://github.com/stonecircle/ember-cli-notifications/blob/master/addon/services/notification-messages-service.js#L72

@jelhan
Copy link

jelhan commented May 12, 2018

Did you tried out to set clearDuration to 1ms in testing environment? I'm using this approach and didn't faced any issues with it so far.

// config/environment.js
module.exports = function(environment) {
  let ENV = {
    'ember-cli-notifications': {
      autoClear: true
    }
  }

  if (environment === 'test') {
    ENV['ember-cli-notifications'].clearDuration = 1;
  }

  return ENV;
};

@concertiv
Copy link

concertiv commented May 12, 2018

We're doing something similar with the same result, but our issue isn't clearDuration.

The delay is hardcoded at 500ms in the run.later here: https://github.com/stonecircle/ember-cli-notifications/blob/ac80976e648814dc2b1804d0e3b169e1e9463083/addon/services/notification-messages-service.js#L80-L82

@jelhan
Copy link

jelhan commented May 13, 2018

I see. Didn't noticed that one.

In my opinion this dismissal animation duration should also be configurable. Maybe call it a dismissalAnimationDuration or to be more general delayRemovingOnClose. In this case it would not only be possible to set this one to 1ms for testing but also to have a different duration if needed for custom styling. @mansona, @ynnoj: Would you accept a PR for this one?

I'm also not quite sure why the default is 500ms. The animation is only 250ms isn't it?

https://github.com/stonecircle/ember-cli-notifications/blob/ac80976e648814dc2b1804d0e3b169e1e9463083/addon/styles/components/notification-message.css#L30

@mistahenry
Copy link

mistahenry commented Apr 10, 2019

Another work around, in your tests/test-helper, reopen the class and patch the remove

import NotificationMessageService from 'ember-cli-notifications/services/notification-messages-service';
NotificationMessageService.reopen({
    removeNotification(notification) {
        if (!notification) {
          return;
        }
    
        notification.set('dismiss', true);
        this.removeObject(notification);
    }
})

laura-bergoens pushed a commit to 1024pix/pix that referenced this issue Mar 26, 2020
Ember-cli-notifications have a fixed 500ms delay removal animation.
It impacts test duration indeed. There is an issue opened about this
to make delay removal animation configurable. In the mean time, we need
to modify a little bit the removeNotification() method in the
notifications services to bump those 500ms delay.

removeNotification() source code :
https://github.com/mansona/ember-cli-notifications/blob/master/addon/services/notifications.js

issue :
mansona/ember-cli-notifications#111
laura-bergoens pushed a commit to 1024pix/pix that referenced this issue Mar 27, 2020
Ember-cli-notifications have a fixed 500ms delay removal animation.
It impacts test duration indeed. There is an issue opened about this
to make delay removal animation configurable. In the mean time, we need
to modify a little bit the removeNotification() method in the
notifications services to bump those 500ms delay.

removeNotification() source code :
https://github.com/mansona/ember-cli-notifications/blob/master/addon/services/notifications.js

issue :
mansona/ember-cli-notifications#111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants