-
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 #668 from adevinta/pre-release/component/progress-bar
[ProgressBar] Copied Progress bar to a new branch from last clean tag (0.7.13) to make a clean release of this component
- Loading branch information
Showing
22 changed files
with
1,835 additions
and
90 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...es/Common/UIKit/Extension/NSLayoutConstraint/NSLayoutConstraint+MultiplierExtension.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,30 @@ | ||
// | ||
// NSLayoutConstraint+MultiplierExtension.swift | ||
// SparkCore | ||
// | ||
// Created by robin.lemaire on 26/09/2023. | ||
// Copyright © 2023 Adevinta. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
extension NSLayoutConstraint { | ||
|
||
/// There is no native possibility to update the multiplier | ||
/// So we need to recreate the constraint with the new multiplier | ||
static func updateMultiplier( | ||
on constraint: inout NSLayoutConstraint?, | ||
multiplier: CGFloat, | ||
layout: NSLayoutDimension, | ||
equalTo: NSLayoutDimension | ||
) { | ||
constraint?.isActive = false | ||
|
||
constraint = layout.constraint( | ||
equalTo: equalTo, | ||
multiplier: multiplier | ||
) | ||
|
||
constraint?.isActive = true | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
core/Sources/Components/ProgressBar/View/Common/ProgressBarConfigurationSnapshotTests.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,36 @@ | ||
// | ||
// ProgressBarConfigurationSnapshotTests.swift | ||
// SparkCoreTests | ||
// | ||
// Created by robin.lemaire on 05/10/2023. | ||
// Copyright © 2023 Adevinta. All rights reserved. | ||
// | ||
|
||
@testable import SparkCore | ||
import XCTest | ||
|
||
struct ProgressBarConfigurationSnapshotTests<Intent: CaseIterable> { | ||
|
||
// MARK: - Properties | ||
|
||
let scenario: ProgressBarScenarioSnapshotTests | ||
|
||
let intent: Intent | ||
let shape: ProgressBarShape | ||
let value: CGFloat | ||
var bottomValue: CGFloat { return self.value + 0.1 } | ||
let width: CGFloat = 100 | ||
let modes: [ComponentSnapshotTestMode] | ||
let sizes: [UIContentSizeCategory] | ||
|
||
// MARK: - Getter | ||
|
||
func testName() -> String { | ||
return [ | ||
"\(self.scenario.rawValue)", | ||
"\(self.intent)", | ||
"\(self.shape)" + "Shape", | ||
"\(self.value)" + "Value" | ||
].joined(separator: "-") | ||
} | ||
} |
132 changes: 132 additions & 0 deletions
132
core/Sources/Components/ProgressBar/View/Common/ProgressBarScenarioSnapshotTests.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,132 @@ | ||
// | ||
// ProgressBarScenarioSnapshotTests.swift | ||
// SparkCoreSnapshotTests | ||
// | ||
// Created by robin.lemaire on 18/10/2023. | ||
// Copyright © 2023 Adevinta. All rights reserved. | ||
// | ||
|
||
@testable import SparkCore | ||
import UIKit | ||
import SwiftUI | ||
|
||
enum ProgressBarScenarioSnapshotTests: String, CaseIterable { | ||
case test1 | ||
case test2 | ||
case test3 | ||
|
||
// MARK: - Type Alias | ||
|
||
typealias Constants = ComponentSnapshotTestConstants | ||
|
||
// MARK: - Configurations | ||
|
||
func configuration<Intent: CaseIterable>() throws -> [ProgressBarConfigurationSnapshotTests<Intent>] { | ||
switch self { | ||
case .test1: | ||
return self.test1() | ||
case .test2: | ||
return try self.test2() | ||
case .test3: | ||
return try self.test3() | ||
} | ||
} | ||
|
||
// MARK: - Scenarios | ||
|
||
/// Test 1 | ||
/// | ||
/// Description: To test all intents | ||
/// | ||
/// Content: | ||
/// - intents: all | ||
/// - value : 0.5 | ||
/// - shape: default | ||
/// - mode : all | ||
/// - size : default | ||
private func test1<Intent: CaseIterable>() -> [ProgressBarConfigurationSnapshotTests<Intent>] { | ||
let intentPossibilities = Intent.allCases | ||
|
||
return intentPossibilities.map { intent -> ProgressBarConfigurationSnapshotTests<Intent> in | ||
.init( | ||
scenario: self, | ||
intent: intent, | ||
shape: .square, | ||
value: 0.5, | ||
modes: Constants.Modes.all, | ||
sizes: Constants.Sizes.default | ||
) | ||
} | ||
} | ||
|
||
/// Test 2 | ||
/// | ||
/// Description: To test all shapes for all a11y sizes | ||
/// | ||
/// Content: | ||
/// - intent: main | ||
/// - value : 0.5 | ||
/// - shapes: all | ||
/// - mode : default | ||
/// - sizes : all | ||
private func test2<Intent: CaseIterable>() throws -> [ProgressBarConfigurationSnapshotTests<Intent>] { | ||
let shapesPossibilities = ProgressBarShape.allCases | ||
|
||
return try shapesPossibilities.map { shape -> ProgressBarConfigurationSnapshotTests<Intent> in | ||
.init( | ||
scenario: self, | ||
intent: try Intent.firstCase, | ||
shape: shape, | ||
value: 0.5, | ||
modes: Constants.Modes.default, | ||
sizes: Constants.Sizes.all | ||
) | ||
} | ||
} | ||
|
||
/// Test 3 | ||
/// | ||
/// Description: To test some values for all a11y sizes | ||
/// | ||
/// Content: | ||
/// - intent: basic | ||
/// - value : 0 + 0.3 + 0.75 + 1 | ||
/// - shape: default | ||
/// - mode : default | ||
/// - sizes : all | ||
private func test3<Intent: CaseIterable>() throws -> [ProgressBarConfigurationSnapshotTests<Intent>] { | ||
let valuesPossibilities = [0, 0.3, 0.75, 1] | ||
|
||
return try valuesPossibilities.map { value -> ProgressBarConfigurationSnapshotTests<Intent> in | ||
.init( | ||
scenario: self, | ||
intent: try Intent.firstCase, | ||
shape: .square, | ||
value: value, | ||
modes: Constants.Modes.default, | ||
sizes: Constants.Sizes.all | ||
) | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Extension | ||
|
||
private extension CaseIterable { | ||
|
||
static var firstCase: Self { | ||
get throws { | ||
guard let firstCase = Self.allCases.first else { | ||
throw ProgressBarScenarioError.noIntent | ||
} | ||
|
||
return firstCase | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Error | ||
|
||
private enum ProgressBarScenarioError: Error { | ||
case noIntent | ||
} |
47 changes: 47 additions & 0 deletions
47
...urces/Components/ProgressBar/View/SwiftUI/Public/ProgressBarDoubleViewSnapshotTests.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,47 @@ | ||
// | ||
// ProgressBarDoubleViewSnapshotTests.swift | ||
// SparkCoreTests | ||
// | ||
// Created by robin.lemaire on 05/10/2023. | ||
// Copyright © 2023 Adevinta. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
import SnapshotTesting | ||
@testable import SparkCore | ||
import SwiftUI | ||
|
||
final class ProgressBarDoubleViewSnapshotTests: SwiftUIComponentSnapshotTestCase { | ||
|
||
// MARK: - Properties | ||
|
||
private let theme: Theme = SparkTheme.shared | ||
|
||
// MARK: - Tests | ||
|
||
func test() throws { | ||
let scenarios = ProgressBarScenarioSnapshotTests.allCases | ||
|
||
for scenario in scenarios { | ||
let configurations: [ProgressBarConfigurationSnapshotTests<ProgressBarDoubleIntent>] = try scenario.configuration() | ||
for configuration in configurations { | ||
let view = ProgressBarDoubleView( | ||
theme: self.theme, | ||
intent: configuration.intent, | ||
shape: configuration.shape, | ||
topValue: configuration.value, | ||
bottomValue: configuration.bottomValue | ||
) | ||
.frame(width: configuration.width) | ||
.fixedSize() | ||
|
||
self.assertSnapshot( | ||
matching: view, | ||
modes: configuration.modes, | ||
sizes: configuration.sizes, | ||
testName: configuration.testName() | ||
) | ||
} | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
core/Sources/Components/ProgressBar/View/SwiftUI/Public/ProgressBarViewSnapshotTests.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,46 @@ | ||
// | ||
// ProgressBarViewSnapshotTests.swift | ||
// SparkCoreTests | ||
// | ||
// Created by robin.lemaire on 05/10/2023. | ||
// Copyright © 2023 Adevinta. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
import SnapshotTesting | ||
@testable import SparkCore | ||
import SwiftUI | ||
|
||
final class ProgressBarViewSnapshotTests: SwiftUIComponentSnapshotTestCase { | ||
|
||
// MARK: - Properties | ||
|
||
private let theme: Theme = SparkTheme.shared | ||
|
||
// MARK: - Tests | ||
|
||
func test() throws { | ||
let scenarios = ProgressBarScenarioSnapshotTests.allCases | ||
|
||
for scenario in scenarios { | ||
let configurations: [ProgressBarConfigurationSnapshotTests<ProgressBarIntent>] = try scenario.configuration() | ||
for configuration in configurations { | ||
let view = ProgressBarView( | ||
theme: self.theme, | ||
intent: configuration.intent, | ||
shape: configuration.shape, | ||
value: configuration.value | ||
) | ||
.frame(width: configuration.width) | ||
.fixedSize() | ||
|
||
self.assertSnapshot( | ||
matching: view, | ||
modes: configuration.modes, | ||
sizes: configuration.sizes, | ||
testName: configuration.testName() | ||
) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.