Skip to content

Commit db2df79

Browse files
KM-13292 Add Snapshot tests to PIADesignSystem
1 parent 6c8e111 commit db2df79

9 files changed

Lines changed: 160 additions & 30 deletions

File tree

LocalPackages/PIADesignSystem/Package.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ let package = Package(
1414
targets: ["PIADesignSystem"]
1515
)
1616
],
17+
dependencies: [
18+
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", exact: "1.18.7")
19+
],
1720
targets: [
1821
.target(
1922
name: "PIADesignSystem",
@@ -23,7 +26,10 @@ let package = Package(
2326
),
2427
.testTarget(
2528
name: "PIADesignSystemTests",
26-
dependencies: ["PIADesignSystem"]
29+
dependencies: [
30+
"PIADesignSystem",
31+
.product(name: "SnapshotTesting", package: "swift-snapshot-testing")
32+
]
2733
)
2834
]
2935
)

LocalPackages/PIADesignSystem/Sources/PIADesignSystem/Colors/ColorPreview.swift

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,28 @@ struct ColorPreview: View {
5555
ColorSection(title: "Fixed", colors: fixedColors)
5656

5757
GradientSection(title: "Fixed Gradients", gradients: gradientColors)
58-
5958
}
6059
.padding()
6160
}
6261
.padding(.vertical)
6362
.background(Color.pia.background)
6463
.ignoresSafeArea()
6564
}
66-
65+
6766
private var primaryColors: [ColorInfo] {
6867
[
6968
.init(name: "Primary", color: .pia.primary, lightHex: "#037900", darkHex: "#5DDF5A"),
7069
.init(name: "OnPrimary", color: .pia.onPrimary, lightHex: "#FFFFFF", darkHex: "#323642")
7170
]
7271
}
73-
72+
7473
private var backgroundColors: [ColorInfo] {
7574
[
7675
.init(name: "Background", color: .pia.background, lightHex: "#EEEEEE", darkHex: "#323642"),
7776
.init(name: "OnBackground", color: .pia.onBackground, lightHex: "#323642", darkHex: "#EEEEEE")
7877
]
7978
}
80-
79+
8180
private var surfaceColors: [ColorInfo] {
8281
[
8382
.init(name: "Surface", color: .pia.surface, lightHex: "#EEEEEE", darkHex: "#323642"),
@@ -89,28 +88,28 @@ struct ColorPreview: View {
8988
.init(name: "OnSurfaceContainerSecondary", color: .pia.onSurfaceContainerSecondary, lightHex: "#889099", darkHex: "#A8ADB3")
9089
]
9190
}
92-
91+
9392
private var inverseColors: [ColorInfo] {
9493
[
9594
.init(name: "InverseSurface", color: .pia.inverseSurface, lightHex: "#323642", darkHex: "#EEEEEE"),
9695
.init(name: "InverseOnSurface", color: .pia.inverseOnSurface, lightHex: "#EEEEEE", darkHex: "#323642")
9796
]
9897
}
99-
98+
10099
private var outlineColors: [ColorInfo] {
101100
[
102101
.init(name: "Outline", color: .pia.outline, lightHex: "#D7D8D9", darkHex: "#889099"),
103102
.init(name: "OutlineVariantPrimary", color: .pia.outlineVariantPrimary, lightHex: "#889099", darkHex: "#D7D8D9")
104103
]
105104
}
106-
105+
107106
private var errorColors: [ColorInfo] {
108107
[
109108
.init(name: "Error", color: .pia.error, lightHex: "#B0024C", darkHex: "#FF72A5"),
110109
.init(name: "OnError", color: .pia.onError, lightHex: "#FFFFFF", darkHex: "#FFFFFF")
111110
]
112111
}
113-
112+
114113
private var fixedColors: [ColorInfo] {
115114
[
116115
.init(name: "ErrorContainer", color: .pia.errorContainer, lightHex: "#FEF1F5", darkHex: "#FEF1F5"),
@@ -127,7 +126,7 @@ struct ColorPreview: View {
127126
.init(name: "OnSuccessContainer", color: .pia.onSuccessContainer, lightHex: "#037900", darkHex: "#037900")
128127
]
129128
}
130-
129+
131130
private var gradientColors: [GradientInfo] {
132131
[
133132
.init(name: "SurfaceStatusConnected", gradient: Color.pia.surfaceStatusConnected, startHex: "#4CB649", endHex: "#5DD5FA"),
@@ -159,15 +158,16 @@ struct GradientInfo: Identifiable {
159158
struct ColorSection: View {
160159
let title: String
161160
let colors: [ColorInfo]
162-
161+
163162
private let columns = [
164-
GridItem(.adaptive(minimum: 100))
163+
GridItem(.adaptive(minimum: 220))
165164
]
166165

167166
var body: some View {
168167
VStack(alignment: .leading, spacing: 16) {
169168
Text(title)
170169
.typography(.title2, color: .pia.onBackground)
170+
171171
LazyVGrid(columns: columns, spacing: 20) {
172172
ForEach(colors) { colorInfo in
173173
ColorSwatch(
@@ -186,11 +186,11 @@ struct ColorSection: View {
186186
struct GradientSection: View {
187187
let title: String
188188
let gradients: [GradientInfo]
189-
189+
190190
private let columns = [
191-
GridItem(.adaptive(minimum: 100))
191+
GridItem(.adaptive(minimum: 220))
192192
]
193-
193+
194194
var body: some View {
195195
VStack(alignment: .leading, spacing: 16) {
196196
Text(title)
@@ -225,7 +225,8 @@ struct ColorSwatch: View {
225225
.shadow(radius: 5, y: 2)
226226

227227
Text(name)
228-
.typography(.subtitle2, color: .pia.onBackground)
228+
.typography(.subtitle3, color: .pia.onBackground)
229+
.lineLimit(1)
229230

230231
VStack {
231232
Text(lightHex)
@@ -234,6 +235,7 @@ struct ColorSwatch: View {
234235
.typography(.caption1, color: .pia.onBackground)
235236
}
236237
}
238+
.frame(width: 220)
237239
}
238240
}
239241

@@ -247,12 +249,19 @@ struct GradientSwatch: View {
247249
var body: some View {
248250
VStack(spacing: 8) {
249251
Circle()
250-
.fill(LinearGradient(gradient: Gradient(colors: [gradient.start, gradient.end]), startPoint: .topLeading, endPoint: .bottomTrailing))
252+
.fill(
253+
LinearGradient(
254+
gradient: Gradient(colors: [gradient.start, gradient.end]),
255+
startPoint: .topLeading,
256+
endPoint: .bottomTrailing
257+
)
258+
)
251259
.frame(width: 80, height: 80)
252260
.shadow(radius: 5, y: 2)
253261

254262
Text(name)
255-
.typography(.subtitle2, color: .pia.onBackground)
263+
.typography(.subtitle3, color: .pia.onBackground)
264+
.lineLimit(1)
256265

257266
VStack {
258267
Text("Start: \(startHex)")
@@ -261,17 +270,16 @@ struct GradientSwatch: View {
261270
.typography(.caption1, color: .pia.onBackground)
262271
}
263272
}
273+
.frame(width: 220)
264274
}
265275
}
266276

267-
268277
@available(iOS 15.0, *)
269278
#Preview("Light Mode") {
270279
ColorPreview()
271280
.preferredColorScheme(.light)
272281
}
273282

274-
275283
@available(iOS 15.0, *)
276284
#Preview("Dark Mode") {
277285
ColorPreview()

LocalPackages/PIADesignSystem/Tests/PIADesignSystemTests/PIADesignSystemTests.swift

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// ColorSnapshotTests.swift
3+
// PIADesignSystem
4+
//
5+
// Created by snapshot testing on 08.12.25.
6+
// Copyright © 2025 Private Internet Access, Inc.
7+
//
8+
// This file is part of the Private Internet Access iOS Client.
9+
//
10+
// The Private Internet Access iOS Client is free software: you can redistribute it and/or
11+
// modify it under the terms of the GNU General Public License as published by the Free
12+
// Software Foundation, either version 3 of the License, or (at your option) any later version.
13+
//
14+
// The Private Internet Access iOS Client is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17+
// details.
18+
//
19+
// You should have received a copy of the GNU General Public License along with the Private
20+
// Internet Access iOS Client. If not, see <https://www.gnu.org/licenses/>.
21+
//
22+
23+
import Testing
24+
import SwiftUI
25+
import SnapshotTesting
26+
@testable import PIADesignSystem
27+
28+
@Suite("Color Snapshots")
29+
@MainActor
30+
struct ColorSnapshotTests {
31+
32+
@available(iOS 14.0, *)
33+
@MainActor
34+
@Test func colorPreviewLight() {
35+
let view = ColorPreview()
36+
.environment(\.colorScheme, .light)
37+
.frame(width: 2800, height: 1900)
38+
39+
assertSnapshot(
40+
of: view,
41+
as: .image
42+
)
43+
}
44+
45+
@available(iOS 14.0, *)
46+
@MainActor
47+
@Test func colorPreviewDark() {
48+
let view = ColorPreview()
49+
.environment(\.colorScheme, .dark)
50+
.frame(width: 2800, height: 1900)
51+
52+
assertSnapshot(
53+
of: view,
54+
as: .image
55+
)
56+
}
57+
58+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// TypographySnapshotTests.swift
3+
// PIADesignSystem
4+
//
5+
// Created by snapshot testing on 08.12.25.
6+
// Copyright © 2025 Private Internet Access, Inc.
7+
//
8+
// This file is part of the Private Internet Access iOS Client.
9+
//
10+
// The Private Internet Access iOS Client is free software: you can redistribute it and/or
11+
// modify it under the terms of the GNU General Public License as published by the Free
12+
// Software Foundation, either version 3 of the License, or (at your option) any later version.
13+
//
14+
// The Private Internet Access iOS Client is distributed in the hope that it will be useful,
15+
// but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17+
// details.
18+
//
19+
// You should have received a copy of the GNU General Public License along with the Private
20+
// Internet Access iOS Client. If not, see <https://www.gnu.org/licenses/>.
21+
//
22+
23+
import Testing
24+
import SwiftUI
25+
import SnapshotTesting
26+
@testable import PIADesignSystem
27+
28+
@Suite("Typography Snapshots")
29+
@MainActor
30+
struct TypographySnapshotTests {
31+
32+
@available(iOS 13.0, *)
33+
@MainActor
34+
@Test func typographyPreview() {
35+
let view = TypographyPreview()
36+
.environment(\.colorScheme, .light)
37+
.frame(width: 1024, height: 1350)
38+
.preferredColorScheme(.light)
39+
40+
assertSnapshot(
41+
of: view,
42+
as: .image
43+
)
44+
}
45+
46+
}
1.85 MB
Loading
1.99 MB
Loading
Loading

PIA VPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 22 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)