2018-07-31 09:08:22 +00:00
|
|
|
import './index';
|
|
|
|
|
2019-01-30 07:28:09 +00:00
|
|
|
describe('Client', () => {
|
2018-07-31 09:08:22 +00:00
|
|
|
describe('Component vnClientSampleCreate', () => {
|
2019-11-06 08:32:54 +00:00
|
|
|
let $httpParamSerializer;
|
2018-07-31 09:08:22 +00:00
|
|
|
let $scope;
|
2019-11-11 10:23:39 +00:00
|
|
|
let $element;
|
2018-07-31 09:08:22 +00:00
|
|
|
let $httpBackend;
|
|
|
|
let $state;
|
|
|
|
let controller;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, $rootScope, _$state_, _$httpParamSerializer_) => {
|
2018-07-31 09:08:22 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$scope.sampleType = {};
|
|
|
|
$scope.watcher = {
|
|
|
|
check: () => {},
|
|
|
|
realSubmit: () => {
|
|
|
|
return {
|
|
|
|
then: callback => {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$scope.showPreview = {
|
|
|
|
element: {
|
|
|
|
querySelector: () => {
|
|
|
|
return {
|
|
|
|
innerHTML: () => {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
show: () => {}
|
|
|
|
};
|
|
|
|
$state = _$state_;
|
2021-06-23 11:24:23 +00:00
|
|
|
$state.params.id = 1101;
|
2018-07-31 09:08:22 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2019-11-06 08:32:54 +00:00
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
2019-11-11 10:23:39 +00:00
|
|
|
$element = angular.element('<vn-client-sample-create></vn-client-sample-create>');
|
|
|
|
controller = $componentController('vnClientSampleCreate', {$element, $scope});
|
2022-10-04 07:21:24 +00:00
|
|
|
controller._client = {id: 1101};
|
2020-02-18 10:14:02 +00:00
|
|
|
const element = document.createElement('div');
|
|
|
|
document.body.querySelector = () => {
|
|
|
|
return {
|
|
|
|
querySelector: () => {
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
2022-10-04 07:21:24 +00:00
|
|
|
// $httpBackend.expectGET('EmailUsers?filter=%7B%22where%22:%7B%7D%7D').respond();
|
2018-07-31 09:08:22 +00:00
|
|
|
}));
|
|
|
|
|
2020-02-18 10:14:02 +00:00
|
|
|
describe('onSubmit()', () => {
|
2022-10-04 05:41:40 +00:00
|
|
|
it(`should call send() method`, () => {
|
2022-10-04 07:21:24 +00:00
|
|
|
controller.send = jest.fn();
|
|
|
|
|
|
|
|
controller.$.sampleType.selection = {
|
|
|
|
hasCompany: false,
|
|
|
|
code: 'MyReport',
|
|
|
|
model: 'Clients'
|
|
|
|
};
|
|
|
|
|
|
|
|
controller.clientSample = {
|
|
|
|
recipient: 'email@email'
|
|
|
|
};
|
|
|
|
|
2020-02-18 10:14:02 +00:00
|
|
|
controller.onSubmit();
|
|
|
|
|
2022-10-04 05:41:40 +00:00
|
|
|
expect(controller.send).toHaveBeenCalledWith();
|
2020-02-18 10:14:02 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('send()', () => {
|
|
|
|
it(`should not perform an HTTP query if no recipient is specified`, () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$http, 'get');
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2019-11-11 10:23:39 +00:00
|
|
|
controller.$.sampleType.selection = {
|
2018-07-31 09:08:22 +00:00
|
|
|
hasCompany: false,
|
2022-10-04 05:41:40 +00:00
|
|
|
code: 'MyReport',
|
|
|
|
model: 'Clients'
|
2018-07-31 09:08:22 +00:00
|
|
|
};
|
|
|
|
controller.clientSample = {
|
2021-06-23 11:24:23 +00:00
|
|
|
recipientId: 1101
|
2018-07-31 09:08:22 +00:00
|
|
|
};
|
|
|
|
|
2022-10-04 07:21:24 +00:00
|
|
|
controller.send();
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2020-02-18 10:14:02 +00:00
|
|
|
expect(controller.$http.get).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`should not perform an HTTP query if no sample is specified`, () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$http, 'get');
|
2020-02-18 10:14:02 +00:00
|
|
|
|
|
|
|
controller.$.sampleType.selection = null;
|
|
|
|
controller.clientSample = {
|
2021-06-23 11:24:23 +00:00
|
|
|
recipientId: 1101,
|
2020-02-18 10:14:02 +00:00
|
|
|
recipient: 'client@email.com'
|
2019-11-06 08:32:54 +00:00
|
|
|
};
|
|
|
|
|
2022-10-04 07:21:24 +00:00
|
|
|
controller.send();
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2020-02-18 10:14:02 +00:00
|
|
|
expect(controller.$http.get).not.toHaveBeenCalled();
|
2018-07-31 09:08:22 +00:00
|
|
|
});
|
|
|
|
|
2020-02-18 10:14:02 +00:00
|
|
|
it(`should not perform an HTTP query if company is required and not specified`, () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$http, 'get');
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2019-11-11 10:23:39 +00:00
|
|
|
controller.$.sampleType.selection = {
|
2018-07-31 09:08:22 +00:00
|
|
|
hasCompany: true,
|
|
|
|
code: 'MyReport'
|
|
|
|
};
|
|
|
|
controller.clientSample = {
|
2021-06-23 11:24:23 +00:00
|
|
|
recipientId: 1101,
|
2020-02-18 10:14:02 +00:00
|
|
|
recipient: 'client@email.com'
|
2019-11-06 08:32:54 +00:00
|
|
|
};
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2022-10-04 07:21:24 +00:00
|
|
|
controller.send();
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2020-02-18 10:14:02 +00:00
|
|
|
expect(controller.$http.get).not.toHaveBeenCalled();
|
2018-07-31 09:08:22 +00:00
|
|
|
});
|
|
|
|
|
2020-02-26 13:45:47 +00:00
|
|
|
it(`should perform an HTTP query without passing companyFk param`, () => {
|
2022-10-04 07:21:24 +00:00
|
|
|
$state.go = jest.fn();
|
|
|
|
|
2019-11-11 10:23:39 +00:00
|
|
|
controller.$.sampleType.selection = {
|
2018-07-31 09:08:22 +00:00
|
|
|
hasCompany: false,
|
2022-10-04 07:21:24 +00:00
|
|
|
code: 'my-report',
|
|
|
|
model: 'Clients'
|
2018-07-31 09:08:22 +00:00
|
|
|
};
|
|
|
|
controller.clientSample = {
|
2021-06-23 11:24:23 +00:00
|
|
|
recipientId: 1101,
|
2020-02-18 10:14:02 +00:00
|
|
|
recipient: 'client@email.com'
|
2019-11-06 08:32:54 +00:00
|
|
|
};
|
|
|
|
|
2022-10-04 07:21:24 +00:00
|
|
|
const expectedPath = `Clients/${controller.client.id}/my-report-email`;
|
|
|
|
$httpBackend.expect('POST', expectedPath).respond(true);
|
|
|
|
controller.send();
|
2018-07-31 09:08:22 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
});
|
|
|
|
|
2020-02-26 13:45:47 +00:00
|
|
|
it(`should perform an HTTP query passing companyFk param`, () => {
|
2022-10-04 07:21:24 +00:00
|
|
|
$state.go = jest.fn();
|
|
|
|
|
2019-11-11 10:23:39 +00:00
|
|
|
controller.$.sampleType.selection = {
|
2018-07-31 09:08:22 +00:00
|
|
|
hasCompany: true,
|
2022-10-04 07:21:24 +00:00
|
|
|
code: 'my-report',
|
|
|
|
model: 'Clients'
|
2018-07-31 09:08:22 +00:00
|
|
|
};
|
|
|
|
controller.clientSample = {
|
2021-06-23 11:24:23 +00:00
|
|
|
recipientId: 1101,
|
2020-02-26 13:45:47 +00:00
|
|
|
recipient: 'client@email.com',
|
|
|
|
companyFk: 442
|
|
|
|
};
|
2019-11-06 08:32:54 +00:00
|
|
|
|
2022-10-04 07:21:24 +00:00
|
|
|
const expectedPath = `Clients/${controller.client.id}/my-report-email`;
|
|
|
|
$httpBackend.expect('POST', expectedPath).respond(true);
|
|
|
|
controller.send();
|
2018-07-31 09:08:22 +00:00
|
|
|
$httpBackend.flush();
|
2020-02-18 10:14:02 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-10-04 07:21:24 +00:00
|
|
|
describe('preview()', () => {
|
2020-02-18 10:14:02 +00:00
|
|
|
it(`should open a sample preview`, () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$.showPreview, 'show');
|
2020-02-18 10:14:02 +00:00
|
|
|
|
2022-10-04 07:21:24 +00:00
|
|
|
controller.$.sampleType.selection = {
|
|
|
|
hasCompany: true,
|
|
|
|
code: 'my-report',
|
|
|
|
model: 'Clients'
|
|
|
|
};
|
|
|
|
controller.clientSample = {
|
|
|
|
recipientId: 1101,
|
|
|
|
recipient: 'client@email.com',
|
|
|
|
companyFk: 442
|
2020-02-18 10:14:02 +00:00
|
|
|
};
|
|
|
|
|
2022-10-04 07:21:24 +00:00
|
|
|
const expectedParams = {
|
|
|
|
companyId: 442,
|
|
|
|
recipientId: 1101
|
2020-02-18 10:14:02 +00:00
|
|
|
};
|
2022-10-04 07:21:24 +00:00
|
|
|
const serializedParams = $httpParamSerializer(expectedParams);
|
2018-07-31 09:08:22 +00:00
|
|
|
|
2022-10-04 07:21:24 +00:00
|
|
|
const expectedPath = `Clients/${controller.client.id}/my-report-html?${serializedParams}`;
|
|
|
|
$httpBackend.expect('GET', expectedPath).respond(true);
|
|
|
|
controller.preview();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.$.showPreview.show).toHaveBeenCalledWith();
|
2018-07-31 09:08:22 +00:00
|
|
|
});
|
|
|
|
});
|
2021-04-07 12:14:31 +00:00
|
|
|
|
2023-02-22 12:04:27 +00:00
|
|
|
describe('setClientSample()', () => {
|
2021-04-07 12:14:31 +00:00
|
|
|
it(`should perform a query and then set the replyTo property to the clientSample object`, () => {
|
2023-02-22 12:04:27 +00:00
|
|
|
const client = {email: 'test@example.com'};
|
2021-04-07 12:14:31 +00:00
|
|
|
const expectedEmail = 'batman@arkhamcity.com';
|
|
|
|
const serializedParams = $httpParamSerializer({filter: {where: {}}});
|
|
|
|
$httpBackend.expect('GET', `EmailUsers?${serializedParams}`).respond([{email: expectedEmail}]);
|
2023-02-22 12:04:27 +00:00
|
|
|
controller.setClientSample(client);
|
2021-04-07 12:14:31 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.clientSample.replyTo).toEqual(expectedEmail);
|
2023-02-22 12:04:27 +00:00
|
|
|
expect(controller.clientSample.clientFk).toEqual(controller.$params.id);
|
|
|
|
expect(controller.clientSample.recipient).toEqual(client.email);
|
|
|
|
expect(controller.clientSample.companyId).toEqual(controller.vnConfig.companyFk);
|
2021-04-07 12:14:31 +00:00
|
|
|
});
|
|
|
|
});
|
2018-07-31 09:08:22 +00:00
|
|
|
});
|
|
|
|
});
|