Add parameteres in the url + test
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
e2db0d5742
commit
ea1d6c14e0
|
@ -3,8 +3,23 @@ import Section from 'salix/components/section';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
class Controller extends Section {
|
class Controller extends Section {
|
||||||
|
constructor($element, $scope, $location) {
|
||||||
|
super($element, $scope);
|
||||||
|
this.$location = $location;
|
||||||
|
}
|
||||||
$onInit() {
|
$onInit() {
|
||||||
|
this.$.params = this.$location.search();
|
||||||
|
if (!this.$.params)
|
||||||
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() {
|
$postLink() {
|
||||||
|
@ -14,8 +29,11 @@ class Controller extends Section {
|
||||||
this.$.data = null;
|
this.$.data = null;
|
||||||
this.$http.get(`Zones/getEvents`, {params: this.$.params})
|
this.$http.get(`Zones/getEvents`, {params: this.$.params})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
let data = res.data;
|
const data = res.data;
|
||||||
this.$.data = 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)
|
if (!data.events.length)
|
||||||
this.vnApp.showMessage(this.$t('No service for the specified zone'));
|
this.vnApp.showMessage(this.$t('No service for the specified zone'));
|
||||||
});
|
});
|
||||||
|
@ -27,7 +45,6 @@ class Controller extends Section {
|
||||||
|
|
||||||
set deliveryMethodFk(value) {
|
set deliveryMethodFk(value) {
|
||||||
this._deliveryMethodFk = value;
|
this._deliveryMethodFk = value;
|
||||||
this.$.params.agencyModeFk = null;
|
|
||||||
let filter;
|
let filter;
|
||||||
if (value === 'pickUp') {
|
if (value === 'pickUp') {
|
||||||
filter = {where: {code: 'PICKUP'}};
|
filter = {where: {code: 'PICKUP'}};
|
||||||
|
@ -67,6 +84,8 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Controller.$inject = ['$element', '$scope', '$location'];
|
||||||
|
|
||||||
ngModule.vnComponent('vnZoneDeliveryDays', {
|
ngModule.vnComponent('vnZoneDeliveryDays', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
controller: Controller
|
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()', () => {
|
describe('onSubmit()', () => {
|
||||||
it('should make an HTTP GET query and then call the showMessage() method', () => {
|
it('should make an HTTP GET query and then call the showMessage() method', () => {
|
||||||
jest.spyOn(controller.vnApp, 'showMessage');
|
jest.spyOn(controller.vnApp, 'showMessage');
|
||||||
|
|
||||||
const expectedData = {events: []};
|
const expectedData = {events: []};
|
||||||
|
const expectedUrl = '/zone/delivery-days';
|
||||||
|
const params = {};
|
||||||
|
|
||||||
$httpBackend.when('GET', 'Zones/getEvents').respond({events: []});
|
$httpBackend.when('GET', 'Zones/getEvents').respond({events: []});
|
||||||
controller.onSubmit();
|
controller.onSubmit();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.$location.path('/zone/delivery-days').search(params).$$url).toEqual(expectedUrl);
|
||||||
expect(controller.$.data).toBeDefined();
|
expect(controller.$.data).toBeDefined();
|
||||||
expect(controller.$.data).toEqual(expectedData);
|
expect(controller.$.data).toEqual(expectedData);
|
||||||
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No service for the specified zone');
|
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', () => {
|
it('should make an HTTP GET query and then set the data property', () => {
|
||||||
const expectedData = {events: [{zoneFk: 1}]};
|
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}]});
|
$httpBackend.when('GET', 'Zones/getEvents').respond({events: [{zoneFk: 1}]});
|
||||||
controller.onSubmit();
|
controller.onSubmit();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.$location.path('/zone/delivery-days').search(params).$$url).toEqual(expectedUrl);
|
||||||
expect(controller.$.data).toBeDefined();
|
expect(controller.$.data).toBeDefined();
|
||||||
expect(controller.$.data).toEqual(expectedData);
|
expect(controller.$.data).toEqual(expectedData);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue