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

Statements: 100% (53 / 53)      Branches: 100% (16 / 16)      Functions: 100% (15 / 15)      Lines: 100% (24 / 24)      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    1   1 7   7 7 7 7 6         6   1         1 1       1 1         2       1 1 1     1 1 1   1           1        
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 (ctrl) {
        ctrl.phone = angular.copy(ctrl[originalPhone]);
        ctrl.state = 'view';
    }
 
    updatePhone (ctrl, phone) {
        // return promise here to let the phone form controller know the response status
        return ctrl.PhoneAPI.updatePhone(phone.id, phone)
            .then(_success)
            .catch(_error);
 
        function _success (data) {
            ctrl.state = 'view';
            ctrl.phone = data;
        }
 
        function _error (message) {
            ctrl.Modal.open('Update phone error', message.text, {ok: 'OK'}, () => {
                ctrl.cancelUpdate(ctrl);
            });
            return ctrl.$q.reject();
        }
    }
 
}
 
PhoneDetailController.$inject = ['PhoneAPI', '$stateParams', '$q', 'Modal'];
 
export default PhoneDetailController;