-
Notifications
You must be signed in to change notification settings - Fork 311
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
The head ref may contain hidden characters: "\u8272\u3005\u5B9F\u88C5\u3057\u3061\u3083\u3063\u305F\u3084\u3064"
Conversation
"vue/multi-word-component-names": [ | ||
"error", | ||
{ | ||
ignores: ["Container", "Presentation"], | ||
}, | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コンポーネント名は2単語以上、という制約がディレクトリ区切りのコンポーネントにも採用されてしまうので、この2つだけは許容するようにしてみました。
const wrapper = mount(UpdateNotificationDialogPresentation, { | ||
props: { | ||
modelValue: true, | ||
latestVersion, | ||
newUpdateInfos: [], | ||
onSkipThisVersionClick, | ||
}, | ||
global: { | ||
plugins: [Quasar], | ||
}, | ||
}); | ||
await flushPromises(); | ||
const domWrapper = new DOMWrapper(document.body); // QDialogを取得するワークアラウンド |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
普通にmountしてもQDialogがなぜかうまいこと動かないのでワークアラウンド。
describe("Presentation", () => { | ||
enableAutoUnmount(afterEach); | ||
|
||
it("マウントできる", async () => { | ||
mountUpdateNotificationDialogPresentation(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
表示だけなのでコンポーネントを単体テストできる!
たぶんStoryBookとかも導入できる。
多分問題ないと思うのでマージします! |
内容
アップデート通知ダイアログ周りの処理を、EditorHomeから移動させてみました。
ついでに見た目側の単体テストも書いています。
設計はContainer/Presentationalパターンです。その中でも(↓で書いてある)分割パターンです。
https://zenn.dev/buyselltech/articles/9460c75b7cd8d1
ロジックを分離するだけならコンポーザブルで良く、実際書いてみたのですが、UIの方にpropsを渡すために加工する部分がごちゃついてしまいました。
なのでAPIやVuexを叩いてpropsを加工するだけのContainerを導入してみたら、まあまあ良い感じになりました。
関連 Issue
その他
Containerを含めた複合テストも書いてみようとしたのですが、思った以上に難しかったです。
Vuexを導入する必要がある(これはそんなに難しくない)のと、あとアプリバージョンを取得する周りのmockが綺麗に作れないなと。
Container含めた制御ロジックはテストしづらいので、なるべくロジックを書かないのが良さそうに感じました。
今回のコードは、2つのバージョンを比較してより新しい方を選ぶ部分だけロジックが入ってます。