[fenix] For https://github.com/mozilla-mobile/fenix/issues/20425: Update AC version
[gecko.git] / mobile / android / fenix / app / src / test / java / org / mozilla / fenix / library / bookmarks / DesktopFoldersTest.kt
blob06644a5bf9e6a7226e259f9ee212ccde46849374
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
8 import io.mockk.every
9 import io.mockk.mockk
10 import io.mockk.spyk
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
19 import org.junit.Test
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,
33         parentGuid = null,
34         title = BookmarkRoot.Root.name,
35         position = 0,
36         url = null,
37         dateAdded = 0,
38         children = null
39     )
41     @Before
42     fun setup() {
43         context = spyk(testContext)
44         every { context.components.core.bookmarksStorage } returns mockk()
45     }
47     @Test
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")))
54     }
56     @Test
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))
63     }
65     @Test
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))
71     }
73     private fun mockNodeWithTitle(title: String) = basicNode.copy(title = title)