mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Integrate emojibase (#1449)
* Integrate emojibase * pin emojibase to version rather than revision * Log error in case of failed loading of emojis from emojibase. * Update Package.resolved * Fix tests and bindings version
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import ElementX
|
||||
|
||||
final class EmojiMartJSONLoaderTests: XCTestCase {
|
||||
var sut: EmojiMartJSONLoader!
|
||||
|
||||
override func setUp() {
|
||||
sut = EmojiMartJSONLoader()
|
||||
}
|
||||
|
||||
func test_whenEmojisLoaded_CorrectCategoryCountReturned() async {
|
||||
let categories = await sut.load()
|
||||
XCTAssertEqual(categories.count, 8)
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ final class EmojiProviderTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_whenEmojisLoaded_categoriesAreLoadedFromLoader() async throws {
|
||||
let item = EmojiItem(id: "test", name: "test", keywords: ["1", "2"], skins: ["🙂"])
|
||||
let item = EmojiItem(label: "test", unicode: "test", keywords: ["1", "2"], shortcodes: ["1", "2"], skins: ["🙂"])
|
||||
let category = EmojiCategory(id: "test", emojis: [item])
|
||||
emojiLoaderMock.categories = [category]
|
||||
let categories = await sut.getCategories()
|
||||
@@ -36,7 +36,7 @@ final class EmojiProviderTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_whenEmojisLoadedAndSearchStringEmpty_allCategoriesReturned() async throws {
|
||||
let item = EmojiItem(id: "test", name: "test", keywords: ["1", "2"], skins: ["🙂"])
|
||||
let item = EmojiItem(label: "test", unicode: "test", keywords: ["1", "2"], shortcodes: ["1", "2"], skins: ["🙂"])
|
||||
let category = EmojiCategory(id: "test", emojis: [item])
|
||||
emojiLoaderMock.categories = [category]
|
||||
let categories = await sut.getCategories(searchString: "")
|
||||
@@ -44,10 +44,12 @@ final class EmojiProviderTests: XCTestCase {
|
||||
}
|
||||
|
||||
func test_whenEmojisLoadedSecondTime_cachedValuesAreUsed() async throws {
|
||||
let item = EmojiItem(label: "test", unicode: "test", keywords: ["1", "2"], shortcodes: ["1", "2"], skins: ["🙂"])
|
||||
let item2 = EmojiItem(label: "test2", unicode: "test2", keywords: ["3", "4"], shortcodes: ["3", "4"], skins: ["🙂"])
|
||||
let categoriesForFirstLoad = [EmojiCategory(id: "test",
|
||||
emojis: [EmojiItem(id: "test", name: "test", keywords: ["1", "2"], skins: ["🙂"])])]
|
||||
emojis: [item])]
|
||||
let categoriesForSecondLoad = [EmojiCategory(id: "test2",
|
||||
emojis: [EmojiItem(id: "test2", name: "test2", keywords: ["3", "4"], skins: ["🫠"])])]
|
||||
emojis: [item2])]
|
||||
emojiLoaderMock.categories = categoriesForFirstLoad
|
||||
_ = await sut.getCategories()
|
||||
emojiLoaderMock.categories = categoriesForSecondLoad
|
||||
@@ -58,33 +60,25 @@ final class EmojiProviderTests: XCTestCase {
|
||||
func test_whenEmojisSearched_correctNumberOfCategoriesReturned() async throws {
|
||||
let searchString = "smile"
|
||||
var categories = [EmojiCategory]()
|
||||
let item0WithSearchString = EmojiItem(label: "emoji0", unicode: "\(searchString)_123", keywords: ["key1", "key1"], shortcodes: ["key1", "key1"], skins: ["🙂"])
|
||||
let item1WithSearchString = EmojiItem(label: searchString, unicode: "emoji1", keywords: ["key1", "key1"], shortcodes: ["key1", "key1"], skins: ["🙂"])
|
||||
let item2WithSearchString = EmojiItem(label: "emoji_2", unicode: "emoji_2", keywords: ["key1", "\(searchString)_123"], shortcodes: ["key1", "key2"], skins: ["🙂"])
|
||||
let item3WithSearchString = EmojiItem(label: "emoji_2", unicode: "emoji_2", keywords: ["key1", "key1"], shortcodes: ["key1", "\(searchString)_123"], skins: ["🙂"])
|
||||
let item4WithoutSearchString = EmojiItem(label: "emoji_3", unicode: "emoji_3", keywords: ["key1", "key1"], shortcodes: ["key1", "key1"], skins: ["🙂"])
|
||||
let item5WithSearchString = EmojiItem(label: "emoji0", unicode: "\(searchString)_123", keywords: ["key1", "key1"], shortcodes: ["key1", "key1"], skins: ["🙂"])
|
||||
categories.append(EmojiCategory(id: "test",
|
||||
emojis: [EmojiItem(id: "\(searchString)_123",
|
||||
name: "emoji0",
|
||||
keywords: ["key1", "key1"],
|
||||
skins: ["🙂"]),
|
||||
EmojiItem(id: "emoji_1",
|
||||
name: searchString,
|
||||
keywords: ["key1", "key1"],
|
||||
skins: ["🙂"]),
|
||||
EmojiItem(id: "emoji_2",
|
||||
name: "emoji2",
|
||||
keywords: ["key1", "\(searchString)_123"],
|
||||
skins: ["🙂"]),
|
||||
EmojiItem(id: "emoji_3",
|
||||
name: "emoji_3",
|
||||
keywords: ["key1", "key1"],
|
||||
skins: ["🙂"])]))
|
||||
emojis: [item0WithSearchString,
|
||||
item1WithSearchString,
|
||||
item2WithSearchString,
|
||||
item3WithSearchString,
|
||||
item4WithoutSearchString]))
|
||||
categories.append(EmojiCategory(id: "test",
|
||||
emojis: [EmojiItem(id: "\(searchString)_123",
|
||||
name: "emoji0",
|
||||
keywords: ["key1", "key1"],
|
||||
skins: ["🙂"])]))
|
||||
emojis: [item5WithSearchString]))
|
||||
emojiLoaderMock.categories = categories
|
||||
_ = await sut.getCategories()
|
||||
let result = await sut.getCategories(searchString: searchString)
|
||||
XCTAssertEqual(result.count, 2)
|
||||
XCTAssertEqual(result.first?.emojis.count, 3)
|
||||
XCTAssertEqual(result.first?.emojis.count, 4)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user