Tarea #509 /create/card.js Front unit test

This commit is contained in:
gerard 2018-08-09 15:40:37 +02:00
parent 272a406b66
commit e3cfe9472f
2 changed files with 98 additions and 3 deletions

View File

@ -1,8 +1,7 @@
import ngModule from '../module';
class Controller {
constructor($scope, $http, vnApp, $translate, $state) {
this.$scope = $scope;
constructor($http, vnApp, $translate, $state) {
this.$http = $http;
this.translate = $translate;
this.vnApp = vnApp;
@ -82,7 +81,7 @@ class Controller {
}
}
Controller.$inject = ['$scope', '$http', 'vnApp', '$translate', '$state'];
Controller.$inject = ['$http', 'vnApp', '$translate', '$state'];
ngModule.component('vnOrderCreateCard', {
template: require('./card.html'),

View File

@ -0,0 +1,96 @@
import './card.js';
describe('Order', () => {
describe('Component vnOrderCreateCard', () => {
let $componentController;
let controller;
let $httpBackend;
beforeEach(() => {
angular.mock.module('order');
});
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_, _vnApp_) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
controller = $componentController('vnOrderCreateCard');
controller.item = {id: 3};
}));
describe('set order', () => {
it(`should not set order if the value given is null`, () => {
controller.order = null;
expect(controller.order).toEqual({});
});
it(`should set order if the value given is not null`, () => {
controller.order = 1;
expect(controller.order).toEqual(1);
});
});
describe('set clientFk', () => {
it(`should set addressFk to null and clientFk to a value`, () => {
controller.clientFk = 2;
expect(controller.clientFk).toEqual(2);
expect(controller.order.addressFk).toBe(null);
});
});
describe('set addressFk', () => {
it(`should set agencyModeFk property to null and addressFk to a value`, () => {
controller.addressFk = 101;
expect(controller.addressFk).toEqual(101);
expect(controller.order.agencyModeFk).toBe(null);
});
});
describe('getAvailableAgencies()', () => {
it(`should make a query if landed and addressFk exists`, () => {
controller.order.addressFk = 101;
controller.order.landed = 101;
let filter = {addressFk: controller.order.addressFk, landed: controller.order.landed};
filter = encodeURIComponent(JSON.stringify(filter));
$httpBackend.whenGET(`/api/Agencies/landsThatDay?filter=${filter}`).respond({data: 1});
$httpBackend.expectGET(`/api/Agencies/landsThatDay?filter=${filter}`);
controller.getAvailableAgencies();
$httpBackend.flush();
});
});
describe('onSubmit()', () => {
it(`should call createOrder()`, () => {
spyOn(controller, 'createOrder');
controller.onSubmit();
expect(controller.createOrder).toHaveBeenCalledWith();
});
});
describe('createOrder()', () => {
it(`should make a query, call vnApp.showSuccess and $state.go if the response is defined`, () => {
controller.order.landed = 101;
controller.order.addressFk = 101;
controller.order.agencyModeFk = 101;
spyOn(controller.vnApp, 'showSuccess');
spyOn(controller.$state, 'go');
$httpBackend.when('POST', 'order/api/Orders/new', {landed: 101, addressFk: 101, agencyModeFk: 101}).respond(200, 1);
$httpBackend.expect('POST', 'order/api/Orders/new', {landed: 101, addressFk: 101, agencyModeFk: 101});
controller.createOrder();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.$state.go).toHaveBeenCalledWith("order.card.catalogue", {id: 1});
});
});
});
});