Skip to content

Commit

Permalink
Merge pull request #217 from adevinta/refactoring/tag-intent
Browse files Browse the repository at this point in the history
[Tag] Replace IntentColor to Intent
  • Loading branch information
robergro authored Jul 7, 2023
2 parents 4e19dd1 + cdc3691 commit a9e8081
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 195 deletions.
6 changes: 3 additions & 3 deletions core/Sources/Components/Tag/Enum/TagIntentColor.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// TagIntentColor.swift
// TagIntent.swift
// SparkCore
//
// Created by robin.lemaire on 27/03/2023.
// Copyright © 2023 Adevinta. All rights reserved.
//

/// The intent color of the tag.
public enum TagIntentColor: CaseIterable {
/// The intent of the tag.
public enum TagIntent: CaseIterable {
case alert
case danger
case info
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// TagIntentColors+ExtensionTests.swift
// TagContentColors+ExtensionTests.swift
// SparkCoreTests
//
// Created by robin.lemaire on 07/07/2023.
Expand All @@ -8,7 +8,7 @@

@testable import SparkCore

extension TagIntentColors {
extension TagContentColors {

// MARK: - Properties

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// TagIntentColors.swift
// TagContentColors.swift
// SparkCore
//
// Created by robin.lemaire on 29/03/2023.
// Copyright © 2023 Adevinta. All rights reserved.
//

struct TagIntentColors {
struct TagContentColors {

// MARK: - Properties

Expand All @@ -19,7 +19,7 @@ struct TagIntentColors {

// MARK: Hashable & Equatable

extension TagIntentColors: Hashable, Equatable {
extension TagContentColors: Hashable, Equatable {

func hash(into hasher: inout Hasher) {
hasher.combine(self.color)
Expand All @@ -29,7 +29,7 @@ extension TagIntentColors: Hashable, Equatable {
hasher.combine(self.surfaceColor)
}

static func == (lhs: TagIntentColors, rhs: TagIntentColors) -> Bool {
static func == (lhs: TagContentColors, rhs: TagContentColors) -> Bool {
return lhs.hashValue == rhs.hashValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,52 @@
// sourcery: AutoMockable
protocol TagGetColorsUseCaseable {
func execute(for theme: Theme,
intentColor: TagIntentColor,
intent: TagIntent,
variant: TagVariant) -> TagColors
}

struct TagGetColorsUseCase: TagGetColorsUseCaseable {

// MARK: - Properties

private let getIntentColorsUseCase: any TagGetIntentColorsUseCaseable
private let getContentColorsUseCase: any TagGetContentColorsUseCaseable

// MARK: - Initialization

init(getIntentColorsUseCase: any TagGetIntentColorsUseCaseable = TagGetIntentColorsUseCase()) {
self.getIntentColorsUseCase = getIntentColorsUseCase
init(getContentColorsUseCase: any TagGetContentColorsUseCaseable = TagGetContentColorsUseCase()) {
self.getContentColorsUseCase = getContentColorsUseCase
}

// MARK: - Methods

func execute(for theme: Theme,
intentColor: TagIntentColor,
intent: TagIntent,
variant: TagVariant) -> TagColors {
let intentColors = self.getIntentColorsUseCase.execute(
for: intentColor,
let contentColors = self.getContentColorsUseCase.execute(
for: intent,
colors: theme.colors
)

switch variant {
case .filled:
return .init(
backgroundColor: intentColors.color,
borderColor: intentColors.color,
foregroundColor: intentColors.onColor
backgroundColor: contentColors.color,
borderColor: contentColors.color,
foregroundColor: contentColors.onColor
)

case .outlined:
return .init(
backgroundColor: intentColors.surfaceColor,
borderColor: intentColors.color,
foregroundColor: intentColors.color
backgroundColor: contentColors.surfaceColor,
borderColor: contentColors.color,
foregroundColor: contentColors.color
)

case .tinted:
return .init(
backgroundColor: intentColors.containerColor,
borderColor: intentColors.containerColor,
foregroundColor: intentColors.onContainerColor
backgroundColor: contentColors.containerColor,
borderColor: contentColors.containerColor,
foregroundColor: contentColors.onContainerColor
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,53 @@ final class TagGetColorsUseCaseTests: XCTestCase {

func test_execute_for_all_variant_cases() throws {
// GIVEN
let intentColorsMock = TagIntentColors.mocked()
let contentColorsMock = TagContentColors.mocked()

let items: [TagGetColors] = [
.init(
givenVariant: .filled,
expectedBackgroundToken: intentColorsMock.color,
expectedBorderToken: intentColorsMock.color,
expectedForegroundToken: intentColorsMock.onColor
expectedBackgroundToken: contentColorsMock.color,
expectedBorderToken: contentColorsMock.color,
expectedForegroundToken: contentColorsMock.onColor
),
.init(
givenVariant: .outlined,
expectedBackgroundToken: intentColorsMock.surfaceColor,
expectedBorderToken: intentColorsMock.color,
expectedForegroundToken: intentColorsMock.color
expectedBackgroundToken: contentColorsMock.surfaceColor,
expectedBorderToken: contentColorsMock.color,
expectedForegroundToken: contentColorsMock.color
),
.init(
givenVariant: .tinted,
expectedBackgroundToken: intentColorsMock.containerColor,
expectedBorderToken: intentColorsMock.containerColor,
expectedForegroundToken: intentColorsMock.onContainerColor
expectedBackgroundToken: contentColorsMock.containerColor,
expectedBorderToken: contentColorsMock.containerColor,
expectedForegroundToken: contentColorsMock.onContainerColor
)
]

for item in items {
let intentColorMock: TagIntentColor = .success
let intentMock: TagIntent = .success

let themeColorsMock = ColorsGeneratedMock()

let themeMock = ThemeGeneratedMock()
themeMock.underlyingColors = themeColorsMock

let getIntentColorsUseCaseMock = TagGetIntentColorsUseCaseableGeneratedMock()
getIntentColorsUseCaseMock.executeWithIntentColorAndColorsReturnValue = intentColorsMock
let getContentColorsUseCaseMock = TagGetContentColorsUseCaseableGeneratedMock()
getContentColorsUseCaseMock.executeWithIntentAndColorsReturnValue = contentColorsMock

let useCase = TagGetColorsUseCase(getIntentColorsUseCase: getIntentColorsUseCaseMock)
let useCase = TagGetColorsUseCase(getContentColorsUseCase: getContentColorsUseCaseMock)

// WHEN
let colors = useCase.execute(
for: themeMock,
intentColor: intentColorMock,
intent: intentMock,
variant: item.givenVariant
)

// Other UseCase
Tester.testGetIntentColorsUseCaseExecuteCalling(
givenGetIntentColorsUseCase: getIntentColorsUseCaseMock,
givenIntentColor: intentColorMock,
Tester.testGetContentColorsUseCaseExecuteCalling(
givenGetContentColorsUseCase: getContentColorsUseCaseMock,
givenIntent: intentMock,
givenThemeColors: themeColorsMock
)

Expand All @@ -77,21 +77,21 @@ final class TagGetColorsUseCaseTests: XCTestCase {

private struct Tester {

static func testGetIntentColorsUseCaseExecuteCalling(
givenGetIntentColorsUseCase: TagGetIntentColorsUseCaseableGeneratedMock,
givenIntentColor: TagIntentColor,
static func testGetContentColorsUseCaseExecuteCalling(
givenGetContentColorsUseCase: TagGetContentColorsUseCaseableGeneratedMock,
givenIntent: TagIntent,
givenThemeColors: ColorsGeneratedMock
) {
let getIntentColorsUseCaseArgs = givenGetIntentColorsUseCase.executeWithIntentColorAndColorsReceivedArguments
XCTAssertEqual(givenGetIntentColorsUseCase.executeWithIntentColorAndColorsCallsCount,
let getContentColorsUseCaseArgs = givenGetContentColorsUseCase.executeWithIntentAndColorsReceivedArguments
XCTAssertEqual(givenGetContentColorsUseCase.executeWithIntentAndColorsCallsCount,
1,
"Wrong call number on execute on getIntentColorsUseCase")
XCTAssertEqual(getIntentColorsUseCaseArgs?.intentColor,
givenIntentColor,
"Wrong intentColor parameter on execute on getIntentColorsUseCase")
XCTAssertIdentical(getIntentColorsUseCaseArgs?.colors as? ColorsGeneratedMock,
"Wrong call number on execute on getContentColorsUseCase")
XCTAssertEqual(getContentColorsUseCaseArgs?.intent,
givenIntent,
"Wrong intent parameter on execute on getContentColorsUseCase")
XCTAssertIdentical(getContentColorsUseCaseArgs?.colors as? ColorsGeneratedMock,
givenThemeColors,
"Wrong colors parameter on execute on getIntentColorsUseCase")
"Wrong colors parameter on execute on getContentColorsUseCase")
}

static func testColorsProperties(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
//
// TagGetIntentColorsUseCase.swift
// TagGetContentColorsUseCase.swift
// SparkCore
//
// Created by robin.lemaire on 29/03/2023.
// Copyright © 2023 Adevinta. All rights reserved.
//

// sourcery: AutoMockable
protocol TagGetIntentColorsUseCaseable {
func execute(for intentColor: TagIntentColor,
colors: Colors) -> TagIntentColors
protocol TagGetContentColorsUseCaseable {
func execute(for intent: TagIntent,
colors: Colors) -> TagContentColors
}

struct TagGetIntentColorsUseCase: TagGetIntentColorsUseCaseable {
struct TagGetContentColorsUseCase: TagGetContentColorsUseCaseable {

// MARK: - Methods

func execute(for intentColor: TagIntentColor,
colors: Colors) -> TagIntentColors {
func execute(for intent: TagIntent,
colors: Colors) -> TagContentColors {
let surfaceColor = colors.base.surface

switch intentColor {
switch intent {
case .alert:
return .init(
color: colors.feedback.alert,
Expand Down
Loading

0 comments on commit a9e8081

Please sign in to comment.