Skip to content

Add tests for SOLIDArch #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions Example/SOLIDArch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
0CB13E542758FF7200441B4D /* FirstDataSourceFactory+Delegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CB13E532758FF7200441B4D /* FirstDataSourceFactory+Delegate.swift */; };
0CCB546B275A2E3500625513 /* FirstTableViewFactoryProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CCB546A275A2E3500625513 /* FirstTableViewFactoryProtocol.swift */; };
2C84B686570D7DC3DDC57D01 /* Pods_SOLIDArch_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 813AEFFF8DF1E039F2A5D92C /* Pods_SOLIDArch_Tests.framework */; };
5891A594292A69A200985E62 /* TableViewDataSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5891A586292A69A200985E62 /* TableViewDataSourceTests.swift */; };
5891A595292A69A200985E62 /* ArrayDataProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5891A587292A69A200985E62 /* ArrayDataProviderTests.swift */; };
5891A596292A69A200985E62 /* TableViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5891A588292A69A200985E62 /* TableViewControllerTests.swift */; };
5891A597292A69A200985E62 /* SectionDataProviderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5891A589292A69A200985E62 /* SectionDataProviderTests.swift */; };
5891A598292A69A200985E62 /* GenericTableViewCellFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5891A58A292A69A200985E62 /* GenericTableViewCellFactoryTests.swift */; };
5891A599292A69A200985E62 /* TableViewDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5891A58B292A69A200985E62 /* TableViewDelegateTests.swift */; };
5891A59A292A69A200985E62 /* TableViewDataProviderStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5891A58D292A69A200985E62 /* TableViewDataProviderStub.swift */; };
5891A59B292A69A200985E62 /* ItemViewModelStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5891A58E292A69A200985E62 /* ItemViewModelStub.swift */; };
5891A59C292A69A200985E62 /* UITableViewDelegateStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5891A58F292A69A200985E62 /* UITableViewDelegateStub.swift */; };
5891A59D292A69A200985E62 /* UITableViewCellStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5891A590292A69A200985E62 /* UITableViewCellStub.swift */; };
5891A59E292A69A200985E62 /* SectionInfoStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5891A591292A69A200985E62 /* SectionInfoStub.swift */; };
5891A59F292A69A200985E62 /* UITableViewDataSourceStub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5891A592292A69A200985E62 /* UITableViewDataSourceStub.swift */; };
5891A5A0292A69A200985E62 /* UITableViewMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5891A593292A69A200985E62 /* UITableViewMock.swift */; };
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; };
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; };
Expand Down Expand Up @@ -44,6 +57,19 @@
2F06A501D7BABF33CD868556 /* Pods_SOLIDArch_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SOLIDArch_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
353A90AD87FC5F3580C2303C /* Pods-SOLIDArch_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SOLIDArch_Tests.debug.xcconfig"; path = "Target Support Files/Pods-SOLIDArch_Tests/Pods-SOLIDArch_Tests.debug.xcconfig"; sourceTree = "<group>"; };
4DD7FCC1DC1B025B453F5B6C /* Pods-SOLIDArch_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SOLIDArch_Example.debug.xcconfig"; path = "Target Support Files/Pods-SOLIDArch_Example/Pods-SOLIDArch_Example.debug.xcconfig"; sourceTree = "<group>"; };
5891A586292A69A200985E62 /* TableViewDataSourceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewDataSourceTests.swift; sourceTree = "<group>"; };
5891A587292A69A200985E62 /* ArrayDataProviderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayDataProviderTests.swift; sourceTree = "<group>"; };
5891A588292A69A200985E62 /* TableViewControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewControllerTests.swift; sourceTree = "<group>"; };
5891A589292A69A200985E62 /* SectionDataProviderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SectionDataProviderTests.swift; sourceTree = "<group>"; };
5891A58A292A69A200985E62 /* GenericTableViewCellFactoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GenericTableViewCellFactoryTests.swift; sourceTree = "<group>"; };
5891A58B292A69A200985E62 /* TableViewDelegateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewDelegateTests.swift; sourceTree = "<group>"; };
5891A58D292A69A200985E62 /* TableViewDataProviderStub.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewDataProviderStub.swift; sourceTree = "<group>"; };
5891A58E292A69A200985E62 /* ItemViewModelStub.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemViewModelStub.swift; sourceTree = "<group>"; };
5891A58F292A69A200985E62 /* UITableViewDelegateStub.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITableViewDelegateStub.swift; sourceTree = "<group>"; };
5891A590292A69A200985E62 /* UITableViewCellStub.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITableViewCellStub.swift; sourceTree = "<group>"; };
5891A591292A69A200985E62 /* SectionInfoStub.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SectionInfoStub.swift; sourceTree = "<group>"; };
5891A592292A69A200985E62 /* UITableViewDataSourceStub.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITableViewDataSourceStub.swift; sourceTree = "<group>"; };
5891A593292A69A200985E62 /* UITableViewMock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITableViewMock.swift; sourceTree = "<group>"; };
607FACD01AFB9204008FA782 /* SOLIDArch_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SOLIDArch_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -91,6 +117,34 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
5891A585292A69A200985E62 /* SolidArchTests */ = {
isa = PBXGroup;
children = (
5891A586292A69A200985E62 /* TableViewDataSourceTests.swift */,
5891A587292A69A200985E62 /* ArrayDataProviderTests.swift */,
5891A588292A69A200985E62 /* TableViewControllerTests.swift */,
5891A589292A69A200985E62 /* SectionDataProviderTests.swift */,
5891A58A292A69A200985E62 /* GenericTableViewCellFactoryTests.swift */,
5891A58B292A69A200985E62 /* TableViewDelegateTests.swift */,
5891A58C292A69A200985E62 /* Stub */,
);
path = SolidArchTests;
sourceTree = "<group>";
};
5891A58C292A69A200985E62 /* Stub */ = {
isa = PBXGroup;
children = (
5891A58D292A69A200985E62 /* TableViewDataProviderStub.swift */,
5891A58E292A69A200985E62 /* ItemViewModelStub.swift */,
5891A58F292A69A200985E62 /* UITableViewDelegateStub.swift */,
5891A590292A69A200985E62 /* UITableViewCellStub.swift */,
5891A591292A69A200985E62 /* SectionInfoStub.swift */,
5891A592292A69A200985E62 /* UITableViewDataSourceStub.swift */,
5891A593292A69A200985E62 /* UITableViewMock.swift */,
);
path = Stub;
sourceTree = "<group>";
};
607FACC71AFB9204008FA782 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -141,6 +195,7 @@
607FACE81AFB9204008FA782 /* Tests */ = {
isa = PBXGroup;
children = (
5891A585292A69A200985E62 /* SolidArchTests */,
607FACEB1AFB9204008FA782 /* Tests.swift */,
607FACE91AFB9204008FA782 /* Supporting Files */,
);
Expand Down Expand Up @@ -424,7 +479,20 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5891A59A292A69A200985E62 /* TableViewDataProviderStub.swift in Sources */,
5891A59F292A69A200985E62 /* UITableViewDataSourceStub.swift in Sources */,
5891A597292A69A200985E62 /* SectionDataProviderTests.swift in Sources */,
5891A59D292A69A200985E62 /* UITableViewCellStub.swift in Sources */,
5891A595292A69A200985E62 /* ArrayDataProviderTests.swift in Sources */,
5891A594292A69A200985E62 /* TableViewDataSourceTests.swift in Sources */,
5891A59C292A69A200985E62 /* UITableViewDelegateStub.swift in Sources */,
5891A5A0292A69A200985E62 /* UITableViewMock.swift in Sources */,
5891A59B292A69A200985E62 /* ItemViewModelStub.swift in Sources */,
607FACEC1AFB9204008FA782 /* Tests.swift in Sources */,
5891A599292A69A200985E62 /* TableViewDelegateTests.swift in Sources */,
5891A598292A69A200985E62 /* GenericTableViewCellFactoryTests.swift in Sources */,
5891A596292A69A200985E62 /* TableViewControllerTests.swift in Sources */,
5891A59E292A69A200985E62 /* SectionInfoStub.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,17 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "SOLIDArch_Example.app"
BlueprintName = "SOLIDArch_Example"
ReferencedContainer = "container:SOLIDArch.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -54,23 +63,11 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "SOLIDArch_Example.app"
BlueprintName = "SOLIDArch_Example"
ReferencedContainer = "container:SOLIDArch.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand All @@ -87,8 +84,6 @@
ReferencedContainer = "container:SOLIDArch.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
106 changes: 106 additions & 0 deletions Example/Tests/SolidArchTests/ArrayDataProviderTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// ArrayDataProviderTests.swift
// SOLIDArch_Tests
//
// Created by Maxim Makankov on 20.11.2022.
// Copyright © 2022 CocoaPods. All rights reserved.
//

import XCTest
@testable import SOLIDArch

class ArrayDataProviderTests: XCTestCase {

var viewModel: ItemViewModelStub!

override func setUpWithError() throws {
try super.setUpWithError()
viewModel = ItemViewModelStub()
}

override func tearDownWithError() throws {
viewModel = nil
try super.tearDownWithError()
}

func testNumberOfSections() throws {
// arrange
let arrayDataProvider = ArrayDataProvider(array: [viewModel])

// act
let result = arrayDataProvider.numberOfSections()

// assert
XCTAssertEqual(result, 1)
}

func testNumberOfRows() throws {
// arrange
let arrayDataProvider = ArrayDataProvider(array: [viewModel])

// act
let result = arrayDataProvider.numberOfRows(inSection: 0)

// assert
XCTAssertEqual(result, 1)
}

func testItemForRowSuccess() throws {
// arrange
let arrayDataProvider = ArrayDataProvider(array: [viewModel])

// act
let result = arrayDataProvider.itemForRow(atIndexPath: IndexPath(row: 0, section: 0))

// assert
XCTAssertTrue(result is ItemViewModelStub)
}

func testItemForRowFailure() throws {
// arrange
let arrayDataProvider = ArrayDataProvider(array: [viewModel])

// act
let result = arrayDataProvider.itemForRow(atIndexPath: IndexPath(row: 10, section: 0))

// assert
XCTAssertNil(result)
}

func testTitleForSection() throws {
// arrange
let sectionTitle = "test_title"
let arrayDataProvider = ArrayDataProvider(array: [viewModel], sectionTitle: sectionTitle)

// act
let result = arrayDataProvider.title(forSection: 0)

// assert
XCTAssertEqual(result, sectionTitle)
}

func testSectionIndexTitlesSuccess() throws {
// arrange
let sectionTitle = "test_title"
let arrayDataProvider = ArrayDataProvider(array: [viewModel], sectionTitle: sectionTitle)

// act
let result = arrayDataProvider.sectionIndexTitles()

// assert
XCTAssertEqual(result?.count, 1)
XCTAssertEqual(result?.first, "t")
}

func testSectionIndexTitlesFailure() throws {
// arrange
let sectionTitle = ""
let arrayDataProvider = ArrayDataProvider(array: [viewModel], sectionTitle: sectionTitle)

// act
let result = arrayDataProvider.sectionIndexTitles()

// assert
XCTAssertNil(result)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// GenericTableViewCellFactoryTests.swift
//
//
// Created by Maxim Makankov on 19.11.2022.
//

import XCTest
@testable import SOLIDArch

class GenericTableViewCellFactoryTests: XCTestCase {

var tableView: UITableViewMock!
var itemViewModel: ItemViewModelStub!
var factory: GenericTableViewCellFactory<UITableViewCellStub>!

override func setUpWithError() throws {
try super.setUpWithError()
tableView = UITableViewMock()
itemViewModel = ItemViewModelStub()
factory = GenericTableViewCellFactory<UITableViewCellStub>(cellIdentifier: "")
}

override func tearDownWithError() throws {
factory = nil
tableView = nil
itemViewModel = nil
try super.tearDownWithError()
}

func testMakeCellSuccess() throws {
// arrange
let cell = UITableViewCellStub()
cell.stubbedItemViewModel = itemViewModel
tableView.stubbedDequeuedReusableCell = cell

// act
let result = factory.makeCell(for: tableView, at: IndexPath(row: 0, section: 0), with: itemViewModel)

// assert
XCTAssertEqual(result, cell)
XCTAssertTrue(result is UITableViewCellStub)
let resultCell = result as! UITableViewCellStub
XCTAssertTrue(resultCell.viewModel != nil)
}

func testMakeCellFailure() throws {
// arrange
let cell = UITableViewCell()
tableView.stubbedDequeuedReusableCell = cell

// act
let result = factory.makeCell(for: tableView, at: IndexPath(row: 0, section: 0), with: itemViewModel)

// assert
XCTAssertEqual(result, cell)
XCTAssertFalse(result is UITableViewCellStub)
}
}
Loading