Skip to content

Commit

Permalink
Add snapshot test for SwiftUI dynamic fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-pod committed Jul 3, 2023
1 parent a18d4e0 commit 36e665d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions ADUtilsTests/DynamicFontTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
// Created by Benjamin Lavialle on 25/10/2017.
//

import Foundation
import UIKit
import SwiftUI
import Quick
import ADUtils
import Nimble
Expand All @@ -18,6 +19,13 @@ private extension UIFont {
}
}

private extension Font {

static func ad_mainFont(forTextStyle textStyle: Font.TextStyle) -> Font {
return FontHelper.shared.helveticaNeueDynamicFont.font(forTextStyle: textStyle)
}
}

private class FontHelper {

static let shared = FontHelper()
Expand All @@ -36,7 +44,7 @@ class DynamicFontTest: QuickSpec {

override class func spec() {

describe("display fonts") {
describe("display UIKit fonts") {

let types: [UIFont.TextStyle] = [
.title1,
Expand Down Expand Up @@ -71,5 +79,45 @@ class DynamicFontTest: QuickSpec {
assertSnapshot(matching: stackView, as: .image, named: "DynamicFontLayoutTest")
}
}

describe("display SwiftUI fonts") {

@available(iOS 14.0, *)
struct DynamicFontsView: View {

let types: [Font.TextStyle] = [
.title,
.title2,
.title3,
.headline,
.subheadline,
.body,
.callout,
.footnote,
.caption,
.caption2
]

var body: some View {
VStack(alignment: .leading, spacing: 8) {
ForEach(types.indices, id: \.self) { index in
Text("Lorem sizzle pimpin' sit amizzle").font(.ad_mainFont(forTextStyle: types[index]))
}
}
}
}
it("should layout labels properly") {
if #available(iOS 14.0, *) {
let view = DynamicFontsView()
assertSnapshot(
matching: view,
as: .image(layout: .fixed(width: 200, height: 1000)),
named: "SwiftUIDynamicFontLayoutTest"
)
} else {
throw XCTSkip("title2, title3, caption2 are only available on iOS 14")
}
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 36e665d

Please sign in to comment.