refactor(defaulter): array request
This commit is contained in:
parent
7cf252a8f1
commit
368498d763
|
@ -64,8 +64,8 @@ describe('Client defaulter path', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should first observation changed', async() => {
|
it('should first observation changed', async() => {
|
||||||
const result = await page.waitToGetProperty(selectors.clientDefaulter.firstObservation, 'value');
|
|
||||||
const message = await page.waitForSnackbar();
|
const message = await page.waitForSnackbar();
|
||||||
|
const result = await page.waitToGetProperty(selectors.clientDefaulter.firstObservation, 'value');
|
||||||
|
|
||||||
expect(message.text).toContain('Observation saved!');
|
expect(message.text).toContain('Observation saved!');
|
||||||
expect(result).toContain('My new observation');
|
expect(result).toContain('My new observation');
|
||||||
|
|
|
@ -36,15 +36,18 @@ export default class Controller extends Section {
|
||||||
if (!this.defaulter.observation)
|
if (!this.defaulter.observation)
|
||||||
throw new UserError(`The message can't be empty`);
|
throw new UserError(`The message can't be empty`);
|
||||||
|
|
||||||
|
const params = [];
|
||||||
for (let defaulter of this.checked) {
|
for (let defaulter of this.checked) {
|
||||||
const params = {
|
params.push({
|
||||||
text: this.defaulter.observation,
|
text: this.defaulter.observation,
|
||||||
clientFk: defaulter.clientFk
|
clientFk: defaulter.clientFk
|
||||||
};
|
});
|
||||||
this.$http.post(`ClientObservations`, params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.$http.post(`ClientObservations`, params) .then(() => {
|
||||||
this.vnApp.showMessage(this.$t('Observation saved!'));
|
this.vnApp.showMessage(this.$t('Observation saved!'));
|
||||||
this.$state.reload();
|
this.$state.reload();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
exprBuilder(param, value) {
|
exprBuilder(param, value) {
|
||||||
|
|
|
@ -4,10 +4,12 @@ import crudModel from 'core/mocks/crud-model';
|
||||||
describe('client defaulter', () => {
|
describe('client defaulter', () => {
|
||||||
describe('Component vnClientDefaulterIndex', () => {
|
describe('Component vnClientDefaulterIndex', () => {
|
||||||
let controller;
|
let controller;
|
||||||
|
let $httpBackend;
|
||||||
|
|
||||||
beforeEach(ngModule('client'));
|
beforeEach(ngModule('client'));
|
||||||
|
|
||||||
beforeEach(inject($componentController => {
|
beforeEach(inject(($componentController, _$httpBackend_) => {
|
||||||
|
$httpBackend = _$httpBackend_;
|
||||||
const $element = angular.element('<vn-client-defaulter></vn-client-defaulter>');
|
const $element = angular.element('<vn-client-defaulter></vn-client-defaulter>');
|
||||||
controller = $componentController('vnClientDefaulterIndex', {$element});
|
controller = $componentController('vnClientDefaulterIndex', {$element});
|
||||||
controller.$.model = crudModel;
|
controller.$.model = crudModel;
|
||||||
|
@ -63,9 +65,17 @@ describe('client defaulter', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return saved message', () => {
|
it('should return saved message', () => {
|
||||||
controller.defaulter = {observation: 'asdasd'};
|
const data = controller.$.model.data;
|
||||||
|
data[1].checked = true;
|
||||||
|
controller.defaulter = {observation: 'My new observation'};
|
||||||
|
|
||||||
|
const params = [{text: controller.defaulter.observation, clientFk: data[1].clientFk}];
|
||||||
|
|
||||||
jest.spyOn(controller.vnApp, 'showMessage');
|
jest.spyOn(controller.vnApp, 'showMessage');
|
||||||
|
$httpBackend.expect('POST', `ClientObservations`, params).respond(200, params);
|
||||||
|
|
||||||
controller.onResponse();
|
controller.onResponse();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Observation saved!');
|
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Observation saved!');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue