2019-01-15 05:24:05 +00:00
|
|
|
//
|
|
|
|
// SearchResultFormatterSpec.swift
|
2024-10-01 18:05:41 +00:00
|
|
|
// masTests
|
2019-01-15 05:24:05 +00:00
|
|
|
//
|
|
|
|
// Created by Ben Chatelain on 1/14/19.
|
|
|
|
// Copyright © 2019 mas-cli. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Nimble
|
2019-01-30 06:15:24 +00:00
|
|
|
import Quick
|
2019-01-15 05:24:05 +00:00
|
|
|
|
2024-10-01 18:05:41 +00:00
|
|
|
@testable import mas
|
2021-03-22 05:25:18 +00:00
|
|
|
|
2024-10-21 11:38:51 +00:00
|
|
|
public class SearchResultFormatterSpec: QuickSpec {
|
2024-10-18 14:28:44 +00:00
|
|
|
override public func spec() {
|
2019-01-15 05:24:05 +00:00
|
|
|
// static func reference
|
|
|
|
let format = SearchResultFormatter.format(results:includePrice:)
|
|
|
|
var results: [SearchResult] = []
|
|
|
|
|
2021-04-23 07:01:18 +00:00
|
|
|
beforeSuite {
|
2024-10-25 17:21:19 +00:00
|
|
|
MAS.initialize()
|
2021-04-23 07:01:18 +00:00
|
|
|
}
|
2019-01-15 05:24:05 +00:00
|
|
|
describe("search results formatter") {
|
|
|
|
beforeEach {
|
|
|
|
results = []
|
|
|
|
}
|
|
|
|
it("formats nothing as empty string") {
|
2024-10-21 11:35:16 +00:00
|
|
|
expect(format(results, false)).to(beEmpty())
|
2019-01-15 05:24:05 +00:00
|
|
|
}
|
|
|
|
it("can format a single result") {
|
2021-03-22 05:25:18 +00:00
|
|
|
let result = SearchResult(
|
2024-10-26 05:54:41 +00:00
|
|
|
formattedPrice: "$9.87",
|
2019-01-15 05:24:05 +00:00
|
|
|
trackId: 12345,
|
|
|
|
trackName: "Awesome App",
|
|
|
|
version: "19.2.1"
|
2021-03-22 05:25:18 +00:00
|
|
|
)
|
2024-10-26 05:54:41 +00:00
|
|
|
expect(format([result], false)) == " 12345 Awesome App (19.2.1)"
|
2019-01-15 05:24:05 +00:00
|
|
|
}
|
|
|
|
it("can format a single result with price") {
|
2021-03-22 05:25:18 +00:00
|
|
|
let result = SearchResult(
|
2024-10-26 05:54:41 +00:00
|
|
|
formattedPrice: "$9.87",
|
2019-01-15 05:24:05 +00:00
|
|
|
trackId: 12345,
|
|
|
|
trackName: "Awesome App",
|
|
|
|
version: "19.2.1"
|
2021-03-22 05:25:18 +00:00
|
|
|
)
|
2024-10-26 05:54:41 +00:00
|
|
|
expect(format([result], true)) == " 12345 Awesome App (19.2.1) $9.87"
|
2019-01-15 05:24:05 +00:00
|
|
|
}
|
|
|
|
it("can format a two results") {
|
|
|
|
results = [
|
|
|
|
SearchResult(
|
2024-10-26 05:54:41 +00:00
|
|
|
formattedPrice: "$9.87",
|
2019-01-15 05:24:05 +00:00
|
|
|
trackId: 12345,
|
|
|
|
trackName: "Awesome App",
|
|
|
|
version: "19.2.1"
|
|
|
|
),
|
|
|
|
SearchResult(
|
2024-10-26 05:54:41 +00:00
|
|
|
formattedPrice: "$0.01",
|
2019-01-15 05:24:05 +00:00
|
|
|
trackId: 67890,
|
|
|
|
trackName: "Even Better App",
|
|
|
|
version: "1.2.0"
|
2021-03-22 05:25:18 +00:00
|
|
|
),
|
2019-01-15 05:24:05 +00:00
|
|
|
]
|
2024-10-02 02:16:06 +00:00
|
|
|
expect(format(results, false))
|
2024-10-26 05:54:41 +00:00
|
|
|
== " 12345 Awesome App (19.2.1)\n 67890 Even Better App (1.2.0)"
|
2019-01-15 05:24:05 +00:00
|
|
|
}
|
|
|
|
it("can format a two results with prices") {
|
|
|
|
results = [
|
|
|
|
SearchResult(
|
2024-10-26 05:54:41 +00:00
|
|
|
formattedPrice: "$9.87",
|
2019-01-15 05:24:05 +00:00
|
|
|
trackId: 12345,
|
|
|
|
trackName: "Awesome App",
|
|
|
|
version: "19.2.1"
|
|
|
|
),
|
|
|
|
SearchResult(
|
2024-10-26 05:54:41 +00:00
|
|
|
formattedPrice: "$0.01",
|
2019-01-15 05:24:05 +00:00
|
|
|
trackId: 67890,
|
|
|
|
trackName: "Even Better App",
|
|
|
|
version: "1.2.0"
|
2021-03-22 05:25:18 +00:00
|
|
|
),
|
2019-01-15 05:24:05 +00:00
|
|
|
]
|
2024-10-02 02:16:06 +00:00
|
|
|
expect(format(results, true))
|
2024-10-26 05:54:41 +00:00
|
|
|
== " 12345 Awesome App (19.2.1) $9.87\n 67890 Even Better App (1.2.0) $0.01"
|
2019-01-15 05:24:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|