definma-ui/src/app/app.component.spec.ts

67 lines
2.2 KiB
TypeScript
Raw Normal View History

2020-05-22 09:36:50 +02:00
import {TestBed, async, ComponentFixture} from '@angular/core/testing';
2020-01-14 13:41:28 +01:00
import { AppComponent } from './app.component';
2020-05-22 09:36:50 +02:00
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';
2020-08-16 20:01:56 +02:00
import {Router} from '@angular/router';
// TODO
let loginServiceSpy: jasmine.SpyObj<LoginService>;
2020-08-16 20:01:56 +02:00
let routerServiceSpy: jasmine.SpyObj<Router>;
let windowServiceSpy: jasmine.SpyObj<Window>;
2020-01-14 13:41:28 +01:00
describe('AppComponent', () => {
2020-05-22 09:36:50 +02:00
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;
let css; // get native element by css selector
2020-01-14 13:41:28 +01:00
beforeEach(async(() => {
const loginSpy = jasmine.createSpyObj('LoginService', ['login', 'canActivate']);
2020-08-16 20:01:56 +02:00
const routerSpy = jasmine.createSpyObj('Router', ['navigate', 'events']);
const windowSpy = jasmine.createSpyObj('Window', ['location', 'innerWidth', 'innerHeight', 'scroll']);
2020-01-14 13:41:28 +01:00
TestBed.configureTestingModule({
2020-05-22 09:36:50 +02:00
declarations: [ AppComponent ],
2020-01-14 13:41:28 +01:00
imports: [
2020-05-22 09:36:50 +02:00
RbUiComponentsModule,
2020-01-14 13:41:28 +01:00
RouterTestingModule
],
providers: [
2020-08-16 20:01:56 +02:00
{provide: LoginService, useValue: loginSpy},
{provide: Router, useValue: routerSpy},
{provide: Window, useValue: windowSpy}
2020-05-22 09:36:50 +02:00
]
2020-01-14 13:41:28 +01:00
}).compileComponents();
2020-08-16 20:01:56 +02:00
loginServiceSpy = TestBed.inject(LoginService) as jasmine.SpyObj<LoginService>;
2020-08-16 20:01:56 +02:00
routerServiceSpy = TestBed.inject(Router) as jasmine.SpyObj<Router>;
windowServiceSpy = TestBed.inject(Window) as jasmine.SpyObj<Window>;
2020-01-14 13:41:28 +01:00
}));
2020-05-22 09:36:50 +02:00
beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
fixture.detectChanges();
css = (selector) => fixture.debugElement.query(By.css(selector)).nativeElement;
});
2020-01-14 13:41:28 +01:00
it('should create the app', () => {
2020-05-22 09:36:50 +02:00
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('Digital Fingerprint of Plastics');
2020-01-14 13:41:28 +01:00
});
2020-05-22 09:36:50 +02:00
it('should have the page container', () => {
expect(css('.container')).toBeTruthy();
2020-01-14 13:41:28 +01:00
});
2020-05-22 09:36:50 +02:00
2020-01-14 13:41:28 +01:00
});