definma-ui/src/app/app.component.spec.ts
2020-08-17 14:51:02 +02:00

69 lines
2.3 KiB
TypeScript

import {TestBed, async, ComponentFixture} from '@angular/core/testing';
import { AppComponent } from './app.component';
import {By} from '@angular/platform-browser';
import {RbUiComponentsModule} from '@inst-iot/bosch-angular-ui-components';
import {RouterTestingModule} from '@angular/router/testing';
import {LoginService} from './services/login.service';
import {Router} from '@angular/router';
import {Observable} from 'rxjs';
import {Test} from 'tslint';
import {RbCustomInputsModule} from './rb-custom-inputs/rb-custom-inputs.module';
// TODO
let loginServiceSpy: jasmine.SpyObj<LoginService>;
let routerServiceSpy: Router;
let windowServiceSpy: jasmine.SpyObj<Window>;
describe('AppComponent', () => {
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;
let css; // get native element by css selector
beforeEach(async(() => {
const loginSpy = jasmine.createSpyObj('LoginService', ['login', 'isLevel', 'isLoggedIn']);
const windowSpy = jasmine.createSpyObj('Window', ['location', 'innerWidth', 'innerHeight', 'scroll']);
TestBed.configureTestingModule({
declarations: [ AppComponent ],
imports: [
RbUiComponentsModule,
RbCustomInputsModule,
RouterTestingModule
],
providers: [
{provide: LoginService, useValue: loginSpy},
{provide: Window, useValue: windowSpy}
]
}).compileComponents();
loginServiceSpy = TestBed.inject(LoginService) as jasmine.SpyObj<LoginService>;
routerServiceSpy = TestBed.inject(Router);
windowServiceSpy = TestBed.inject(Window) as jasmine.SpyObj<Window>;
}));
beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
fixture.detectChanges();
css = (selector) => fixture.debugElement.query(By.css(selector)).nativeElement;
});
it('should create the app', () => {
expect(component).toBeTruthy();
});
it('should have the header', () => {
expect(css('rb-full-header')).toBeTruthy();
});
it('should have the correct app title', () => {
expect(css('rb-full-header div.sub-brand-content > div').innerText).toBe('BugDEVELOPMENT DeFinMa');
});
it('should have the page container', () => {
expect(css('.container')).toBeTruthy();
});
});