Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class BarcodeAnalyzerTest {

val toast = mockk<Toast>()
every { toast.show() } just Runs
every { toast.cancel() } just Runs

// Mock Toast
mockkStatic(Toast::class)
every { Toast.makeText(context, any<String>(), any()) } returns toast
Expand All @@ -54,6 +56,6 @@ class BarcodeAnalyzerTest {
verify { onQrScanned(itemId, userUid) }

// Unmock all
unmockkAll()
// unmockkAll()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import android.content.Context
import android.net.Uri
import android.os.Handler
import android.os.Looper
import android.widget.Toast
import androidx.annotation.OptIn
import androidx.camera.core.ExperimentalGetImage
import androidx.camera.core.ImageAnalysis
Expand Down Expand Up @@ -40,6 +43,12 @@ class BarcodeAnalyzer(
if (user != null) {
val uri = Uri.parse(it)
val itemId = uri.getQueryParameter("itemId")
val text = "Qr code scanned successfully"
val toast = Toast.makeText(context, text, Toast.LENGTH_SHORT)
toast.show()

// Cancel the toast after the specified duration
Handler(Looper.getMainLooper()).postDelayed({ toast.cancel() }, 1000)

if (itemId != null) {
onQrScanned(itemId, user.uid)
Expand Down