1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.fenix.library.bookmarks
7 import android.content.Context
11 import kotlinx.coroutines.runBlocking
12 import mozilla.appservices.places.BookmarkRoot
13 import mozilla.components.concept.storage.BookmarkNode
14 import mozilla.components.concept.storage.BookmarkNodeType
15 import mozilla.components.support.test.robolectric.testContext
16 import org.junit.Assert.assertEquals
17 import org.junit.Assert.assertSame
18 import org.junit.Before
20 import org.junit.runner.RunWith
21 import org.mozilla.fenix.R
22 import org.mozilla.fenix.ext.components
23 import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
25 @RunWith(FenixRobolectricTestRunner::class)
26 class DesktopFoldersTest {
28 private lateinit var context: Context
30 private val basicNode = BookmarkNode(
31 type = BookmarkNodeType.FOLDER,
32 guid = BookmarkRoot.Root.id,
34 title = BookmarkRoot.Root.name,
43 context = spyk(testContext)
44 every { context.components.core.bookmarksStorage } returns mockk()
48 fun `withRootTitle and do showMobileRoot`() {
49 assertEquals(testContext.getString(R.string.library_bookmarks), friendlyRootTitle(context, mockNodeWithTitle("root")))
50 assertEquals(testContext.getString(R.string.library_bookmarks), friendlyRootTitle(context, mockNodeWithTitle("mobile")))
51 assertEquals(testContext.getString(R.string.library_desktop_bookmarks_menu), friendlyRootTitle(context, mockNodeWithTitle("menu")))
52 assertEquals(testContext.getString(R.string.library_desktop_bookmarks_toolbar), friendlyRootTitle(context, mockNodeWithTitle("toolbar")))
53 assertEquals(testContext.getString(R.string.library_desktop_bookmarks_unfiled), friendlyRootTitle(context, mockNodeWithTitle("unfiled")))
57 fun `withRootTitle and do not showMobileRoot`() {
58 assertEquals(testContext.getString(R.string.library_desktop_bookmarks_root), friendlyRootTitle(context, mockNodeWithTitle("root"), false))
59 assertEquals(mockNodeWithTitle("mobile").title, friendlyRootTitle(context, mockNodeWithTitle("mobile"), false))
60 assertEquals(testContext.getString(R.string.library_desktop_bookmarks_menu), friendlyRootTitle(context, mockNodeWithTitle("menu"), false))
61 assertEquals(testContext.getString(R.string.library_desktop_bookmarks_toolbar), friendlyRootTitle(context, mockNodeWithTitle("toolbar"), false))
62 assertEquals(testContext.getString(R.string.library_desktop_bookmarks_unfiled), friendlyRootTitle(context, mockNodeWithTitle("unfiled"), false))
66 fun `withOptionalDesktopFolders other node`() = runBlocking {
67 val node = basicNode.copy(guid = "12345")
68 val desktopFolders = DesktopFolders(context, showMobileRoot = true)
70 assertSame(node, desktopFolders.withOptionalDesktopFolders(node))
73 private fun mockNodeWithTitle(title: String) = basicNode.copy(title = title)