feat: add frontTest
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
771c86ba4b
commit
af4e7be229
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
|
@ -4,7 +4,7 @@ import Section from 'salix/components/section';
|
||||||
export default class Controller extends Section {
|
export default class Controller extends Section {
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
return this.$.watcher.submit().then(res =>
|
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})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,121 +1,28 @@
|
||||||
import './index';
|
import './index';
|
||||||
|
import watcher from 'core/mocks/watcher';
|
||||||
|
|
||||||
describe('Client', () => {
|
fdescribe('Shelving', () => {
|
||||||
describe('Component vnClientCreate', () => {
|
describe('Component vnShelvingCreate', () => {
|
||||||
let $scope;
|
|
||||||
let $state;
|
|
||||||
let controller;
|
let controller;
|
||||||
|
let $element;
|
||||||
|
|
||||||
beforeEach(ngModule('client'));
|
beforeEach(ngModule('shelving'));
|
||||||
|
|
||||||
beforeEach(inject(($componentController, $rootScope, _$state_) => {
|
beforeEach(inject(($componentController, $rootScope) => {
|
||||||
$scope = $rootScope.$new();
|
const $scope = $rootScope.$new();
|
||||||
$state = _$state_;
|
$scope.watcher = watcher;
|
||||||
$scope.watcher = {
|
$element = angular.element('<vn-shelving-create></vn-shelving-create>');
|
||||||
submit: () => {
|
controller = $componentController('vnShelvingCreate', {$element, $scope});
|
||||||
return {
|
controller.$params = {};
|
||||||
then: callback => {
|
|
||||||
callback({data: {id: '1234'}});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const $element = angular.element('<vn-client-create></vn-client-create>');
|
|
||||||
controller = $componentController('vnClientCreate', {$element, $scope});
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
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()', () => {
|
describe('onSubmit()', () => {
|
||||||
it(`should call submit() on the watcher then expect a callback`, () => {
|
it(`should redirect to basic data by calling the $state.go function`, () => {
|
||||||
jest.spyOn($state, 'go');
|
jest.spyOn(controller.$state, 'go');
|
||||||
|
|
||||||
controller.onSubmit();
|
controller.onSubmit();
|
||||||
|
|
||||||
expect(controller.$state.go).toHaveBeenCalledWith('client.card.basicData', {id: '1234'});
|
expect(controller.$state.go).toHaveBeenCalledWith('shelving.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);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,64 +1,29 @@
|
||||||
import './index.js';
|
import './index.js';
|
||||||
|
|
||||||
describe('Supplier Component vnSupplierDescriptor', () => {
|
describe('component vnShelvingDescriptor', () => {
|
||||||
let $httpBackend;
|
let $httpBackend;
|
||||||
let controller;
|
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_) => {
|
beforeEach(inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => {
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
$httpParamSerializer = _$httpParamSerializer_;
|
controller = $componentController('vnShelvingDescriptor', {$element: null}, {shelving});
|
||||||
controller = $componentController('vnSupplierDescriptor', {$element: null}, {supplier});
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('loadData()', () => {
|
describe('onDelete()', () => {
|
||||||
it('should perform ask for the supplier', () => {
|
it('should delete entity and go to index', () => {
|
||||||
const filter = {
|
controller.$state.go = jest.fn();
|
||||||
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');
|
|
||||||
|
|
||||||
$httpBackend.expect('GET', query).respond({id: 1});
|
$httpBackend.expectDELETE('Shelvings/1').respond();
|
||||||
controller.loadData();
|
controller.onDelete();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.getData).toHaveBeenCalledTimes(1);
|
expect(controller.$state.go).toHaveBeenCalledWith('shelving.index');
|
||||||
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -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%'}},);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -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});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Reference in New Issue