Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatsumi0000 committed Apr 15, 2024
1 parent baa3afa commit 4c7072a
Showing 1 changed file with 147 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,153 @@ struct RaelizeInputMethodKitTests {
$0 = RaelizeIMKReducer.State(raelizeState: .neutralMode)
}
}

@Test @MainActor
func upArrowKey() async {
let store = TestStore(
initialState: RaelizeIMKReducer.State(raelizeState: .neutralMode),
reducer: { RaelizeIMKReducer() },
withDependencies: {
$0.wordListFileUseCase = WordListFileUseCaseMock()
})
let upArrowKeyEvent = NSEvent.keyEvent(
with: .keyDown, location: NSPoint(), modifierFlags: NSEvent.ModifierFlags(),
timestamp: 0, windowNumber: 0, context: nil, characters: "",
charactersIgnoringModifiers: "", isARepeat: false, keyCode: 126)!
await store.send(.operationEventKey(upArrowKeyEvent)) {
$0.candidateEvent = upArrowKeyEvent
$0.raelizeState = .operationMode
}
}

@Test @MainActor
func backSpaceKey() async {
let store = TestStore(
initialState: RaelizeIMKReducer.State(
raelizeState: .neutralMode, candinates: ["test0", "test1"],
inputWord: "test",
selectedWord: "test0"),
reducer: { RaelizeIMKReducer() },
withDependencies: {
$0.wordListFileUseCase = WordListFileUseCaseMock()
})
let backSpaceKeyEvent = NSEvent.keyEvent(
with: .keyDown, location: NSPoint(), modifierFlags: NSEvent.ModifierFlags(),
timestamp: 0, windowNumber: 0, context: nil, characters: "",
charactersIgnoringModifiers: "", isARepeat: false, keyCode: 51)!
let words = ["test0", "test1", "test2", "test3", "test4"]
await store.send(.operationEventKey(backSpaceKeyEvent)) {
$0.raelizeState = .operationMode
$0.inputWord = "tes"
}
await store.receive(.candinates(words)) {
$0.candinates = words
}
}

@Test @MainActor
func undifinedKey() async {
let store = TestStore(
initialState: RaelizeIMKReducer.State(raelizeState: .neutralMode),
reducer: { RaelizeIMKReducer() },
withDependencies: {
$0.wordListFileUseCase = WordListFileUseCaseMock()
})
let undifinedKeyEvent = NSEvent.keyEvent(
with: .keyDown, location: NSPoint(), modifierFlags: NSEvent.ModifierFlags(),
timestamp: 0, windowNumber: 0, context: nil, characters: "",
charactersIgnoringModifiers: "", isARepeat: false, keyCode: 12345)!
await store.send(.operationEventKey(undifinedKeyEvent)) {
$0.raelizeState = .operationMode
}
}
}

@Test @MainActor
func insertText() async {
let store = TestStore(
initialState: RaelizeIMKReducer.State(raelizeState: .neutralMode),
reducer: { RaelizeIMKReducer() },
withDependencies: {
$0.wordListFileUseCase = WordListFileUseCaseMock()
})
await store.send(.insertText("hoge")) {
$0.raelizeState = .inputMode
$0.insertText = "hoge"
}
await store.receive(.resetState(.neutralMode)) {
$0 = RaelizeIMKReducer.State(raelizeState: .neutralMode)
}
}

@Test @MainActor
func candinates() async {
let store = TestStore(
initialState: RaelizeIMKReducer.State(raelizeState: .neutralMode),
reducer: { RaelizeIMKReducer() },
withDependencies: {
$0.wordListFileUseCase = WordListFileUseCaseMock()
})
let words = ["test0", "test1", "test2", "test3", "test4"]
await store.send(.candinates(words)) {
$0.candinates = words
}
}

@Test @MainActor
func candinatesNil() async {
let store = TestStore(
initialState: RaelizeIMKReducer.State(
raelizeState: .neutralMode, candinates: ["test"]),
reducer: { RaelizeIMKReducer() },
withDependencies: {
$0.wordListFileUseCase = WordListFileUseCaseMock()
})
await store.send(.candinates(nil)) {
$0.candinates = []
}
}

@Test @MainActor
func selectedWord() async {
let store = TestStore(
initialState: RaelizeIMKReducer.State(raelizeState: .neutralMode),
reducer: { RaelizeIMKReducer() },
withDependencies: {
$0.wordListFileUseCase = WordListFileUseCaseMock()
})
await store.send(.selectedWord("test")) {
$0.raelizeState = .operationMode
$0.selectedWord = "test"
}
}

final class HandleRaelizeState {
@Test @MainActor
func backSpaceKey() async {
let store = TestStore(
initialState: RaelizeIMKReducer.State(
raelizeState: .neutralMode),
reducer: { RaelizeIMKReducer() },
withDependencies: {
$0.wordListFileUseCase = WordListFileUseCaseMock()
})
let undifinedKeyEvent = NSEvent.keyEvent(
with: .keyDown, location: NSPoint(), modifierFlags: NSEvent.ModifierFlags(),
timestamp: 0, windowNumber: 0, context: nil, characters: "test",
charactersIgnoringModifiers: "", isARepeat: false, keyCode: 17)!
await store.send(.handleRaelizeState(undifinedKeyEvent)) {
$0.raelizeState = .inputMode
}
await store.receive(.inputWord("test")) {
$0.inputWord = "test"
$0.fileName = "a"
}
let words = ["test0", "test1", "test2", "test3", "test4"]
await store.receive(.candinates(words)) {
$0.candinates = words
}
}
}
}
}

0 comments on commit 4c7072a

Please sign in to comment.