Skip to content

Commit 16e6fce

Browse files
committed
Add tests for backward compatible initializers
1 parent 3b644a2 commit 16e6fce

2 files changed

Lines changed: 95 additions & 5 deletions

File tree

Source/Model/Deprecated.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Created by bcylin on 01/01/2019.
66
// Copyright © 2019 bcylin.
77
//
8-
//
98
// Permission is hereby granted, free of charge, to any person obtaining a copy
109
// of this software and associated documentation files (the "Software"), to deal
1110
// in the Software without restriction, including without limitation the rights
@@ -71,15 +70,14 @@ public extension OptionRow {
7170
@available(*, deprecated, message: "Use `init(text:detailText:isSelected:icon:customization:action:)` instead.")
7271
public convenience init(
7372
title: String,
74-
subtitle: Subtitle? = nil,
7573
isSelected: Bool,
7674
icon: Icon? = nil,
7775
customization: ((UITableViewCell, Row & RowStyle) -> Void)? = nil,
7876
action: ((Row) -> Void)?
7977
) {
8078
self.init(
8179
text: title,
82-
detailText: subtitle?.detailText,
80+
detailText: nil,
8381
isSelected: isSelected,
8482
icon: icon,
8583
customization: customization,
@@ -96,15 +94,14 @@ public extension SwitchRow {
9694
@available(*, deprecated, message: "Use `init(text:detailText:switchValue:icon:customization:action:)` instead.")
9795
public convenience init(
9896
title: String,
99-
subtitle: Subtitle? = nil,
10097
switchValue: Bool,
10198
icon: Icon? = nil,
10299
customization: ((UITableViewCell, Row & RowStyle) -> Void)? = nil,
103100
action: ((Row) -> Void)?
104101
) {
105102
self.init(
106103
text: title,
107-
detailText: subtitle?.detailText,
104+
detailText: nil,
108105
switchValue: switchValue,
109106
icon: icon,
110107
customization: customization,

Tests/Model/SubtitleSpec.swift

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,99 @@ internal final class SubtitleSpec: QuickSpec {
3737
expect(Subtitle.rightAligned("text").detailText) == .value1("text")
3838
expect(Subtitle.leftAligned("text").detailText) == .value2("text")
3939
}
40+
41+
context("NavigationRow") {
42+
let subtitle = Subtitle.belowTitle("detail text")
43+
let detailText = DetailText.subtitle("detail text")
44+
let icon = Icon.named("icon")
45+
46+
var invoked = false
47+
let row = NavigationRow(title: "text", subtitle: subtitle, icon: icon, action: { _ in invoked = true })
48+
49+
it("should support deprecated initializers") {
50+
expect(row.text) == "text"
51+
expect(row.detailText) == detailText
52+
expect(row.icon) == icon
53+
expect(row.cellReuseIdentifier) == "UITableViewCell.subtitle"
54+
55+
row.action?(row)
56+
expect(invoked) == true
57+
}
58+
59+
it("should support deprecated properties") {
60+
expect(row.title) == "text"
61+
expect(row.subtitle?.text) == "detail text"
62+
}
63+
}
64+
65+
context("OptionRow") {
66+
let icon = Icon.named("icon")
67+
68+
var invoked = false
69+
let row = OptionRow(title: "text", isSelected: true, icon: icon) { _ in invoked = true }
70+
71+
it("should support deprecated initializers") {
72+
// Row
73+
expect(row.text) == "text"
74+
expect(row.detailText).to(beNil())
75+
expect(row.isSelected) == true
76+
77+
row.action?(row)
78+
expect(invoked) == true
79+
80+
// RowStyle
81+
expect(row.cellReuseIdentifier) == "UITableViewCell"
82+
expect(row.cellStyle) == UITableViewCell.CellStyle.default
83+
expect(row.icon) == icon
84+
expect(row.accessoryType) == UITableViewCell.AccessoryType.checkmark
85+
expect(row.isSelectable) == true
86+
expect(row.customize).to(beNil())
87+
}
88+
89+
it("should support deprecated properties") {
90+
expect(row.title) == "text"
91+
expect(row.subtitle?.text).to(beNil())
92+
}
93+
}
94+
95+
context("SwitchRow") {
96+
var invoked = false
97+
let row = SwitchRow(title: "text", switchValue: true) { _ in invoked = true }
98+
99+
it("should support deprecated initializers") {
100+
expect(row.text) == "text"
101+
expect(row.detailText).to(beNil())
102+
expect(row.switchValue) == true
103+
expect(row.cellReuseIdentifier) == "SwitchCell"
104+
105+
row.action?(row)
106+
expect(invoked) == true
107+
}
108+
109+
it("should support deprecated properties") {
110+
expect(row.title) == "text"
111+
expect(row.subtitle?.text).to(beNil())
112+
}
113+
}
114+
115+
context("TapActionRow") {
116+
var invoked = false
117+
let row = TapActionRow(title: "text") { _ in invoked = true }
118+
119+
it("should initialize with given parameters") {
120+
expect(row.text) == "text"
121+
expect(row.detailText).to(beNil())
122+
expect(row.cellReuseIdentifier) == "TapActionCell"
123+
124+
row.action?(row)
125+
expect(invoked) == true
126+
}
127+
128+
it("should support deprecated properties") {
129+
expect(row.title) == "text"
130+
expect(row.subtitle?.text).to(beNil())
131+
}
132+
}
40133
}
41134
}
42135

0 commit comments

Comments
 (0)