-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CollapsibleTableViewHeader unit tests
- Loading branch information
Showing
4 changed files
with
104 additions
and
1 deletion.
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
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
81 changes: 81 additions & 0 deletions
81
SWDestinyTradesTests/Base/View/CollapsibleTableViewHeaderTests.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,81 @@ | ||
// | ||
// CollapsibleTableViewHeaderTests.swift | ||
// SWDestinyTradesTests | ||
// | ||
// Created by Diogo Autilio on 27/08/24. | ||
// Copyright © 2024 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
|
||
@testable import SWDestinyTrades | ||
|
||
final class CollapsibleTableViewHeaderTests: XCTestCase { | ||
|
||
func test_initialization() { | ||
let header = CollapsibleTableViewHeader(reuseIdentifier: "header") | ||
|
||
XCTAssertNotNil(header) | ||
XCTAssertNotNil(header.titleLabel) | ||
XCTAssertNotNil(header.arrowLabel) | ||
XCTAssertEqual(header.section, 0) | ||
XCTAssertNil(header.delegate) | ||
} | ||
|
||
func test_height() { | ||
XCTAssertEqual(CollapsibleTableViewHeader.height(), 44) | ||
} | ||
|
||
func test_tap_header_calls_delegate() { | ||
let header = CollapsibleTableViewHeader(reuseIdentifier: "header") | ||
let mockDelegate = CollapsibleTableViewHeaderDelegateMock() | ||
header.delegate = mockDelegate | ||
header.section = 1 | ||
|
||
header.tapHeader(header.gestureRecognizers?[0] as! UITapGestureRecognizer) | ||
|
||
XCTAssertTrue(mockDelegate.toggleSectionCalled) | ||
XCTAssertEqual(mockDelegate.toggledSection, 1) | ||
} | ||
|
||
func test_tap_header_dont_calls_delegate() { | ||
let header = CollapsibleTableViewHeader(reuseIdentifier: "header") | ||
let mockDelegate = CollapsibleTableViewHeaderDelegateMock() | ||
header.delegate = mockDelegate | ||
header.section = 1 | ||
|
||
header.tapHeader(UITapGestureRecognizer()) | ||
|
||
XCTAssertFalse(mockDelegate.toggleSectionCalled) | ||
XCTAssertNil(mockDelegate.toggledSection) | ||
} | ||
|
||
func test_set_collapsed_rotates_arrow_label() { | ||
let header = CollapsibleTableViewHeader(reuseIdentifier: "header") | ||
|
||
header.setCollapsed(true) | ||
XCTAssertEqual(header.arrowLabel.transform.rotationAngle, 0.0, accuracy: 1e-10) | ||
|
||
header.setCollapsed(false) | ||
XCTAssertEqual(header.arrowLabel.transform.rotationAngle, CGFloat.pi / 2, accuracy: 1e-10) | ||
} | ||
} | ||
|
||
// MARK: - Mocks | ||
|
||
private extension CGAffineTransform { | ||
var rotationAngle: CGFloat { | ||
return atan2(b, a) | ||
} | ||
} | ||
|
||
final class CollapsibleTableViewHeaderDelegateMock: CollapsibleTableViewHeaderDelegate { | ||
private(set) var toggleSectionCalled = false | ||
private(set) var toggledSection: Int? | ||
|
||
func toggleSection(header: CollapsibleTableViewHeader, section: Int) { | ||
toggleSectionCalled = true | ||
toggledSection = section | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
SWDestinyTradesTests/Base/View/Mirror/CollapsibleTableViewHeader+Mirror.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,19 @@ | ||
// | ||
// CollapsibleTableViewHeader+Mirror.swift | ||
// SWDestinyTradesTests | ||
// | ||
// Created by Diogo Autilio on 27/08/24. | ||
// Copyright © 2024 Diogo Autilio. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
@testable import SWDestinyTrades | ||
|
||
extension CollapsibleTableViewHeader { | ||
|
||
var arrowLabel: UILabel { | ||
Mirror.extract(variable: "arrowLabel", from: self)! | ||
} | ||
} |