Skip to content

Commit e5ba983

Browse files
feat: add way more tests to the project
1 parent 90790c3 commit e5ba983

10 files changed

Lines changed: 262 additions & 1 deletion

EmojiPicker.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
F0A434FC2971A67F00663826 /* UnicodeManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0A434FB2971A67F00663826 /* UnicodeManagerTests.swift */; };
1414
F0A434FE2971A69100663826 /* Observable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0A434FD2971A69100663826 /* Observable.swift */; };
1515
F0A435002971A6A500663826 /* PickerArrowDirectionModeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0A434FF2971A6A500663826 /* PickerArrowDirectionModeTests.swift */; };
16+
F0A435022971A87500663826 /* EmojiCategoryTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0A435012971A87500663826 /* EmojiCategoryTypeTests.swift */; };
1617
F0BB7EC3297157D3004EEBFC /* EmojiPicker.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F0BB7EBA297157D3004EEBFC /* EmojiPicker.framework */; };
1718
F0BB7EC8297157D3004EEBFC /* ConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0BB7EC7297157D3004EEBFC /* ConfigurationTests.swift */; };
1819
F0BB7ED629715831004EEBFC /* EmojiPicker.h in Headers */ = {isa = PBXBuildFile; fileRef = F0BB7ED329715830004EEBFC /* EmojiPicker.h */; };
@@ -62,6 +63,7 @@
6263
F0A434FB2971A67F00663826 /* UnicodeManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnicodeManagerTests.swift; sourceTree = "<group>"; };
6364
F0A434FD2971A69100663826 /* Observable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Observable.swift; sourceTree = "<group>"; };
6465
F0A434FF2971A6A500663826 /* PickerArrowDirectionModeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PickerArrowDirectionModeTests.swift; sourceTree = "<group>"; };
66+
F0A435012971A87500663826 /* EmojiCategoryTypeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCategoryTypeTests.swift; sourceTree = "<group>"; };
6567
F0BB7EBA297157D3004EEBFC /* EmojiPicker.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = EmojiPicker.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6668
F0BB7EC2297157D3004EEBFC /* EmojiPickerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = EmojiPickerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
6769
F0BB7EC7297157D3004EEBFC /* ConfigurationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationTests.swift; sourceTree = "<group>"; };
@@ -155,6 +157,7 @@
155157
children = (
156158
F0BB7EC7297157D3004EEBFC /* ConfigurationTests.swift */,
157159
F0A434F32971A0C200663826 /* EmojiPickerViewModelTests.swift */,
160+
F0A435012971A87500663826 /* EmojiCategoryTypeTests.swift */,
158161
F0A434FB2971A67F00663826 /* UnicodeManagerTests.swift */,
159162
F0A434FF2971A6A500663826 /* PickerArrowDirectionModeTests.swift */,
160163
F0A434F92971A3B900663826 /* ArrayExtensionTests.swift */,
@@ -459,6 +462,7 @@
459462
F0A435002971A6A500663826 /* PickerArrowDirectionModeTests.swift in Sources */,
460463
F0BB7EC8297157D3004EEBFC /* ConfigurationTests.swift in Sources */,
461464
F0BB7F3829716AFD004EEBFC /* EmojiPickerDelegateMock.swift in Sources */,
465+
F0A435022971A87500663826 /* EmojiCategoryTypeTests.swift in Sources */,
462466
F0A434F42971A0C200663826 /* EmojiPickerViewModelTests.swift in Sources */,
463467
F0A434FE2971A69100663826 /* Observable.swift in Sources */,
464468
F0A434FC2971A67F00663826 /* UnicodeManagerTests.swift in Sources */,

Tests/ArrayExtensionTests.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// ArrayExtensionTests.swift
3+
// EmojiPickerTests
4+
//
5+
// Created by Егор Бадмаев on 13.01.2023.
6+
//
7+
8+
import XCTest
9+
@testable import EmojiPicker
10+
11+
class ArrayExtensionTests: XCTestCase {
12+
13+
var array: [Int]!
14+
15+
override func tearDownWithError() throws {
16+
array = nil
17+
}
18+
19+
func testConvertingEmptyArray() throws {
20+
array = []
21+
22+
let result = array.emoji()
23+
24+
XCTAssertEqual(result, "")
25+
}
26+
27+
func testConvertingSomeEmojis() throws {
28+
array = [0x1F600,
29+
0x1F601,
30+
0x1F602,
31+
0x1F923,
32+
0x1F603]
33+
34+
let result = array.emoji()
35+
36+
XCTAssertEqual(result, "😀😁😂🤣😃")
37+
}
38+
}

Tests/EmojiCategoryTypeTests.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// EmojiCategoryTypeTests.swift
3+
// EmojiPickerTests
4+
//
5+
// Created by Егор Бадмаев on 13.01.2023.
6+
//
7+
8+
import XCTest
9+
@testable import EmojiPicker
10+
11+
class EmojiCategoryTypeTests: XCTestCase {
12+
13+
override func setUpWithError() throws {
14+
}
15+
16+
override func tearDownWithError() throws {
17+
}
18+
19+
/// Since we have special order for our emojis, we must test it.
20+
func testEmojiCategoryTypesOrder() throws {
21+
let people = EmojiCategoryType(rawValue: 0)
22+
let nature = EmojiCategoryType(rawValue: 1)
23+
let foodAndDrink = EmojiCategoryType(rawValue: 2)
24+
let activity = EmojiCategoryType(rawValue: 3)
25+
let travelAndPlaces = EmojiCategoryType(rawValue: 4)
26+
let objects = EmojiCategoryType(rawValue: 5)
27+
let symbols = EmojiCategoryType(rawValue: 6)
28+
let flags = EmojiCategoryType(rawValue: 7)
29+
30+
XCTAssertEqual(people, EmojiCategoryType.people, "The value of this variable should equal \"people\"")
31+
XCTAssertEqual(nature, EmojiCategoryType.nature, "The value of this variable should equal \"nature\"")
32+
XCTAssertEqual(foodAndDrink, EmojiCategoryType.foodAndDrink, "The value of this variable should equal \"foodAndDrink\"")
33+
XCTAssertEqual(activity, EmojiCategoryType.activity, "The value of this variable should equal \"activity\"")
34+
XCTAssertEqual(travelAndPlaces, EmojiCategoryType.travelAndPlaces, "The value of this variable should equal \"travelAndPlaces\"")
35+
XCTAssertEqual(objects, EmojiCategoryType.objects, "The value of this variable should equal \"objects\"")
36+
XCTAssertEqual(symbols, EmojiCategoryType.symbols, "The value of this variable should equal \"symbols\"")
37+
XCTAssertEqual(flags, EmojiCategoryType.flags, "The value of this variable should equal \"flags\"")
38+
}
39+
40+
/// Signals (fails) us about new emoji category, that must be handled in source code. That is why we test it.
41+
func testNewEmojiCategoryWasAdded() throws {
42+
let newValue = EmojiCategoryType(rawValue: 8)
43+
44+
XCTAssertNil(newValue)
45+
}
46+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// EmojiPickerViewModelTests.swift
3+
// EmojiPickerTests
4+
//
5+
// Created by Егор Бадмаев on 13.01.2023.
6+
//
7+
8+
import XCTest
9+
@testable import EmojiPicker
10+
11+
class EmojiPickerViewModelTests: XCTestCase {
12+
13+
var unicodeManagerStub: UnicodeManagerStub!
14+
/// SUT.
15+
var viewModel: EmojiPickerViewModel!
16+
17+
override func setUpWithError() throws {
18+
unicodeManagerStub = UnicodeManagerStub()
19+
viewModel = EmojiPickerViewModel(unicodeManager: unicodeManagerStub)
20+
}
21+
22+
override func tearDownWithError() throws {
23+
viewModel = nil
24+
unicodeManagerStub = nil
25+
}
26+
27+
/// Tests default values for selected emoji.
28+
func testSelectedEmojiDefaultValues() throws {
29+
XCTAssertEqual(viewModel.selectedEmoji.value, "")
30+
XCTAssertEqual(viewModel.selectedEmojiCategoryIndex.value, 0)
31+
}
32+
33+
func testNumberOfSectionsMethod() throws {
34+
let result = viewModel.numberOfSections()
35+
36+
XCTAssertEqual(result, unicodeManagerStub.emojiCategories.count)
37+
}
38+
39+
func testNumberOfItemsMethod() throws {
40+
let section = 0
41+
42+
let result = viewModel.numberOfItems(in: 0)
43+
44+
XCTAssertEqual(result, unicodeManagerStub.emojiCategories[section].emojis.count)
45+
}
46+
47+
func testEmojiAtIndexPathMethod() throws {
48+
let indexPath = IndexPath(row: 1, section: 1)
49+
50+
let result = viewModel.emoji(at: indexPath)
51+
52+
XCTAssertEqual(result,
53+
unicodeManagerStub.emojiCategories[indexPath.section].emojis[indexPath.row].emoji())
54+
}
55+
56+
func testSectionHeaderViewModelMethod() throws {
57+
let section = 0
58+
59+
let result = viewModel.sectionHeaderViewModel(for: section)
60+
61+
XCTAssertEqual(result, unicodeManagerStub.emojiCategories[section].categoryName)
62+
}
63+
}

Tests/Mocks/EmojiPickerDelegateMock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Егор Бадмаев on 13.01.2023.
66
//
77

8-
import EmojiPicker
8+
@testable import EmojiPicker
99

1010
class EmojiPickerDelegateMock: EmojiPickerDelegate {
1111
func didGetEmoji(emoji: String) {

Tests/Observable.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Observable.swift
3+
// EmojiPickerTests
4+
//
5+
// Created by Егор Бадмаев on 13.01.2023.
6+
//
7+
8+
import XCTest
9+
@testable import EmojiPicker
10+
11+
class Observable: XCTestCase {
12+
13+
override func setUpWithError() throws {
14+
}
15+
16+
override func tearDownWithError() throws {
17+
}
18+
19+
func testExample() throws {
20+
}
21+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// PickerArrowDirectionModeTests.swift
3+
// EmojiPickerTests
4+
//
5+
// Created by Егор Бадмаев on 13.01.2023.
6+
//
7+
8+
import XCTest
9+
@testable import EmojiPicker
10+
11+
class PickerArrowDirectionModeTests: XCTestCase {
12+
13+
var arrowDirection: PickerArrowDirectionMode!
14+
15+
override func tearDownWithError() throws {
16+
arrowDirection = nil
17+
}
18+
19+
func testSuccessInitValue1() throws {
20+
arrowDirection = PickerArrowDirectionMode(rawValue: 1)
21+
22+
XCTAssertEqual(PickerArrowDirectionMode.up, arrowDirection)
23+
}
24+
25+
func testSuccessInitValue2() throws {
26+
arrowDirection = PickerArrowDirectionMode(rawValue: 2)
27+
28+
XCTAssertEqual(PickerArrowDirectionMode.down, arrowDirection)
29+
}
30+
31+
func testFailureInitValue0() throws {
32+
arrowDirection = PickerArrowDirectionMode(rawValue: 0)
33+
34+
XCTAssertNil(arrowDirection)
35+
}
36+
37+
func testFailureInitAllLeftValues() throws {
38+
for i in 3...100 {
39+
arrowDirection = PickerArrowDirectionMode(rawValue: UInt(i))
40+
XCTAssertNil(arrowDirection)
41+
}
42+
}
43+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// UnicodeManagerStub.swift
3+
// EmojiPicker
4+
//
5+
// Created by Егор Бадмаев on 13.01.2023.
6+
//
7+
8+
@testable import EmojiPicker
9+
10+
class UnicodeManagerStub: UnicodeManagerProtocol {
11+
12+
var emojiCategories = [EmojiCategory(categoryName: "People", emojis: [[1, 2, 3]]),
13+
EmojiCategory(categoryName: "Nature", emojis: [[1, 2], [2, 3]]),
14+
EmojiCategory(categoryName: "Food", emojis: [[1], [2], [3]])]
15+
16+
func getEmojisForCurrentIOSVersion() -> [EmojiCategory] {
17+
return emojiCategories
18+
}
19+
}

Tests/UnicodeManagerTests.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// UnicodeManagerTests.swift
3+
// EmojiPickerTests
4+
//
5+
// Created by Егор Бадмаев on 13.01.2023.
6+
//
7+
8+
import XCTest
9+
@testable import EmojiPicker
10+
11+
class UnicodeManagerTests: XCTestCase {
12+
13+
override func setUpWithError() throws {
14+
}
15+
16+
override func tearDownWithError() throws {
17+
}
18+
19+
func testExample() throws {
20+
}
21+
22+
func testPerfomanceExample() throws {
23+
measure {
24+
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)