import './index';

describe('Ticket Component vnTicketSearchPanel', () => {
    let $httpBackend;
    let controller;

    beforeEach(ngModule('ticket'));

    beforeEach(inject(($componentController, _$httpBackend_) => {
        $httpBackend = _$httpBackend_;
        controller = $componentController('vnTicketSearchPanel', {$element: null});
        controller.$t = () => {};
        controller.filter = {};
    }));

    describe('getGroupedStates()', () => {
        it('should set an array of groupedStates with the adition of a name translation', () => {
            jest.spyOn(controller, '$t').mockReturnValue('miCodigo');
            const data = [
                {
                    id: 9999,
                    code: 'myCode'
                }
            ];
            $httpBackend.whenGET('AlertLevels').respond(data);
            controller.getGroupedStates();
            $httpBackend.flush();

            expect(controller.groupedStates).toEqual([{
                id: 9999,
                code: 'myCode',
                name: 'miCodigo'
            }]);
        });
    });

    describe('from() setter', () => {
        it('should clear the scope days when setting the from property', () => {
            controller.filter.scopeDays = 1;

            controller.from = Date.vnNew();

            expect(controller.filter.scopeDays).toBeNull();
            expect(controller.from).toBeDefined();
        });
    });

    describe('to() setter', () => {
        it('should clear the scope days when setting the to property', () => {
            controller.filter.scopeDays = 1;

            controller.to = Date.vnNew();

            expect(controller.filter.scopeDays).toBeNull();
            expect(controller.to).toBeDefined();
        });
    });

    describe('scopeDays() setter', () => {
        it('should clear the date range when setting the scopeDays property', () => {
            controller.filter.from = Date.vnNew();
            controller.filter.to = Date.vnNew();

            controller.scopeDays = 1;

            expect(controller.filter.from).toBeNull();
            expect(controller.filter.to).toBeNull();
            expect(controller.scopeDays).toBeDefined();
        });
    });
});