Code coverage report for app/pages/phone/detail/phone-detail.controller.js

Statements: 100% (54 / 54)      Branches: 100% (16 / 16)      Functions: 100% (15 / 15)      Lines: 100% (25 / 25)      Ignored: 2 statements, 5 branches     

All files » app/pages/phone/detail/ » phone-detail.controller.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59                                                                     
import angular from 'angular';
 
const originalPhone = Symbol();
class PhoneDetailController {
    constructor (PhoneAPI, $stateParams, $q, Modal) {
        Object.assign(this, {PhoneAPI, $stateParams, $q, Modal});
 
        this[originalPhone] = {};
        this.state = 'view';
        const id = $stateParams.id;
        if (id) {
            this._getPhoneDetail(id);
        }
    }
 
    _getPhoneDetail (id) {
        this.PhoneAPI.getPhoneDetail(id)
            .then((data) => {
                this.phone = data;
            });
    }
 
    beginEdit () {
        this[originalPhone] = angular.copy(this.phone);
        this.state = 'edit';
    }
 
    cancelUpdate () {
        this.phone = angular.copy(this[originalPhone]);
        this.state = 'view';
    }
 
    updatePhone (phone) {
        const self = this;
        // return promise here to let the phone form controller know the response status
        return this.PhoneAPI.updatePhone(phone.id, phone)
            .then(_success)
            .catch(_error);
 
        function _success (data) {
            self.state = 'view';
            self.phone = data;
        }
 
        function _error (message) {
            self.Modal.open('Update phone error', message.text, {ok: 'OK'}, () => {
                self.cancelUpdate();
            });
            return self.$q.reject();
        }
    }
 
}
 
PhoneDetailController.$inject = ['PhoneAPI', '$stateParams', '$q', 'Modal'];
 
export default PhoneDetailController;