-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alexander Zakharov
committed
Oct 7, 2023
1 parent
e18bb0d
commit c1c75f7
Showing
8 changed files
with
785 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import XCTest | ||
import ComposableArchitecture | ||
@testable import VocabVerse | ||
|
||
@MainActor | ||
final class CategoryTests: XCTestCase { | ||
func testOnAppearCategories() async { | ||
let categories: [VocabVerse.Category] = [ | ||
Category(id: UUID(0), name: "Test category", addedDate: .distantPast) | ||
] | ||
|
||
let store = TestStore(initialState: CategoryListFeature.State()) { | ||
CategoryListFeature() | ||
} withDependencies: { | ||
$0.categoryClient.fetchCategories = { | ||
categories | ||
} | ||
} | ||
|
||
await store.send(.onAppear) | ||
await store.receive(.categoriesFetched(categories)) { | ||
$0.categories = categories | ||
$0.isCategoriesFetched = true | ||
} | ||
} | ||
|
||
func testDeleteCategory() async { | ||
let store = TestStore(initialState: CategoryListFeature.State(categories: [ | ||
Category(id: UUID(0), name: "Test category 1", addedDate: .distantPast), | ||
Category(id: UUID(1), name: "Test category 2", addedDate: .distantPast) | ||
])) { | ||
CategoryListFeature() | ||
} withDependencies: { | ||
$0.categoryClient = .testValue | ||
} | ||
|
||
await store.send( | ||
.deleteWordsCategoryTapped( | ||
Category( | ||
id: UUID(1), | ||
name: "Test category 2", | ||
addedDate: .distantPast | ||
) | ||
) | ||
) | ||
await store.receive(.categoryDeleted(Category(id: UUID(1), name: "Test category 2", addedDate: .distantPast))) { | ||
$0.categories = [Category(id: UUID(0), name: "Test category 1", addedDate: .distantPast)] | ||
} | ||
} | ||
|
||
func testAddCategory() async { | ||
let store = TestStore(initialState: CategoryListFeature.State()) { | ||
CategoryListFeature() | ||
} withDependencies: { | ||
$0.uuid = .incrementing | ||
$0.date = .constant(.distantPast) | ||
$0.categoryClient = .testValue | ||
} | ||
|
||
var category = Category(id: UUID(0), addedDate: .distantPast) | ||
|
||
await store.send(.addCategoryButtonTapped) { | ||
$0.addCategory = CategoryFormFeature.State(category: category) | ||
} | ||
|
||
category.name = "Test category" | ||
await store.send(.addCategory(.presented(.set(\.$category, category)))) { | ||
$0.addCategory?.category.name = "Test category" | ||
} | ||
|
||
await store.send(.createCategoryButtonTapped) | ||
await store.receive(.categoryCreated(category)) { | ||
$0.addCategory = nil | ||
$0.categories = [Category(id: UUID(0), name: "Test category", addedDate: .distantPast)] | ||
} | ||
} | ||
|
||
func testAddWordToCategory() async { | ||
var word = Word(id: UUID(0), categoryId: UUID(0), addedDate: .distantPast) | ||
let category = Category(id: UUID(0), addedDate: .distantPast) | ||
let store = TestStore(initialState: CategoryListFeature.State(categories: [category])) { | ||
CategoryListFeature() | ||
} withDependencies: { | ||
$0.date = .constant(.distantPast) | ||
$0.uuid = .incrementing | ||
$0.categoryClient = .testValue | ||
} | ||
|
||
await store.send(.path(.push(id: 0, state: .wordsList(WordsListFeature.State(categoryId: UUID(0)))))) { | ||
$0.path[id: 0] = .wordsList(WordsListFeature.State(categoryId: UUID(0))) | ||
} | ||
|
||
await store.send(.path(.element(id: 0, action: .wordsList(.addButtonTapped)))) { | ||
$0.path[id: 0] = .wordsList(WordsListFeature.State( | ||
addWord: WordFormFeature.State(word: word, formType: .add), | ||
categoryId: UUID(0) | ||
)) | ||
} | ||
word.nativeWord = "Native word" | ||
word.translation = "Translation" | ||
|
||
await store.send(.path(.element(id: 0, action: .wordsList(.addWord(.presented(.set(\.$word, word))))))) { | ||
$0.path[id: 0] = .wordsList( | ||
WordsListFeature.State( | ||
addWord: WordFormFeature.State( | ||
word: Word( | ||
id: UUID(0), | ||
categoryId: UUID(0), | ||
nativeWord: "Native word", | ||
translation: "Translation", | ||
addedDate: .distantPast | ||
), | ||
formType: .add | ||
), | ||
categoryId: UUID(0) | ||
) | ||
) | ||
} | ||
|
||
await store.send(.path(.element(id: 0, action: .wordsList(.saveWordButtonTaped)))) | ||
await store.receive(.path(.element(id: 0, action: .wordsList(.wordSaved(word))))) { | ||
$0.path[id: 0] = .wordsList( | ||
WordsListFeature.State( | ||
addWord: nil, | ||
words: [ | ||
Word( | ||
id: UUID(0), | ||
categoryId: UUID(0), | ||
nativeWord: "Native word", | ||
translation: "Translation", | ||
addedDate: .distantPast | ||
) | ||
], | ||
categoryId: UUID(0) | ||
) | ||
) | ||
$0.categories = [ | ||
Category( | ||
id: UUID(0), | ||
words: [ | ||
Word( | ||
id: UUID(0), | ||
categoryId: UUID(0), | ||
nativeWord: "Native word", | ||
translation: "Translation", | ||
addedDate: .distantPast | ||
) | ||
], | ||
addedDate: .distantPast | ||
) | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import XCTest | ||
import ComposableArchitecture | ||
@testable import VocabVerse | ||
|
||
@MainActor | ||
final class CorrectWritingTests: XCTestCase { | ||
func testHint() async { | ||
let word: Word = Word( | ||
id: UUID(0), | ||
categoryId: UUID(0), | ||
nativeWord: "Native word", | ||
translation: "Te", | ||
addedDate: .distantPast | ||
) | ||
|
||
let store = TestStore(initialState: CorrectWritingFeature.State(words: [word])) { | ||
CorrectWritingFeature() | ||
} | ||
|
||
await store.send(.hintTapped) { | ||
$0.userInput = "T" | ||
$0.currentWordState.hintProgress = 1 | ||
} | ||
await store.send(.hintTapped) { | ||
$0.userInput = "Te" | ||
$0.currentWordState.hintProgress = 2 | ||
} | ||
await store.send(.hintTapped) | ||
} | ||
|
||
func testCorrectTranlation() async { | ||
let word: Word = Word( | ||
id: UUID(0), | ||
categoryId: UUID(0), | ||
nativeWord: "Native word", | ||
translation: "Translation", | ||
addedDate: .distantPast | ||
) | ||
|
||
let store = TestStore( | ||
initialState: CorrectWritingFeature.State( | ||
words: [word], | ||
userInput: "Translation" | ||
) | ||
) { | ||
CorrectWritingFeature() | ||
} | ||
|
||
await store.send(.checkTranslation) { | ||
$0.currentWordState.isWordCorrect = true | ||
$0.currentWordState.attempsCount = 1 | ||
$0.correctWordsCount = 1 | ||
} | ||
} | ||
|
||
func testNextWordSwitching() async { | ||
let word: Word = Word( | ||
id: UUID(0), | ||
categoryId: UUID(0), | ||
nativeWord: "Native word", | ||
translation: "Translation", | ||
addedDate: .distantPast | ||
) | ||
|
||
let store = TestStore( | ||
initialState: CorrectWritingFeature.State( | ||
words: [word], | ||
userInput: "Translation" | ||
) | ||
) { | ||
CorrectWritingFeature() | ||
} | ||
|
||
store.exhaustivity = .off | ||
|
||
await store.send(.checkTranslation) | ||
|
||
await store.send(.nextWordButtonTapped) { | ||
$0.userInput = "" | ||
$0.correctWordsCount = 1 | ||
$0.currentWordIndex = 1 | ||
$0.currentWordState.attempsCount = 0 | ||
$0.currentWordState.isWordCorrect = false | ||
$0.currentWordState.hintProgress = 0 | ||
} | ||
} | ||
|
||
func testTotalAttempsReached() async { | ||
let word: Word = Word( | ||
id: UUID(0), | ||
categoryId: UUID(0), | ||
nativeWord: "Native word", | ||
translation: "Translation", | ||
addedDate: .distantPast | ||
) | ||
|
||
let store = TestStore( | ||
initialState: CorrectWritingFeature.State( | ||
words: [word], | ||
userInput: "Incorrect word" | ||
) | ||
) { | ||
CorrectWritingFeature() | ||
} | ||
|
||
store.exhaustivity = .off | ||
|
||
await store.send(.checkTranslation) | ||
await store.send(.checkTranslation) | ||
await store.send(.checkTranslation) { | ||
$0.currentWordState.attempsCount = 3 | ||
$0.currentWordState.isWordCorrect = false | ||
$0.incorrectWordsCount = 1 | ||
} | ||
} | ||
|
||
func testReset() async { | ||
let word: Word = Word( | ||
id: UUID(0), | ||
categoryId: UUID(0), | ||
nativeWord: "Native word", | ||
translation: "Translation", | ||
addedDate: .distantPast | ||
) | ||
|
||
let store = TestStore( | ||
initialState: CorrectWritingFeature.State( | ||
words: [word], | ||
currentWordIndex: 1, | ||
userInput: "Some word", | ||
currentWordState: .init(attempsCount: 2, isWordCorrect: true) | ||
) | ||
) { | ||
CorrectWritingFeature() | ||
} | ||
|
||
await store.send(.reset) { | ||
$0 = CorrectWritingFeature.State(words: [word]) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import XCTest | ||
import ComposableArchitecture | ||
@testable import VocabVerse | ||
|
||
@MainActor | ||
final class LearningListTests: XCTestCase { | ||
func testOnAppearLearningList() async { | ||
let categories: [VocabVerse.Category] = [ | ||
Category(id: UUID(0), name: "Test category", addedDate: .distantPast) | ||
] | ||
|
||
let store = TestStore(initialState: LearningListFeature.State()) { | ||
LearningListFeature() | ||
} withDependencies: { | ||
$0.categoryClient.fetchCategories = { categories } | ||
$0.stateClient = .testValue | ||
} | ||
|
||
await store.send(.onAppear) | ||
await store.receive(.categoriesFetched(categories)) { | ||
$0.categories = [Category(id: UUID(0), name: "Test category", addedDate: .distantPast)] | ||
$0.isCategoriesFecthed = true | ||
} | ||
} | ||
|
||
func testSelectCategory() async { | ||
let categories: [VocabVerse.Category] = [ | ||
Category(id: UUID(0), name: "Test category1", addedDate: .distantPast), | ||
Category(id: UUID(1), name: "Test category2", addedDate: .distantPast) | ||
] | ||
|
||
let store = TestStore(initialState: LearningListFeature.State(categories: categories)) { | ||
LearningListFeature() | ||
} | ||
|
||
await store.send(.selectCategoryButtonTapped) { | ||
$0.categorySelect = CategorySelectFeature.State(categories: categories) | ||
} | ||
|
||
await store.send(.categorySelect(.presented(.selectCategoryTapped(categories[0])))) { | ||
$0.categorySelect?.selectedCategories = [categories[0].id] | ||
} | ||
|
||
await store.send(.categoriesSelected([categories[0].id])) { | ||
$0.categorySelect = nil | ||
$0.categories = categories | ||
$0.selectedCategories = [categories[0].id] | ||
} | ||
} | ||
} |
Oops, something went wrong.