mardi 3 novembre 2015

Ember Service and Route testing

How can I test e.g that simple route?

import Ember from 'ember';
import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin';

export default Ember.Route.extend(UnauthenticatedRouteMixin, {
  actions: {
    register() {
      this.transitionTo('index');
    },
  },
});

I need to test for example transition or simple logic.

or service like that: How to use other services?

import Ember from 'ember';
import DS from 'ember-data';

const { service } = Ember.inject;

export default Ember.Service.extend({
  session: service('session'),
  notify: service('notify-alert'),
  store: service(),

  serverRegisterEndpoint: EmberENV.baseAPI + 'auth/sign_up',
  resetPasswordEndpoint: EmberENV.baseAPI + 'auth/password',
  resendMailEndpoint: EmberENV.baseAPI + 'auth/confirmation',

  profile: Ember.computed('session.data.authenticated.user.id', function() {
    const userId = this.get('session.data.authenticated.user.id');
    if (!Ember.isEmpty(userId)) {
      return DS.PromiseObject.create({
        promise: this.get('store').find('user', userId),
      });
    }
  }),

  loggedIn: Ember.computed.bool('session.isAuthenticated'),

  logout() {
    return this.get('session').invalidate(this.get('session.data.authenticated.token'));
  },

  login(email, password) {
    return this.get('session').authenticate('authenticator:devise', email, password).then(()=> {
      this.get('notify').success('notify.auth.login.successful');
    }).catch(()=> {});
  },
});

I will be very appreciate for any resources and examples of code.

What is also the trends in testing? Should I write unit testing for component or only acceptance?

Aucun commentaire:

Enregistrer un commentaire