Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1711のテスト書いてみた #1

Conversation

Hiroshiba
Copy link

内容

VOICEVOX#1711 のテストを書いてみました。
めちゃくちゃ難しかったです。。。。。。。

その他

Copy link
Author

@Hiroshiba Hiroshiba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テスト書いてみたので、よかったら!!

import { isMac } from "@/type/preload";

const createUseKey = (key: string) => (): Ref<boolean> => {
// FIXME: Vue3.3以上では定義済みなので削除する
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

早くバージョン上げたい。


type Target = EventTarget & GlobalEventHandlers;

const useCreateUseKey = (
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コンポーザブルを作る関数はちょっと合法か怪しかったのでコンポーザブルに変えてみました。
(たぶん今のとこ合法)


const useCreateUseKey = (
key: string,
_target: MaybeRefOrGetter<Target> = window
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DIできるようにしてみたけど・・・。

Comment on lines +43 to +47
onUnmounted(() => {
target.removeEventListener("keydown", onKeydown);
target.removeEventListener("keyup", onKeyup);
target.removeEventListener("blur", onBlur);
});
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ベストプラクティスで「後処理もしましょう」みたいなことがVueUseに書いてたので。

Comment on lines 66 to +69
if (isMac) {
return useMetaKey();
return useMetaKey(target);
}
return useControlKey();
return useControlKey(target);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ifのなかでcomposable実行するのは今のとこ合法っぽい。
(今のVueコンポーネントがどれかさえ追えればなんでも良い)

Comment on lines +12 to +19
const mountWrapper = (func: (elem: HTMLElement) => Ref<boolean>) =>
mount({
setup: () => {
const elem = document.createElement("div");
return { elem, isActive: func(elem) };
},
render: () => null, // 警告防止
});
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これにたどり着くまでにすごく時間がかかった。。。

Copy link
Owner

@sevenc-nanashi sevenc-nanashi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMです。合法とかの概念があるんですね(知らなかった)

@Hiroshiba
Copy link
Author

合法とかの概念があるんですね(知らなかった)

といってもVueのコンポーザブルのとこにちょっと書いてるくらいなんですけどね。
https://ja.vuejs.org/guide/reusability/composables#conventions-and-best-practices
(ちなみに合法というのは日本エンジニアのスラング)


あ、これ @sevenc-nanashi さんのリポジトリへのプルリクなので、マージしていただければ @sevenc-nanashi さんのプルリクに反映されると思います!

@sevenc-nanashi
Copy link
Owner

(マージ忘れてました)

@sevenc-nanashi sevenc-nanashi merged commit 53e1e12 into sevenc-nanashi:fix/multi-select-with-unfocus Jan 15, 2024
7 checks passed
@Hiroshiba Hiroshiba deleted the テスト書いてみた branch January 15, 2024 14:53
sevenc-nanashi added a commit that referenced this pull request Jan 16, 2024
* Refactor: 修飾キーのcomposableを追加

* Dlete: 不要なexportを削除

Co-authored-by: Hiroshiba <[email protected]>

* #1711のテスト書いてみた (#1)

---------

Co-authored-by: Hiroshiba <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants