2024-03-05 03:55:01 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google LLC All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
2024-09-20 15:23:15 +00:00
|
|
|
* found in the LICENSE file at https://angular.dev/license
|
2024-03-05 03:55:01 +00:00
|
|
|
*/
|
|
|
|
|
|
2024-11-27 09:43:54 +00:00
|
|
|
import {Component} from '@angular/core';
|
2024-03-05 03:55:01 +00:00
|
|
|
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
2025-01-15 12:42:01 +00:00
|
|
|
import {FrameManager} from './application-services/frame_manager';
|
2024-03-05 03:55:01 +00:00
|
|
|
import {DevToolsComponent} from './devtools.component';
|
|
|
|
|
import {DevToolsTabsComponent} from './devtools-tabs/devtools-tabs.component';
|
2025-05-08 13:20:37 +00:00
|
|
|
import {MessageBus} from '../../../protocol';
|
2025-08-07 12:53:29 +00:00
|
|
|
import {SETTINGS_MOCK} from './application-services/test-utils/settings_mock';
|
2024-03-05 03:55:01 +00:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'ng-devtools-tabs',
|
|
|
|
|
template: '',
|
|
|
|
|
})
|
|
|
|
|
export class MockNgDevToolsTabs {}
|
|
|
|
|
|
|
|
|
|
describe('DevtoolsComponent', () => {
|
|
|
|
|
let fixture: ComponentFixture<DevToolsComponent>;
|
|
|
|
|
let component: DevToolsComponent;
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
const mockMessageBus = jasmine.createSpyObj('MessageBus', ['on', 'emit', 'once']);
|
|
|
|
|
|
|
|
|
|
TestBed.configureTestingModule({
|
2025-08-07 12:53:29 +00:00
|
|
|
providers: [{provide: MessageBus, useValue: mockMessageBus}, SETTINGS_MOCK],
|
2024-03-05 03:55:01 +00:00
|
|
|
}).overrideComponent(DevToolsComponent, {
|
|
|
|
|
remove: {imports: [DevToolsTabsComponent], providers: [FrameManager]},
|
|
|
|
|
add: {
|
|
|
|
|
imports: [MockNgDevToolsTabs],
|
|
|
|
|
providers: [{provide: FrameManager, useFactory: () => FrameManager.initialize(123)}],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
fixture = TestBed.createComponent(DevToolsComponent);
|
|
|
|
|
component = fixture.componentInstance;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should render ng devtools tabs when Angular Status is EXISTS and is in dev mode and is supported version', () => {
|
2024-11-01 07:27:33 +00:00
|
|
|
component.angularStatus.set(component.AngularStatus.EXISTS);
|
|
|
|
|
component.angularIsInDevMode.set(true);
|
|
|
|
|
component.angularVersion.set('0.0.0');
|
|
|
|
|
component.ivy.set(true);
|
2024-03-05 03:55:01 +00:00
|
|
|
fixture.detectChanges();
|
|
|
|
|
expect(fixture.nativeElement.querySelector('ng-devtools-tabs')).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should render Angular Devtools dev mode only support text when Angular Status is EXISTS and is angular is not in dev mode', () => {
|
2024-11-01 07:27:33 +00:00
|
|
|
component.angularStatus.set(component.AngularStatus.EXISTS);
|
|
|
|
|
component.angularIsInDevMode.set(false);
|
2024-03-05 03:55:01 +00:00
|
|
|
fixture.detectChanges();
|
|
|
|
|
expect(fixture.nativeElement.querySelector('.devtools').textContent).toContain(
|
2024-09-18 05:02:30 +00:00
|
|
|
'We detected an application built with production configuration. Angular DevTools only supports development builds.',
|
2024-03-05 03:55:01 +00:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should render version support message when Angular Status is EXISTS and angular version is not supported', () => {
|
2024-11-01 07:27:33 +00:00
|
|
|
component.angularStatus.set(component.AngularStatus.EXISTS);
|
|
|
|
|
component.angularIsInDevMode.set(true);
|
|
|
|
|
component.angularVersion.set('1.0.0');
|
2024-03-05 03:55:01 +00:00
|
|
|
fixture.detectChanges();
|
|
|
|
|
expect(fixture.nativeElement.querySelector('.devtools').textContent).toContain(
|
|
|
|
|
'Angular Devtools only supports Angular versions 12 and above',
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should render Angular application not detected when Angular Status is DOES_NOT_EXIST', () => {
|
2024-11-01 07:27:33 +00:00
|
|
|
component.angularStatus.set(component.AngularStatus.DOES_NOT_EXIST);
|
2024-03-05 03:55:01 +00:00
|
|
|
fixture.detectChanges();
|
|
|
|
|
// expect the text to be "Angular application not detected"
|
|
|
|
|
expect(fixture.nativeElement.querySelector('.not-detected').textContent).toContain(
|
|
|
|
|
'Angular application not detected',
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should render loading svg when Angular Status is UNKNOWN', () => {
|
2024-11-01 07:27:33 +00:00
|
|
|
component.angularStatus.set(component.AngularStatus.UNKNOWN);
|
2024-03-05 03:55:01 +00:00
|
|
|
fixture.detectChanges();
|
|
|
|
|
expect(fixture.nativeElement.querySelector('.loading svg')).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
});
|