Skip to content
Open
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
86 changes: 45 additions & 41 deletions Tests/SebGreenComponentsSnapshotTests/InfoCardSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,80 @@
// InfoCardSnapshotTests.swift
// SebGreenComponents
//
// Created by Chakraborty, Sujata on 2026-02-05.
//

import SwiftUI
import XCTest
import SnapshotTesting
@testable import SebGreenComponents

final class InfoCardPreviewSnapshotTests: XCTestCase {
private static let recordSnapshots = false

// MARK: - Information

func test_InfoCard_information_close() {
let view = infoCard(
variant: .information,
actions: .init(onClose: {})
assertOnAllDevices(
name: "information_close",
view: infoCard(variant: .information, actions: .init(onClose: {})),
record: Self.recordSnapshots
)
assertSnapshot(of: view, as: .image(layout: .sizeThatFits), record: Self.recordSnapshots)
}

func test_InfoCard_information_closeAndCTA() {
let view = infoCard(
variant: .information,
actions: .init(
onClose: {},
callToAction: .init(title: "Spärra kort", action: {})
)
assertOnAllDevices(
name: "information_closeAndCTA",
view: infoCard(
variant: .information,
actions: .init(
onClose: {},
callToAction: .init(title: "Spärra kort", action: {})
)
),
record: Self.recordSnapshots
)
assertSnapshot(of: view, as: .image(layout: .sizeThatFits), record: Self.recordSnapshots)
}

func test_InfoCard_information_tap() {
let view = infoCard(
variant: .information,
actions: .init(onTap: {})
assertOnAllDevices(
name: "information_tap",
view: infoCard(variant: .information, actions: .init(onTap: {})),
record: Self.recordSnapshots
)
assertSnapshot(of: view, as: .image(layout: .sizeThatFits), record: Self.recordSnapshots)
}

// MARK: - InformationHd

func test_InfoCard_informationHd_close() {
let view = infoCard(
variant: .informationHd,
actions: .init(onClose: {})
assertOnAllDevices(
name: "informationHd_close",
view: infoCard(variant: .informationHd, actions: .init(onClose: {})),
record: Self.recordSnapshots
)
assertSnapshot(of: view, as: .image(layout: .sizeThatFits), record: Self.recordSnapshots)
}

func test_InfoCard_informationHd_closeAndCTA() {
let view = infoCard(
variant: .informationHd,
actions: .init(
onClose: {},
callToAction: .init(title: "Spärra kort", action: {})
)
assertOnAllDevices(
name: "informationHd_closeAndCTA",
view: infoCard(
variant: .informationHd,
actions: .init(
onClose: {},
callToAction: .init(title: "Spärra kort", action: {})
)
),
record: Self.recordSnapshots
)
assertSnapshot(of: view, as: .image(layout: .sizeThatFits), record: Self.recordSnapshots)
}

func test_InfoCard_informationHd_tap() {
let view = infoCard(
variant: .informationHd,
actions: .init(onTap: {})
assertOnAllDevices(
name: "informationHd_tap",
view: infoCard(variant: .informationHd, actions: .init(onTap: {})),
record: Self.recordSnapshots
)
assertSnapshot(of: view, as: .image(layout: .sizeThatFits), record: Self.recordSnapshots)
}

// MARK: - Helpers

private func infoCard(
variant: InfoCardView.Variant,
actions: InfoCardView.Actions
Expand Down
48 changes: 48 additions & 0 deletions Tests/SebGreenComponentsSnapshotTests/SnapshotHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// SnapshotHelper.swift
// SebGreenComponents
//
//
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file header comment is incomplete. It has an empty "Created by" section on line 5. Either add the author information or remove this line to maintain consistency with the updated InfoCardSnapshotTests.swift file which has this line removed.

Suggested change
//

Copilot uses AI. Check for mistakes.
import SwiftUI
import SnapshotTesting

enum SnapshotDevice: String, CaseIterable {
case iPhoneSE3 = "iPhoneSE3"
case iPhone15Pro = "iPhone15Pro"
case iPad10th = "iPad10th"

var config: ViewImageConfig {
switch self {
case .iPhoneSE3:
return .iPhoneSe
case .iPhone15Pro:
return .iPhone13Pro
Comment on lines +8 to +19
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The device configuration for iPhone15Pro is mapped to .iPhone13Pro, which may not accurately represent the actual iPhone 15 Pro device dimensions and characteristics. Consider using a more appropriate configuration or creating a custom ViewImageConfig that matches iPhone 15 Pro specifications.

Suggested change
enum SnapshotDevice: String, CaseIterable {
case iPhoneSE3 = "iPhoneSE3"
case iPhone15Pro = "iPhone15Pro"
case iPad10th = "iPad10th"
var config: ViewImageConfig {
switch self {
case .iPhoneSE3:
return .iPhoneSe
case .iPhone15Pro:
return .iPhone13Pro
import UIKit
enum SnapshotDevice: String, CaseIterable {
case iPhoneSE3 = "iPhoneSE3"
case iPhone15Pro = "iPhone15Pro"
case iPad10th = "iPad10th"
// Custom configuration approximating iPhone 15 Pro dimensions and safe area.
private static let iPhone15ProConfig = ViewImageConfig(
safeArea: UIEdgeInsets(top: 59, left: 0, bottom: 34, right: 0),
size: CGSize(width: 393, height: 852),
traits: UITraitCollection()
)
var config: ViewImageConfig {
switch self {
case .iPhoneSE3:
return .iPhoneSe
case .iPhone15Pro:
return SnapshotDevice.iPhone15ProConfig

Copilot uses AI. Check for mistakes.
case .iPad10th:
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The iPad10th device is mapped to .iPadPro11 configuration. While this may be acceptable if the screen dimensions are similar, consider documenting why this mapping was chosen or if a more accurate configuration should be used for the 10th generation iPad.

Suggested change
case .iPad10th:
case .iPad10th:
// Use the 11" iPad Pro snapshot configuration for the 10th generation iPad,
// as SnapshotTesting does not provide a dedicated config and the screen size
// is sufficiently similar for our snapshot purposes.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Copilot has a point here.

return .iPadPro11
}
}
}

func assertOnAllDevices<V: View>(
name: String,
view: V,
record: Bool,
file: StaticString = #file,
testName: String = #function,
line: UInt = #line
) {
for device in SnapshotDevice.allCases {
assertSnapshot(
of: view,
as: .image(
layout: .device(config: device.config),
traits: .init(userInterfaceStyle: .light)
),
named: device.rawValue,
record: record,
file: file,
testName: "\(testName)_\(name)",
line: line
)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.