jeudi 26 janvier 2017

Ember confused on testing route hooks and actions

I am just starting looking at testing with Ember and I am bit confused on how to test the following:

1 - Route hooks

Here's an example what I have, I am not sure if should be done through unit testing or user acceptance testing? How do I triggers the hooks, wait the promise etc.?

/**
 * Model hook.
 */
model() {
    return this.modelFor('new');
},

/**
 * AfterModel hook.
 */
afterModel() {
    /**
     * Setup provinces.
     */
    return new Ember.RSVP.Promise((resolve) => {
        const provinces = Ember.A([
            Ember.Object.create({
                code: 'AB',
                description: 'Alberta'
            }),
            Ember.Object.create({
                code: 'BC',
                description: 'British Columbia'
            }),
            Ember.Object.create({
                code: 'MB',
                description: 'Manitoba'
            }),
            Ember.Object.create({
                code: 'NB',
                description: 'New Brunswick'
            }),
            Ember.Object.create({
                code: 'NL',
                description: 'Newfoundland and Labrador'
            }),
            Ember.Object.create({
                code: 'NS',
                description: 'Nova Scotia'
            }),
            Ember.Object.create({
                code: 'NT',
                description: 'Northwest Territories'
            }),
            Ember.Object.create({
                code: 'NU',
                description: 'Nunavut'
            }),
            Ember.Object.create({
                code: 'ON',
                description: 'Ontario'
            }),
            Ember.Object.create({
                code: 'PE',
                description: 'Prince Edward Island'
            }),
            Ember.Object.create({
                code: 'QC',
                description: 'Quebec'
            }),
            Ember.Object.create({
                code: 'SK',
                description: 'Saskatchewan'
            }),
            Ember.Object.create({
                code: 'YK',
                description: 'Yukon'
            })
        ]);
        resolve(provinces);
    }).then((provinces) => {
        this.set('provinces', provinces);
    });
},

/**
 * Setup controller hook.
 * @param controller the controller
 * @param model The model
 */
setupController(controller, model) {
    this._super(controller, model);
    controller.set('provinces', this.get('provinces'));
}

2 - Controller/Route Actions

Here I mostly just either going to different route or displaying error message, is this something that should be unit tested? if so how?

actions: {
    /**
     * Go previous step
     */
    back() {
        this.transitionToRoute('new.step1');
    },
    /**
     * Go to next step.
     */
    next() {
        this.get('model').save().then(() => {
            this.transitionToRoute('new.step3');
        }).catch(() => {
            this.get('notificationService')
                .notifyError('common.error.system_error');
        });
    }
}




Aucun commentaire:

Enregistrer un commentaire