Skip to content

Instantly share code, notes, and snippets.

@edmilsonlani
Last active January 3, 2016 14:39
Show Gist options
  • Save edmilsonlani/8477631 to your computer and use it in GitHub Desktop.
Save edmilsonlani/8477631 to your computer and use it in GitHub Desktop.
'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'];
'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