2022-03-02 13:59:30 +00:00
|
|
|
import './index';
|
2022-03-03 13:42:12 +00:00
|
|
|
import watcher from 'core/mocks/watcher.js';
|
2022-03-02 13:59:30 +00:00
|
|
|
|
2022-03-03 13:42:12 +00:00
|
|
|
describe('AgencyTerm', () => {
|
|
|
|
describe('Component vnAgencyTermCreateInvoiceIn', () => {
|
2022-03-02 13:59:30 +00:00
|
|
|
let controller;
|
|
|
|
let $scope;
|
|
|
|
let $httpBackend;
|
|
|
|
let $httpParamSerializer;
|
|
|
|
|
2022-03-03 13:42:12 +00:00
|
|
|
beforeEach(ngModule('route'));
|
2022-03-02 13:59:30 +00:00
|
|
|
|
|
|
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
2022-03-03 13:42:12 +00:00
|
|
|
const $element = angular.element('<vn-agency-term-create-invoice-in></vn-agency-term-create-invoice-in>');
|
|
|
|
controller = $componentController('vnAgencyTermCreateInvoiceIn', {$element});
|
|
|
|
controller._route = {
|
|
|
|
id: 1
|
|
|
|
};
|
2022-03-02 13:59:30 +00:00
|
|
|
}));
|
|
|
|
|
2022-03-03 13:42:12 +00:00
|
|
|
describe('$onChanges()', () => {
|
|
|
|
it('should update the params data when $params.q is defined', () => {
|
|
|
|
controller.$params = {q: '{"supplierName": "Plants SL","rows": null}'};
|
|
|
|
|
|
|
|
const params = {q: '{"supplierName": "Plants SL", "rows": null}'};
|
|
|
|
const json = JSON.parse(params.q);
|
|
|
|
|
|
|
|
controller.$onChanges();
|
|
|
|
|
|
|
|
expect(controller.params).toEqual(json);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('route() setter', () => {
|
|
|
|
it('should set the ticket data and then call setDefaultParams() and getAllowedContentTypes()', () => {
|
2022-03-02 13:59:30 +00:00
|
|
|
jest.spyOn(controller, 'setDefaultParams');
|
|
|
|
jest.spyOn(controller, 'getAllowedContentTypes');
|
2022-03-03 13:42:12 +00:00
|
|
|
controller.route = {
|
|
|
|
id: 1
|
2022-03-02 13:59:30 +00:00
|
|
|
};
|
|
|
|
|
2022-03-03 13:42:12 +00:00
|
|
|
expect(controller.route).toBeDefined();
|
2022-03-02 13:59:30 +00:00
|
|
|
expect(controller.setDefaultParams).toHaveBeenCalledWith();
|
|
|
|
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-03-03 13:42:12 +00:00
|
|
|
describe('getAllowedContentTypes()', () => {
|
|
|
|
it('should make an HTTP GET request to get the allowed content types', () => {
|
|
|
|
const expectedResponse = ['image/png', 'image/jpg'];
|
|
|
|
$httpBackend.expect('GET', `DmsContainers/allowedContentTypes`).respond(expectedResponse);
|
|
|
|
controller.getAllowedContentTypes();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.allowedContentTypes).toBeDefined();
|
|
|
|
expect(controller.allowedContentTypes).toEqual('image/png, image/jpg');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-03-02 13:59:30 +00:00
|
|
|
describe('setDefaultParams()', () => {
|
|
|
|
it('should perform a GET query and define the dms property on controller', () => {
|
2022-03-08 12:42:44 +00:00
|
|
|
const params = {filter: {
|
2022-03-03 13:42:12 +00:00
|
|
|
where: {code: 'invoiceIn'}
|
2022-03-02 13:59:30 +00:00
|
|
|
}};
|
2022-03-08 12:42:44 +00:00
|
|
|
const serializedParams = $httpParamSerializer(params);
|
2022-03-03 13:42:12 +00:00
|
|
|
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 1, code: 'invoiceIn'});
|
|
|
|
controller.params = {supplierName: 'Plants SL'};
|
2022-03-02 13:59:30 +00:00
|
|
|
controller.setDefaultParams();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.dms).toBeDefined();
|
2022-03-03 13:42:12 +00:00
|
|
|
expect(controller.dms.dmsTypeId).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onSubmit()', () => {
|
|
|
|
it('should make an HTTP POST request to save the form data', () => {
|
|
|
|
controller.$.watcher = watcher;
|
|
|
|
|
|
|
|
jest.spyOn(controller.$.watcher, 'updateOriginalData');
|
|
|
|
const files = [{id: 1, name: 'MyFile'}];
|
|
|
|
controller.dms = {files};
|
|
|
|
const serializedParams = $httpParamSerializer(controller.dms);
|
|
|
|
const query = `dms/uploadFile?${serializedParams}`;
|
|
|
|
controller.params = {rows: null};
|
|
|
|
|
|
|
|
$httpBackend.expect('POST', query).respond({});
|
|
|
|
$httpBackend.expect('POST', 'AgencyTerms/createInvoiceIn').respond({});
|
|
|
|
controller.onSubmit();
|
|
|
|
$httpBackend.flush();
|
2022-03-02 13:59:30 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onFileChange()', () => {
|
|
|
|
it('should set dms hasFileAttached property to true if has any files', () => {
|
|
|
|
const files = [{id: 1, name: 'MyFile'}];
|
|
|
|
controller.onFileChange(files);
|
|
|
|
$scope.$apply();
|
|
|
|
|
|
|
|
expect(controller.dms.hasFileAttached).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|