import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { OnlineBoardFlightsMiniListComponent } from '@online-board/pages/flight-details/components/flights-mini-list/online-board-flights-mini-list.component';

describe('OnlineBoardFlightsMiniListComponent', () => {
    let fixture: ComponentFixture<OnlineBoardFlightsMiniListComponent>;
    let component: OnlineBoardFlightsMiniListComponent;

    const emitMock = jasmine.createSpy('emit');

    beforeEach(async () => {
        await TestBed.configureTestingModule({
            declarations: [OnlineBoardFlightsMiniListComponent],
            schemas: [NO_ERRORS_SCHEMA],
        });
    });

    beforeEach(() => {
        fixture = TestBed.createComponent(OnlineBoardFlightsMiniListComponent);
        component = fixture.componentInstance;

        (component.open as any) = {
            emit: emitMock,
        };
        emitMock.calls.reset();
    });

    it('should not emit open event because no flight was provided', () => {
        component.openFlight();
        expect(emitMock).not.toHaveBeenCalled();
    });

    it('should emit open event', () => {
        const flight = { pId: '111' } as any;
        component.openFlight(flight);
        expect(emitMock).toHaveBeenCalledWith(flight);
    });

    it('should return false because no flights were provided', () => {
        component.flight = { pId: '111' } as any;

        expect(component.isFlightSelected({ pId: '111' } as any)).toBe(false);
    });

    it('should return false because flights array contains only one item', () => {
        const flight = { pId: '111' } as any;
        component.flightsLegacy = [flight];

        expect(component.isFlightSelected(flight)).toBe(false);
    });

    it('should return true if flight is selected', () => {
        const firstFlight = { pId: '111' } as any;
        const secondFlight = { pId: '222' } as any;
        component.flightsLegacy = [firstFlight, secondFlight] as any;
        component.flight = firstFlight;

        expect(component.isFlightSelected(firstFlight)).toBe(true);
        expect(component.isFlightSelected(secondFlight)).toBe(false);
    });
});
