Files
openproject/modules/github_integration/frontend/module/github-tab/github-tab.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

85 lines
2.6 KiB
TypeScript

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, DebugElement, Input } from '@angular/core';
import { GitHubTabComponent } from 'core-app/features/plugins/linked/openproject-github_integration/github-tab/github-tab.component';
import { By } from '@angular/platform-browser';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
@Component({
selector: 'tab-header',
template: '',
standalone: false,
})
class TabHeaderStubComponent {
@Input() workPackage:WorkPackageResource;
}
@Component({
selector: 'op-tab-prs',
template: '',
standalone: false,
})
class TabPrsStubComponent {
@Input() workPackage:WorkPackageResource;
}
describe('GitHubTabComponent.', () => {
let component:GitHubTabComponent;
let fixture:ComponentFixture<GitHubTabComponent>;
let element:DebugElement;
const workPackage = { id: 'testId' } as WorkPackageResource;
const apiV3Base = 'http://www.openproject.com/api/v3/';
const IPathHelperServiceStub = { api: { v3: { apiV3Base } } };
const I18nServiceStub = {
t: function (key:string) {
return 'test translation';
}
};
beforeEach(async () => {
await TestBed
.configureTestingModule({
declarations: [
GitHubTabComponent,
TabHeaderStubComponent,
TabPrsStubComponent,
],
providers: [
{ provide: I18nService, useValue: I18nServiceStub },
{ provide: PathHelperService, useValue: IPathHelperServiceStub },
],
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(GitHubTabComponent);
component = fixture.componentInstance;
element = fixture.debugElement;
component.workPackage = workPackage;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should render header and pull requests components', () => {
const tabHeader = fixture.debugElement.query(By.css('tab-header'));
const tabPrs = fixture.debugElement.query(By.css('op-tab-prs'));
expect(tabHeader).toBeTruthy();
expect(tabPrs).toBeTruthy();
});
it('should pass the work package to the child components', () => {
const tabHeader = fixture.debugElement.query(By.directive(TabHeaderStubComponent));
const tabPrs = fixture.debugElement.query(By.directive(TabPrsStubComponent));
expect(tabHeader.componentInstance.workPackage).toBe(workPackage);
expect(tabPrs.componentInstance.workPackage).toBe(workPackage);
});
});