Skip to content

Commit 11d5d64

Browse files
refactor: update tests
According to the latest updates
1 parent d4679fc commit 11d5d64

9 files changed

Lines changed: 503 additions & 527 deletions

File tree

Binary file not shown.

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

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

Tests/EmojiPickerTests/ArrayExtensionTests.swift

Lines changed: 0 additions & 38 deletions
This file was deleted.

Tests/EmojiPickerTests/EmojiCategoryTypeTests.swift

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// EmojiManagerTests.swift
3+
// EmojiPickerTests
4+
//
5+
// Created by Егор Бадмаев on 25.01.2023.
6+
//
7+
8+
import XCTest
9+
@testable import EmojiPicker
10+
11+
class EmojiManagerTests: XCTestCase {
12+
13+
/// SUT.
14+
var emojiManager: EmojiManager!
15+
16+
override func setUpWithError() throws {
17+
emojiManager = EmojiManager()
18+
}
19+
20+
override func tearDownWithError() throws {
21+
emojiManager = nil
22+
}
23+
24+
/**
25+
Tests providing emoji set.
26+
27+
Due to the fact that the tests can be run on different devices, we have to check that the answer does not come to us an empty array.
28+
*/
29+
func testProvideEmojisMethod() throws {
30+
let result = emojiManager.provideEmojis()
31+
32+
XCTAssertGreaterThan(result.emojis.count, 0)
33+
XCTAssertGreaterThan(result.categories.count, 0)
34+
XCTAssertGreaterThan(result.aliases.count, 0)
35+
}
36+
37+
/**
38+
Tests that device version are identical.
39+
*/
40+
func testDeterminingDeviceVersion() throws {
41+
let expectedVersion = (UIDevice.current.systemVersion as NSString).doubleValue
42+
43+
XCTAssertEqual(emojiManager.deviceVersion, expectedVersion)
44+
}
45+
}

Tests/EmojiPickerTests/EmojiPickerViewModelTests.swift

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ import XCTest
1010

1111
class EmojiPickerViewModelTests: XCTestCase {
1212

13-
var unicodeManagerStub: UnicodeManagerStub!
13+
var emojiManagerStub: EmojiManagerStub!
1414
/// SUT.
1515
var viewModel: EmojiPickerViewModel!
1616

1717
override func setUpWithError() throws {
18-
unicodeManagerStub = UnicodeManagerStub()
19-
viewModel = EmojiPickerViewModel(unicodeManager: unicodeManagerStub)
18+
emojiManagerStub = EmojiManagerStub()
19+
viewModel = EmojiPickerViewModel(emojiManager: emojiManagerStub)
2020
}
2121

2222
override func tearDownWithError() throws {
2323
viewModel = nil
24-
unicodeManagerStub = nil
24+
emojiManagerStub = nil
2525
}
2626

2727
/// Tests default values for selected emoji.
@@ -33,31 +33,43 @@ class EmojiPickerViewModelTests: XCTestCase {
3333
func testNumberOfSectionsMethod() throws {
3434
let result = viewModel.numberOfSections()
3535

36-
XCTAssertEqual(result, unicodeManagerStub.emojiCategories.count)
36+
XCTAssertEqual(result, emojiManagerStub.emojiSet.categories.count)
3737
}
3838

3939
func testNumberOfItemsMethod() throws {
4040
let section = 0
4141

4242
let result = viewModel.numberOfItems(in: 0)
4343

44-
XCTAssertEqual(result, unicodeManagerStub.emojiCategories[section].emojis.count)
44+
XCTAssertEqual(result, emojiManagerStub.emojiSet.categories[section].emojis.count)
4545
}
4646

4747
func testEmojiAtIndexPathMethod() throws {
48-
let indexPath = IndexPath(row: 1, section: 1)
48+
let indexPath = IndexPath(row: 1, section: 0)
4949

5050
let result = viewModel.emoji(at: indexPath)
5151

52-
XCTAssertEqual(result,
53-
unicodeManagerStub.emojiCategories[indexPath.section].emojis[indexPath.row].emoji())
52+
let expectedResult = emojiManagerStub.emojiSet.emojis[
53+
emojiManagerStub.emojiSet.categories[indexPath.section].emojis[indexPath.row]
54+
]?
55+
.skins[0]
56+
.native
57+
XCTAssertEqual(
58+
result,
59+
expectedResult
60+
)
5461
}
5562

5663
func testSectionHeaderViewModelMethod() throws {
5764
let section = 0
5865

5966
let result = viewModel.sectionHeaderViewModel(for: section)
6067

61-
XCTAssertEqual(result, unicodeManagerStub.emojiCategories[section].categoryName)
68+
let expectedResult = NSLocalizedString(
69+
emojiManagerStub.emojiSet.categories[section].type.rawValue,
70+
bundle: .module,
71+
comment: ""
72+
)
73+
XCTAssertEqual(result, expectedResult)
6274
}
6375
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// EmojiManagerStub.swift
3+
// EmojiPicker
4+
//
5+
// Created by Егор Бадмаев on 25.01.2023.
6+
//
7+
8+
@testable import EmojiPicker
9+
10+
class EmojiManagerStub: EmojiManagerProtocol {
11+
12+
var deviceVersion: Double {
13+
11.1
14+
}
15+
16+
func provideEmojis() -> EmojiSet {
17+
emojiSet
18+
}
19+
20+
var emojiSet = EmojiSet(
21+
categories: [
22+
Category(type: .people, emojis: [
23+
"smile",
24+
"laughing",
25+
"grin"
26+
]),
27+
Category(type: .foods, emojis: [
28+
"peach"
29+
]),
30+
],
31+
emojis: [
32+
"smile": Emoji(
33+
id: "smile",
34+
name: "Grinning Face with Smiling Eyes",
35+
keywords: [],
36+
skins: [
37+
Skin(unified: "1f604", native: "😄")
38+
],
39+
version: 1.0),
40+
"laughing": Emoji(
41+
id: "laughing",
42+
name: "Grinning Squinting Face",
43+
keywords: [],
44+
skins: [
45+
Skin(unified: "1f606", native: "😆")
46+
],
47+
version: 1.0),
48+
"grin": Emoji(
49+
id: "grin",
50+
name: "Beaming Face with Smiling Eyes",
51+
keywords: [],
52+
skins: [
53+
Skin(unified: "1f601", native: "😁")
54+
],
55+
version: 1.0),
56+
"peach": Emoji(
57+
id: "peach",
58+
name: "Peach",
59+
keywords: [],
60+
skins: [
61+
Skin(unified: "1f351", native: "🍑")
62+
],
63+
version: 1.0),
64+
],
65+
aliases: [:]
66+
)
67+
}

Tests/EmojiPickerTests/Stubs/UnicodeManagerStub.swift

Lines changed: 0 additions & 19 deletions
This file was deleted.

Tests/EmojiPickerTests/UnicodeManagerTests.swift

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)