1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import { Location } from '@angular/common';
- import { ComponentFixture, TestBed } from '@angular/core/testing';
- import { MatMenuModule } from '@angular/material/menu';
- import { MqttRequestService } from './Service/Mqtt/mqtt-request.service';
- import { AppComponent } from './app.component';
-
- describe('AppComponent', () => {
- let component: AppComponent;
- let fixture: ComponentFixture<AppComponent>;
- let mqttRequestServiceSpy: jasmine.SpyObj<MqttRequestService>;
- let locationStub: Partial<Location>;
-
- beforeEach(async () => {
- const mqttRequestServiceMock = jasmine.createSpyObj('MqttRequestService', ['someMethod']);
-
- locationStub = {
- path: () => '/home'
- };
-
- await TestBed.configureTestingModule({
- imports: [MatMenuModule],
- declarations: [AppComponent],
- providers: [
- { provide: MqttRequestService, useValue: mqttRequestServiceMock },
- { provide: Location, useValue: locationStub }
- ]
- }).compileComponents();
- });
-
- beforeEach(() => {
- fixture = TestBed.createComponent(AppComponent);
- component = fixture.componentInstance;
-
- mqttRequestServiceSpy = TestBed.inject(MqttRequestService) as jasmine.SpyObj<MqttRequestService>;
-
- fixture.detectChanges();
- });
-
- it('should create', () => {
- expect(component).toBeTruthy();
- });
-
- it('should set header to "Home" if the route is empty', () => {
- expect(component.header).toBe('Home');
- });
-
- it('should set header to the capitalized route value', () => {
- locationStub.path = () => '/about';
- const componentNew = new AppComponent(mqttRequestServiceSpy, locationStub as Location);
-
- expect(componentNew.header).toBe('About');
- });
-
- it('should update header when onMenuSelect is called', () => {
- component.onMenuSelect('Map');
-
- expect(component.header).toBe('Map');
- });
- });
|