vitest implementation

This commit is contained in:
2026-03-16 18:38:15 +01:00
parent 2173ad6abf
commit ecb25ee322
70 changed files with 3560 additions and 1067 deletions

View File

@@ -1,5 +1,5 @@
import {TestBed} from '@angular/core/testing';
import {of} from 'rxjs';
import {firstValueFrom, of} from 'rxjs';
import {DbService} from './db.service';
import {ConfigService} from './config.service';
@@ -27,11 +27,8 @@ describe('ConfigService', () => {
expect(dbServiceSpy.doc$).toHaveBeenCalledWith('global/config');
});
it('should expose the shared config stream via get$', done => {
service.get$().subscribe(config => {
expect(config).toEqual({copyright: 'CCLI'} as never);
done();
});
it('should expose the shared config stream via get$', async () => {
await expectAsync(firstValueFrom(service.get$())).toBeResolvedTo({copyright: 'CCLI'} as never);
});
it('should resolve the current config via get()', async () => {

View File

@@ -4,12 +4,11 @@ import {Firestore} from '@angular/fire/firestore';
import {DbService} from './db.service';
describe('DbService', () => {
beforeEach(
() =>
void TestBed.configureTestingModule({
providers: [{provide: Firestore, useValue: {}}],
})
);
beforeEach(async () => {
await TestBed.configureTestingModule({
providers: [{provide: Firestore, useValue: {}}],
});
});
it('should be created', () => {
const service: DbService = TestBed.inject(DbService);

View File

@@ -1,5 +1,5 @@
import {TestBed} from '@angular/core/testing';
import {of} from 'rxjs';
import {firstValueFrom, of} from 'rxjs';
import {DbService} from './db.service';
import {GlobalSettingsService} from './global-settings.service';
@@ -30,11 +30,8 @@ describe('GlobalSettingsService', () => {
expect(dbServiceSpy.doc$).toHaveBeenCalledWith('global/static');
});
it('should expose the shared settings stream via the getter', done => {
service.get$.subscribe(settings => {
expect(settings).toEqual({churchName: 'ICF'} as never);
done();
});
it('should expose the shared settings stream via the getter', async () => {
await expectAsync(firstValueFrom(service.get$)).toBeResolvedTo({churchName: 'ICF'} as never);
});
it('should update the static global settings document', async () => {

View File

@@ -5,8 +5,8 @@ import {ScrollService} from './scroll.service';
describe('ScrollService', () => {
let service: ScrollService;
beforeEach(() => {
void TestBed.configureTestingModule({});
beforeEach(async () => {
await TestBed.configureTestingModule({});
service = TestBed.inject(ScrollService);
});

View File

@@ -1,5 +1,5 @@
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
import {of} from 'rxjs';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {firstValueFrom, of} from 'rxjs';
import {UserService} from '../user.service';
import {UserNameComponent} from './user-name.component';
@@ -8,15 +8,15 @@ describe('UserNameComponent', () => {
let fixture: ComponentFixture<UserNameComponent>;
let userServiceSpy: jasmine.SpyObj<UserService>;
beforeEach(waitForAsync(() => {
beforeEach(async () => {
userServiceSpy = jasmine.createSpyObj<UserService>('UserService', ['getUserbyId$']);
userServiceSpy.getUserbyId$.and.returnValue(of({name: 'Benjamin'} as never));
void TestBed.configureTestingModule({
await TestBed.configureTestingModule({
imports: [UserNameComponent],
providers: [{provide: UserService, useValue: userServiceSpy}],
}).compileComponents();
}));
});
beforeEach(() => {
fixture = TestBed.createComponent(UserNameComponent);
@@ -28,24 +28,18 @@ describe('UserNameComponent', () => {
expect(component).toBeTruthy();
});
it('should resolve the user name when the userId input changes', done => {
it('should resolve the user name when the userId input changes', async () => {
component.userId = 'user-1';
component.name$?.subscribe(name => {
expect(userServiceSpy.getUserbyId$).toHaveBeenCalledWith('user-1');
expect(name).toBe('Benjamin');
done();
});
expect(userServiceSpy.getUserbyId$).toHaveBeenCalledWith('user-1');
await expectAsync(firstValueFrom(component.name$!)).toBeResolvedTo('Benjamin');
});
it('should map missing users to null names', done => {
it('should map missing users to null names', async () => {
userServiceSpy.getUserbyId$.and.returnValue(of(null));
component.userId = 'missing-user';
component.name$?.subscribe(name => {
expect(name).toBeNull();
done();
});
await expectAsync(firstValueFrom(component.name$!)).toBeResolvedTo(null);
});
});

View File

@@ -1,5 +1,5 @@
import {TestBed} from '@angular/core/testing';
import {of} from 'rxjs';
import {firstValueFrom, of} from 'rxjs';
import {UserService} from './user.service';
import {UserSessionService} from './user-session.service';
import {UserSongUsageService} from './user-song-usage.service';
@@ -54,17 +54,10 @@ describe('UserService', () => {
expect(service).toBeTruthy();
});
it('should expose the session streams directly', done => {
service.userId$.subscribe(userId => {
expect(userId).toBe('user-1');
service.user$.subscribe(user => {
expect(user).toEqual({id: 'user-1'} as never);
service.users$.subscribe(users => {
expect(users).toEqual([{id: 'user-1'}] as never);
done();
});
});
});
it('should expose the session streams directly', async () => {
await expectAsync(firstValueFrom(service.userId$)).toBeResolvedTo('user-1');
await expectAsync(firstValueFrom(service.user$)).toBeResolvedTo({id: 'user-1'} as never);
await expectAsync(firstValueFrom(service.users$)).toBeResolvedTo([{id: 'user-1'}] as never);
});
it('should delegate session operations to UserSessionService', async () => {
@@ -85,20 +78,13 @@ describe('UserService', () => {
expect(sessionSpy.createNewUser).toHaveBeenCalledWith('mail', 'Benjamin', 'secret');
});
it('should delegate user lookup and loggedIn/list streams to UserSessionService', done => {
service.getUserbyId$('user-2').subscribe(user => {
expect(user).toEqual({id: 'user-2'} as never);
service.loggedIn$().subscribe(loggedIn => {
expect(loggedIn).toBeTrue();
service.list$().subscribe(users => {
expect(users).toEqual([{id: 'user-1'}] as never);
expect(sessionSpy.getUserbyId$).toHaveBeenCalledWith('user-2');
expect(sessionSpy.loggedIn$).toHaveBeenCalled();
expect(sessionSpy.list$).toHaveBeenCalled();
done();
});
});
});
it('should delegate user lookup and loggedIn/list streams to UserSessionService', async () => {
await expectAsync(firstValueFrom(service.getUserbyId$('user-2'))).toBeResolvedTo({id: 'user-2'} as never);
await expectAsync(firstValueFrom(service.loggedIn$())).toBeResolvedTo(true);
await expectAsync(firstValueFrom(service.list$())).toBeResolvedTo([{id: 'user-1'}] as never);
expect(sessionSpy.getUserbyId$).toHaveBeenCalledWith('user-2');
expect(sessionSpy.loggedIn$).toHaveBeenCalled();
expect(sessionSpy.list$).toHaveBeenCalled();
});
it('should delegate song usage operations to UserSongUsageService', async () => {