SelfManga parser

This commit is contained in:
Koitharu
2020-02-02 15:27:22 +02:00
parent 6d4a77b023
commit 7d677833fa
5 changed files with 82 additions and 3 deletions

View File

@@ -5,9 +5,12 @@ import kotlinx.android.parcel.Parcelize
import org.koitharu.kotatsu.core.parser.MangaRepository
import org.koitharu.kotatsu.core.parser.site.MintMangaRepository
import org.koitharu.kotatsu.core.parser.site.ReadmangaRepository
import org.koitharu.kotatsu.core.parser.site.SelfMangaRepository
@Suppress("SpellCheckingInspection")
@Parcelize
enum class MangaSource(val title: String, val cls: Class<out MangaRepository>): Parcelable {
READMANGA_RU("ReadManga", ReadmangaRepository::class.java),
MINTMANGA("MintManga", MintMangaRepository::class.java)
MINTMANGA("MintManga", MintMangaRepository::class.java),
SELFMANGA("SelfManga", SelfMangaRepository::class.java)
}

View File

@@ -0,0 +1,10 @@
package org.koitharu.kotatsu.core.parser.site
import org.koitharu.kotatsu.core.model.MangaSource
import org.koitharu.kotatsu.domain.MangaLoaderContext
class SelfMangaRepository(loaderContext: MangaLoaderContext) :
GroupleRepository(MangaSource.SELFMANGA, loaderContext) {
override val domain: String = "selfmanga.ru"
}

View File

@@ -30,7 +30,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
navigationView.setNavigationItemSelectedListener(this)
if (!supportFragmentManager.isStateSaved) {
setPrimaryFragment(RemoteListFragment.newInstance(MangaSource.READMANGA_RU))
navigationView.setCheckedItem(R.id.nav_history)
}
}

View File

@@ -35,7 +35,7 @@ abstract class RepositoryTestEnvironment {
fun getMangaList() = runBlocking { repository.getList(2) }
fun getMangaItem() = runBlocking { repository.getDetails(repository.getList(4).last()) }
fun getMangaItem() = runBlocking { repository.getDetails(repository.getList(5).last()) }
fun getTags() = runBlocking { repository.getTags() }
}

View File

@@ -0,0 +1,66 @@
package org.koitharu.kotatsu.parsers.repository
import kotlinx.coroutines.runBlocking
import org.junit.Assert
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.koitharu.kotatsu.core.model.MangaSource
import org.koitharu.kotatsu.parsers.MangaParserTest
import org.koitharu.kotatsu.parsers.RepositoryTestEnvironment
import org.koitharu.kotatsu.utils.TestUtil
import org.mockito.junit.MockitoJUnitRunner
@RunWith(MockitoJUnitRunner::class)
class SelfMangaTest : MangaParserTest {
@Test
override fun testMangaList() {
val list = getMangaList()
Assert.assertTrue(list.size == 70)
val item = list[40]
Assert.assertTrue(item.title.isNotEmpty())
Assert.assertTrue(item.rating in 0f..1f)
TestUtil.assertValidUrl(item.url)
TestUtil.assertValidUrl(item.coverUrl)
Assert.assertEquals(item.source, MangaSource.SELFMANGA)
}
@Test
override fun testMangaDetails() {
val manga = getMangaItem()
Assert.assertNotNull(manga.largeCoverUrl)
TestUtil.assertValidUrl(manga.largeCoverUrl!!)
Assert.assertNotNull(manga.chapters)
val chapter = manga.chapters!!.last()
Assert.assertEquals(chapter.source, MangaSource.SELFMANGA)
TestUtil.assertValidUrl(chapter.url)
}
@Test
override fun testMangaPages() {
val chapter = getMangaItem().chapters!!.first()
val pages = runBlocking { repository.getPages(chapter) }
Assert.assertFalse(pages.isEmpty())
Assert.assertEquals(pages.first().source, MangaSource.SELFMANGA)
TestUtil.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.first()) })
TestUtil.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.last()) })
}
@Test
override fun testTags() {
val tags = getTags()
Assert.assertFalse(tags.isEmpty())
val tag = tags.first()
Assert.assertFalse(tag.title.isBlank())
Assert.assertEquals(tag.source, MangaSource.SELFMANGA)
TestUtil.assertValidUrl("https://selfmanga.ru/list/genre/${tag.key}")
}
companion object : RepositoryTestEnvironment() {
@JvmStatic
@BeforeClass
fun setUp() = initialize(MangaSource.SELFMANGA)
}
}