Introduce a new eBook reader with support for EPUB, MOBI, AZW3, and FB2 formats (#2258)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
@@ -38,7 +38,7 @@ class BookServiceDeleteTests {
|
||||
void setUp() {
|
||||
BookRepository bookRepository = Mockito.mock(BookRepository.class);
|
||||
PdfViewerPreferencesRepository pdfViewerPreferencesRepository = Mockito.mock(PdfViewerPreferencesRepository.class);
|
||||
EpubViewerPreferencesRepository epubViewerPreferencesRepository = Mockito.mock(EpubViewerPreferencesRepository.class);
|
||||
EbookViewerPreferenceRepository ebookViewerPreferenceRepository = Mockito.mock(EbookViewerPreferenceRepository.class);
|
||||
CbxViewerPreferencesRepository cbxViewerPreferencesRepository = Mockito.mock(CbxViewerPreferencesRepository.class);
|
||||
NewPdfViewerPreferencesRepository newPdfViewerPreferencesRepository = Mockito.mock(NewPdfViewerPreferencesRepository.class);
|
||||
FileService fileService = Mockito.mock(FileService.class);
|
||||
@@ -54,7 +54,6 @@ class BookServiceDeleteTests {
|
||||
bookService = new BookService(
|
||||
bookRepository,
|
||||
pdfViewerPreferencesRepository,
|
||||
epubViewerPreferencesRepository,
|
||||
cbxViewerPreferencesRepository,
|
||||
newPdfViewerPreferencesRepository,
|
||||
fileService,
|
||||
@@ -65,7 +64,8 @@ class BookServiceDeleteTests {
|
||||
userProgressService,
|
||||
bookDownloadService,
|
||||
monitoringRegistrationService,
|
||||
bookUpdateService
|
||||
bookUpdateService,
|
||||
ebookViewerPreferenceRepository
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+28
-7
@@ -20,6 +20,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -38,7 +39,7 @@ import java.util.Set;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(org.mockito.junit.jupiter.MockitoExtension.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class BookServiceTest {
|
||||
|
||||
@Mock
|
||||
@@ -46,7 +47,7 @@ class BookServiceTest {
|
||||
@Mock
|
||||
private PdfViewerPreferencesRepository pdfViewerPreferencesRepository;
|
||||
@Mock
|
||||
private EpubViewerPreferencesRepository epubViewerPreferencesRepository;
|
||||
private EbookViewerPreferenceRepository ebookViewerPreferenceRepository;
|
||||
@Mock
|
||||
private CbxViewerPreferencesRepository cbxViewerPreferencesRepository;
|
||||
@Mock
|
||||
@@ -170,15 +171,35 @@ class BookServiceTest {
|
||||
primaryFile.setBookType(BookFileType.EPUB);
|
||||
entity.setBookFiles(List.of(primaryFile));
|
||||
when(bookRepository.findByIdWithBookFiles(4L)).thenReturn(Optional.of(entity));
|
||||
EpubViewerPreferencesEntity epubPref = new EpubViewerPreferencesEntity();
|
||||
epubPref.setFont("Arial");
|
||||
when(epubViewerPreferencesRepository.findByBookIdAndUserId(4L, testUser.getId())).thenReturn(Optional.of(epubPref));
|
||||
EbookViewerPreferenceEntity epubPref = new EbookViewerPreferenceEntity();
|
||||
epubPref.setFontFamily("Arial");
|
||||
epubPref.setFontSize(16);
|
||||
epubPref.setGap(0.2f);
|
||||
epubPref.setHyphenate(true);
|
||||
epubPref.setIsDark(false);
|
||||
epubPref.setJustify(true);
|
||||
epubPref.setLineHeight(1.5f);
|
||||
epubPref.setMaxBlockSize(800);
|
||||
epubPref.setMaxColumnCount(2);
|
||||
epubPref.setMaxInlineSize(1200);
|
||||
epubPref.setTheme("light");
|
||||
when(ebookViewerPreferenceRepository.findByBookIdAndUserId(4L, testUser.getId())).thenReturn(Optional.of(epubPref));
|
||||
when(authenticationService.getAuthenticatedUser()).thenReturn(testUser);
|
||||
|
||||
BookViewerSettings settings = bookService.getBookViewerSetting(4L);
|
||||
|
||||
assertNotNull(settings.getEpubSettings());
|
||||
assertEquals("Arial", settings.getEpubSettings().getFont());
|
||||
assertNotNull(settings.getEbookSettings());
|
||||
assertEquals("Arial", settings.getEbookSettings().getFontFamily());
|
||||
assertEquals(16, settings.getEbookSettings().getFontSize());
|
||||
assertEquals(0.2f, settings.getEbookSettings().getGap());
|
||||
assertTrue(settings.getEbookSettings().getHyphenate());
|
||||
assertFalse(settings.getEbookSettings().getIsDark());
|
||||
assertTrue(settings.getEbookSettings().getJustify());
|
||||
assertEquals(1.5f, settings.getEbookSettings().getLineHeight());
|
||||
assertEquals(800, settings.getEbookSettings().getMaxBlockSize());
|
||||
assertEquals(2, settings.getEbookSettings().getMaxColumnCount());
|
||||
assertEquals(1200, settings.getEbookSettings().getMaxInlineSize());
|
||||
assertEquals("light", settings.getEbookSettings().getTheme());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+33
-23
@@ -34,8 +34,6 @@ class BookUpdateServiceTest {
|
||||
@Mock
|
||||
private PdfViewerPreferencesRepository pdfViewerPreferencesRepository;
|
||||
@Mock
|
||||
private EpubViewerPreferencesRepository epubViewerPreferencesRepository;
|
||||
@Mock
|
||||
private CbxViewerPreferencesRepository cbxViewerPreferencesRepository;
|
||||
@Mock
|
||||
private NewPdfViewerPreferencesRepository newPdfViewerPreferencesRepository;
|
||||
@@ -55,6 +53,8 @@ class BookUpdateServiceTest {
|
||||
private UserProgressService userProgressService;
|
||||
@Mock
|
||||
private KoboReadingStateService koboReadingStateService;
|
||||
@Mock
|
||||
private EbookViewerPreferenceRepository ebookViewerPreferenceRepository;
|
||||
|
||||
@InjectMocks
|
||||
private BookUpdateService bookUpdateService;
|
||||
@@ -65,7 +65,6 @@ class BookUpdateServiceTest {
|
||||
bookUpdateService = new BookUpdateService(
|
||||
bookRepository,
|
||||
pdfViewerPreferencesRepository,
|
||||
epubViewerPreferencesRepository,
|
||||
cbxViewerPreferencesRepository,
|
||||
newPdfViewerPreferencesRepository,
|
||||
shelfRepository,
|
||||
@@ -75,7 +74,8 @@ class BookUpdateServiceTest {
|
||||
authenticationService,
|
||||
bookQueryService,
|
||||
userProgressService,
|
||||
koboReadingStateService
|
||||
koboReadingStateService,
|
||||
ebookViewerPreferenceRepository
|
||||
);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ class BookUpdateServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateBookViewerSetting_epub_shouldUpdateEpubPrefs() {
|
||||
void updateBookViewerSetting_epub_shouldUpdateEpubPrefsV2() {
|
||||
long bookId = 1L;
|
||||
BookEntity book = new BookEntity();
|
||||
book.setId(bookId);
|
||||
@@ -123,30 +123,40 @@ class BookUpdateServiceTest {
|
||||
when(authenticationService.getAuthenticatedUser()).thenReturn(user);
|
||||
when(user.getId()).thenReturn(2L);
|
||||
|
||||
EpubViewerPreferencesEntity epubPrefs = new EpubViewerPreferencesEntity();
|
||||
when(epubViewerPreferencesRepository.findByBookIdAndUserId(bookId, 2L)).thenReturn(Optional.of(epubPrefs));
|
||||
EbookViewerPreferenceEntity epubPrefs = new EbookViewerPreferenceEntity();
|
||||
when(ebookViewerPreferenceRepository.findByBookIdAndUserId(bookId, 2L)).thenReturn(Optional.of(epubPrefs));
|
||||
BookViewerSettings settings = BookViewerSettings.builder()
|
||||
.epubSettings(EpubViewerPreferences.builder()
|
||||
.font("font")
|
||||
.fontSize(12)
|
||||
.theme("theme")
|
||||
.flow("flow")
|
||||
.spread("spread")
|
||||
.letterSpacing(1.2f)
|
||||
.lineHeight(1.3f)
|
||||
.ebookSettings(EbookViewerPreferences.builder()
|
||||
.fontFamily("serif")
|
||||
.fontSize(18)
|
||||
.gap(0.1f)
|
||||
.hyphenate(true)
|
||||
.isDark(true)
|
||||
.justify(true)
|
||||
.lineHeight(1.7f)
|
||||
.maxBlockSize(800)
|
||||
.maxColumnCount(3)
|
||||
.maxInlineSize(1200)
|
||||
.theme("dark")
|
||||
.flow("paginated")
|
||||
.build())
|
||||
.build();
|
||||
|
||||
bookUpdateService.updateBookViewerSetting(bookId, settings);
|
||||
|
||||
verify(epubViewerPreferencesRepository).save(epubPrefs);
|
||||
assertEquals("font", epubPrefs.getFont());
|
||||
assertEquals(12, epubPrefs.getFontSize());
|
||||
assertEquals("theme", epubPrefs.getTheme());
|
||||
assertEquals("flow", epubPrefs.getFlow());
|
||||
assertEquals("spread", epubPrefs.getSpread());
|
||||
assertEquals(1.2f, epubPrefs.getLetterSpacing());
|
||||
assertEquals(1.3f, epubPrefs.getLineHeight());
|
||||
verify(ebookViewerPreferenceRepository).save(epubPrefs);
|
||||
assertEquals("serif", epubPrefs.getFontFamily());
|
||||
assertEquals(18, epubPrefs.getFontSize());
|
||||
assertEquals(0.1f, epubPrefs.getGap());
|
||||
assertTrue(epubPrefs.getHyphenate());
|
||||
assertTrue(epubPrefs.getIsDark());
|
||||
assertTrue(epubPrefs.getJustify());
|
||||
assertEquals(1.7f, epubPrefs.getLineHeight());
|
||||
assertEquals(800, epubPrefs.getMaxBlockSize());
|
||||
assertEquals(3, epubPrefs.getMaxColumnCount());
|
||||
assertEquals(1200, epubPrefs.getMaxInlineSize());
|
||||
assertEquals("dark", epubPrefs.getTheme());
|
||||
assertEquals("paginated", epubPrefs.getFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user