feat: add frontTest
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-07-20 13:41:33 +02:00
parent 771c86ba4b
commit af4e7be229
7 changed files with 113 additions and 189 deletions

View File

@ -0,0 +1,26 @@
import './index';
describe('component vnShelvingCard', () => {
let controller;
let $httpBackend;
const data = {id: 1, code: 'AAA'};
beforeEach(ngModule('shelving'));
beforeEach(inject(($componentController, _$httpBackend_, $stateParams) => {
$httpBackend = _$httpBackend_;
let $element = angular.element('<div></div>');
controller = $componentController('vnShelvingCard', {$element});
$stateParams.id = data.id;
$httpBackend.whenRoute('GET', 'Shelvings/:id').respond(data);
}));
it('should reload the controller data', () => {
controller.reload();
$httpBackend.flush();
expect(controller.shelving).toEqual(data);
});
});

View File

@ -4,7 +4,7 @@ import Section from 'salix/components/section';
export default class Controller extends Section {
onSubmit() {
return this.$.watcher.submit().then(res =>
this.$state.go('shelving.card.summary', {id: res.data.id})
this.$state.go('shelving.card.basicData', {id: res.data.id})
);
}
}

View File

@ -1,121 +1,28 @@
import './index';
import watcher from 'core/mocks/watcher';
describe('Client', () => {
describe('Component vnClientCreate', () => {
let $scope;
let $state;
fdescribe('Shelving', () => {
describe('Component vnShelvingCreate', () => {
let controller;
let $element;
beforeEach(ngModule('client'));
beforeEach(ngModule('shelving'));
beforeEach(inject(($componentController, $rootScope, _$state_) => {
$scope = $rootScope.$new();
$state = _$state_;
$scope.watcher = {
submit: () => {
return {
then: callback => {
callback({data: {id: '1234'}});
}
};
}
};
const $element = angular.element('<vn-client-create></vn-client-create>');
controller = $componentController('vnClientCreate', {$element, $scope});
beforeEach(inject(($componentController, $rootScope) => {
const $scope = $rootScope.$new();
$scope.watcher = watcher;
$element = angular.element('<vn-shelving-create></vn-shelving-create>');
controller = $componentController('vnShelvingCreate', {$element, $scope});
controller.$params = {};
}));
it('should define and set scope, state and client properties', () => {
expect(controller.$).toBe($scope);
expect(controller.$state).toBe($state);
expect(controller.client.active).toBe(true);
});
describe('onSubmit()', () => {
it(`should call submit() on the watcher then expect a callback`, () => {
jest.spyOn($state, 'go');
it(`should redirect to basic data by calling the $state.go function`, () => {
jest.spyOn(controller.$state, 'go');
controller.onSubmit();
expect(controller.$state.go).toHaveBeenCalledWith('client.card.basicData', {id: '1234'});
});
});
describe('province() setter', () => {
it(`should set countryFk property`, () => {
controller.client.countryFk = null;
controller.province = {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
};
expect(controller.client.countryFk).toEqual(2);
});
});
describe('town() setter', () => {
it(`should set provinceFk property`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: []
};
expect(controller.client.provinceFk).toEqual(1);
});
it(`should set provinceFk property and fill the postalCode if there's just one`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: [{code: '46001'}]
};
expect(controller.client.provinceFk).toEqual(1);
expect(controller.client.postcode).toEqual('46001');
});
});
describe('postcode() setter', () => {
it(`should set the town, provinceFk and contryFk properties`, () => {
controller.postcode = {
townFk: 1,
code: 46001,
town: {
id: 1,
name: 'New York',
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
}
}
};
expect(controller.client.city).toEqual('New York');
expect(controller.client.provinceFk).toEqual(1);
expect(controller.client.countryFk).toEqual(2);
expect(controller.$state.go).toHaveBeenCalledWith('shelving.card.basicData', {id: 1234});
});
});
});

View File

@ -1,64 +1,29 @@
import './index.js';
describe('Supplier Component vnSupplierDescriptor', () => {
describe('component vnShelvingDescriptor', () => {
let $httpBackend;
let controller;
let $httpParamSerializer;
const supplier = {id: 1};
beforeEach(ngModule('supplier'));
const shelving = {id: 1, code: 'AA6'};
beforeEach(ngModule('shelving'));
beforeEach(inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => {
$httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
controller = $componentController('vnSupplierDescriptor', {$element: null}, {supplier});
controller = $componentController('vnShelvingDescriptor', {$element: null}, {shelving});
jest.spyOn(controller.vnApp, 'showSuccess');
}));
describe('loadData()', () => {
it('should perform ask for the supplier', () => {
const filter = {
fields: [
'id',
'name',
'nickname',
'nif',
'payMethodFk',
'payDemFk',
'payDay',
'isActive',
'isSerious',
'account'
],
include: [
{
relation: 'payMethod',
scope: {
fields: ['id', 'name']
}
},
{
relation: 'payDem',
scope: {
fields: ['id', 'payDem']
}
},
{
relation: 'client',
scope: {
fields: ['id', 'fi']
}
}
]
};
const serializedParams = $httpParamSerializer({filter});
let query = `Suppliers/${controller.supplier.id}?${serializedParams}`;
jest.spyOn(controller, 'getData');
describe('onDelete()', () => {
it('should delete entity and go to index', () => {
controller.$state.go = jest.fn();
$httpBackend.expect('GET', query).respond({id: 1});
controller.loadData();
$httpBackend.expectDELETE('Shelvings/1').respond();
controller.onDelete();
$httpBackend.flush();
expect(controller.getData).toHaveBeenCalledTimes(1);
expect(controller.$state.go).toHaveBeenCalledWith('shelving.index');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
});

View File

@ -0,0 +1,39 @@
import './index.js';
describe('Component vnShelvingIndex', () => {
let controller;
let $window;
let shelvings = [{
id: 1,
code: 'AAA'
}, {
id: 2,
code: 'AA1'
}, {
id: 3,
code: 'AA2'
}];
beforeEach(ngModule('shelving'));
beforeEach(inject(($componentController, _$window_) => {
$window = _$window_;
const $element = angular.element('<vn-shelving-index></vn-shelving-index>');
controller = $componentController('vnShelvingIndex', {$element});
}));
describe('preview()', () => {
it('should show the dialog summary', () => {
controller.$.summary = {show: () => {}};
jest.spyOn(controller.$.summary, 'show');
let event = new MouseEvent('click', {
view: $window,
bubbles: true,
cancelable: true
});
controller.preview(event, shelvings[0]);
expect(controller.$.summary.show).toHaveBeenCalledWith();
});
});
});

View File

@ -0,0 +1,19 @@
import './index';
describe('component vnShelving', () => {
let controller;
beforeEach(ngModule('shelving'));
beforeEach(inject($componentController => {
controller = $componentController('vnShelving', {$element: null});
}));
describe('exprBuilder()', () => {
it('should search by code', () => {
let expr = controller.exprBuilder('search', 'UXN');
expect(expr).toEqual({code: {like: '%UXN%'}},);
});
});
});

View File

@ -1,32 +0,0 @@
import './index';
describe('Supplier', () => {
describe('Component vnSupplierSummary', () => {
let controller;
let $httpBackend;
let $scope;
beforeEach(ngModule('supplier'));
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
const $element = angular.element('<vn-supplier-summary></vn-supplier-summary>');
controller = $componentController('vnSupplierSummary', {$element, $scope});
}));
describe('getSummary()', () => {
it('should perform a get asking for the supplier data', () => {
controller.supplier = {id: 1};
const query = `Suppliers/${controller.supplier.id}/getSummary`;
$httpBackend.expectGET(query).respond({id: 1});
controller.getSummary();
$httpBackend.flush();
expect(controller.summary).toEqual({id: 1});
});
});
});
});