tested controller modifications accordingly
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
0c71b915ca
commit
d20b717c1b
|
@ -19,46 +19,67 @@ describe('Zone Component vnZoneDeliveryDays', () => {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('deliveryMethodFk() setter', () => {
|
describe('deliveryMethodFk() setter', () => {
|
||||||
it(`should set the deliveryMethodFk property and check just agencymode focus`, () => {
|
it('should set the deliveryMethodFk property as pickup and then perform a query that sets the filter', () => {
|
||||||
controller.$.agencymode = {focus: jasmine.createSpy('focus')};
|
$httpBackend.expect('GET', 'DeliveryMethods').respond([{id: 999}]);
|
||||||
|
|
||||||
controller.deliveryMethodFk = 'pickUp';
|
controller.deliveryMethodFk = 'pickUp';
|
||||||
|
|
||||||
expect(controller.$.agencymode.focus).toHaveBeenCalledWith();
|
|
||||||
});
|
|
||||||
|
|
||||||
it(`should set the deliveryMethodFk property, call method http and sets the agencyfilter`, () => {
|
|
||||||
$httpBackend.when('GET', 'DeliveryMethods').respond([{id: 'id'}]);
|
|
||||||
|
|
||||||
controller.deliveryMethodFk = 'no pickUp';
|
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.agencyFilter).toEqual({deliveryMethodFk: {inq: ['id']}});
|
expect(controller.agencyFilter).toEqual({deliveryMethodFk: {inq: [999]}});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('onSubmit()', () => {
|
describe('setParams()', () => {
|
||||||
|
it('should do nothing when no params are received', () => {
|
||||||
|
controller.setParams();
|
||||||
|
|
||||||
|
expect(controller.deliveryMethodFk).toBeUndefined();
|
||||||
|
expect(controller.geoFk).toBeUndefined();
|
||||||
|
expect(controller.agencyModeFk).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set the controller properties when the params are provided', () => {
|
||||||
|
controller.$params = {
|
||||||
|
deliveryMethodFk: 3,
|
||||||
|
geoFk: 2,
|
||||||
|
agencyModeFk: 1
|
||||||
|
};
|
||||||
|
controller.setParams();
|
||||||
|
|
||||||
|
expect(controller.deliveryMethodFk).toEqual(controller.$params.deliveryMethodFk);
|
||||||
|
expect(controller.geoFk).toEqual(controller.$params.geoFk);
|
||||||
|
expect(controller.agencyModeFk).toEqual(controller.$params.agencyModeFk);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('fetchData()', () => {
|
||||||
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');
|
||||||
|
jest.spyOn(controller.$state, 'go');
|
||||||
|
|
||||||
|
controller.agencyModeFk = 1;
|
||||||
|
controller.deliveryMethodFk = 2;
|
||||||
|
controller.geoFk = 3;
|
||||||
|
controller.$state.current.name = 'myState';
|
||||||
|
|
||||||
const expectedData = {events: []};
|
const expectedData = {events: []};
|
||||||
$httpBackend.when('GET', 'Zones/getEvents').respond({events: []});
|
|
||||||
controller.onSubmit();
|
const url = 'Zones/getEvents?agencyModeFk=1&deliveryMethodFk=2&geoFk=3';
|
||||||
|
|
||||||
|
$httpBackend.when('GET', 'DeliveryMethods').respond([]);
|
||||||
|
$httpBackend.expect('GET', url).respond({events: []});
|
||||||
|
controller.fetchData();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
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');
|
||||||
});
|
expect(controller.$state.go).toHaveBeenCalledWith(
|
||||||
|
controller.$state.current.name,
|
||||||
it('should make an HTTP GET query and then set the data property', () => {
|
{
|
||||||
const expectedData = {events: [{zoneFk: 1}]};
|
agencyModeFk: 1,
|
||||||
$httpBackend.when('GET', 'Zones/getEvents').respond({events: [{zoneFk: 1}]});
|
deliveryMethodFk: 2,
|
||||||
controller.onSubmit();
|
geoFk: 3
|
||||||
$httpBackend.flush();
|
}
|
||||||
|
);
|
||||||
expect(controller.$.data).toBeDefined();
|
|
||||||
expect(controller.$.data).toEqual(expectedData);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue