Skip to content

Commit

Permalink
Merge pull request #668 from adevinta/pre-release/component/progress-bar
Browse files Browse the repository at this point in the history
[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
LouisBorleeAdevinta authored Dec 4, 2023
2 parents c022339 + a7fa342 commit 993eff8
Show file tree
Hide file tree
Showing 22 changed files with 1,835 additions and 90 deletions.
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
}
}
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: "-")
}
}
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
}
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()
)
}
}
}
}
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()
)
}
}
}
}
Loading

0 comments on commit 993eff8

Please sign in to comment.