import { ComponentFixture, TestBed } from '@angular/core/testing'; import { AdminSessionService } from '../admin-session.service'; import { OperationsService } from '../operations.service'; import { AdminDashboardComponent } from './admin-dashboard.component'; describe('AdminDashboardComponent', () => { let fixture: ComponentFixture; let operations: jasmine.SpyObj; let sessions: jasmine.SpyObj; beforeEach(async () => { operations = jasmine.createSpyObj('OperationsService', ['dashboard']); sessions = jasmine.createSpyObj('AdminSessionService', ['applyIdentity']); operations.dashboard.and.resolveTo({ identity: { objectId: 'admin-1', username: 'ops', displayName: '运营经理', roles: ['admin', 'ops-manager'], isSuperAdmin: false, operationsRole: 'ops-manager' }, date: '2026-08-20', metrics: [], alerts: [] }); await TestBed.configureTestingModule({ imports: [AdminDashboardComponent], providers: [ { provide: OperationsService, useValue: operations }, { provide: AdminSessionService, useValue: sessions } ] }).compileComponents(); fixture = TestBed.createComponent(AdminDashboardComponent); }); it('refreshes the stored operations role from the cloud identity', async () => { fixture.detectChanges(); await fixture.whenStable(); expect(sessions.applyIdentity).toHaveBeenCalledWith(jasmine.objectContaining({ operationsRole: 'ops-manager' })); }); });