-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #514 from adevinta/refacto/tag/snapshot
[Snapshot-1544] Update the Tag snapshot
- Loading branch information
Showing
8 changed files
with
306 additions
and
142 deletions.
There are no files selected for viewing
196 changes: 196 additions & 0 deletions
196
core/Sources/Components/Tag/View/Common/TagScenarioSnapshotTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
// | ||
// TagScenarioSnapshotTestsTests.swift | ||
// SparkCoreSnapshotTests | ||
// | ||
// Created by robin.lemaire on 10/10/2023. | ||
// Copyright © 2023 Adevinta. All rights reserved. | ||
// | ||
|
||
@testable import SparkCore | ||
import UIKit | ||
import SwiftUI | ||
|
||
enum TagScenarioSnapshotTests: String, CaseIterable { | ||
case test1 | ||
case test2 | ||
case test3 | ||
case test4 | ||
case test5 | ||
|
||
// MARK: - Type Alias | ||
|
||
typealias Constants = ComponentSnapshotTestConstants | ||
|
||
// MARK: - Configurations | ||
|
||
func configuration(isSwiftUIComponent: Bool) -> [TagConfigurationSnapshotTests] { | ||
switch self { | ||
case .test1: | ||
return self.test1(isSwiftUIComponent: isSwiftUIComponent) | ||
case .test2: | ||
return self.test2(isSwiftUIComponent: isSwiftUIComponent) | ||
case .test3: | ||
return self.test3(isSwiftUIComponent: isSwiftUIComponent) | ||
case .test4: | ||
return self.test4(isSwiftUIComponent: isSwiftUIComponent) | ||
case .test5: | ||
return self.test5(isSwiftUIComponent: isSwiftUIComponent) | ||
} | ||
} | ||
|
||
// MARK: - Scenarios | ||
|
||
/// Test 1 | ||
/// | ||
/// Description: To test all intents | ||
/// | ||
/// Content: | ||
/// - intents: all | ||
/// - variant: tinted | ||
/// - content: icon + text | ||
/// - mode: all | ||
/// - size: default | ||
private func test1(isSwiftUIComponent: Bool) -> [TagConfigurationSnapshotTests] { | ||
let intents = TagIntent.allCases | ||
|
||
return intents.map { | ||
.init( | ||
scenario: self, | ||
intent: $0, | ||
variant: .tinted, | ||
iconImage: .mock(isSwiftUIComponent: isSwiftUIComponent), | ||
text: "Text", | ||
isLongText: false, | ||
modes: Constants.Modes.all, | ||
sizes: Constants.Sizes.default | ||
) | ||
} | ||
} | ||
|
||
/// Test 2 | ||
/// | ||
/// Description: To test all variants | ||
/// | ||
/// Content: | ||
/// - intent: main | ||
/// - variant: all | ||
/// - content: text only | ||
/// - mode: all | ||
/// - size: default | ||
private func test2(isSwiftUIComponent: Bool) -> [TagConfigurationSnapshotTests] { | ||
let variants = TagVariant.allCases | ||
|
||
return variants.map { | ||
.init( | ||
scenario: self, | ||
intent: .main, | ||
variant: $0, | ||
iconImage: nil, | ||
text: "Text", | ||
isLongText: false, | ||
modes: Constants.Modes.all, | ||
sizes: Constants.Sizes.default | ||
) | ||
} | ||
} | ||
|
||
/// Test 3 | ||
/// | ||
/// Description: To test all color for filled variant | ||
/// | ||
/// Content: | ||
/// - intents: all | ||
/// - variant: filled | ||
/// - content: icon + text | ||
/// - mode: default | ||
/// - size: default | ||
private func test3(isSwiftUIComponent: Bool) -> [TagConfigurationSnapshotTests] { | ||
let intents = TagIntent.allCases | ||
|
||
return intents.map { | ||
.init( | ||
scenario: self, | ||
intent: $0, | ||
variant: .filled, | ||
iconImage: .mock(isSwiftUIComponent: isSwiftUIComponent), | ||
text: "Text", | ||
isLongText: false, | ||
modes: Constants.Modes.default, | ||
sizes: Constants.Sizes.default | ||
) | ||
} | ||
} | ||
|
||
/// Test 4 | ||
/// | ||
/// Description: To test content resilience | ||
/// | ||
/// Content: | ||
/// - intent: neutral | ||
/// - variant: tinted | ||
/// - content: all (icon only / long text/ long text + icon) | ||
/// - mode: default | ||
/// - size: default | ||
private func test4(isSwiftUIComponent: Bool) -> [TagConfigurationSnapshotTests] { | ||
let contents: [(isIconImage: Bool, isLongText: Bool)] = [ | ||
(isIconImage: true, isLongText: false), // Only Icon | ||
(isIconImage: false, isLongText: true), // Only long text | ||
(isIconImage: true, isLongText: true) // Icon + Long text | ||
] | ||
|
||
return contents.map { | ||
.init( | ||
scenario: self, | ||
intent: .neutral, | ||
variant: .tinted, | ||
iconImage: $0.isIconImage ? .mock(isSwiftUIComponent: isSwiftUIComponent) : nil, | ||
text: $0.isLongText ? "Very very long long text" : nil, | ||
isLongText: $0.isLongText, | ||
modes: Constants.Modes.default, | ||
sizes: Constants.Sizes.default | ||
) | ||
} | ||
} | ||
|
||
/// Test 6 | ||
/// | ||
/// Description: To test a11y sizes | ||
/// | ||
/// Content: | ||
/// - intent: main | ||
/// - variant: tinted | ||
/// - content: icon + text | ||
/// - mode: default | ||
/// - size: all | ||
private func test5(isSwiftUIComponent: Bool) -> [TagConfigurationSnapshotTests] { | ||
return [ | ||
.init( | ||
scenario: self, | ||
intent: .main, | ||
variant: .tinted, | ||
iconImage: .mock(isSwiftUIComponent: isSwiftUIComponent), | ||
text: "Text", | ||
isLongText: false, | ||
modes: Constants.Modes.default, | ||
sizes: Constants.Sizes.all | ||
) | ||
] | ||
} | ||
} | ||
|
||
// MARK: - Private Extensions | ||
|
||
private extension ImageEither { | ||
|
||
static func mock(isSwiftUIComponent: Bool) -> Self { | ||
return isSwiftUIComponent ? .right(Image.mock) : .left(UIImage.mock) | ||
} | ||
} | ||
|
||
private extension Image { | ||
static let mock = Image(systemName: "person.2.circle.fill") | ||
} | ||
|
||
private extension UIImage { | ||
static var mock = UIImage(systemName: "person.2.circle.fill") ?? UIImage() | ||
} |
45 changes: 20 additions & 25 deletions
45
core/Sources/Components/Tag/View/Common/TagSutSnapshotTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,40 @@ | ||
// | ||
// TagSutSnapshotTests.swift | ||
// TagConfigurationSnapshotTests.swift | ||
// SparkCoreTests | ||
// | ||
// Created by robin.lemaire on 05/05/2023. | ||
// Copyright © 2023 Adevinta. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
@testable import SparkCore | ||
|
||
struct TagSutSnapshotTests { | ||
struct TagConfigurationSnapshotTests { | ||
|
||
// MARK: - Properties | ||
|
||
let scenario: TagScenarioSnapshotTests | ||
|
||
let intent: TagIntent | ||
let variant: TagVariant | ||
|
||
// MARK: - Getter | ||
|
||
func testName(on function: String = #function) -> String { | ||
return "\(function)-\(self.intent)-\(self.variant)" | ||
let iconImage: ImageEither? | ||
let text: String? | ||
let isLongText: Bool | ||
var width: CGFloat? { | ||
return self.isLongText ? 100 : nil | ||
} | ||
let modes: [ComponentSnapshotTestMode] | ||
let sizes: [UIContentSizeCategory] | ||
|
||
// MARK: - Cases | ||
|
||
static var allCases: [Self] { | ||
return Self.allVariantCases(for: .alert) + | ||
Self.allVariantCases(for: .danger) + | ||
Self.allVariantCases(for: .info) + | ||
Self.allVariantCases(for: .neutral) + | ||
Self.allVariantCases(for: .main) + | ||
Self.allVariantCases(for: .support) + | ||
Self.allVariantCases(for: .success) + | ||
Self.allVariantCases(for: .accent) + | ||
Self.allVariantCases(for: .basic) | ||
} | ||
// MARK: - Getter | ||
|
||
private static func allVariantCases(for intent: TagIntent) -> [Self] { | ||
func testName() -> String { | ||
return [ | ||
.init(intent: intent, variant: .filled), | ||
.init(intent: intent, variant: .outlined), | ||
.init(intent: intent, variant: .tinted) | ||
] | ||
"\(self.scenario.rawValue)", | ||
"\(self.intent)", | ||
"\(self.variant)", | ||
self.iconImage != nil ? "withImage" : "withoutImage", | ||
self.text != nil ? (self.isLongText ? "longText" : "normalText") : "withoutText" | ||
].joined(separator: "-") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.