[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 {
|
public final class ClassificationDataSource: NSObject, CatalogDataSource {
|
||||||
/// The type of cell catalogDataSource supports
|
/// The type of cell catalogDataSource supports
|
||||||
public typealias Cell = UITableViewCell
|
public typealias Cell = UITableViewCell
|
||||||
|
|
||||||
/// Represents the cell type
|
/// Represents the cell type
|
||||||
public static var cell: Cell.Type { UITableViewCell.self }
|
public static var cell: Cell.Type { UITableViewCell.self }
|
||||||
/// Identifier to identify the cell
|
/// Identifier to identify the cell
|
||||||
public static var cellIdentifier: String { "ClassificationTableCell" }
|
public static var cellIdentifier: String { "ClassificationTableCell" }
|
||||||
/// Represents the title of catalog
|
/// Represents the title of catalog
|
||||||
public var navigationTitle: String?
|
public let navigationTitle: String?
|
||||||
/// Represents categories in the catalog
|
/// Represents categories in the catalog
|
||||||
public var categories: [Classification]
|
public let categories: [Classification]
|
||||||
|
|
||||||
/// Used to initialize the `ClassificationDataSource`
|
/// Used to initialize the `ClassificationDataSource`
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
|
@ -45,7 +44,7 @@ public final class ClassificationDataSource: NSObject, CatalogDataSource {
|
||||||
withIdentifier: ClassificationDataSource.cellIdentifier,
|
withIdentifier: ClassificationDataSource.cellIdentifier,
|
||||||
for: indexPath
|
for: indexPath
|
||||||
)
|
)
|
||||||
let category = categories[indexPath.row]
|
let category = category(for: indexPath)
|
||||||
|
|
||||||
cell.textLabel?.text = category.name
|
cell.textLabel?.text = category.name
|
||||||
cell.accessoryType = .disclosureIndicator
|
cell.accessoryType = .disclosureIndicator
|
||||||
|
|
|
@ -8,6 +8,10 @@ import Foundation
|
||||||
|
|
||||||
/// Represents catalog category
|
/// Represents catalog category
|
||||||
public struct CatalogCategory: Classification {
|
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
|
/// Represents destination of the catalog category
|
||||||
public var destination: Destination {
|
public var destination: Destination {
|
||||||
SubcategoryDetailDestination(
|
SubcategoryDetailDestination(
|
||||||
|
@ -15,9 +19,4 @@ public struct CatalogCategory: Classification {
|
||||||
subcategories: subcategories
|
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.
|
// Created by Y Media Labs on 05/09/22.
|
||||||
//
|
//
|
||||||
|
@ -8,12 +8,12 @@ import UIKit
|
||||||
|
|
||||||
/// Represents the CatalogDetailDestination
|
/// Represents the CatalogDetailDestination
|
||||||
public struct CatalogDetailDestination<View: ContentView>: Destination {
|
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
|
/// Represents the presentation style of catalog destination VC
|
||||||
public var presentationStyle: Presentation = .detail
|
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
|
// TODO: Update after catalogFactory Ticket
|
||||||
public var controller = UIViewController()
|
public var controller = UIViewController()
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// SubcategoryDestination.swift
|
// SubcategoryDetailDestination.swift
|
||||||
//
|
//
|
||||||
// Created by Y Media Labs on 05/09/22.
|
// Created by Y Media Labs on 05/09/22.
|
||||||
//
|
//
|
||||||
|
@ -8,13 +8,12 @@ import UIKit
|
||||||
|
|
||||||
/// Represents the sub category destination
|
/// Represents the sub category destination
|
||||||
public struct SubcategoryDetailDestination: 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
|
/// Represents the presentation style of subcategory
|
||||||
public var presentationStyle: Presentation = .detail
|
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
|
/// Represents the sub category view controller
|
||||||
// TODO: Update after catalogFactory Ticket
|
// TODO: Update after catalogFactory Ticket
|
||||||
public var controller = UIViewController()
|
public var controller = UIViewController()
|
|
@ -10,10 +10,10 @@ import UIKit
|
||||||
public protocol CatalogDataSource: UITableViewDataSource {
|
public protocol CatalogDataSource: UITableViewDataSource {
|
||||||
/// The type of cell catalogDataSource supports
|
/// The type of cell catalogDataSource supports
|
||||||
associatedtype Cell: UITableViewCell
|
associatedtype Cell: UITableViewCell
|
||||||
/// Identifier to identify the cell
|
|
||||||
static var cellIdentifier: String { get }
|
|
||||||
/// Represents the cell type
|
/// Represents the cell type
|
||||||
static var cell: Cell.Type { get }
|
static var cell: Cell.Type { get }
|
||||||
|
/// Identifier to identify the cell
|
||||||
|
static var cellIdentifier: String { get }
|
||||||
/// Represents the title of catalog
|
/// Represents the title of catalog
|
||||||
var navigationTitle: String? { get }
|
var navigationTitle: String? { get }
|
||||||
/// Represents categories in the catalog
|
/// 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