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

[refactor] アップデート通知ダイアログ周りをEditorHome.vueから分離 #1717

Merged
merged 7 commits into from
Jan 20, 2024

Conversation

Hiroshiba
Copy link
Member

@Hiroshiba Hiroshiba commented Jan 17, 2024

内容

アップデート通知ダイアログ周りの処理を、EditorHomeから移動させてみました。
ついでに見た目側の単体テストも書いています。

設計はContainer/Presentationalパターンです。その中でも(↓で書いてある)分割パターンです。
https://zenn.dev/buyselltech/articles/9460c75b7cd8d1

ロジックを分離するだけならコンポーザブルで良く、実際書いてみたのですが、UIの方にpropsを渡すために加工する部分がごちゃついてしまいました。
なのでAPIやVuexを叩いてpropsを加工するだけのContainerを導入してみたら、まあまあ良い感じになりました。

関連 Issue

その他

Containerを含めた複合テストも書いてみようとしたのですが、思った以上に難しかったです。
Vuexを導入する必要がある(これはそんなに難しくない)のと、あとアプリバージョンを取得する周りのmockが綺麗に作れないなと。
Container含めた制御ロジックはテストしづらいので、なるべくロジックを書かないのが良さそうに感じました。
今回のコードは、2つのバージョンを比較してより新しい方を選ぶ部分だけロジックが入ってます。

Comment on lines +58 to +63
"vue/multi-word-component-names": [
"error",
{
ignores: ["Container", "Presentation"],
},
],
Copy link
Member Author

Choose a reason for hiding this comment

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

コンポーネント名は2単語以上、という制約がディレクトリ区切りのコンポーネントにも採用されてしまうので、この2つだけは許容するようにしてみました。

Comment on lines +20 to +32
const wrapper = mount(UpdateNotificationDialogPresentation, {
props: {
modelValue: true,
latestVersion,
newUpdateInfos: [],
onSkipThisVersionClick,
},
global: {
plugins: [Quasar],
},
});
await flushPromises();
const domWrapper = new DOMWrapper(document.body); // QDialogを取得するワークアラウンド
Copy link
Member Author

Choose a reason for hiding this comment

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

普通にmountしてもQDialogがなぜかうまいこと動かないのでワークアラウンド。

Comment on lines +45 to +50
describe("Presentation", () => {
enableAutoUnmount(afterEach);

it("マウントできる", async () => {
mountUpdateNotificationDialogPresentation();
});
Copy link
Member Author

Choose a reason for hiding this comment

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

表示だけなのでコンポーネントを単体テストできる!
たぶんStoryBookとかも導入できる。

@Hiroshiba Hiroshiba marked this pull request as ready for review January 17, 2024 18:43
@Hiroshiba Hiroshiba requested a review from a team as a code owner January 17, 2024 18:43
@Hiroshiba Hiroshiba requested review from y-chan and removed request for a team January 17, 2024 18:43
@Hiroshiba
Copy link
Member Author

多分問題ないと思うのでマージします!

@Hiroshiba Hiroshiba merged commit ab7bd48 into VOICEVOX:main Jan 20, 2024
8 checks passed
@Hiroshiba Hiroshiba deleted the 色々実装しちゃったやつ branch January 20, 2024 14:02
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.

1 participant