-
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 #440 from adevinta/tech/displayedText
[Tech] Update DisplayedTextViewModel: Add a model, deprecate some var
- Loading branch information
Showing
7 changed files
with
283 additions
and
20 deletions.
There are no files selected for viewing
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
48 changes: 48 additions & 0 deletions
48
core/Sources/Common/DisplayedText/Enum/DisplayedTextTypeTests.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,48 @@ | ||
// | ||
// DisplayedTextTypeTests.swift | ||
// SparkCoreTests | ||
// | ||
// Created by robin.lemaire on 14/09/2023. | ||
// Copyright © 2023 Adevinta. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import SparkCore | ||
|
||
final class DisplayedTextTypeTests: XCTestCase { | ||
|
||
// MARK: - Tests | ||
|
||
func test_containsText_when_type_is_none() { | ||
// GIVEN | ||
let type: DisplayedTextType = .none | ||
|
||
// WHEN | ||
let containsText = type.containsText | ||
|
||
// THEN | ||
XCTAssertFalse(containsText) | ||
} | ||
|
||
func test_containsText_when_type_is_text() { | ||
// GIVEN | ||
let type: DisplayedTextType = .text | ||
|
||
// WHEN | ||
let containsText = type.containsText | ||
|
||
// THEN | ||
XCTAssertTrue(containsText) | ||
} | ||
|
||
func test_containsText_when_type_is_attributedText() { | ||
// GIVEN | ||
let type: DisplayedTextType = .attributedText | ||
|
||
// WHEN | ||
let containsText = type.containsText | ||
|
||
// THEN | ||
XCTAssertTrue(containsText) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
core/Sources/Common/DisplayedText/Model/DisplayedText+ExtensionTests.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,22 @@ | ||
// | ||
// DisplayedText+ExtensionTests.swift | ||
// SparkCoreTests | ||
// | ||
// Created by robin.lemaire on 14/09/2023. | ||
// Copyright © 2023 Adevinta. All rights reserved. | ||
// | ||
|
||
@testable import SparkCore | ||
|
||
extension DisplayedText { | ||
|
||
// MARK: - Properties | ||
|
||
static func mocked( | ||
text: String = "My text" | ||
) -> Self { | ||
return .init( | ||
text: text | ||
) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
core/Sources/Common/DisplayedText/Model/DisplayedText.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,37 @@ | ||
// | ||
// DisplayedText.swift | ||
// SparkCore | ||
// | ||
// Created by robin.lemaire on 13/09/2023. | ||
// Copyright © 2023 Adevinta. All rights reserved. | ||
// | ||
|
||
struct DisplayedText: Equatable { | ||
|
||
// MARK: - Properties | ||
|
||
let text: String? | ||
let attributedText: AttributedStringEither? | ||
|
||
// MARK: - Initialization | ||
|
||
init?(text: String?, attributedText: AttributedStringEither?) { | ||
// Both values cannot be nil | ||
guard text != nil || attributedText != nil else { | ||
return nil | ||
} | ||
|
||
self.text = text | ||
self.attributedText = attributedText | ||
} | ||
|
||
init(text: String) { | ||
self.text = text | ||
self.attributedText = nil | ||
} | ||
|
||
init(attributedText: AttributedStringEither) { | ||
self.text = nil | ||
self.attributedText = attributedText | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
core/Sources/Common/DisplayedText/Model/DisplayedTextTests.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,119 @@ | ||
// | ||
// DisplayedTextTests.swift | ||
// SparkCoreTests | ||
// | ||
// Created by robin.lemaire on 14/09/2023. | ||
// Copyright © 2023 Adevinta. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import SparkCore | ||
|
||
final class DisplayedTextTests: XCTestCase { | ||
|
||
// MARK: - Optional Init | ||
|
||
func test_optional_init_with_only_text() { | ||
// GIVEN | ||
let textMock = "My text" | ||
|
||
// WHEN | ||
let displayedText = DisplayedText( | ||
text: textMock, | ||
attributedText: nil | ||
) | ||
|
||
// THEN | ||
XCTAssertEqual( | ||
displayedText?.text, | ||
textMock, | ||
"Wrong text" | ||
) | ||
XCTAssertNil( | ||
displayedText?.attributedText, | ||
"Wrong attributedText" | ||
) | ||
} | ||
|
||
func test_optional_init_with_only_attributedText() { | ||
// GIVEN | ||
let attributedMock: AttributedStringEither = .left(.init(string: "Holà")) | ||
|
||
// WHEN | ||
let displayedText = DisplayedText( | ||
text: nil, | ||
attributedText: attributedMock | ||
) | ||
|
||
// THEN | ||
XCTAssertNil( | ||
displayedText?.text, | ||
"Wrong text" | ||
) | ||
XCTAssertEqual( | ||
displayedText?.attributedText, | ||
attributedMock, | ||
"Wrong attributedText" | ||
) | ||
} | ||
|
||
func test_optional_init_without_text_and_attributedText() { | ||
// GIVEN / WHEN | ||
let displayedText = DisplayedText( | ||
text: nil, | ||
attributedText: nil | ||
) | ||
|
||
// THEN | ||
XCTAssertNil( | ||
displayedText, | ||
"Wrong displayedText" | ||
) | ||
} | ||
|
||
// MARK: - Text Init | ||
|
||
func test_init_with_text() { | ||
// GIVEN | ||
let textMock = "My text" | ||
|
||
// WHEN | ||
let displayedText = DisplayedText( | ||
text: textMock | ||
) | ||
|
||
// THEN | ||
XCTAssertEqual( | ||
displayedText.text, | ||
textMock, | ||
"Wrong text" | ||
) | ||
XCTAssertNil( | ||
displayedText.attributedText, | ||
"Wrong attributedText" | ||
) | ||
} | ||
|
||
// MARK: - AttributedText Init | ||
|
||
func test_init_with_attributedText() { | ||
// GIVEN | ||
let attributedMock: AttributedStringEither = .left(.init(string: "Holà")) | ||
|
||
// WHEN | ||
let displayedText = DisplayedText( | ||
attributedText: attributedMock | ||
) | ||
|
||
// THEN | ||
XCTAssertNil( | ||
displayedText.text, | ||
"Wrong text" | ||
) | ||
XCTAssertEqual( | ||
displayedText.attributedText, | ||
attributedMock, | ||
"Wrong attributedText" | ||
) | ||
} | ||
} |
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.