address & ticket card front unit tests

This commit is contained in:
Joan Sanchez 2018-08-09 14:42:02 +02:00
parent 37c24ba3dd
commit 337b4114f0
4 changed files with 150 additions and 2 deletions

View File

@ -0,0 +1,42 @@
import './index';
describe('Client', () => {
describe('Component vnClientAddressIndex', () => {
let $componentController;
let controller;
let $scope;
let $state;
let $httpBackend;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_, _$httpBackend_) => {
$componentController = _$componentController_;
$state = _$state_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$scope = $rootScope.$new();
$scope.model = {
refresh: () => {}
};
controller = $componentController('vnClientAddressIndex', {$state: $state}, {$scope: $scope});
}));
describe('setDefault()', () => {
it('should perform a PATCH if the address is active and call the refresh method', () => {
spyOn($scope.model, 'refresh');
let address = {id: 1, isActive: true};
$httpBackend.when('PATCH', `/client/api/Addresses/1`).respond(200);
$httpBackend.expect('PATCH', `/client/api/Addresses/1`);
controller.setDefault(address);
$httpBackend.flush();
expect($scope.model.refresh).toHaveBeenCalledWith();
});
});
});
});

View File

@ -0,0 +1,64 @@
import './index';
describe('Ticket', () => {
describe('Component vnTicketCard', () => {
let $componentController;
let controller;
let $state;
let $httpBackend;
beforeEach(() => {
angular.mock.module('ticket');
});
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => {
$componentController = _$componentController_;
$state = _$state_;
$state.params.id = 1;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
controller = $componentController('vnTicketCard', {$state: $state});
}));
describe('getTicket()', () => {
it('should perform a GET query and define the ticket property on controller', () => {
let filter = {
include: [
{relation: 'warehouse', scope: {fields: ['name']}},
{relation: 'agencyMode', scope: {fields: ['name']}},
{
relation: 'client',
scope: {
fields: ['salesPersonFk', 'name', 'isActive', 'isFreezed', 'isTaxDataChecked'],
include: {
relation: 'salesPerson',
fields: ['firstName', 'name']
}
}
},
{
relation: 'tracking',
scope: {
fields: ['stateFk'],
include: {
relation: 'state',
fields: ['name']
}
}
}
]
};
filter = encodeURIComponent(JSON.stringify(filter));
$httpBackend.when('GET', `/ticket/api/Tickets/1?filter=${filter}`).respond({id: 1});
$httpBackend.expect('GET', `/ticket/api/Tickets/1?filter=${filter}`);
controller.getTicket();
$httpBackend.flush();
expect(controller.ticket).toBeDefined();
expect(controller.ticket.id).toEqual(1);
});
});
});
});

View File

@ -1,6 +1,6 @@
import './index.js';
describe('ticket', () => {
describe('Ticket', () => {
describe('Component vnTicketDataStepOne', () => {
let $componentController;
let $state;
@ -20,7 +20,7 @@ describe('ticket', () => {
}));
describe('ticket() setter', () => {
it('should set ticket property and call onChangeAddress() method ', () => {
it('should set ticket property and call onChangeAddress() method', () => {
spyOn(controller, 'onChangeAddress');
controller.ticket = {id: 1, clientFk: 101};

View File

@ -0,0 +1,42 @@
import './index';
describe('Ticket', () => {
describe('Component vnTicketExpedition', () => {
let $componentController;
let controller;
let $scope;
let $state;
let $httpBackend;
beforeEach(() => {
angular.mock.module('ticket');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_, _$httpBackend_) => {
$componentController = _$componentController_;
$state = _$state_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$scope = $rootScope.$new();
$scope.model = {
refresh: () => {}
};
controller = $componentController('vnTicketExpedition', {$state: $state}, {$scope: $scope});
}));
describe('deleteExpedition()', () => {
it('should perform a DELETE query', () => {
spyOn($scope.model, 'refresh');
let expedition = {id: 1};
$httpBackend.when('DELETE', `/ticket/api/Expeditions/1`).respond(200);
$httpBackend.expect('DELETE', `/ticket/api/Expeditions/1`);
controller.deleteExpedition(expedition);
$httpBackend.flush();
expect($scope.model.refresh).toHaveBeenCalledWith();
});
});
});
});