Skip to content

Commit cf9dcc0

Browse files
Add view extension tests
1 parent 33a5a4b commit cf9dcc0

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// ViewExtensionsTests.swift
3+
// MCMaps
4+
//
5+
// Created by Marquis Kurt on 05-08-2025.
6+
//
7+
8+
import SwiftUI
9+
import Testchamber
10+
import Testing
11+
import ViewInspector
12+
13+
@testable import Alidade
14+
15+
extension InspectableView {
16+
// NOTE(alicerunsonfedora): This is a pretty stupid fucking hack, but this is the only real way I can guarantee
17+
// that I can see whether the specified modifier exists for now, because the modifier itself is private.
18+
//
19+
// Please, for Renzo's sake, PLEASE USE THE `.modifier(viewType:)` method wherever possible!
20+
func containsModifier(named name: String) -> Bool {
21+
let description = String(describing: self)
22+
return description.contains(name)
23+
}
24+
}
25+
26+
@MainActor
27+
struct ViewExtensionsTests {
28+
@Test func applyGlassEffectWhenAvailable() throws {
29+
let rootView = Text("Hello, world!")
30+
.glassEffectIfAvailable()
31+
32+
let sut = try rootView.inspect()
33+
#expect(!sut.isAbsent)
34+
35+
36+
let textView = try sut.group().find(text: "Hello, world!")
37+
if #available(iOS 19, macOS 16, *) {
38+
#expect(textView.containsModifier(named: "GlassEffectModifier"))
39+
} else {
40+
#expect(!textView.containsModifier(named: "GlassEffectModifier"))
41+
}
42+
}
43+
44+
@Test func applyBackgroundExtensionEffectWhenAvailable() throws {
45+
let rootView = Text("Hello, world!")
46+
.backgroundExtensionEffectIfAvailable()
47+
48+
let sut = try rootView.inspect()
49+
#expect(!sut.isAbsent)
50+
51+
52+
let textView = try sut.group().find(text: "Hello, world!")
53+
if #available(iOS 19, macOS 16, *) {
54+
#expect(textView.containsModifier(named: "BackgroundExtensionViewModifier"))
55+
} else {
56+
#expect(!textView.containsModifier(named: "BackgroundExtensionViewModifier"))
57+
}
58+
}
59+
}
60+
61+

0 commit comments

Comments
 (0)