[CM-793] Added unit test case for concrete types
This commit is contained in:
parent
8a4c8c2073
commit
c2ea81ddb8
|
@ -10,15 +10,14 @@ import UIKit
|
|||
public final class ClassificationDataSource: NSObject, CatalogDataSource {
|
||||
/// The type of cell catalogDataSource supports
|
||||
public typealias Cell = UITableViewCell
|
||||
|
||||
/// Represents the cell type
|
||||
public static var cell: Cell.Type { UITableViewCell.self }
|
||||
/// Identifier to identify the cell
|
||||
public static var cellIdentifier: String { "ClassificationTableCell" }
|
||||
/// Represents the title of catalog
|
||||
public var navigationTitle: String?
|
||||
public let navigationTitle: String?
|
||||
/// Represents categories in the catalog
|
||||
public var categories: [Classification]
|
||||
public let categories: [Classification]
|
||||
|
||||
/// Used to initialize the `ClassificationDataSource`
|
||||
/// - Parameters:
|
||||
|
@ -45,7 +44,7 @@ public final class ClassificationDataSource: NSObject, CatalogDataSource {
|
|||
withIdentifier: ClassificationDataSource.cellIdentifier,
|
||||
for: indexPath
|
||||
)
|
||||
let category = categories[indexPath.row]
|
||||
let category = category(for: indexPath)
|
||||
|
||||
cell.textLabel?.text = category.name
|
||||
cell.accessoryType = .disclosureIndicator
|
||||
|
|
|
@ -8,6 +8,10 @@ import Foundation
|
|||
|
||||
/// Represents catalog category
|
||||
public struct CatalogCategory: Classification {
|
||||
/// Name of the catalog category
|
||||
public let name: String
|
||||
/// Represents the subcategories of the given category
|
||||
public let subcategories: [Classification]
|
||||
/// Represents destination of the catalog category
|
||||
public var destination: Destination {
|
||||
SubcategoryDetailDestination(
|
||||
|
@ -15,9 +19,4 @@ public struct CatalogCategory: Classification {
|
|||
subcategories: subcategories
|
||||
)
|
||||
}
|
||||
/// Name of the catalog category
|
||||
public var name: String
|
||||
/// Represents the subcategories of the given category
|
||||
public var subcategories: [Classification]
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// CatalogDestination.swift
|
||||
// CatalogDetailDestination.swift
|
||||
//
|
||||
// Created by Y Media Labs on 05/09/22.
|
||||
//
|
||||
|
@ -8,12 +8,12 @@ import UIKit
|
|||
|
||||
/// Represents the CatalogDetailDestination
|
||||
public struct CatalogDetailDestination<View: ContentView>: Destination {
|
||||
/// NavigationTitle of the destination screen
|
||||
public var navigationTitle: String?
|
||||
/// Represents the model of catalog destination VC
|
||||
public var models: [View.Model]
|
||||
/// Represents the presentation style of catalog destination VC
|
||||
public var presentationStyle: Presentation = .detail
|
||||
/// NavigationTitle of the destination screen
|
||||
public let navigationTitle: String?
|
||||
/// Represents the model of catalog destination VC
|
||||
public let models: [View.Model]
|
||||
// TODO: Update after catalogFactory Ticket
|
||||
public var controller = UIViewController()
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
//
|
||||
// SubcategoryDestination.swift
|
||||
// SubcategoryDetailDestination.swift
|
||||
//
|
||||
// Created by Y Media Labs on 05/09/22.
|
||||
//
|
||||
|
@ -8,13 +8,12 @@ import UIKit
|
|||
|
||||
/// Represents the sub category destination
|
||||
public struct SubcategoryDetailDestination: Destination {
|
||||
/// NavigationTitle for subcategory VC
|
||||
public var navigationTitle: String?
|
||||
|
||||
/// Represents subcateogries of the category
|
||||
public var subcategories: [Classification]
|
||||
/// Represents the presentation style of subcategory
|
||||
public var presentationStyle: Presentation = .detail
|
||||
/// NavigationTitle for subcategory VC
|
||||
public let navigationTitle: String?
|
||||
/// Represents subcategories of the category
|
||||
public let subcategories: [Classification]
|
||||
/// Represents the sub category view controller
|
||||
// TODO: Update after catalogFactory Ticket
|
||||
public var controller = UIViewController()
|
|
@ -10,10 +10,10 @@ import UIKit
|
|||
public protocol CatalogDataSource: UITableViewDataSource {
|
||||
/// The type of cell catalogDataSource supports
|
||||
associatedtype Cell: UITableViewCell
|
||||
/// Identifier to identify the cell
|
||||
static var cellIdentifier: String { get }
|
||||
/// Represents the cell type
|
||||
static var cell: Cell.Type { get }
|
||||
/// Identifier to identify the cell
|
||||
static var cellIdentifier: String { get }
|
||||
/// Represents the title of catalog
|
||||
var navigationTitle: String? { get }
|
||||
/// Represents categories in the catalog
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
//
|
||||
// catalogCategoryTest.swift
|
||||
//
|
||||
// Created by Y Media Labs on 08/09/22.
|
||||
//
|
||||
import XCTest
|
||||
@testable import YCatalogViewer
|
||||
final class CatalogCategoryTest: XCTestCase {
|
||||
var controller = UIViewController()
|
||||
func testCatalogCategory() {
|
||||
let category = CatalogCategory(
|
||||
name: "category",
|
||||
subcategories:
|
||||
[
|
||||
Demo(
|
||||
destination: Demodestination(
|
||||
present: .detail,
|
||||
title: "color",
|
||||
controller: controller
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
XCTAssertEqual("category", category.destination.navigationTitle)
|
||||
XCTAssertEqual(.detail, category.destination.presentationStyle)
|
||||
XCTAssert(type(of: controller) == type(of: category.destinationController))
|
||||
}
|
||||
|
||||
func testSubcategoryDestination() {
|
||||
let subcategory = SubcategoryDetailDestination(
|
||||
presentationStyle: .detail,
|
||||
navigationTitle: "title",
|
||||
subcategories:
|
||||
[
|
||||
Demo(
|
||||
destination: Demodestination(
|
||||
present: .detail,
|
||||
title: "color",
|
||||
controller: controller
|
||||
)
|
||||
)
|
||||
],
|
||||
controller:
|
||||
controller
|
||||
)
|
||||
XCTAssertEqual("title", subcategory.navigationTitle)
|
||||
XCTAssertEqual(.detail, subcategory.subcategories[0].presentationStyle)
|
||||
}
|
||||
|
||||
func testCatalogDestination() {
|
||||
let catalogDestination = CatalogDetailDestination<DemoView>(
|
||||
presentationStyle: .detail,
|
||||
navigationTitle: "title",
|
||||
models: [DemoModel()],
|
||||
controller: controller
|
||||
)
|
||||
XCTAssertEqual(controller, catalogDestination.controller)
|
||||
XCTAssertEqual(.detail, catalogDestination.presentationStyle)
|
||||
}
|
||||
|
||||
func testClassificationDataSource() {
|
||||
let tableview = UITableView()
|
||||
let classificationDataSource = ClassificationDataSource(navigationTitle: "title", classification:
|
||||
[
|
||||
Demo(
|
||||
destination: Demodestination(
|
||||
present: .detail,
|
||||
title: "color",
|
||||
controller: controller
|
||||
)
|
||||
)
|
||||
])
|
||||
XCTAssertEqual(
|
||||
1,
|
||||
classificationDataSource.tableView(
|
||||
UITableView(),
|
||||
numberOfRowsInSection: classificationDataSource.categories.count
|
||||
)
|
||||
)
|
||||
|
||||
tableview.register(
|
||||
ClassificationDataSource.cell,
|
||||
forCellReuseIdentifier: ClassificationDataSource.cellIdentifier
|
||||
)
|
||||
let tableCell = classificationDataSource.tableView(tableview, cellForRowAt: [0, 0])
|
||||
XCTAssertNotNil(tableCell)
|
||||
}
|
||||
}
|
||||
|
||||
class Demo: Classification {
|
||||
var name: String = ""
|
||||
var destination: Destination
|
||||
public init(destination: Destination) {
|
||||
self.destination = destination
|
||||
}
|
||||
}
|
||||
|
||||
class Demodestination: Destination {
|
||||
var presentationStyle: Presentation
|
||||
var navigationTitle: String?
|
||||
var controller: UIViewController
|
||||
public init(present: Presentation, title: String, controller: UIViewController) {
|
||||
presentationStyle = present
|
||||
navigationTitle = title
|
||||
self.controller = controller
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue