refactor(ui): replace SVG artwork placeholders with CSS (#292)
* chore(ui): replace SVG placeholders with CSS alternative * fix(ui): Placeholder review followup
This commit is contained in:
@@ -4,8 +4,6 @@ import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
|
||||
|
||||
import {API_CONFIG} from '../../core/config/api-config';
|
||||
import {Book, BookType} from '../../features/book/model/book.model';
|
||||
import {BookService} from '../../features/book/service/book.service';
|
||||
import {CoverGeneratorComponent} from '../components/cover-generator/cover-generator.component';
|
||||
import {AuthService} from './auth.service';
|
||||
import {UrlHelperService} from './url-helper.service';
|
||||
|
||||
@@ -14,24 +12,12 @@ describe('UrlHelperService', () => {
|
||||
getInternalAccessToken: vi.fn(),
|
||||
};
|
||||
|
||||
const bookServiceStub = {
|
||||
findBookById: vi.fn(),
|
||||
};
|
||||
|
||||
const routerStub = {
|
||||
createUrlTree: vi.fn((commands: unknown[], extras?: unknown) => ({commands, extras})),
|
||||
};
|
||||
|
||||
let service: UrlHelperService;
|
||||
|
||||
const bookWithMetadata = {
|
||||
id: 42,
|
||||
metadata: {
|
||||
title: 'The Testing Atlas',
|
||||
authors: ['Ada Lovelace', 'Grace Hopper'],
|
||||
},
|
||||
} as Book;
|
||||
|
||||
const supportedReadingRoutes: {bookType: BookType; readerSegment: string}[] = [
|
||||
{bookType: 'PDF', readerSegment: 'pdf-reader'},
|
||||
{bookType: 'EPUB', readerSegment: 'ebook-reader'},
|
||||
@@ -44,15 +30,12 @@ describe('UrlHelperService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
authServiceStub.getInternalAccessToken.mockReturnValue('token-123');
|
||||
bookServiceStub.findBookById.mockReset();
|
||||
bookServiceStub.findBookById.mockReturnValue(undefined);
|
||||
routerStub.createUrlTree.mockClear();
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
UrlHelperService,
|
||||
{provide: AuthService, useValue: authServiceStub},
|
||||
{provide: BookService, useValue: bookServiceStub},
|
||||
{provide: Router, useValue: routerStub},
|
||||
],
|
||||
});
|
||||
@@ -64,17 +47,8 @@ describe('UrlHelperService', () => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('generates a portrait cover when cached metadata exists and no updated marker is provided', () => {
|
||||
bookServiceStub.findBookById.mockReturnValue(bookWithMetadata);
|
||||
|
||||
const generateCoverSpy = vi.spyOn(CoverGeneratorComponent.prototype, 'generateCover').mockImplementation(function (this: CoverGeneratorComponent) {
|
||||
return `${this.title}|${this.author}|${this.isSquare ? 'square' : 'portrait'}`;
|
||||
});
|
||||
|
||||
const url = service.getThumbnailUrl(42);
|
||||
|
||||
expect(generateCoverSpy).toHaveBeenCalledTimes(1);
|
||||
expect(url).toBe('The Testing Atlas|Ada Lovelace, Grace Hopper|portrait');
|
||||
it('returns null for thumbnail when no coverUpdatedOn is provided', () => {
|
||||
expect(service.getThumbnailUrl(42)).toBeNull();
|
||||
});
|
||||
|
||||
it('appends the token to thumbnail urls that already have a cache key', () => {
|
||||
@@ -83,6 +57,22 @@ describe('UrlHelperService', () => {
|
||||
expect(url).toBe(`${API_CONFIG.BASE_URL}/api/v1/media/book/42/thumbnail?updated-2024&token=token-123`);
|
||||
});
|
||||
|
||||
it('returns null for cover url when no coverUpdatedOn is provided', () => {
|
||||
expect(service.getCoverUrl(42)).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for audiobook cover when no updated marker is provided', () => {
|
||||
expect(service.getAudiobookCoverUrl(42)).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for audiobook thumbnail when no updated marker is provided', () => {
|
||||
expect(service.getAudiobookThumbnailUrl(42)).toBeNull();
|
||||
});
|
||||
|
||||
it('uses the audiobook media url when an updated marker is present', () => {
|
||||
expect(service.getAudiobookThumbnailUrl(42, 'updated-2024')).toBe(`${API_CONFIG.BASE_URL}/api/v1/media/book/42/audiobook-thumbnail?updated-2024&token=token-123`);
|
||||
});
|
||||
|
||||
it('returns direct thumbnail and backup urls without a token when auth is unavailable', () => {
|
||||
authServiceStub.getInternalAccessToken.mockReturnValue(null);
|
||||
|
||||
@@ -90,23 +80,6 @@ describe('UrlHelperService', () => {
|
||||
expect(service.getBackupCoverUrl(42)).toBe(`${API_CONFIG.BASE_URL}/api/v1/media/book/42/backup-cover`);
|
||||
});
|
||||
|
||||
it('generates a square audiobook cover when cached metadata exists', () => {
|
||||
bookServiceStub.findBookById.mockReturnValue(bookWithMetadata);
|
||||
|
||||
const generateCoverSpy = vi.spyOn(CoverGeneratorComponent.prototype, 'generateCover').mockImplementation(function (this: CoverGeneratorComponent) {
|
||||
return `${this.title}|${this.author}|${this.isSquare ? 'square' : 'portrait'}`;
|
||||
});
|
||||
|
||||
const url = service.getAudiobookCoverUrl(42);
|
||||
|
||||
expect(generateCoverSpy).toHaveBeenCalledTimes(1);
|
||||
expect(url).toBe('The Testing Atlas|Ada Lovelace, Grace Hopper|square');
|
||||
});
|
||||
|
||||
it('uses the audiobook media url when an updated marker is present', () => {
|
||||
expect(service.getAudiobookThumbnailUrl(42, 'updated-2024')).toBe(`${API_CONFIG.BASE_URL}/api/v1/media/book/42/audiobook-thumbnail?updated-2024&token=token-123`);
|
||||
});
|
||||
|
||||
it.each(supportedReadingRoutes)('routes %s books to the correct reader path', ({bookType, readerSegment}: {bookType: BookType; readerSegment: string}) => {
|
||||
const book = {
|
||||
id: 77,
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {API_CONFIG} from '../../core/config/api-config';
|
||||
import {AuthService} from './auth.service';
|
||||
import {BookService} from '../../features/book/service/book.service';
|
||||
import {CoverGeneratorComponent} from '../components/cover-generator/cover-generator.component';
|
||||
import {Router} from '@angular/router';
|
||||
import {Book,BookType} from '../../features/book/model/book.model';
|
||||
import {Book, BookType} from '../../features/book/model/book.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -13,7 +11,6 @@ export class UrlHelperService {
|
||||
private readonly baseUrl = API_CONFIG.BASE_URL;
|
||||
private readonly mediaBaseUrl = `${this.baseUrl}/api/v1/media`;
|
||||
private authService = inject(AuthService);
|
||||
private bookService = inject(BookService);
|
||||
private router = inject(Router);
|
||||
|
||||
private getToken(): string | null {
|
||||
@@ -25,21 +22,9 @@ export class UrlHelperService {
|
||||
return token ? `${url}${url.includes('?') ? '&' : '?'}token=${token}` : url;
|
||||
}
|
||||
|
||||
getThumbnailUrl(bookId: number, coverUpdatedOn?: string): string {
|
||||
if (!coverUpdatedOn) {
|
||||
const book = this.bookService.findBookById(bookId);
|
||||
if (book && book.metadata) {
|
||||
const coverGenerator = new CoverGeneratorComponent();
|
||||
coverGenerator.title = book.metadata.title || '';
|
||||
coverGenerator.author = (book.metadata.authors || []).join(', ');
|
||||
return coverGenerator.generateCover();
|
||||
}
|
||||
}
|
||||
let url = `${this.mediaBaseUrl}/book/${bookId}/thumbnail`;
|
||||
if (coverUpdatedOn) {
|
||||
url += `?${coverUpdatedOn}`;
|
||||
}
|
||||
return this.appendToken(url);
|
||||
getThumbnailUrl(bookId: number, coverUpdatedOn?: string): string | null {
|
||||
if (!coverUpdatedOn) return null;
|
||||
return this.appendToken(`${this.mediaBaseUrl}/book/${bookId}/thumbnail?${coverUpdatedOn}`);
|
||||
}
|
||||
|
||||
getDirectThumbnailUrl(bookId: number, coverUpdatedOn?: string): string {
|
||||
@@ -50,21 +35,9 @@ export class UrlHelperService {
|
||||
return this.appendToken(url);
|
||||
}
|
||||
|
||||
getCoverUrl(bookId: number, coverUpdatedOn?: string): string {
|
||||
if (!coverUpdatedOn) {
|
||||
const book = this.bookService.findBookById(bookId);
|
||||
if (book && book.metadata) {
|
||||
const coverGenerator = new CoverGeneratorComponent();
|
||||
coverGenerator.title = book.metadata.title || '';
|
||||
coverGenerator.author = (book.metadata.authors || []).join(', ');
|
||||
return coverGenerator.generateCover();
|
||||
}
|
||||
}
|
||||
let url = `${this.mediaBaseUrl}/book/${bookId}/cover`;
|
||||
if (coverUpdatedOn) {
|
||||
url += `?${coverUpdatedOn}`;
|
||||
}
|
||||
return this.appendToken(url);
|
||||
getCoverUrl(bookId: number, coverUpdatedOn?: string): string | null {
|
||||
if (!coverUpdatedOn) return null;
|
||||
return this.appendToken(`${this.mediaBaseUrl}/book/${bookId}/cover?${coverUpdatedOn}`);
|
||||
}
|
||||
|
||||
getBackupCoverUrl(bookId: number): string {
|
||||
@@ -72,35 +45,17 @@ export class UrlHelperService {
|
||||
return this.appendToken(url);
|
||||
}
|
||||
|
||||
getAudiobookCoverUrl(bookId: number, audiobookCoverUpdatedOn?: string): string {
|
||||
if (!audiobookCoverUpdatedOn) {
|
||||
const book = this.bookService.findBookById(bookId);
|
||||
if (book && book.metadata) {
|
||||
const coverGenerator = new CoverGeneratorComponent();
|
||||
coverGenerator.title = book.metadata.title || '';
|
||||
coverGenerator.author = (book.metadata.authors || []).join(', ');
|
||||
coverGenerator.isSquare = true;
|
||||
return coverGenerator.generateCover();
|
||||
}
|
||||
}
|
||||
let url = `${this.mediaBaseUrl}/book/${bookId}/audiobook-cover`;
|
||||
if (audiobookCoverUpdatedOn) {
|
||||
url += `?${audiobookCoverUpdatedOn}`;
|
||||
}
|
||||
return this.appendToken(url);
|
||||
getAudiobookCoverUrl(bookId: number, audiobookCoverUpdatedOn?: string): string | null {
|
||||
if (!audiobookCoverUpdatedOn) return null;
|
||||
return this.appendToken(`${this.mediaBaseUrl}/book/${bookId}/audiobook-cover?${audiobookCoverUpdatedOn}`);
|
||||
}
|
||||
|
||||
getAudiobookThumbnailUrl(bookId: number, audiobookCoverUpdatedOn?: string): string {
|
||||
if (!audiobookCoverUpdatedOn) {
|
||||
const book = this.bookService.findBookById(bookId);
|
||||
if (book && book.metadata) {
|
||||
const coverGenerator = new CoverGeneratorComponent();
|
||||
coverGenerator.title = book.metadata.title || '';
|
||||
coverGenerator.author = (book.metadata.authors || []).join(', ');
|
||||
coverGenerator.isSquare = true;
|
||||
return coverGenerator.generateCover();
|
||||
}
|
||||
}
|
||||
getAudiobookThumbnailUrl(bookId: number, audiobookCoverUpdatedOn?: string): string | null {
|
||||
if (!audiobookCoverUpdatedOn) return null;
|
||||
return this.appendToken(`${this.mediaBaseUrl}/book/${bookId}/audiobook-thumbnail?${audiobookCoverUpdatedOn}`);
|
||||
}
|
||||
|
||||
getDirectAudiobookThumbnailUrl(bookId: number, audiobookCoverUpdatedOn?: string): string {
|
||||
let url = `${this.mediaBaseUrl}/book/${bookId}/audiobook-thumbnail`;
|
||||
if (audiobookCoverUpdatedOn) {
|
||||
url += `?${audiobookCoverUpdatedOn}`;
|
||||
|
||||
Reference in New Issue
Block a user