[CM-793] Added unit test case for concrete types

This commit is contained in:
PanchamiShenoy 2022-09-09 13:06:38 +05:30 committed by Tim Barrett
parent 8a4c8c2073
commit c2ea81ddb8
6 changed files with 126 additions and 22 deletions

View File

@ -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

View File

@ -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]
}

View File

@ -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()
}

View File

@ -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()

View File

@ -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

View File

@ -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
}
}