Skip to content

Commit

Permalink
Add missing UserCollection unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dogo committed Mar 29, 2024
1 parent 0763d7e commit 2b7a4e4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Expand Up @@ -39,6 +39,15 @@ final class UserCollectionDatasourceTests: XCTestCase {
XCTAssertTrue(cell is LoanDetailCell)
}

func test_stepperValueChanged() {
let cell = sut.tableView(tableView, cellForRowAt: IndexPath(row: 0, section: 0)) as? LoanDetailCell
cell?.stepperValueChanged?(2)

XCTAssertEqual(delegate.didCallStepperValueChanged.count, 1)
XCTAssertEqual(delegate.didCallStepperValueChanged[0].newValue, 2)
XCTAssertNotNil(delegate.didCallStepperValueChanged[0].card)
}

func test_deleteRow() {
XCTAssertEqual(sut.collectionList?.count, 2)

Expand Down
Expand Up @@ -120,7 +120,19 @@ final class UserCollectionPresenterTests: XCTestCase {

// MARK: - Test loadDataFromRealm

func test_loadDataFromRealm() {
func test_loadDataFromRealm_creating_new_database() {
createSUT(databaseName: "EmptyDatabase")

sut.loadDataFromRealm()

XCTAssertEqual(controller.didCallUpdateTableViewData.count, 1)
XCTAssertNotNil(controller.didCallUpdateTableViewData[0])

XCTAssertEqual(controller.didCallSort.count, 1)
XCTAssertEqual(controller.didCallSort[0], 0)
}

func test_loadDataFromRealm_using_existing_database() {
sut.loadDataFromRealm()

XCTAssertEqual(controller.didCallUpdateTableViewData.count, 1)
Expand Down Expand Up @@ -178,4 +190,17 @@ final class UserCollectionPresenterTests: XCTestCase {

return foundObject
}

private func createSUT(databaseName: String = #function) {
controller = UserCollectionViewControllerSpy()
navigationController = UINavigationControllerMock(rootViewController: controller)
database = RealmDatabaseHelper.createMemoryDatabase(identifier: databaseName)
manager = PopoverMenuManagerSpy()
navigator = UserCollectionNavigator(controller)
sut = UserCollectionPresenter(controller: controller,
dispatchQueue: DispatchQueueSpy(),
manager: manager,
database: database,
navigator: navigator)
}
}

0 comments on commit 2b7a4e4

Please sign in to comment.