-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1214 from planetary-social/feature/new-media-flag
Add feature flag and unit test for new media display
- Loading branch information
Showing
9 changed files
with
169 additions
and
23 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
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
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
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,34 @@ | ||
import Foundation | ||
import Dependencies | ||
|
||
/// The set of feature flags used by the app. | ||
protocol FeatureFlags { | ||
/// Whether the new media display should be enabled or not. | ||
/// - Note: See [#1177](https://github.com/planetary-social/nos/issues/1177) for details on the new media display. | ||
var newMediaDisplayEnabled: Bool { get } | ||
|
||
// MARK: - Additional requirements for debug mode | ||
|
||
#if DEBUG | ||
/// Sets the value of `newMediaDisplayEnabled`. | ||
func setNewMediaDisplayEnabled(_ enabled: Bool) | ||
#endif | ||
} | ||
|
||
/// The default set of feature flag values for the app. | ||
class DefaultFeatureFlags: FeatureFlags, DependencyKey { | ||
/// The one and only instance of `DefaultFeatureFlags`. | ||
static let liveValue = DefaultFeatureFlags() | ||
|
||
private init() {} | ||
|
||
private(set) var newMediaDisplayEnabled = false | ||
} | ||
|
||
#if DEBUG | ||
extension DefaultFeatureFlags { | ||
func setNewMediaDisplayEnabled(_ enabled: Bool) { | ||
newMediaDisplayEnabled = enabled | ||
} | ||
} | ||
#endif |
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
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
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,8 @@ | ||
/// A set of feature flag values used for testing that can be customized. | ||
class MockFeatureFlags: FeatureFlags { | ||
var newMediaDisplayEnabled = false | ||
|
||
func setNewMediaDisplayEnabled(_ enabled: Bool) { | ||
newMediaDisplayEnabled = enabled | ||
} | ||
} |
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,29 @@ | ||
import Dependencies | ||
import ViewInspector | ||
import XCTest | ||
|
||
final class CompactNoteViewTests: CoreDataTestCase { | ||
@MainActor func testNewMediaDisplayDisabledUsesLinkPreviewCarousel() throws { | ||
// Arrange | ||
let viewContext = persistenceController.viewContext | ||
let parseContext = persistenceController.parseContext | ||
|
||
let eventID = "123456" | ||
let eventContent = "https://nos.social" | ||
|
||
// Act | ||
_ = try Event.findOrCreateStubBy(id: eventID, context: viewContext) | ||
let fullEvent = try Event.findOrCreateStubBy(id: eventID, context: parseContext) | ||
fullEvent.content = eventContent | ||
fullEvent.kind = 1 | ||
fullEvent.contentLinks = [try XCTUnwrap(URL(string: eventContent))] | ||
|
||
let subject = CompactNoteView(note: fullEvent) | ||
ViewHosting.host(view: subject.environment(\.managedObjectContext, persistenceController.container.viewContext)) | ||
ViewHosting.host(view: subject.environmentObject(DependencyValues().router)) | ||
|
||
// Assert | ||
let result = try subject.inspect().find(LinkPreviewCarousel.self) | ||
XCTAssertNotNil(result) | ||
} | ||
} |
File renamed without changes.