Skip to content
Merged
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 @@ -11,7 +11,7 @@ public struct HorizontalLabeledContentStyle: LabeledContentStyle {
Spacer()

configuration.content
.foregroundStyle(.secondary)
.applyIf(self.muteContent) { $0.foregroundStyle(.secondary) }
}
}
}
Expand Down
38 changes: 38 additions & 0 deletions Tests/HandySwiftUITests/HorizontalLabeledContentStyleTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import SwiftUI
import Testing

@testable import HandySwiftUI

@MainActor
struct HorizontalLabeledContentStyleTests {
func labeledContent(muteContent: Bool) -> some View {
LabeledContent {
Text(verbatim: "Content")
} label: {
Text(verbatim: "Label")
}
.labeledContentStyle(.horizontal(muteContent: muteContent))
.frame(width: 200)
}

func reference(contentStyle: HierarchicalShapeStyle) -> some View {
HStack {
Text(verbatim: "Label")
Spacer()
Text(verbatim: "Content").foregroundStyle(contentStyle)
}
.frame(width: 200)
}

@Test
func mutedContentIsSecondary() throws {
let muted = try #require(renderedPixels(of: self.labeledContent(muteContent: true)))
#expect(muted == renderedPixels(of: self.reference(contentStyle: .secondary)))
}

@Test
func unmutedContentIsPrimary() throws {
let unmuted = try #require(renderedPixels(of: self.labeledContent(muteContent: false)))
#expect(unmuted == renderedPixels(of: self.reference(contentStyle: .primary)))
}
}
10 changes: 10 additions & 0 deletions Tests/HandySwiftUITests/RenderingHelpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import SwiftUI

/// Renders a view into raw pixel data so that two renderings can be compared for equality.
@MainActor
func renderedPixels(of view: some View) -> Data? {
let renderer = ImageRenderer(content: view)
renderer.scale = 1
guard let cgImage = renderer.cgImage else { return nil }
return cgImage.dataProvider?.data as Data?
}
Loading