Files
openproject/modules/github_integration/frontend/module/tab-header/tab-header.component.spec.ts
T
Alexander Brandon Coles 6e8510ca1d [#66563] Migrate specs to Vitest
Apply Angular's Vitest migration schematic to update frontend and plugin
specs from Jasmine globals to Vitest APIs.

    ng g @schematics/angular:refactor-jasmine-vitest

Fix migrated edge cases where async assertions or shallow tests changed.

https://community.openproject.org/wp/66563
2026-05-08 09:52:17 +02:00

65 lines
2.3 KiB
TypeScript

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DebugElement } from '@angular/core';
import { TabHeaderComponent } from 'core-app/features/plugins/linked/openproject-github_integration/tab-header/tab-header.component';
import { By } from '@angular/platform-browser';
import { OpIconComponent } from 'core-app/shared/components/icon/icon.component';
import { GitActionsMenuDirective } from 'core-app/features/plugins/linked/openproject-github_integration/git-actions-menu/git-actions-menu.directive';
import { OPContextMenuService } from 'core-app/shared/components/op-context-menu/op-context-menu.service';
import { I18nService } from 'core-app/core/i18n/i18n.service';
describe('TabHeaderComponent', () => {
let component:TabHeaderComponent;
let fixture:ComponentFixture<TabHeaderComponent>;
let element:DebugElement;
const I18nServiceStub = {
t: function (key:string) {
return 'test translation';
}
};
let oPContextMenuService:{ show:ReturnType<typeof vi.fn> };
// @ts-ignore
window.Mousetrap = () => () => { };
beforeEach(async () => {
const oPContextMenuServiceSpy = {
show: vi.fn().mockName('OPContextMenuService.show')
};
await TestBed
.configureTestingModule({
declarations: [
TabHeaderComponent,
OpIconComponent,
GitActionsMenuDirective,
],
providers: [
{ provide: I18nService, useValue: I18nServiceStub },
{ provide: OPContextMenuService, useValue: oPContextMenuServiceSpy },
],
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(TabHeaderComponent);
component = fixture.componentInstance;
element = fixture.debugElement;
oPContextMenuService = fixture.debugElement.injector.get(OPContextMenuService) as unknown as typeof oPContextMenuService;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should render title and copy button', () => {
const headerTitle = fixture.debugElement.query(By.css('h3')).nativeElement;
const headerCopyButton = fixture.debugElement.query(By.css('button.github-git-copy[gitActionsCopyDropdown]')).nativeElement;
expect(headerTitle.textContent.trim()).toBe('test translation');
expect(headerCopyButton).toBeTruthy();
});
});