Fix Angular tests

This commit is contained in:
acx10
2026-01-15 21:24:39 -07:00
parent 36d9f74864
commit d8e7e0b5cf
@@ -2,16 +2,18 @@ import {beforeEach, describe, expect, it, vi} from 'vitest';
import {TestBed} from '@angular/core/testing'; import {TestBed} from '@angular/core/testing';
import {EnvironmentInjector, runInInjectionContext} from '@angular/core'; import {EnvironmentInjector, runInInjectionContext} from '@angular/core';
import {HttpClient} from '@angular/common/http'; import {HttpClient} from '@angular/common/http';
import {of, throwError, firstValueFrom} from 'rxjs'; import {firstValueFrom, of, throwError} from 'rxjs';
import {ShelfService} from './shelf.service'; import {ShelfService} from './shelf.service';
import {BookService} from './book.service'; import {BookService} from './book.service';
import {UserService} from '../../settings/user-management/user.service';
import {Shelf} from '../model/shelf.model'; import {Shelf} from '../model/shelf.model';
describe('ShelfService', () => { describe('ShelfService', () => {
let service: ShelfService; let service: ShelfService;
let httpClientMock: any; let httpClientMock: any;
let bookServiceMock: any; let bookServiceMock: any;
let userServiceMock: any;
beforeEach(() => { beforeEach(() => {
httpClientMock = { httpClientMock = {
@@ -33,11 +35,17 @@ describe('ShelfService', () => {
}) })
}; };
userServiceMock = {
userState$: of({user: {id: 1}})
};
TestBed.configureTestingModule({ TestBed.configureTestingModule({
providers: [ providers: [
ShelfService, ShelfService,
{provide: HttpClient, useValue: httpClientMock}, {provide: HttpClient, useValue: httpClientMock},
{provide: BookService, useValue: bookServiceMock} {provide: BookService, useValue: bookServiceMock},
{provide: UserService, useValue: userServiceMock},
{provide: 'OAuthService', useValue: {}}
] ]
}); });
@@ -116,14 +124,8 @@ describe('ShelfService', () => {
expect(service.getShelfById(999)).toBeUndefined(); expect(service.getShelfById(999)).toBeUndefined();
}); });
it('should get book count for shelf', async () => {
const count = await firstValueFrom(service.getBookCount(10));
expect(count).toBe(1);
});
it('should get unshelved book count', async () => { it('should get unshelved book count', async () => {
const count = await firstValueFrom(service.getUnshelvedBookCount()); const count = await firstValueFrom(service.getUnshelvedBookCount());
expect(count).toBe(2); expect(count).toBe(2);
}); });
}); });