migration
This commit is contained in:
65
PediFoodsTests/SnackbarCenterTests.swift
Normal file
65
PediFoodsTests/SnackbarCenterTests.swift
Normal file
@@ -0,0 +1,65 @@
|
||||
import Testing
|
||||
@testable import PediFoods
|
||||
|
||||
@Test("show sets current with the given title, style, and persistence flag")
|
||||
@MainActor
|
||||
func showSetsCurrentMessage() {
|
||||
let center = SnackbarCenter()
|
||||
center.show(title: "Saved!", style: .success, isPersistent: false)
|
||||
#expect(center.current?.title == "Saved!")
|
||||
#expect(center.current?.style == .success)
|
||||
#expect(center.current?.isPersistent == false)
|
||||
}
|
||||
|
||||
@Test("handleTap dismisses a non-persistent message and runs its action")
|
||||
@MainActor
|
||||
func handleTapDismissesAndRunsAction() {
|
||||
let center = SnackbarCenter()
|
||||
var actionRan = false
|
||||
center.show(title: "Undo?", isPersistent: false, action: { actionRan = true })
|
||||
center.handleTap()
|
||||
#expect(center.current == nil)
|
||||
#expect(actionRan)
|
||||
}
|
||||
|
||||
@Test("handleTap does nothing for a persistent message")
|
||||
@MainActor
|
||||
func handleTapIgnoresPersistentMessage() {
|
||||
let center = SnackbarCenter()
|
||||
var actionRan = false
|
||||
center.show(title: "Uploading…", isPersistent: true, action: { actionRan = true })
|
||||
center.handleTap()
|
||||
#expect(center.current != nil)
|
||||
#expect(actionRan == false)
|
||||
}
|
||||
|
||||
@Test("dismiss(animated:) clears the current message unconditionally")
|
||||
@MainActor
|
||||
func dismissClearsCurrentMessage() {
|
||||
let center = SnackbarCenter()
|
||||
center.show(title: "Hello", isPersistent: true)
|
||||
center.dismiss(animated: false)
|
||||
#expect(center.current == nil)
|
||||
}
|
||||
|
||||
@Test("dismissPersistent only clears the message when it's actually persistent")
|
||||
@MainActor
|
||||
func dismissPersistentOnlyClearsPersistentMessages() {
|
||||
let center = SnackbarCenter()
|
||||
center.show(title: "Transient", isPersistent: false)
|
||||
center.dismissPersistent()
|
||||
#expect(center.current != nil)
|
||||
|
||||
center.show(title: "Persistent", isPersistent: true)
|
||||
center.dismissPersistent()
|
||||
#expect(center.current == nil)
|
||||
}
|
||||
|
||||
@Test("show replaces a currently-displayed message with the new one")
|
||||
@MainActor
|
||||
func showReplacesCurrentMessage() {
|
||||
let center = SnackbarCenter()
|
||||
center.show(title: "First", isPersistent: true)
|
||||
center.show(title: "Second", isPersistent: true)
|
||||
#expect(center.current?.title == "Second")
|
||||
}
|
||||
Reference in New Issue
Block a user