-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MBL-1500] Update and use banners for ppo (#2094)
* Create view modifier for swiftui testing * Update messageBanner * Use message banner in ppo view * Update pr based on feedback
- Loading branch information
Showing
10 changed files
with
175 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
Kickstarter-iOS/Features/MessageBanner/Views/MessageBannerViewTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
@testable import Kickstarter_Framework | ||
import Library | ||
import SnapshotTesting | ||
import SwiftUI | ||
import XCTest | ||
|
||
internal final class MessageBannerViewTests: TestCase { | ||
func testBannerSuccess() { | ||
@State var viewModel: MessageBannerViewViewModel? = MessageBannerViewViewModel(( | ||
.success, | ||
"Everything completed successfully and now's the time to celebrate! Goooooo team!" | ||
)) | ||
let messageBannerView = MessageBannerView(viewModel: $viewModel) | ||
.defaultPortraitFrame() | ||
|
||
assertSnapshot(matching: messageBannerView, as: .image) | ||
} | ||
|
||
func testBannerError() { | ||
@State var viewModel: MessageBannerViewViewModel? = MessageBannerViewViewModel(( | ||
.error, | ||
"Something went wrong" | ||
)) | ||
let messageBannerView = MessageBannerView(viewModel: $viewModel) | ||
.defaultPortraitFrame() | ||
|
||
assertSnapshot(matching: messageBannerView, as: .image) | ||
} | ||
|
||
func testBannerInfo_shortString() { | ||
@State var viewModel: MessageBannerViewViewModel? = MessageBannerViewViewModel(( | ||
.info, | ||
"Something happened" | ||
)) | ||
let messageBannerView = MessageBannerView(viewModel: $viewModel) | ||
.defaultPortraitFrame() | ||
|
||
assertSnapshot(matching: messageBannerView, as: .image) | ||
} | ||
|
||
func testBannerInfo_longString() { | ||
@State var viewModel: MessageBannerViewViewModel? = MessageBannerViewViewModel(( | ||
.info, | ||
"Something unexpected happened but everything is probably fine." | ||
)) | ||
let messageBannerView = MessageBannerView(viewModel: $viewModel) | ||
.defaultPortraitFrame() | ||
|
||
assertSnapshot(matching: messageBannerView, as: .image) | ||
} | ||
} |
Binary file added
BIN
+24 KB
.../MessageBanner/Views/__Snapshots__/MessageBannerViewTests/testBannerError.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+28.5 KB
...nner/Views/__Snapshots__/MessageBannerViewTests/testBannerInfo_longString.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.9 KB
...ner/Views/__Snapshots__/MessageBannerViewTests/testBannerInfo_shortString.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+32.8 KB
...essageBanner/Views/__Snapshots__/MessageBannerViewTests/testBannerSuccess.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Kickstarter-iOS/Features/PledgedProjectsOverview/PPOViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,29 @@ | ||
import Combine | ||
import Foundation | ||
import Library | ||
|
||
public class PPOViewModel: ObservableObject { | ||
let greeting = "Hello, PPO" | ||
|
||
@Published public var bannerViewModel: MessageBannerViewViewModel? = nil | ||
|
||
private var cancellables = Set<AnyCancellable>() | ||
|
||
public init() { | ||
// TODO: Send actual banner messages in response to card actions instead. | ||
self.shouldSendSampleMessageSubject | ||
.sink { [weak self] _ in | ||
// self?.bannerViewModel = MessageBannerViewViewModel(( | ||
// .success, | ||
// "Survey submitted! Need to change your address? Visit your backing details on our website." | ||
// )) | ||
self?.bannerViewModel = MessageBannerViewViewModel((.success, "Your payment has been processed.")) | ||
} | ||
.store(in: &self.cancellables) | ||
} | ||
|
||
private let shouldSendSampleMessageSubject = PassthroughSubject<(), Never>() | ||
public func shouldSendSampleMessage() { | ||
self.shouldSendSampleMessageSubject.send(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import SwiftUI | ||
|
||
struct DefaultPortraitFrame: ViewModifier { | ||
func body(content: Content) -> some View { | ||
content | ||
.frame(width: 320, height: 580) | ||
} | ||
} | ||
|
||
extension View { | ||
func defaultPortraitFrame() -> some View { | ||
modifier(DefaultPortraitFrame()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters