Switch to a new Ktlint Formatter (#705)
* Switch to new Ktlint plugin * Add ktlintCheck to PR builds * Run formatter * Put ktlint version in libs toml * Fix lint * Use Zip4Java from libs.toml
This commit is contained in:
@@ -39,9 +39,10 @@ class CloudFlareTest {
|
||||
Unit
|
||||
}
|
||||
|
||||
nhentai = Source.getSourceList()
|
||||
.firstNotNullOf { it.id.toLong().takeIf { it == 3122156392225024195L } }
|
||||
.let(GetCatalogueSource::getCatalogueSourceOrNull) as HttpSource
|
||||
nhentai =
|
||||
Source.getSourceList()
|
||||
.firstNotNullOf { it.id.toLong().takeIf { it == 3122156392225024195L } }
|
||||
.let(GetCatalogueSource::getCatalogueSourceOrNull) as HttpSource
|
||||
}
|
||||
setLoggingEnabled(true)
|
||||
}
|
||||
@@ -49,9 +50,10 @@ class CloudFlareTest {
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
@Test
|
||||
fun `test nhentai browse`() = runTest {
|
||||
assert(nhentai.getPopularManga(1).mangas.isNotEmpty()) {
|
||||
"NHentai results were empty"
|
||||
fun `test nhentai browse`() =
|
||||
runTest {
|
||||
assert(nhentai.getPopularManga(1).mangas.isNotEmpty()) {
|
||||
"NHentai results were empty"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ class TestExtensionCompatibility {
|
||||
repeat { source.getPopularManga(1) }
|
||||
.mangas.firstOrNull()
|
||||
?: throw Exception("Source returned no manga")
|
||||
)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
logger.warn { "Failed to fetch popular manga from $source: ${e.message}" }
|
||||
failedToFetch += source to e
|
||||
@@ -102,7 +102,7 @@ class TestExtensionCompatibility {
|
||||
failedToFetch.joinToString("\n") { (source, exception) ->
|
||||
"${source.name} (${source.lang.uppercase()}, ${source.id}):" +
|
||||
" ${exception.message}"
|
||||
}
|
||||
},
|
||||
)
|
||||
logger.info { "Now fetching manga info from ${mangaToFetch.size} sources" }
|
||||
|
||||
@@ -116,7 +116,9 @@ class TestExtensionCompatibility {
|
||||
manga.initialized = true
|
||||
} catch (e: Exception) {
|
||||
logger.warn {
|
||||
"Failed to fetch manga info from $source for ${manga.title} (${source.mangaDetailsRequest(manga).url}): ${e.message}"
|
||||
"Failed to fetch manga info from $source for ${manga.title} (${source.mangaDetailsRequest(
|
||||
manga,
|
||||
).url}): ${e.message}"
|
||||
}
|
||||
mangaFailedToFetch += Triple(source, manga, e)
|
||||
}
|
||||
@@ -128,7 +130,7 @@ class TestExtensionCompatibility {
|
||||
"${source.name} (${source.lang}, ${source.id}):" +
|
||||
" ${manga.title} (${source.mangaDetailsRequest(manga).url}):" +
|
||||
" ${exception.message}"
|
||||
}
|
||||
},
|
||||
)
|
||||
logger.info { "Now fetching manga chapters from ${mangaToFetch.size} sources" }
|
||||
|
||||
@@ -138,19 +140,24 @@ class TestExtensionCompatibility {
|
||||
semaphore.withPermit {
|
||||
logger.info { "${chapterCount.getAndIncrement()} - Now fetching manga chapters from $source" }
|
||||
try {
|
||||
chaptersToFetch += Triple(
|
||||
source,
|
||||
manga,
|
||||
repeat { source.getChapterList(manga) }.firstOrNull() ?: throw Exception("Source returned no chapters")
|
||||
)
|
||||
chaptersToFetch +=
|
||||
Triple(
|
||||
source,
|
||||
manga,
|
||||
repeat { source.getChapterList(manga) }.firstOrNull() ?: throw Exception("Source returned no chapters"),
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
logger.warn {
|
||||
"Failed to fetch manga chapters from $source for ${manga.title} (${source.mangaDetailsRequest(manga).url}): ${e.message}"
|
||||
"Failed to fetch manga chapters from $source for ${manga.title} (${source.mangaDetailsRequest(
|
||||
manga,
|
||||
).url}): ${e.message}"
|
||||
}
|
||||
chaptersFailedToFetch += Triple(source, manga, e)
|
||||
} catch (e: NoClassDefFoundError) {
|
||||
logger.warn {
|
||||
"Failed to fetch manga chapters from $source for ${manga.title} (${source.mangaDetailsRequest(manga).url}): ${e.message}"
|
||||
"Failed to fetch manga chapters from $source for ${manga.title} (${source.mangaDetailsRequest(
|
||||
manga,
|
||||
).url}): ${e.message}"
|
||||
}
|
||||
chaptersFailedToFetch += Triple(source, manga, e)
|
||||
}
|
||||
@@ -163,7 +170,7 @@ class TestExtensionCompatibility {
|
||||
"${source.name} (${source.lang}, ${source.id}):" +
|
||||
" ${manga.title} (${source.mangaDetailsRequest(manga).url}):" +
|
||||
" ${exception.message}"
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
val pageListCount = AtomicInteger(1)
|
||||
@@ -175,7 +182,9 @@ class TestExtensionCompatibility {
|
||||
repeat { source.getPageList(chapter) }
|
||||
} catch (e: Exception) {
|
||||
logger.warn {
|
||||
"Failed to fetch manga info from $source for ${manga.title} (${source.mangaDetailsRequest(manga).url}): ${e.message}"
|
||||
"Failed to fetch manga info from $source for ${manga.title} (${source.mangaDetailsRequest(
|
||||
manga,
|
||||
).url}): ${e.message}"
|
||||
}
|
||||
chaptersPageListFailedToFetch += Triple(source, manga to chapter, e)
|
||||
}
|
||||
@@ -188,7 +197,7 @@ class TestExtensionCompatibility {
|
||||
"${source.name} (${source.lang}, ${source.id}):" +
|
||||
" ${manga.first.title} (${source.mangaDetailsRequest(manga.first).url}):" +
|
||||
" ${manga.second.name} (${manga.second.url}): ${exception.message}"
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -197,7 +206,8 @@ class TestExtensionCompatibility {
|
||||
for (i in 1..2) {
|
||||
try {
|
||||
return block()
|
||||
} catch (e: Exception) {}
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
return block()
|
||||
}
|
||||
|
||||
@@ -20,41 +20,80 @@ class RequestParserTest {
|
||||
private val requestParser = JavalinGraphQLRequestParser()
|
||||
|
||||
@Test
|
||||
fun testZero() = runTest {
|
||||
every { ctx.appAttribute<JsonMapper>(JSON_MAPPER_KEY) } returns (JavalinJackson(JavalinJackson.defaultMapper()))
|
||||
every { ctx.formParam("operations") } returns """{ "query": "mutation (${'$'}file: Upload!) { singleUpload(file: ${'$'}file) { id } }", "variables": { "file": null } }"""
|
||||
every { ctx.formParam("map") } returns """{ "0": ["variables.file"] }"""
|
||||
every { ctx.uploadedFile("0") } returns UploadedFile(ByteArrayInputStream(byteArrayOf()), "", "", "", 0)
|
||||
val test = requestParser.parseRequest(ctx)
|
||||
assertIs<GraphQLRequest>(test)
|
||||
assertNotNull(test.variables?.get("file"))
|
||||
println("File: " + test.variables?.get("file"))
|
||||
}
|
||||
fun testZero() =
|
||||
runTest {
|
||||
every { ctx.appAttribute<JsonMapper>(JSON_MAPPER_KEY) } returns
|
||||
(JavalinJackson(JavalinJackson.defaultMapper()))
|
||||
every {
|
||||
ctx.formParam("operations")
|
||||
} returns
|
||||
"""{ "query": "mutation (${'$'}file: Upload!) {
|
||||
|singleUpload(file: ${'$'}file) { id } }", "variables": { "file": null }
|
||||
|}
|
||||
""".trimMargin()
|
||||
every { ctx.formParam("map") } returns """{ "0": ["variables.file"] }"""
|
||||
every { ctx.uploadedFile("0") } returns
|
||||
UploadedFile(
|
||||
ByteArrayInputStream(byteArrayOf()), "", "", "", 0,
|
||||
)
|
||||
val test = requestParser.parseRequest(ctx)
|
||||
assertIs<GraphQLRequest>(test)
|
||||
assertNotNull(test.variables?.get("file"))
|
||||
println("File: " + test.variables?.get("file"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTest() = runTest {
|
||||
every { ctx.appAttribute<JsonMapper>(JSON_MAPPER_KEY) } returns (JavalinJackson(JavalinJackson.defaultMapper()))
|
||||
every { ctx.formParam("operations") } returns """{ "query": "mutation (${'$'}file: Upload!) { singleUpload(file: ${'$'}file) { id } }", "variables": { "file": null } }"""
|
||||
every { ctx.formParam("map") } returns """{ "test": ["variables.file"] }"""
|
||||
every { ctx.uploadedFile("test") } returns UploadedFile(ByteArrayInputStream(byteArrayOf()), "", "", "", 0)
|
||||
val test = requestParser.parseRequest(ctx)
|
||||
assertIs<GraphQLRequest>(test)
|
||||
assertNotNull(test.variables?.get("file"))
|
||||
println("File: " + test.variables?.get("file"))
|
||||
}
|
||||
fun testTest() =
|
||||
runTest {
|
||||
every { ctx.appAttribute<JsonMapper>(JSON_MAPPER_KEY) } returns
|
||||
(JavalinJackson(JavalinJackson.defaultMapper()))
|
||||
every {
|
||||
ctx.formParam("operations")
|
||||
} returns
|
||||
"""{ "query": "mutation (${'$'}file: Upload!) {
|
||||
|singleUpload(file: ${'$'}file) { id } }", "variables": { "file": null }
|
||||
|}
|
||||
""".trimMargin()
|
||||
every { ctx.formParam("map") } returns """{ "test": ["variables.file"] }"""
|
||||
every { ctx.uploadedFile("test") } returns
|
||||
UploadedFile(
|
||||
ByteArrayInputStream(byteArrayOf()), "", "", "", 0,
|
||||
)
|
||||
val test = requestParser.parseRequest(ctx)
|
||||
assertIs<GraphQLRequest>(test)
|
||||
assertNotNull(test.variables?.get("file"))
|
||||
println("File: " + test.variables?.get("file"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testList() = runTest {
|
||||
every { ctx.appAttribute<JsonMapper>(JSON_MAPPER_KEY) } returns (JavalinJackson(JavalinJackson.defaultMapper()))
|
||||
every { ctx.formParam("operations") } returns """{ "query": "mutation (${'$'}files: [Upload!]!) { singleUpload(files: ${'$'}files) { id } }", "variables": { "files": [null, null] } }"""
|
||||
every { ctx.formParam("map") } returns """{ "test": ["variables.files.0"], "test2": ["variables.files.1"] }"""
|
||||
every { ctx.uploadedFile("test") } returns UploadedFile(ByteArrayInputStream(byteArrayOf()), "", "", "", 0)
|
||||
every { ctx.uploadedFile("test2") } returns UploadedFile(ByteArrayInputStream(byteArrayOf()), "", "", "", 0)
|
||||
val test = requestParser.parseRequest(ctx)
|
||||
assertIs<GraphQLRequest>(test)
|
||||
val files = test.variables?.get("files")
|
||||
assertIs<List<*>>(files)
|
||||
assert(files.all { it is UploadedFile })
|
||||
println("Files: $files")
|
||||
}
|
||||
fun testList() =
|
||||
runTest {
|
||||
every { ctx.appAttribute<JsonMapper>(JSON_MAPPER_KEY) } returns
|
||||
(JavalinJackson(JavalinJackson.defaultMapper()))
|
||||
every {
|
||||
ctx.formParam("operations")
|
||||
} returns
|
||||
"""{ "query": "mutation (${'$'}files: [Upload!]!) {
|
||||
|singleUpload(files: ${'$'}files) { id } }", "variables": { "files": [null, null] }
|
||||
|}
|
||||
""".trimMargin()
|
||||
every { ctx.formParam("map") } returns
|
||||
"""
|
||||
{ "test": ["variables.files.0"], "test2": ["variables.files.1"] }
|
||||
""".trimIndent()
|
||||
every { ctx.uploadedFile("test") } returns
|
||||
UploadedFile(
|
||||
ByteArrayInputStream(byteArrayOf()), "", "", "", 0,
|
||||
)
|
||||
every { ctx.uploadedFile("test2") } returns
|
||||
UploadedFile(
|
||||
ByteArrayInputStream(byteArrayOf()), "", "", "", 0,
|
||||
)
|
||||
val test = requestParser.parseRequest(ctx)
|
||||
assertIs<GraphQLRequest>(test)
|
||||
val files = test.variables?.get("files")
|
||||
assertIs<List<*>>(files)
|
||||
assert(files.all { it is UploadedFile })
|
||||
println("Files: $files")
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ class CategoryControllerTest : ApplicationTest() {
|
||||
@AfterEach
|
||||
internal fun tearDown() {
|
||||
clearTables(
|
||||
CategoryTable
|
||||
CategoryTable,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,9 +63,7 @@ internal class UpdateControllerTest : ApplicationTest() {
|
||||
assertEquals(3, updater.status.value.numberOfJobs)
|
||||
}
|
||||
|
||||
private fun createLibraryManga(
|
||||
_title: String
|
||||
): Int {
|
||||
private fun createLibraryManga(_title: String): Int {
|
||||
return transaction {
|
||||
MangaTable.insertAndGetId {
|
||||
it[title] = _title
|
||||
@@ -81,7 +79,7 @@ internal class UpdateControllerTest : ApplicationTest() {
|
||||
clearTables(
|
||||
CategoryMangaTable,
|
||||
MangaTable,
|
||||
CategoryTable
|
||||
CategoryTable,
|
||||
)
|
||||
val updater by DI.global.instance<IUpdater>()
|
||||
runBlocking { updater.reset() }
|
||||
|
||||
@@ -33,36 +33,36 @@ class CategoryMangaTest : ApplicationTest() {
|
||||
assertEquals(
|
||||
0,
|
||||
CategoryManga.getCategoryMangaList(DEFAULT_CATEGORY_ID)[0].unreadCount,
|
||||
"Manga should not have any unread chapters"
|
||||
"Manga should not have any unread chapters",
|
||||
)
|
||||
createChapters(mangaId, 10, false)
|
||||
assertEquals(
|
||||
10,
|
||||
CategoryManga.getCategoryMangaList(DEFAULT_CATEGORY_ID)[0].unreadCount,
|
||||
"Manga should have unread chapters"
|
||||
"Manga should have unread chapters",
|
||||
)
|
||||
|
||||
val categoryId = Category.createCategory("Old")
|
||||
assertEquals(
|
||||
0,
|
||||
CategoryManga.getCategoryMangaList(categoryId).size,
|
||||
"Newly created category shouldn't have any Mangas"
|
||||
"Newly created category shouldn't have any Mangas",
|
||||
)
|
||||
CategoryManga.addMangaToCategory(mangaId, categoryId)
|
||||
assertEquals(
|
||||
1,
|
||||
CategoryManga.getCategoryMangaList(categoryId).size,
|
||||
"Manga should been moved"
|
||||
"Manga should been moved",
|
||||
)
|
||||
assertEquals(
|
||||
10,
|
||||
CategoryManga.getCategoryMangaList(categoryId)[0].unreadCount,
|
||||
"Manga should keep it's unread count in moved category"
|
||||
"Manga should keep it's unread count in moved category",
|
||||
)
|
||||
assertEquals(
|
||||
0,
|
||||
CategoryManga.getCategoryMangaList(DEFAULT_CATEGORY_ID).size,
|
||||
"Manga shouldn't be member of default category after moving"
|
||||
"Manga shouldn't be member of default category after moving",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class CategoryMangaTest : ApplicationTest() {
|
||||
ChapterTable,
|
||||
CategoryMangaTable,
|
||||
MangaTable,
|
||||
CategoryTable
|
||||
CategoryTable,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,24 +33,24 @@ class MangaTest : ApplicationTest() {
|
||||
assertEquals(
|
||||
1,
|
||||
Manga.getMangaMetaMap(metaManga).size,
|
||||
"Manga meta should still only have one pair"
|
||||
"Manga meta should still only have one pair",
|
||||
)
|
||||
assertEquals(
|
||||
"newValue",
|
||||
Manga.getMangaMetaMap(metaManga)["test"],
|
||||
"Manga meta with key 'test' should use the value `newValue`"
|
||||
"Manga meta with key 'test' should use the value `newValue`",
|
||||
)
|
||||
|
||||
Manga.modifyMangaMeta(metaManga, "test2", "value2")
|
||||
assertEquals(
|
||||
2,
|
||||
Manga.getMangaMetaMap(metaManga).size,
|
||||
"Manga Meta should have an additional pair"
|
||||
"Manga Meta should have an additional pair",
|
||||
)
|
||||
assertEquals(
|
||||
"value2",
|
||||
Manga.getMangaMetaMap(metaManga)["test2"],
|
||||
"Manga Meta for key 'test2' should be 'value2'"
|
||||
"Manga Meta for key 'test2' should be 'value2'",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class MangaTest : ApplicationTest() {
|
||||
internal fun tearDown() {
|
||||
clearTables(
|
||||
MangaMetaTable,
|
||||
MangaTable
|
||||
MangaTable,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,14 +13,14 @@ import suwayomi.tachidesk.test.ApplicationTest
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class PageTest : ApplicationTest() {
|
||||
|
||||
@Test
|
||||
fun testGetPageName() {
|
||||
val tests = listOf(0, 1, 2, 100)
|
||||
|
||||
val testResults = tests.map {
|
||||
getPageName(it)
|
||||
}
|
||||
val testResults =
|
||||
tests.map {
|
||||
getPageName(it)
|
||||
}
|
||||
|
||||
assertEquals(testResults[0], "001")
|
||||
assertEquals(testResults[1], "002")
|
||||
|
||||
@@ -39,7 +39,11 @@ class SearchTest : ApplicationTest() {
|
||||
var mangas: List<SManga> = emptyList()
|
||||
|
||||
@Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getSearchManga"))
|
||||
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
|
||||
override fun fetchSearchManga(
|
||||
page: Int,
|
||||
query: String,
|
||||
filters: FilterList,
|
||||
): Observable<MangasPage> {
|
||||
return Observable.just(MangasPage(mangas, false))
|
||||
}
|
||||
}
|
||||
@@ -57,9 +61,10 @@ class SearchTest : ApplicationTest() {
|
||||
|
||||
@Test
|
||||
fun searchWorks() {
|
||||
val searchResults = runBlocking {
|
||||
sourceSearch(sourceId, "all the mangas", 1)
|
||||
}
|
||||
val searchResults =
|
||||
runBlocking {
|
||||
sourceSearch(sourceId, "all the mangas", 1)
|
||||
}
|
||||
|
||||
assertEquals(mangasCount, searchResults.mangaList.size, "should return all the mangas")
|
||||
}
|
||||
@@ -89,39 +94,45 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
assertEquals(
|
||||
0,
|
||||
filterList.size
|
||||
filterList.size,
|
||||
)
|
||||
}
|
||||
|
||||
class FilterListSource(id: Long) : EmptyFilterListSource(id) {
|
||||
class SelectFilter(name: String, values: Array<String>) : Filter.Select<String>(name, values)
|
||||
|
||||
class TextFilter(name: String) : Filter.Text(name)
|
||||
|
||||
class TestCheckBox(name: String) : Filter.CheckBox(name, false)
|
||||
|
||||
class TriState(name: String, state: Int) : Filter.TriState(name, state)
|
||||
|
||||
class Group(name: String, state: List<TestCheckBox>) : Filter.Group<TestCheckBox>(name, state)
|
||||
|
||||
class Sort(name: String, values: Array<String>, state: Selection) : Filter.Sort(name, values, state)
|
||||
|
||||
override var mFilterList = FilterList(
|
||||
Filter.Header("This is a header"),
|
||||
Filter.Separator(),
|
||||
SelectFilter("Select one of these:", arrayOf("this", "that", "none of them")),
|
||||
TextFilter("text filter"),
|
||||
TestCheckBox("check this or else!"),
|
||||
TriState("wanna hook up?", Filter.TriState.STATE_IGNORE),
|
||||
Group(
|
||||
"my Todo",
|
||||
listOf(
|
||||
TestCheckBox("Write Tests"),
|
||||
TestCheckBox("Write More Tests"),
|
||||
TestCheckBox("Write Even More Tests")
|
||||
)
|
||||
),
|
||||
Sort(
|
||||
"Sort",
|
||||
arrayOf("Alphabetic", "Date published", "Rating"),
|
||||
Filter.Sort.Selection(2, false)
|
||||
override var mFilterList =
|
||||
FilterList(
|
||||
Filter.Header("This is a header"),
|
||||
Filter.Separator(),
|
||||
SelectFilter("Select one of these:", arrayOf("this", "that", "none of them")),
|
||||
TextFilter("text filter"),
|
||||
TestCheckBox("check this or else!"),
|
||||
TriState("wanna hook up?", Filter.TriState.STATE_IGNORE),
|
||||
Group(
|
||||
"my Todo",
|
||||
listOf(
|
||||
TestCheckBox("Write Tests"),
|
||||
TestCheckBox("Write More Tests"),
|
||||
TestCheckBox("Write Even More Tests"),
|
||||
),
|
||||
),
|
||||
Sort(
|
||||
"Sort",
|
||||
arrayOf("Alphabetic", "Date published", "Rating"),
|
||||
Filter.Sort.Selection(2, false),
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,27 +142,27 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
assertEquals(
|
||||
FilterObject("Header", source.mFilterList[0]),
|
||||
filterList[0]
|
||||
filterList[0],
|
||||
)
|
||||
assertEquals(
|
||||
FilterObject("Separator", source.mFilterList[1]),
|
||||
filterList[1]
|
||||
filterList[1],
|
||||
)
|
||||
assertEquals(
|
||||
FilterObject("Select", source.mFilterList[2]),
|
||||
filterList[2]
|
||||
filterList[2],
|
||||
)
|
||||
assertEquals(
|
||||
FilterObject("Text", source.mFilterList[3]),
|
||||
filterList[3]
|
||||
filterList[3],
|
||||
)
|
||||
assertEquals(
|
||||
FilterObject("CheckBox", source.mFilterList[4]),
|
||||
filterList[4]
|
||||
filterList[4],
|
||||
)
|
||||
assertEquals(
|
||||
FilterObject("TriState", source.mFilterList[5]),
|
||||
filterList[5]
|
||||
filterList[5],
|
||||
)
|
||||
assertEquals(
|
||||
filterList[6],
|
||||
@@ -162,14 +173,14 @@ class FilterListTest : ApplicationTest() {
|
||||
listOf(
|
||||
FilterObject("CheckBox", (source.mFilterList[6].state as List<Filter<*>>)[0]),
|
||||
FilterObject("CheckBox", (source.mFilterList[6].state as List<Filter<*>>)[1]),
|
||||
FilterObject("CheckBox", (source.mFilterList[6].state as List<Filter<*>>)[2])
|
||||
)
|
||||
)
|
||||
)
|
||||
FilterObject("CheckBox", (source.mFilterList[6].state as List<Filter<*>>)[2]),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
assertEquals(
|
||||
FilterObject("Sort", source.mFilterList[7]),
|
||||
filterList[7]
|
||||
filterList[7],
|
||||
)
|
||||
|
||||
// make sure that we can convert this to json
|
||||
@@ -182,24 +193,24 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(0, "change!")
|
||||
FilterChange(0, "change!"),
|
||||
)
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(1, "change!")
|
||||
FilterChange(1, "change!"),
|
||||
)
|
||||
|
||||
val filterList = getFilterList(source.id, false)
|
||||
|
||||
assertEquals(
|
||||
filterList[0].filter.state,
|
||||
0
|
||||
0,
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
filterList[1].filter.state,
|
||||
0
|
||||
0,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -209,14 +220,14 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(2, "1")
|
||||
FilterChange(2, "1"),
|
||||
)
|
||||
|
||||
val filterList = getFilterList(source.id, false)
|
||||
|
||||
assertEquals(
|
||||
filterList[2].filter.state,
|
||||
1
|
||||
1,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -226,14 +237,14 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(3, "I'm a changed man!")
|
||||
FilterChange(3, "I'm a changed man!"),
|
||||
)
|
||||
|
||||
val filterList = getFilterList(source.id, false)
|
||||
|
||||
assertEquals(
|
||||
filterList[3].filter.state,
|
||||
"I'm a changed man!"
|
||||
"I'm a changed man!",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -243,14 +254,14 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(4, "true")
|
||||
FilterChange(4, "true"),
|
||||
)
|
||||
|
||||
val filterList = getFilterList(source.id, false)
|
||||
|
||||
assertEquals(
|
||||
filterList[4].filter.state,
|
||||
true
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -260,14 +271,14 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(5, "1")
|
||||
FilterChange(5, "1"),
|
||||
)
|
||||
|
||||
val filterList = getFilterList(source.id, false)
|
||||
|
||||
assertEquals(
|
||||
filterList[5].filter.state,
|
||||
Filter.TriState.STATE_INCLUDE
|
||||
Filter.TriState.STATE_INCLUDE,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -277,14 +288,14 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(6, """{"position":0,"state":"true"}""")
|
||||
FilterChange(6, """{"position":0,"state":"true"}"""),
|
||||
)
|
||||
|
||||
val filterList = getFilterList(source.id, false)
|
||||
|
||||
assertEquals(
|
||||
(filterList[6].filter.state as List<FilterObject>)[0].filter.state,
|
||||
true
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -294,14 +305,14 @@ class FilterListTest : ApplicationTest() {
|
||||
|
||||
setFilter(
|
||||
source.id,
|
||||
FilterChange(7, """{"index":1,"ascending":"true"}""")
|
||||
FilterChange(7, """{"index":1,"ascending":"true"}"""),
|
||||
)
|
||||
|
||||
val filterList = getFilterList(source.id, false)
|
||||
|
||||
assertEquals(
|
||||
filterList[7].filter.state,
|
||||
Filter.Sort.Selection(1, true)
|
||||
Filter.Sort.Selection(1, true),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ package suwayomi.tachidesk.manga.model
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import suwayomi.tachidesk.manga.model.dataclass.PAGINATION_FACTOR
|
||||
import suwayomi.tachidesk.manga.model.dataclass.PaginatedList
|
||||
import suwayomi.tachidesk.manga.model.dataclass.PaginationFactor
|
||||
import suwayomi.tachidesk.manga.model.dataclass.paginatedFrom
|
||||
import suwayomi.tachidesk.test.ApplicationTest
|
||||
|
||||
@@ -21,85 +21,88 @@ class PaginatedListTest : ApplicationTest() {
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(emptyList<Int>(), false),
|
||||
paginated
|
||||
paginated,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `size smaller than PaginationFactor`() {
|
||||
val paginated = paginatedFrom(0) { listIndicesOf(0, PaginationFactor - 1) }
|
||||
val paginated = paginatedFrom(0) { listIndicesOf(0, PAGINATION_FACTOR - 1) }
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(0, PaginationFactor - 1), false),
|
||||
paginated
|
||||
PaginatedList(listIndicesOf(0, PAGINATION_FACTOR - 1), false),
|
||||
paginated,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `one less than two times PaginationFactor`() {
|
||||
val masterLister = { listIndicesOf(0, PaginationFactor * 2 - 1) }
|
||||
val masterLister = { listIndicesOf(0, PAGINATION_FACTOR * 2 - 1) }
|
||||
|
||||
val firstPage = paginatedFrom(0, lister = masterLister)
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(0, PaginationFactor), true),
|
||||
firstPage
|
||||
PaginatedList(listIndicesOf(0, PAGINATION_FACTOR), true),
|
||||
firstPage,
|
||||
)
|
||||
|
||||
val secondPage = paginatedFrom(1, lister = masterLister)
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(PaginationFactor, PaginationFactor * 2 - 1), false),
|
||||
secondPage
|
||||
PaginatedList(listIndicesOf(PAGINATION_FACTOR, PAGINATION_FACTOR * 2 - 1), false),
|
||||
secondPage,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `two times PaginationFactor`() {
|
||||
val masterLister = { listIndicesOf(0, PaginationFactor * 2) }
|
||||
val masterLister = { listIndicesOf(0, PAGINATION_FACTOR * 2) }
|
||||
|
||||
val firstPage = paginatedFrom(0, lister = masterLister)
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(0, PaginationFactor), true),
|
||||
firstPage
|
||||
PaginatedList(listIndicesOf(0, PAGINATION_FACTOR), true),
|
||||
firstPage,
|
||||
)
|
||||
|
||||
val secondPage = paginatedFrom(1, lister = masterLister)
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(PaginationFactor, PaginationFactor * 2), false),
|
||||
secondPage
|
||||
PaginatedList(listIndicesOf(PAGINATION_FACTOR, PAGINATION_FACTOR * 2), false),
|
||||
secondPage,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `one more than two times PaginationFactor`() {
|
||||
val masterLister = { listIndicesOf(0, PaginationFactor * 2 + 1) }
|
||||
val masterLister = { listIndicesOf(0, PAGINATION_FACTOR * 2 + 1) }
|
||||
|
||||
val firstPage = paginatedFrom(0, lister = masterLister)
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(0, PaginationFactor), true),
|
||||
firstPage
|
||||
PaginatedList(listIndicesOf(0, PAGINATION_FACTOR), true),
|
||||
firstPage,
|
||||
)
|
||||
|
||||
val secondPage = paginatedFrom(1, lister = masterLister)
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(PaginationFactor, PaginationFactor * 2), true),
|
||||
secondPage
|
||||
PaginatedList(listIndicesOf(PAGINATION_FACTOR, PAGINATION_FACTOR * 2), true),
|
||||
secondPage,
|
||||
)
|
||||
|
||||
val thirdPage = paginatedFrom(2, lister = masterLister)
|
||||
|
||||
assertEquals(
|
||||
PaginatedList(listIndicesOf(PaginationFactor * 2, PaginationFactor * 2 + 1), false),
|
||||
thirdPage
|
||||
PaginatedList(listIndicesOf(PAGINATION_FACTOR * 2, PAGINATION_FACTOR * 2 + 1), false),
|
||||
thirdPage,
|
||||
)
|
||||
}
|
||||
|
||||
private fun listIndicesOf(first: Int, last: Int): List<Int> {
|
||||
private fun listIndicesOf(
|
||||
first: Int,
|
||||
last: Int,
|
||||
): List<Int> {
|
||||
return (first until last).toList()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ open class ApplicationTest {
|
||||
bind<ApplicationDirs>() with singleton { applicationDirs }
|
||||
bind<JsonMapper>() with singleton { JavalinJackson() }
|
||||
bind<IUpdater>() with singleton { TestUpdater() }
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
logger.debug("Data Root directory is set to: ${applicationDirs.dataRoot}")
|
||||
@@ -76,14 +76,14 @@ open class ApplicationTest {
|
||||
applicationDirs.extensionsRoot + "/icon",
|
||||
applicationDirs.tempThumbnailCacheRoot,
|
||||
applicationDirs.downloadsRoot,
|
||||
applicationDirs.localMangaRoot
|
||||
applicationDirs.localMangaRoot,
|
||||
).forEach {
|
||||
File(it).mkdirs()
|
||||
}
|
||||
|
||||
// register Tachidesk's config which is dubbed "ServerConfig"
|
||||
GlobalConfigManager.registerModule(
|
||||
ServerConfig.register { GlobalConfigManager.config }
|
||||
ServerConfig.register { GlobalConfigManager.config },
|
||||
)
|
||||
|
||||
// Make sure only one instance of the app is running
|
||||
@@ -128,7 +128,8 @@ open class ApplicationTest {
|
||||
if (serverConfig.systemTrayEnabled.value) {
|
||||
try {
|
||||
SystemTray.create()
|
||||
} catch (e: Throwable) { // cover both java.lang.Exception and java.lang.Error
|
||||
} catch (e: Throwable) {
|
||||
// cover both java.lang.Exception and java.lang.Error
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,18 +21,17 @@ import suwayomi.tachidesk.manga.model.table.MangaTable
|
||||
|
||||
fun setLoggingEnabled(enabled: Boolean = true) {
|
||||
val logger = (KotlinLogging.logger(Logger.ROOT_LOGGER_NAME).underlyingLogger as ch.qos.logback.classic.Logger)
|
||||
logger.level = if (enabled) {
|
||||
Level.DEBUG
|
||||
} else {
|
||||
Level.ERROR
|
||||
}
|
||||
logger.level =
|
||||
if (enabled) {
|
||||
Level.DEBUG
|
||||
} else {
|
||||
Level.ERROR
|
||||
}
|
||||
}
|
||||
|
||||
const val BASE_PATH = "build/tmp/TestDesk"
|
||||
|
||||
fun createLibraryManga(
|
||||
_title: String
|
||||
): Int {
|
||||
fun createLibraryManga(_title: String): Int {
|
||||
return transaction {
|
||||
MangaTable.insertAndGetId {
|
||||
it[title] = _title
|
||||
@@ -43,9 +42,7 @@ fun createLibraryManga(
|
||||
}
|
||||
}
|
||||
|
||||
fun createSMangas(
|
||||
count: Int
|
||||
): List<SManga> {
|
||||
fun createSMangas(count: Int): List<SManga> {
|
||||
return (0 until count).map {
|
||||
SManga.create().apply {
|
||||
title = "Manga $it"
|
||||
@@ -57,7 +54,7 @@ fun createSMangas(
|
||||
fun createChapters(
|
||||
mangaId: Int,
|
||||
amount: Int,
|
||||
read: Boolean
|
||||
read: Boolean,
|
||||
) {
|
||||
val list = listOf((0 until amount)).flatten().map { 1 }
|
||||
transaction {
|
||||
|
||||
Reference in New Issue
Block a user