repository to manage all files related to the makeathon farm bot project (Software + Documentation).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.component.spec.ts 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Location } from '@angular/common';
  2. import { ComponentFixture, TestBed } from '@angular/core/testing';
  3. import { MatMenuModule } from '@angular/material/menu';
  4. import { MqttRequestService } from './Service/Mqtt/mqtt-request.service';
  5. import { AppComponent } from './app.component';
  6. describe('AppComponent', () => {
  7. let component: AppComponent;
  8. let fixture: ComponentFixture<AppComponent>;
  9. let mqttRequestServiceSpy: jasmine.SpyObj<MqttRequestService>;
  10. let locationStub: Partial<Location>;
  11. beforeEach(async () => {
  12. const mqttRequestServiceMock = jasmine.createSpyObj('MqttRequestService', ['someMethod']);
  13. locationStub = {
  14. path: () => '/home'
  15. };
  16. await TestBed.configureTestingModule({
  17. imports: [MatMenuModule],
  18. declarations: [AppComponent],
  19. providers: [
  20. { provide: MqttRequestService, useValue: mqttRequestServiceMock },
  21. { provide: Location, useValue: locationStub }
  22. ]
  23. }).compileComponents();
  24. });
  25. beforeEach(() => {
  26. fixture = TestBed.createComponent(AppComponent);
  27. component = fixture.componentInstance;
  28. mqttRequestServiceSpy = TestBed.inject(MqttRequestService) as jasmine.SpyObj<MqttRequestService>;
  29. fixture.detectChanges();
  30. });
  31. it('should create', () => {
  32. expect(component).toBeTruthy();
  33. });
  34. it('should set header to "Home" if the route is empty', () => {
  35. expect(component.header).toBe('Home');
  36. });
  37. it('should set header to the capitalized route value', () => {
  38. locationStub.path = () => '/about';
  39. const componentNew = new AppComponent(mqttRequestServiceSpy, locationStub as Location);
  40. expect(componentNew.header).toBe('About');
  41. });
  42. it('should update header when onMenuSelect is called', () => {
  43. component.onMenuSelect('Map');
  44. expect(component.header).toBe('Map');
  45. });
  46. });