salix/modules/travel/front/search-panel/index.spec.js

39 lines
1.2 KiB
JavaScript

import './index';
describe('Travel Component vnTravelSearchPanel', () => {
let controller;
beforeEach(ngModule('travel'));
beforeEach(inject($componentController => {
controller = $componentController('vnTravelSearchPanel', {$element: null});
controller.$t = () => {};
}));
describe('applyFilters()', () => {
it('should apply filters', async() => {
controller.filter = {foo: 'bar'};
controller.model = {
applyFilter: jest.fn().mockResolvedValue(),
_orgData: [{id: 1}]
};
controller.$state = {
current: {
name: 'foo'
},
go: jest.fn()
};
await controller.applyFilters(true);
expect(controller.model.applyFilter).toHaveBeenCalledWith({}, controller.filter);
expect(controller.$state.go).toHaveBeenCalledWith('travel.card.summary', {id: 1});
await controller.applyFilters(false);
expect(controller.$state.go).toHaveBeenCalledWith(controller.$state.current.name,
{q: JSON.stringify(controller.filter)}, {location: 'replace'});
});
});
});