Skip to content

Commit e03f946

Browse files
feat: add tests for Category
1 parent 8166fa7 commit e03f946

5 files changed

Lines changed: 87 additions & 4 deletions

File tree

Binary file not shown.

Example App/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/EmojiPicker/Services/EmojiManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protocol EmojiManagerProtocol {
3535
/// The class is responsible for getting a relevant set of emojis for iOS version.
3636
final class EmojiManager: EmojiManagerProtocol {
3737

38-
// MARK: - Private
38+
// MARK: - Private Properties
3939

4040
private let decoder = JSONDecoder()
4141
/// Version of emoji set.

Sources/EmojiPicker/ViewModel/EmojiPickerViewModel.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
// SOFTWARE.
2121

22-
import Foundation
23-
2422
/// Protocol for a ViewModel which is being used in `EmojiPickerViewController`.
2523
protocol EmojiPickerViewModelProtocol {
2624
/// The observed variable that is responsible for the choice of emoji.
@@ -70,7 +68,7 @@ final class EmojiPickerViewModel: EmojiPickerViewModelProtocol {
7068

7169
func emoji(at indexPath: IndexPath) -> String {
7270
let name = emojiSet.categories[indexPath.section].emojis[indexPath.row]
73-
return emojiSet.emojis[name]?.skins[0].native ?? ""
71+
return emojiSet.emojis[name]?.skins[0].native ?? "❗️"
7472
}
7573

7674
func sectionHeaderViewModel(for section: Int) -> String {
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// CategoryTests.swift
3+
// EmojiPicker-Unit-Tests
4+
//
5+
// Created by Егор Бадмаев on 25.01.2023.
6+
//
7+
8+
import XCTest
9+
@testable import EmojiPicker
10+
11+
class CategoryTests: XCTestCase {
12+
13+
var category: EmojiPicker.Category!
14+
15+
override func tearDownWithError() throws {
16+
category = nil
17+
}
18+
19+
func test_decodeCategory_success() throws {
20+
let result = try? JSONDecoder().decode(EmojiPicker.Category.self, from: category1)
21+
22+
XCTAssertNotNil(result)
23+
XCTAssertEqual(result?.emojis, ["grinning", "smiley", "smile"])
24+
}
25+
26+
func test_decodeCategory_arraySuccess() throws {
27+
let result = try? JSONDecoder().decode([EmojiPicker.Category].self, from: category3)
28+
29+
XCTAssertNotNil(result)
30+
XCTAssertEqual(result?.count, 2)
31+
}
32+
33+
func test_decodeCategory_wrongCodingKeys() throws {
34+
let result = try? JSONDecoder().decode(EmojiPicker.Category.self, from: category2)
35+
36+
XCTAssertNil(result)
37+
}
38+
}
39+
40+
fileprivate let category1 = Data("""
41+
{
42+
"id": "people",
43+
"emojis": [
44+
"grinning",
45+
"smiley",
46+
"smile",
47+
]
48+
}
49+
""".utf8)
50+
51+
fileprivate let category2 = Data("""
52+
{
53+
"type": "people",
54+
"emojis": [
55+
"grinning",
56+
"smiley",
57+
"smile",
58+
]
59+
}
60+
""".utf8)
61+
62+
fileprivate let category3 = Data("""
63+
[
64+
{
65+
"id": "people",
66+
"emojis": [
67+
"grinning",
68+
"smile",
69+
"zzz"
70+
]
71+
},
72+
{
73+
"id": "nature",
74+
"emojis": [
75+
"monkey",
76+
"leaves",
77+
"dog"
78+
]
79+
}
80+
]
81+
""".utf8)

0 commit comments

Comments
 (0)