Skip to content

Commit b897a2c

Browse files
committed
Move macOS-clean utility tests into the cross-platform Swift package
Relocate the Queue, LoggingURLRedactor, DashboardDynamicCardAnalyticsEvent, SiteCreationHeaderData, QRLoginURLParser, and ReaderCSS tests from KeystoneTests into WordPressSharedTests, moving each subject into WordPressShared so it builds on macOS and runs under `swift test` at the repo root. Also move URLHelpersTests and delete two stale KeystoneTests copies (DictionaryHelpersTests, URLIncrementalFilenameTests) whose WordPressShared copies already ran.
1 parent 7915a92 commit b897a2c

25 files changed

Lines changed: 65 additions & 130 deletions

WordPress/Classes/Utility/Analytics/DashboardDynamicCardAnalyticsEvent.swift renamed to Modules/Sources/WordPressShared/Analytics/DashboardDynamicCardAnalyticsEvent.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
enum DashboardDynamicCardAnalyticsEvent: Hashable {
1+
public enum DashboardDynamicCardAnalyticsEvent: Hashable {
22

33
case cardShown(id: String)
44
case cardTapped(id: String, url: String?)
55
case cardCtaTapped(id: String, url: String?)
66

7-
var name: String {
7+
public var name: String {
88
switch self {
99
case .cardShown: return "dynamic_dashboard_card_shown"
1010
case .cardTapped: return "dynamic_dashboard_card_tapped"
1111
case .cardCtaTapped: return "dynamic_dashboard_card_cta_tapped"
1212
}
1313
}
1414

15-
var properties: [String: String] {
15+
public var properties: [String: String] {
1616
switch self {
1717
case .cardShown(let id):
1818
return [Keys.id: id]

WordPress/Classes/Utility/Logging/LoggingURLRedactor.swift renamed to Modules/Sources/WordPressShared/Utility/LoggingURLRedactor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Foundation
22

3-
struct LoggingURLRedactor {
3+
public struct LoggingURLRedactor {
44

5-
static func redactedURL(_ url: URL) -> URL {
5+
public static func redactedURL(_ url: URL) -> URL {
66

77
if isAuthURL(url) {
88
return redactParameter(named: "token", in: url)

WordPress/Classes/ViewRelated/QR Login/Helpers/QRLoginURLParser.swift renamed to Modules/Sources/WordPressShared/Utility/QRLoginURLParser.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
import Foundation
22

3-
struct QRLoginToken: Equatable {
4-
let token: String
5-
let data: String
3+
public struct QRLoginToken: Equatable {
4+
public let token: String
5+
public let data: String
66

7-
static func == (lhs: Self, rhs: Self) -> Bool {
8-
return lhs.token == rhs.token && lhs.data == rhs.data
7+
public init(token: String, data: String) {
8+
self.token = token
9+
self.data = data
10+
}
11+
12+
public static func == (lhs: Self, rhs: Self) -> Bool {
13+
lhs.token == rhs.token && lhs.data == rhs.data
914
}
1015
}
1116

12-
struct QRLoginURLParser {
17+
public struct QRLoginURLParser {
1318
private let urlString: String
1419

15-
init(urlString: String) {
20+
public init(urlString: String) {
1621
self.urlString = urlString
1722
}
1823

1924
/// Attempts to retrieve the QR Login token information from the incoming urlString
2025
/// - Returns: QRLoginToken or nil if the parsing fails for any reason
21-
func parse() -> QRLoginToken? {
26+
public func parse() -> QRLoginToken? {
2227
// Early validation, making sure this is a valid URL from a valid host
2328
guard let url = URL(string: urlString), Self.isValidHost(url: url) else {
2429
return nil
@@ -39,7 +44,7 @@ struct QRLoginURLParser {
3944
}
4045

4146
/// Validates that the input URL is coming from a valid host
42-
static func isValidHost(url: URL) -> Bool {
47+
public static func isValidHost(url: URL) -> Bool {
4348
guard let host = url.host else {
4449
return false
4550
}

WordPress/Classes/Utility/Queue.swift renamed to Modules/Sources/WordPressShared/Utility/Queue.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@ import Foundation
66
public struct Queue<Element> {
77
private var elements = [Element]()
88

9+
public init() {}
10+
911
/// Push `element` onto the back of the queue
1012
///
11-
mutating func push(_ element: Element) {
13+
public mutating func push(_ element: Element) {
1214
elements.insert(element, at: elements.startIndex)
1315
}
1416

1517
/// Remove and return the item at the front of the queue
1618
///
17-
mutating func pop() -> Element? {
18-
return elements.popLast()
19+
public mutating func pop() -> Element? {
20+
elements.popLast()
1921
}
2022

2123
/// Removes all elements; If `where` is given, only the elements matching the
2224
/// predicate will be removed.
23-
mutating func removeAll(where shouldBeRemoved: ((Element) -> Bool)? = nil) {
25+
public mutating func removeAll(where shouldBeRemoved: ((Element) -> Bool)? = nil) {
2426
if let shouldBeRemoved {
2527
elements.removeAll(where: shouldBeRemoved)
2628
} else {

WordPress/Classes/ViewRelated/Reader/Detail/WebView/ReaderCSS.swift renamed to Modules/Sources/WordPressShared/Utility/ReaderCSS.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import Foundation
2-
import WordPressShared
32

43
/// A struct that returns the Reader CSS URL
54
/// If you need to fix an issue in the CSS, see pbArwn-GU-p2
65
///
7-
struct ReaderCSS {
6+
public struct ReaderCSS {
87
private let store: KeyValueDatabase
98

109
private let now: Int
@@ -14,17 +13,17 @@ struct ReaderCSS {
1413
private let expirationDays: Int = 5
1514

1615
private var expirationDaysInSeconds: Int {
17-
return expirationDays * 60 * 60 * 24
16+
expirationDays * 60 * 60 * 24
1817
}
1918

2019
static let updatedKey = "ReaderCSSLastUpdated"
2120

2221
/// Returns a custom Reader CSS URL
2322
/// This value can be changed under Settings > Debug
2423
///
25-
var customAddress: String? {
24+
public var customAddress: String? {
2625
get {
27-
return store.object(forKey: "reader-css-url") as? String
26+
store.object(forKey: "reader-css-url") as? String
2827
}
2928
set {
3029
store.set(newValue, forKey: "reader-css-url")
@@ -34,19 +33,22 @@ struct ReaderCSS {
3433
/// Returns the Reader CSS appending a timestamp
3534
/// We force it to update based on the `expirationDays` property
3635
///
37-
var address: String {
36+
public var address: String {
3837
guard let lastUpdated = store.object(forKey: type(of: self).updatedKey) as? Int,
39-
now - lastUpdated < expirationDaysInSeconds || !isInternetReachable() else {
38+
now - lastUpdated < expirationDaysInSeconds || !isInternetReachable()
39+
else {
4040
saveCurrentDate()
4141
return url(appendingTimestamp: now)
4242
}
4343

4444
return url(appendingTimestamp: lastUpdated)
4545
}
4646

47-
init(now: Int = Int(Date().timeIntervalSince1970),
48-
store: KeyValueDatabase = UserPersistentStoreFactory.instance(),
49-
isInternetReachable: @escaping () -> Bool = ReachabilityUtils.isInternetReachable) {
47+
public init(
48+
now: Int = Int(Date().timeIntervalSince1970),
49+
store: KeyValueDatabase = UserPersistentStoreFactory.instance(),
50+
isInternetReachable: @escaping () -> Bool = ReachabilityUtils.isInternetReachable
51+
) {
5052
self.store = store
5153
self.now = now
5254
self.isInternetReachable = isInternetReachable
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// Describes the header information presented to a user during individual steps of Site Creation.
2+
/// This struct is best suited for cases where these values are static (i.e., not retrieved from the server).
3+
///
4+
public struct SiteCreationHeaderData {
5+
public let title: String
6+
public let subtitle: String
7+
8+
public init(title: String, subtitle: String) {
9+
self.title = title
10+
self.subtitle = subtitle
11+
}
12+
}

Tests/KeystoneTests/Tests/Features/Dashboard/DashboardDynamicCardAnalyticsEventTests.swift renamed to Modules/Tests/WordPressSharedTests/DashboardDynamicCardAnalyticsEventTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@testable import WordPress
1+
@testable import WordPressShared
22
import XCTest
33

44
final class DashboardDynamicCardAnalyticsEventTests: XCTestCase {

Tests/KeystoneTests/Tests/Utility/LoggingURLRedactorTests.swift renamed to Modules/Tests/WordPressSharedTests/LoggingURLRedactorTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import XCTest
2-
@testable import WordPress
2+
@testable import WordPressShared
33

44
class LoggingURLRedactorTests: XCTestCase {
55

Tests/KeystoneTests/Tests/Login/QRLoginURLParserTests.swift renamed to Modules/Tests/WordPressSharedTests/QRLoginURLParserTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import XCTest
2-
@testable import WordPress
2+
@testable import WordPressShared
33

44
class QRLoginURLParserTests: XCTestCase {
55
/// Test to make sure isValidHost returns true when passed a valid URL host

Tests/KeystoneTests/Tests/Utility/QueueTests.swift renamed to Modules/Tests/WordPressSharedTests/QueueTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import XCTest
2-
@testable import WordPress
2+
@testable import WordPressShared
33

44
class QueueTests: XCTestCase {
55
private var queue = Queue<Int>()

0 commit comments

Comments
 (0)