Commit e1b5ad39 authored by Shivansh Saini's avatar Shivansh Saini

Done PlaylistsViewModelTest

parent 8101fdd4
......@@ -74,6 +74,14 @@ public class StubDataSource {
mFolders.clear();
mVideoMediaWrappers.clear();
mAudioMediaWrappers.clear();
mStreamMediaWrappers.clear();
mHistory.clear();
mPlaylists.clear();
mAlbums.clear();
mArtists.clear();
mGenres.clear();
mBannedFolders.clear();
mDevices.clear();
}
public void setVideoByCount(int count, @Nullable String folder) {
......
......@@ -142,56 +142,4 @@ class FoldersViewModelTest: BaseTest() {
assertTrue(foldersViewModel.isEmpty())
}
@Test
fun whenNoVideoFolderAndFilteredWithNonExistingFolder_checkResultIsEmpty() {
StubDataSource.getInstance().setVideoByCount(3, "test1")
foldersViewModel.provider.pagedList.test()
.awaitValue()
assertFalse(foldersViewModel.isEmpty())
foldersViewModel.filter("unknown")
foldersViewModel.refresh()
foldersViewModel.provider.pagedList.test()
.awaitValue()
assertTrue(foldersViewModel.isEmpty())
}
@Test
fun whenNoVideoFolderAndFilteredWithExistingFolder_checkResultIsNotEmpty() {
StubDataSource.getInstance().setVideoByCount(3, "test1")
foldersViewModel.provider.pagedList.test()
.awaitValue()
assertFalse(foldersViewModel.isEmpty())
foldersViewModel.filter("test")
foldersViewModel.refresh()
foldersViewModel.provider.pagedList.test()
.awaitValue()
assertFalse(foldersViewModel.isEmpty())
}
@Test
fun whenThereAreVideoFoldersButFilteredResultContainsNone_restoringViewModelResetsFilterAndShowsItemAgain() {
StubDataSource.getInstance().setVideoByCount(3, "test")
foldersViewModel.filter("unknown")
foldersViewModel.provider.pagedList.test()
.awaitValue()
assertTrue(foldersViewModel.isEmpty())
foldersViewModel.restore()
foldersViewModel.provider.pagedList.test()
.awaitValue()
assertFalse(foldersViewModel.isEmpty())
}
}
\ No newline at end of file
package org.videolan.vlc.viewmodels.mobile
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.vlc.BaseTest
import org.junit.Assert.*
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.medialibrary.stubs.StubDataSource
@ObsoleteCoroutinesApi
@ExperimentalCoroutinesApi
class PlaylistViewModelTest : BaseTest() {
private lateinit var playlistViewModel: PlaylistViewModel
override fun beforeTest() {
super.beforeTest()
StubDataSource.getInstance().resetData()
}
internal fun setupViewModel(parent: MediaLibraryItem) {
playlistViewModel = PlaylistViewModel(context, application, parent)
}
}
\ No newline at end of file
package org.videolan.vlc.viewmodels.mobile
import com.jraska.livedata.test
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.vlc.BaseTest
import org.junit.Assert.*
import org.junit.Test
import org.videolan.medialibrary.MLServiceLocator
import org.videolan.medialibrary.stubs.StubDataSource
import org.videolan.vlc.util.MEDIALIBRARY_PAGE_SIZE
@ObsoleteCoroutinesApi
@ExperimentalCoroutinesApi
class PlaylistsViewModelTest : BaseTest() {
private lateinit var playlistsViewModel: PlaylistsViewModel
private val mediaLibrary = MLServiceLocator.getAbstractMedialibrary()
override fun beforeTest() {
super.beforeTest()
StubDataSource.getInstance().resetData()
playlistsViewModel = PlaylistsViewModel(context, application)
}
private fun createDummyPlaylists(count: Int) {
(1..count).map {
mediaLibrary.createPlaylist("test$it")
}
}
@Test
fun whenNoPlaylist_checkResultIsEmpty() {
playlistsViewModel.provider.pagedList.test()
.awaitValue()
assertTrue(playlistsViewModel.isEmpty())
}
@Test
fun whenThereAre2Playlists_checkResultContainsThem() {
createDummyPlaylists(2)
val testResult = playlistsViewModel.provider.pagedList.test()
.awaitValue()
.value()
assertEquals(2, testResult.size)
assertEquals("test1", testResult[0]!!.title)
assertEquals("test2", testResult[1]!!.title)
}
@Test
fun whenNoPlaylists_checkTotalCountIsZero() {
playlistsViewModel.provider.pagedList.test()
.awaitValue()
assertEquals(0, playlistsViewModel.provider.getTotalCount())
}
@Test
fun whenThereAre2Playlists_checkTotalCountIsZero() {
createDummyPlaylists(2)
playlistsViewModel.provider.pagedList.test()
.awaitValue()
assertEquals(2, playlistsViewModel.provider.getTotalCount())
}
@Test
fun whenPlaylistsAreMoreThanMaxSize_checkLastIsNotLoadedYet() {
val count = MEDIALIBRARY_PAGE_SIZE * 3 + 1
createDummyPlaylists(count)
val testResult = playlistsViewModel.provider.pagedList.test()
.awaitValue()
.value()
assertNull(testResult[count - 1])
}
@Test
fun whenPlayListsAreMoreThanMaxSize_checkGetAllReturnsAll() {
val count = MEDIALIBRARY_PAGE_SIZE * 3 + 1
createDummyPlaylists(count)
val testResult = playlistsViewModel.provider.getAll()
assertNotNull(testResult[count - 1])
}
@Test
fun whenNoPlaylistsAndLaterAdded2Playlists_checkRefreshUpdatesTheList() {
playlistsViewModel.provider.pagedList.test()
.awaitValue()
assertTrue(playlistsViewModel.isEmpty())
assertEquals(0, playlistsViewModel.provider.getTotalCount())
createDummyPlaylists(2)
playlistsViewModel.refresh()
playlistsViewModel.provider.pagedList.test()
.awaitValue()
assertFalse(playlistsViewModel.isEmpty())
assertEquals(2, playlistsViewModel.provider.getTotalCount())
}
@Test
fun whenNoPlaylistsAndFiltered_checkResultIsEmpty() {
playlistsViewModel.filter("unknown")
playlistsViewModel.provider.pagedList.test()
.awaitValue()
assertTrue(playlistsViewModel.isEmpty())
}
@Test
fun whenThereAre2PlaylistsAndFilteredWithNonExistingPlaylist_checkResultIsEmpty() {
createDummyPlaylists(2)
playlistsViewModel.filter("unknown")
playlistsViewModel.provider.pagedList.test()
.awaitValue()
assertTrue(playlistsViewModel.isEmpty())
}
@Test
fun whenThereAre2PlaylistsAndFilteredWithExistingPlaylistTitle_checkResultContainsThem() {
createDummyPlaylists(2)
playlistsViewModel.filter("test")
playlistsViewModel.provider.pagedList.test()
.awaitValue()
assertFalse(playlistsViewModel.isEmpty())
assertEquals(2, playlistsViewModel.provider.getTotalCount())
}
@Test
fun whenFilteredAndLaterRestored_isFilteringIsTrueLaterFalse() {
createDummyPlaylists(2)
assertFalse(playlistsViewModel.isFiltering())
playlistsViewModel.filter(StubDataSource.STUBBED_VIDEO_TITLE.substring(2, 6))
assertTrue(playlistsViewModel.isFiltering())
playlistsViewModel.restore()
assertFalse(playlistsViewModel.isFiltering())
}
@Test
fun whenThereAreSomePlaylistsButFilteredResultContainsNone_restoringViewModelResetsFilterAndShowsItemAgain() {
createDummyPlaylists(2)
playlistsViewModel.filter("unknown")
playlistsViewModel.provider.pagedList.test()
.awaitValue()
assertTrue(playlistsViewModel.isEmpty())
playlistsViewModel.restore()
playlistsViewModel.provider.pagedList.test()
.awaitValue()
assertFalse(playlistsViewModel.isEmpty())
}
@Test
fun whenThereAre2PlaylistsStartingWithT_checkHeaders() {
createDummyPlaylists(2)
playlistsViewModel.provider.pagedList.test()
.awaitValue()
val headers = playlistsViewModel.provider.liveHeaders.test()
.value()
assertEquals(1, headers.size())
assertEquals("T", headers[0])
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment