Ng18 migration fix unit tests (#4468)

* Fix details unit tests
This commit is contained in:
dominikiwanekhyland
2025-03-20 09:21:44 +01:00
committed by DominikIwanek
parent a666ae45e7
commit 7cb18bc19a

View File

@@ -57,14 +57,7 @@ describe('DetailsComponent', () => {
select: () => mockStream select: () => mockStream
}; };
const extensionsServiceMock = { const mockAspectActionsSubject$ = new BehaviorSubject<Array<ContentActionRef>>([]);
getAllowedSidebarActions: jasmine.createSpy('getAllowedSidebarActions')
};
const mockAspectActions: ContentActionRef[] = [];
const mockAspectActionsSubject$ = new BehaviorSubject(mockAspectActions);
extensionsServiceMock.getAllowedSidebarActions.and.returnValue(mockAspectActionsSubject$.asObservable());
const getBreadcrumb = (): BreadcrumbComponent => fixture.debugElement.query(By.directive(BreadcrumbComponent)).componentInstance; const getBreadcrumb = (): BreadcrumbComponent => fixture.debugElement.query(By.directive(BreadcrumbComponent)).componentInstance;
@@ -99,6 +92,9 @@ describe('DetailsComponent', () => {
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}); });
const appExtensionService = TestBed.inject(AppExtensionService);
spyOn(appExtensionService, 'getAllowedSidebarActions').and.returnValue(mockAspectActionsSubject$.asObservable());
fixture = TestBed.createComponent(DetailsComponent); fixture = TestBed.createComponent(DetailsComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
contentApiService = TestBed.inject(ContentApiService); contentApiService = TestBed.inject(ContentApiService);
@@ -130,6 +126,34 @@ describe('DetailsComponent', () => {
fixture.destroy(); fixture.destroy();
}); });
it('should set aspectActions from extension mock', () => {
const extensionMock = [
{
id: 'app.sidebar.close',
order: 100,
title: 'close',
icon: 'highlight_off'
} as ContentActionRef
];
mockAspectActionsSubject$.next(extensionMock);
fixture.detectChanges();
expect(component.aspectActions).toEqual([
{
id: 'app.sidebar.close',
order: 100,
title: 'close',
icon: 'highlight_off'
} as ContentActionRef
]);
});
describe('', () => {
beforeEach(() => {
mockAspectActionsSubject$.next([]);
});
it('should get node id from router', () => { it('should get node id from router', () => {
fixture.detectChanges(); fixture.detectChanges();
expect(component.nodeId).toBe('someId'); expect(component.nodeId).toBe('someId');
@@ -175,10 +199,9 @@ describe('DetailsComponent', () => {
}); });
it('should set aspectActions from extensions', async () => { it('should set aspectActions from extensions', async () => {
extensionsServiceMock.getAllowedSidebarActions.and.returnValue(of(mockAspectActions));
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable().then(() => { await fixture.whenStable().then(() => {
expect(component.aspectActions).toEqual(mockAspectActions); expect(component.aspectActions).toEqual([]);
}); });
}); });
@@ -191,38 +214,6 @@ describe('DetailsComponent', () => {
expect(component.nodeIcon).toContain(expectedIcon); expect(component.nodeIcon).toContain(expectedIcon);
}); });
it('should set aspectActions from extension mock', () => {
const extensionMock = {
getAllowedSidebarActions: () =>
of([
{
id: 'app.sidebar.close',
order: 100,
title: 'close',
icon: 'highlight_off'
}
])
};
extensionsServiceMock.getAllowedSidebarActions.and.returnValue(of(extensionMock));
fixture.detectChanges();
fixture
.whenStable()
.then(() => {
expect(component.aspectActions).toEqual([
{
id: 'app.sidebar.close',
order: 100,
title: 'close',
icon: 'highlight_off'
} as ContentActionRef
]);
})
.catch((error) => {
fail(`An error occurred: ${error}`);
});
});
it('should disable the permissions tab for smart folders based on aspects', () => { it('should disable the permissions tab for smart folders based on aspects', () => {
node.entry.isFolder = true; node.entry.isFolder = true;
node.entry.aspectNames = ['smf:customConfigSmartFolder']; node.entry.aspectNames = ['smf:customConfigSmartFolder'];
@@ -263,6 +254,7 @@ describe('DetailsComponent', () => {
component.setActiveTab('permissions'); component.setActiveTab('permissions');
expect(component.activeTab).not.toBe(2); expect(component.activeTab).not.toBe(2);
}); });
});
it('should navigate back when nodesDeleted event is triggered', () => { it('should navigate back when nodesDeleted event is triggered', () => {
const locationSpy = spyOn(location, 'back'); const locationSpy = spyOn(location, 'back');