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

Automatic logout triggered by ember-user-activity and acceptance tests #136

Open
gilles-gosuin opened this issue Mar 21, 2018 · 3 comments

Comments

@gilles-gosuin
Copy link

We're using ember-user-activity to trigger an automatic logout after IDLE_TIMEOUT.

The problem is that the logout is triggered after 10ms in acceptance tests, which is obviously not what we want.

Raising the IDLE_TIMEOUT only delays the issue, since our "andThen()s" wait for the timeout to be reached anyway.

The only solution we can imagine is to completely deactivate ember-user-activity in tests.

Is there something we're missing or is this use case not covered by the addon?

@elwayman02
Copy link
Owner

@gilles-gosuin Thanks for pointing this out! You're right that the idle service is not "test-aware", since it just continues to operate as normal. To solve this, you could override the setIdle method for the service in your tests, such that it doesn't actually set idle. Then, for tests that you want to actually test that a logout is triggered upon idle, you can just let the service operate as normal, or you can manually set isIdle to true and assert the resulting behavior.

If you can think of a reasonable API for exposing test-friendly behavior in a better way, I'd be happy to review a PR to that effect.

@Abhishekmnt
Copy link

Abhishekmnt commented Dec 27, 2018

@gilles-gosuin @elwayman02 I've used ember-user-activity and was facing the same issue, Actually in addon (user-idle) service' set timeout 10ms for testing environment. You're right that the idle service is not "test-aware"
We can override init method in user-idle service and set timeout for test invironment
// app/services/user-idle.js

import Ember from 'ember';
import UserIdleService from 'ember-user-activity/services/user-idle';

const {
  testing,
  set
} = Ember;

export default UserIdleService.extend({
  IDLE_TIMEOUT: 900000, // 15 minutes

  init() {
    // timeout in testing mode
    if (testing) {
      set(this, 'IDLE_TIMEOUT', 1000);
    } else {
      this._super(...arguments);
    }
  }
});

@Arijit-Roy
Copy link

For those who are struggling to implement above clue, you can do something like this in your tests:

function setupActivityService(hooks) {
  hooks.beforeEach(function() {
    this.owner.register(
      'service:user-idle',
      idleService.extend({
        setIdle() {
          this.isIdle = false;
          this.trigger('idleChanged', true);
        },
      })
    );
  });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants