Last active
January 3, 2016 14:39
-
-
Save edmilsonlani/8477631 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var AgenteController = Class.extend({ | |
$scope: null, | |
$routeParams: null, | |
agenteService: null, | |
init: function ($scope, $routeParams, agenteService) { | |
this.$scope = $scope; | |
this.$routeParams = $routeParams; | |
this.agenteService = agenteService; | |
this.definirEscopo(); | |
}, | |
definirEscopo: function () { | |
this.$scope.agenteService = this.agenteService; | |
this.$scope.$routeParams = this.$routeParams; | |
this.$scope.carregarAgentePorLogin = this.carregarAgentePorLogin; | |
this.$scope.atualizarInformacoesDoAgente = this.atualizarInformacoesDoAgente; | |
this.$scope.carregarAgentePorLogin(); | |
} | |
carregarAgentePorLogin: function () { | |
if (this.$routeParams.login != undefined) { | |
this.agenteService.carregarPorLogin(this.$routeParams.login) | |
.then(this.atualizarInformacoesDoAgente.bind(this)); | |
} | |
}, | |
atualizarInformacoesDoAgente: function (resultado) { | |
this.agente = resultado.data; | |
} | |
}); | |
AgenteController.$inject = ['$scope', '$routeParams', 'AgenteService']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
describe("AgenteController", function () { | |
var scopeMock, routeParamsMock, agenteServiceMock; | |
var controller; | |
beforeEach(function() { | |
module('RecursosHumanosApp'); | |
module(function ($provide) { | |
$provide.value('$routeParams', routeParamsMock); | |
$provide.value('AgenteService', agenteServiceMock); | |
}); | |
routeParamsMock = jasmine.createSpy('routeParamsMock'); | |
agenteServiceMock = jasmine.createSpyObj('agenteServiceMock', ['carregarPorLogin']); | |
inject(function ($rootScope, $controller, $q) { | |
scopeMock = $rootScope.$new(); | |
var deferred = $q.defer(); | |
deferred.resolve('resolveData'); | |
agenteServiceMock.carregarPorLogin.andReturn(deferred.promise); | |
controller = $controller('AgenteController', { $scope: scopeMock }); | |
}); | |
}); | |
it("Quando login na url for undefined não chama servico para carregar agente", function () { | |
scopeMock.carregarAgentePorLogin(); | |
expect(routeParamsMock.login).toBeUndefined(); | |
expect(agenteServiceMock.carregarPorLogin).not.toHaveBeenCalled(); | |
}); | |
it("Quando login na url for teste chama servico para carregar agente", function () { | |
routeParamsMock.login = 'teste'; | |
scopeMock.carregarAgentePorLogin(); | |
expect(routeParamsMock.login).toBe('teste'); | |
expect(agenteServiceMock.carregarPorLogin).toHaveBeenCalled(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment