import './index.js';
import watcher from 'core/mocks/watcher';

describe('InvoiceIn', () => {
    describe('Component vnInvoiceInCreate', () => {
        let controller;
        let $element;

        beforeEach(ngModule('invoiceIn'));

        beforeEach(inject(($componentController, $rootScope) => {
            const $scope = $rootScope.$new();
            $scope.watcher = watcher;
            $element = angular.element('<vn-invoice-in-create></vn-invoice-in-create>');
            controller = $componentController('vnInvoiceInCreate', {$element, $scope});
            controller.$params = {};
        }));

        afterEach(() => {
            $element.remove();
        });

        describe('onInit()', () => {
            it(`should defined the controller's invoiceIn property`, () => {
                expect(controller.invoiceIn).toBeUndefined();

                controller.$onInit();

                expect(controller.invoiceIn).toEqual({});
            });

            it(`should define invoiceIn and it's supplierFk when received via params`, () => {
                controller.$params.supplierFk = 'supplierId';

                controller.$onInit();

                expect(controller.invoiceIn.supplierFk).toEqual('supplierId');
            });
        });

        describe('onSubmit()', () => {
            it(`should redirect to basic data by calling the $state.go function`, () => {
                jest.spyOn(controller.$state, 'go');

                controller.onSubmit();

                expect(controller.$state.go).toHaveBeenCalledWith('invoiceIn.card.basicData', {id: 1234});
            });
        });
    });
});