2747 Zone delivery days save parameters in the url #581
|
@ -3,19 +3,43 @@ import Section from 'salix/components/section';
|
|||
import './style.scss';
|
||||
|
||||
class Controller extends Section {
|
||||
constructor($element, $scope, $location) {
|
||||
super($element, $scope);
|
||||
this.$location = $location;
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
this.$.params = {};
|
||||
this.$.params = this.$location.search();
|
||||
if (!this.$.params)
|
||||
this.$.params = {};
|
||||
this.$.data = null;
|
||||
|
||||
this.$http.get(`Zones/getEvents`, {params: this.$.params})
|
||||
.then(res => {
|
||||
const data = res.data;
|
||||
this.$.data = data;
|
||||
const agencyModeFk = this.$.params.agencyModeFk;
|
||||
const geoFk = this.$.params.geoFk;
|
||||
|
||||
this.$location.path('/zone/delivery-days').search({agencyModeFk, geoFk});
|
||||
});
|
||||
}
|
||||
|
||||
$postLink() {
|
||||
this.deliveryMethodFk = 'delivery';
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
this.$.data = null;
|
||||
|
||||
this.$http.get(`Zones/getEvents`, {params: this.$.params})
|
||||
.then(res => {
|
||||
let data = res.data;
|
||||
const data = res.data;
|
||||
this.$.data = data;
|
||||
const agencyModeFk = this.$.params.agencyModeFk;
|
||||
const geoFk = this.$.params.geoFk;
|
||||
|
||||
this.$location.path('/zone/delivery-days').search({agencyModeFk, geoFk});
|
||||
if (!data.events.length)
|
||||
this.vnApp.showMessage(this.$t('No service for the specified zone'));
|
||||
});
|
||||
|
@ -27,7 +51,6 @@ class Controller extends Section {
|
|||
|
||||
set deliveryMethodFk(value) {
|
||||
this._deliveryMethodFk = value;
|
||||
this.$.params.agencyModeFk = null;
|
||||
let filter;
|
||||
if (value === 'pickUp') {
|
||||
filter = {where: {code: 'PICKUP'}};
|
||||
|
@ -67,6 +90,8 @@ class Controller extends Section {
|
|||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$element', '$scope', '$location'];
|
||||
|
||||
ngModule.vnComponent('vnZoneDeliveryDays', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller
|
||||
|
|
|
@ -37,15 +37,50 @@ describe('Zone Component vnZoneDeliveryDays', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('$onInit()', () => {
|
||||
it('should set params empty by default', () => {
|
||||
const expectedData = {events: []};
|
||||
const expectedUrl = '/zone/delivery-days';
|
||||
const params = {};
|
||||
|
||||
$httpBackend.when('GET', 'Zones/getEvents').respond({events: []});
|
||||
controller.$onInit();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.$location.path('/zone/delivery-days').search(params).$$url).toEqual(expectedUrl);
|
||||
expect(controller.$.data).toBeDefined();
|
||||
expect(controller.$.data).toEqual(expectedData);
|
||||
});
|
||||
|
||||
it('should do load the params that has been saved in the URL when page open', () => {
|
||||
const expectedData = {events: [{zoneFk: 1}]};
|
||||
const expectedUrl = '/zone/delivery-days?agencyModeFk=1&geoFk=1';
|
||||
const params = {
|
||||
agencyModeFk: 1,
|
||||
geoFk: 1};
|
||||
|
||||
$httpBackend.when('GET', 'Zones/getEvents').respond({events: [{zoneFk: 1}]});
|
||||
controller.$onInit();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.$location.path('/zone/delivery-days').search(params).$$url).toEqual(expectedUrl);
|
||||
expect(controller.$.data).toBeDefined();
|
||||
expect(controller.$.data).toEqual(expectedData);
|
||||
});
|
||||
});
|
||||
|
||||
describe('onSubmit()', () => {
|
||||
it('should make an HTTP GET query and then call the showMessage() method', () => {
|
||||
jest.spyOn(controller.vnApp, 'showMessage');
|
||||
|
||||
const expectedData = {events: []};
|
||||
const expectedUrl = '/zone/delivery-days';
|
||||
const params = {};
|
||||
|
||||
$httpBackend.when('GET', 'Zones/getEvents').respond({events: []});
|
||||
controller.onSubmit();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.$location.path('/zone/delivery-days').search(params).$$url).toEqual(expectedUrl);
|
||||
expect(controller.$.data).toBeDefined();
|
||||
expect(controller.$.data).toEqual(expectedData);
|
||||
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No service for the specified zone');
|
||||
|
@ -53,10 +88,16 @@ describe('Zone Component vnZoneDeliveryDays', () => {
|
|||
|
||||
it('should make an HTTP GET query and then set the data property', () => {
|
||||
const expectedData = {events: [{zoneFk: 1}]};
|
||||
const expectedUrl = '/zone/delivery-days?agencyModeFk=1&geoFk=1';
|
||||
const params = {
|
||||
agencyModeFk: 1,
|
||||
geoFk: 1};
|
||||
|
||||
$httpBackend.when('GET', 'Zones/getEvents').respond({events: [{zoneFk: 1}]});
|
||||
controller.onSubmit();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.$location.path('/zone/delivery-days').search(params).$$url).toEqual(expectedUrl);
|
||||
expect(controller.$.data).toBeDefined();
|
||||
expect(controller.$.data).toEqual(expectedData);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue