Deletes these very confusing mocks into account viewmodels for the test
This commit is contained in:
+7
-5
@@ -281,8 +281,10 @@ open class ShortNotePostViewModel :
|
|||||||
pTags = null
|
pTags = null
|
||||||
}
|
}
|
||||||
|
|
||||||
canAddInvoice = accountViewModel.userProfile().info?.lnAddress() != null
|
val user = account.userProfile()
|
||||||
canAddZapRaiser = accountViewModel.userProfile().info?.lnAddress() != null
|
|
||||||
|
canAddInvoice = user.info?.lnAddress() != null
|
||||||
|
canAddZapRaiser = user.info?.lnAddress() != null
|
||||||
canUsePoll = originalNote == null
|
canUsePoll = originalNote == null
|
||||||
multiOrchestrator = null
|
multiOrchestrator = null
|
||||||
|
|
||||||
@@ -290,12 +292,12 @@ open class ShortNotePostViewModel :
|
|||||||
message = TextFieldValue(message.text + "\nnostr:${quotedNote.toNEvent()}")
|
message = TextFieldValue(message.text + "\nnostr:${quotedNote.toNEvent()}")
|
||||||
|
|
||||||
quotedNote.author?.let { quotedUser ->
|
quotedNote.author?.let { quotedUser ->
|
||||||
if (quotedUser.pubkeyHex != accountViewModel.userProfile().pubkeyHex) {
|
if (quotedUser.pubkeyHex != user.pubkeyHex) {
|
||||||
if (forwardZapTo.value.items.none { it.key.pubkeyHex == quotedUser.pubkeyHex }) {
|
if (forwardZapTo.value.items.none { it.key.pubkeyHex == quotedUser.pubkeyHex }) {
|
||||||
forwardZapTo.value.addItem(quotedUser)
|
forwardZapTo.value.addItem(quotedUser)
|
||||||
}
|
}
|
||||||
if (forwardZapTo.value.items.none { it.key.pubkeyHex == accountViewModel.userProfile().pubkeyHex }) {
|
if (forwardZapTo.value.items.none { it.key.pubkeyHex == user.pubkeyHex }) {
|
||||||
forwardZapTo.value.addItem(accountViewModel.userProfile())
|
forwardZapTo.value.addItem(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
val pos = forwardZapTo.value.items.indexOfFirst { it.key.pubkeyHex == quotedUser.pubkeyHex }
|
val pos = forwardZapTo.value.items.indexOfFirst { it.key.pubkeyHex == quotedUser.pubkeyHex }
|
||||||
|
|||||||
@@ -1,132 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2025 Vitor Pamplona
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to use,
|
|
||||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
|
||||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
||||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package com.vitorpamplona.amethyst.ui.actions
|
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
|
||||||
import com.vitorpamplona.amethyst.model.User
|
|
||||||
import com.vitorpamplona.amethyst.model.nip30CustomEmojis.EmojiPackState.EmojiMedia
|
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.home.ShortNotePostViewModel
|
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
|
||||||
import com.vitorpamplona.quartz.nip01Core.tags.people.PTag
|
|
||||||
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
|
|
||||||
import io.mockk.MockKAnnotations
|
|
||||||
import io.mockk.every
|
|
||||||
import io.mockk.impl.annotations.MockK
|
|
||||||
import io.mockk.mockk
|
|
||||||
import io.mockk.mockkObject
|
|
||||||
import io.mockk.unmockkAll
|
|
||||||
import io.mockk.verify
|
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
|
||||||
import kotlinx.coroutines.test.runTest
|
|
||||||
import org.junit.After
|
|
||||||
import org.junit.Before
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
@ExperimentalCoroutinesApi
|
|
||||||
class NewPostViewModelTest {
|
|
||||||
@MockK
|
|
||||||
lateinit var accountViewModel: AccountViewModel
|
|
||||||
|
|
||||||
@MockK(relaxed = true)
|
|
||||||
lateinit var replyingTo: Note
|
|
||||||
|
|
||||||
private lateinit var shortNoteViewModelUnderTest: ShortNotePostViewModel
|
|
||||||
|
|
||||||
@Before
|
|
||||||
fun setup() {
|
|
||||||
mockkObject(LocalCache)
|
|
||||||
every { LocalCache.getOrCreateUser(any<HexKey>()) } returns mockk<User>()
|
|
||||||
shortNoteViewModelUnderTest = ShortNotePostViewModel()
|
|
||||||
MockKAnnotations.init(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
fun tearDown() {
|
|
||||||
unmockkAll()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test load with mentions`() =
|
|
||||||
runTest {
|
|
||||||
// Arrange: Setup with non empty mentions
|
|
||||||
every { accountViewModel.account } returns mockk<Account>()
|
|
||||||
|
|
||||||
val textNoteEvent = mockk<TextNoteEvent>(relaxed = true)
|
|
||||||
every { textNoteEvent.mentions() } returns listOf(PTag("user1"), PTag("user2"))
|
|
||||||
every { replyingTo.event } returns textNoteEvent
|
|
||||||
|
|
||||||
every { accountViewModel.userProfile() } returns mockk<User>(relaxed = true)
|
|
||||||
every { accountViewModel.account.userProfile() } returns mockk<User>(relaxed = true)
|
|
||||||
every { accountViewModel.account.emoji.myEmojis } returns mockk<StateFlow<List<EmojiMedia>>>(relaxed = true)
|
|
||||||
|
|
||||||
// Act: Call load with mentions
|
|
||||||
shortNoteViewModelUnderTest.init(accountViewModel)
|
|
||||||
shortNoteViewModelUnderTest.load(replyingTo, quote = null, fork = null, version = null, draft = null)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
// Two mentions should call LocalCache.getOrCreateUser twice
|
|
||||||
verify(exactly = 2) { LocalCache.getOrCreateUser(any()) }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test load with zero mentions`() =
|
|
||||||
runTest {
|
|
||||||
every { accountViewModel.account } returns mockk<Account>()
|
|
||||||
|
|
||||||
// Arrange: Setup Note with zero mentions
|
|
||||||
val textNoteEvent = mockk<TextNoteEvent>(relaxed = true)
|
|
||||||
every { textNoteEvent.mentions() } returns emptyList()
|
|
||||||
every { replyingTo.event } returns textNoteEvent
|
|
||||||
|
|
||||||
every { accountViewModel.userProfile() } returns mockk<User>(relaxed = true)
|
|
||||||
|
|
||||||
// Act: Call load with empty mentions
|
|
||||||
shortNoteViewModelUnderTest.load(replyingTo, quote = null, fork = null, version = null, draft = null)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
// With no mentions LocalCache.getOrCreateUser should not be called
|
|
||||||
verify(exactly = 0) { LocalCache.getOrCreateUser(any()) }
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `test load with empty mentions`() =
|
|
||||||
runTest {
|
|
||||||
every { accountViewModel.account } returns mockk<Account>()
|
|
||||||
|
|
||||||
// Arrange: Setup empty mentions
|
|
||||||
val textNoteEvent = mockk<TextNoteEvent>(relaxed = true)
|
|
||||||
every { textNoteEvent.mentions() } returns emptyList()
|
|
||||||
every { replyingTo.event } returns textNoteEvent
|
|
||||||
|
|
||||||
every { accountViewModel.userProfile() } returns mockk<User>(relaxed = true)
|
|
||||||
|
|
||||||
// Act: Call load with empty mentions
|
|
||||||
shortNoteViewModelUnderTest.load(replyingTo, quote = null, fork = null, version = null, draft = null)
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
// Verify LocalCache.getOrCreateUser(it) is not called with empty hex, it will crash the app
|
|
||||||
verify(exactly = 0) { LocalCache.getOrCreateUser(any()) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user