import { inject, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { RouterTestingModule } from "@angular/router/testing";
import { Component } from '@angular/core';
import { BixiLayoutModule } from '.';
import { TranslateModule } from '@ngx-translate/core';
import { BixiLayoutService } from './layout.service';
import { TableOutline, UserOutline } from '@ant-design/icons-angular/icons';
import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations';
import { NzIconModule } from 'ng-zorro-antd';
import { ActivatedRoute } from '@angular/router';
import { of } from 'rxjs';

const icons = [TableOutline, UserOutline];

describe('bixi layout', () => {
  let srv: BixiLayoutService;

  beforeEach(async () => {
    TestBed.configureTestingModule({
      imports: [BixiLayoutModule, TranslateModule.forRoot(), NzIconModule.forRoot(icons), RouterTestingModule.withRoutes([]), BrowserAnimationsModule, NoopAnimationsModule],
      providers: [
        BixiLayoutService,
        {
          provide: ActivatedRoute,
          useValue: {
            params: of([{ id: 1 }]),
          },
        }
      ],
      declarations: [BixiLayoutServiceComponent]
    }).compileComponents();
  });

  beforeEach(inject([BixiLayoutService], (layoutService: BixiLayoutService) => {
    srv = layoutService;
  }));

  it('should be init', () => {
    srv.headerVisible$.subscribe((res) => {
      expect(res).toBe(true);
    })
    srv.openChange.subscribe((res) => {
      expect(res).toBe(true);
    })
    srv.menuVisible$.subscribe((res) => {
      expect(res).toBe(true);
    })
    srv.breadcrumb$.subscribe((res) => {
      expect(res).toEqual([]);
    })
  })

  // toggle menu
  it('should be toggle menu', fakeAsync(() => {
    srv.toggleMenu();
    srv.toggleHeader();
    tick(200);
    srv.openChange.subscribe((res) => {
      expect(res).toBe(false);
    })
    srv.headerVisible$.subscribe((res) => {
      expect(res).toBe(false);
    })
  }))

  // setBreadcrumbs
  it('shold be update bread', fakeAsync(() => {
    srv.setBreadcrumbs(() => ([
      { name: '1' }, { name: '2' }
    ]));
    tick(200);
    srv.breadcrumb$.subscribe((res) => {
      expect(res.length).toBe(2);
    })
  }))
});


@Component({
  selector: 'app-demo',
  template: ''
})
export class BixiLayoutServiceComponent {

}
