import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ResultTipComponent } from './result-tip.component';
import {
    UserPermissionDefaultService,
    UserPermissionService,
    VulnerabilitySummary,
} from '../../../../../shared/services';
import { VULNERABILITY_SCAN_STATUS } from '../../../../../shared/units/utils';
import { SharedTestingModule } from '../../../../../shared/shared.module';

describe('ResultTipComponent (inline template)', () => {
    let component: ResultTipComponent;
    let fixture: ComponentFixture<ResultTipComponent>;
    let mockData: VulnerabilitySummary = {
        scan_status: VULNERABILITY_SCAN_STATUS.SUCCESS,
        severity: 'High',
        end_time: new Date(),
        summary: {
            total: 124,
            fixable: 50,
            summary: {
                High: 5,
                Low: 5,
            },
        },
    };

    beforeEach(async () => {
        await TestBed.configureTestingModule({
            imports: [SharedTestingModule],
            declarations: [ResultTipComponent],
            providers: [
                {
                    provide: UserPermissionService,
                    useClass: UserPermissionDefaultService,
                },
            ],
        }).compileComponents();
    });

    beforeEach(() => {
        fixture = TestBed.createComponent(ResultTipComponent);
        component = fixture.componentInstance;
        component.summary = mockData;

        fixture.detectChanges();
    });

    it('should be created', () => {
        expect(component).toBeTruthy();
    });

    it('should reader the bar with different width', () => {
        fixture.detectChanges();
        fixture.whenStable().then(() => {
            fixture.detectChanges();
            let el: HTMLElement =
                fixture.nativeElement.querySelector('.bar-block-none');
            expect(el).not.toBeNull();
            expect(el.style.width).toEqual('0px');
            let el2: HTMLElement =
                fixture.nativeElement.querySelector('.bar-block-high');
            expect(el2).not.toBeNull();
            expect(el2.style.width).toEqual('0px');
        });
    });
});
