Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| id, | ||
| name, | ||
| imageUrl, | ||
| difficulty = 1, // デフォルト値1を設定 |
There was a problem hiding this comment.
[imo]難易度未設定の場合はゼロ値を入れて、何も情報がないことがわかるほうがいい気がしました!(誤った情報になりうるため)
There was a problem hiding this comment.
ここで修正DONE 🩹 update: PRレビュー修正: 色素さんのレビュー対応
|
|
||
| return ( | ||
| <Link href={{ pathname: `/${id}` }} className={styles.listItem}> | ||
| <div className={styles.difficultyStars}>{renderStars()}</div> |
There was a problem hiding this comment.
There was a problem hiding this comment.
ここにはロジックのテストを書きたいです。
UIがPropsによって意図した通りに表示されるかどうかというのは、ロジックで書くものではなく、ChromaticなどのVRTで実装すべきです。(作ってないですが...)
There was a problem hiding this comment.
Frontendの単体テストの対象はロジックであることが一般的です。
例えば以下のテストだと、どこまでをテストできてると言えるでしょうか?
it("タグが正しく表示される", () => {
render(<OrigamiListItem {...mockModel} />);
expect(screen.getByText("初心者向け")).toBeInTheDocument();
expect(screen.getByText("楽しい")).toBeInTheDocument();
});DOMの中に"初心者向け"と"楽しい"というテキストが含まれているかしか見れません。
例えばvisually: hiddenが付いてて画面に表示されてないとか、予期せぬ場所にレンダリングされてるとか、UI観点でのテストはカバーされてないです。
コードを見るとただ渡されたPropsを表示しているだけなので、このテストを毎回書くと工数がかかる割に得られる効果は少ないです。
There was a problem hiding this comment.
🩹 update: PR修正対応: ゆってぃーのFEテストの指摘点を反映
UIテストあんまり詳しくないから勉強になるっす.
ロジックテストになるように考えて,AIに書いてもらっています.
ベストプラクティスではないかも...
There was a problem hiding this comment.
結論から言えば、これらのテストは全て不要だと思います。
このコンポーネント自体、ロジックは持っていないからです。
propsが渡されて、それをそのままレンダリングしてるだけですよね。(altとかlinkとか特に)
どういう見た目になるかとか、それはstorybookで書いてるので重複したコードになってます。
There was a problem hiding this comment.
強いて言えば、星のテストの部分はあってもなくてもいいかなくらいの認識です。
| const renderStars = () => { | ||
| const stars = []; | ||
| for (let i = 1; i <= 5; i++) { | ||
| const isFilled = i <= difficulty; | ||
| stars.push( | ||
| <FaStar | ||
| key={i} | ||
| className={`${styles.star} ${ | ||
| isFilled ? styles.filled : styles.empty | ||
| }`} | ||
| /> | ||
| ); | ||
| } | ||
| return stars; | ||
| }; |
There was a problem hiding this comment.
reactではあまりdomを直接操作する書き方はしないかな...
https://ja.react.dev/reference/rules/react-calls-components-and-hooks#never-call-component-functions-directly
There was a problem hiding this comment.
宣言的UIについて調べると良さそう
https://zenn.dev/begineer/articles/8bc95caec85d86
There was a problem hiding this comment.
ありがと〜,以前にも言われた気がするわ.申し訳!
🩹 update: PRレビュー対応: DOMを操作しないように修正
ここで対応
| }, | ||
| colorStyle: { | ||
| control: "select", | ||
| options: ["purple-blue", "red-pink", "green", "blue", "orange", "yellow"], |
There was a problem hiding this comment.
There was a problem hiding this comment.
There was a problem hiding this comment.
こちらもこのコンポーネントにロジックはないのでテストは不要です。
| @@ -0,0 +1,3 @@ | |||
| export { Tag } from "./Tag"; | |||
| export { IconButton } from "./IconButton"; | |||
| export { default as AddOrigamiButton } from "./AddOrigamiButton"; | |||
There was a problem hiding this comment.
default as AddOrigamiButton これあってる?
There was a problem hiding this comment.
変だった...ごめん
There was a problem hiding this comment.
storybookのバージョンが悪さしてそうでした.
🩹 update: PRレビュー対応: main.tsの変更をロールバック
ここで修正DONE
| imageUrl: string; | ||
| searchKeyword?: string[]; | ||
| procedure: Procedure; | ||
| difficulty?: number; |
There was a problem hiding this comment.
型の情報量を減らしたい
少数が入ってきた場合のテストがあったけど、そもそも少数が入らないように設計すべきと思いました。
| difficulty?: number; | |
| difficulty?: 1 | 2 | 3 | 4 | 5; |
There was a problem hiding this comment.
| export type RotateAxis = [Point, Point] | []; | ||
|
|
||
| // タグの色スタイル定義 | ||
| export type ColorStyle = |
There was a problem hiding this comment.
なんのカラースタイルかわかる命名にしたい
(ローカル変数ならこれでもいいが、exportしてるので)
There was a problem hiding this comment.
タグ名とカラーはセットではなくて,ユーザーが好きに選べる,というのを想定していたんだけど,ゆってぃー的には違ったかな?
とりあえず色がわかりやすいようにColorStyleを変更した上で,今日のミーティングで確認しますm
There was a problem hiding this comment.
🐛 fix: テストの削除, ColorStyleの命名変更, difficulyの型変更
とりあえずこちらで修正
There was a problem hiding this comment.
命名が分かりにくいという指摘でした!
別ファイルからColorStyleをimportした場合を想定すると、
tagで使うためのstyleだとわからず、意図しない場所で使われそうと思いました
There was a problem hiding this comment.
結論から言えば、これらのテストは全て不要だと思います。
このコンポーネント自体、ロジックは持っていないからです。
propsが渡されて、それをそのままレンダリングしてるだけですよね。(altとかlinkとか特に)
どういう見た目になるかとか、それはstorybookで書いてるので重複したコードになってます。
There was a problem hiding this comment.
こちらもこのコンポーネントにロジックはないのでテストは不要です。
| {Array.from({ length: 5 }, (_, index) => { | ||
| const starNumber = index + 1; | ||
| const isFilled = starNumber <= difficulty; | ||
| return ( | ||
| <FaStar | ||
| key={starNumber} | ||
| className={`${styles.star} ${ | ||
| isFilled ? styles.filled : styles.empty | ||
| }`} | ||
| /> | ||
| ); | ||
| })} |
There was a problem hiding this comment.
よくなりましたが、jsxのなかにconstとかが入ってくるのは宣言的UIの原則には反しているかと思います。ここはロジックを持たず、UIの宣言のみになるべきです。
UIとロジックを分離して書くとすればこうなるかなと思います。
const stars = Array.from({ length: 5 }, (_, index) => {
const starNumber = index + 1;
const isFilled = starNumber <= difficulty;
return {
number: starNumber,
isFilled,
};
});
...
return (
...
{stars.map((star) => (
<FaStar
key={star.number}
className={`${styles.star} ${
star.isFilled ? styles.filled : styles.empty
}`}
/>
))}
...
)There was a problem hiding this comment.
こちらで修正
There was a problem hiding this comment.
強いて言えば、星のテストの部分はあってもなくてもいいかなくらいの認識です。
yutteee
left a comment
There was a problem hiding this comment.
nits commentしましたが全体的にokだと思います!
| export type RotateAxis = [Point, Point] | []; | ||
|
|
||
| // タグの色スタイル定義 | ||
| export type ColorStyle = |
There was a problem hiding this comment.
命名が分かりにくいという指摘でした!
別ファイルからColorStyleをimportした場合を想定すると、
tagで使うためのstyleだとわからず、意図しない場所で使われそうと思いました
| type OrigamiListItem = ( | ||
| props: Omit<Model, "searchKeyWord" | "procedure" | "color"> | ||
| ) => JSX.Element; |
There was a problem hiding this comment.
imo
omit知らなかったけどちょっと型安全性悪そう
Omit<T, Keys>のKeysにTには無いプロパティキーを指定しても、TypeScriptコンパイラーは指摘しません。たとえば、Keysにタイポがあっても検出できないので注意が必要です。
https://typescriptbook.jp/reference/type-reuse/utility-types/omit
There was a problem hiding this comment.
omitで不要なプロパティを除くのではなく、
pick使って必要なプロパティを明示的に指定した方が安全性は上がりそう
There was a problem hiding this comment.
個人的にはtypeベタ書きで良い気がする
UIがmodelを意識する必要があるか?と言われるとないので
| type OrigamiListItem = ( | |
| props: Omit<Model, "searchKeyWord" | "procedure" | "color"> | |
| ) => JSX.Element; | |
| type OrigamiListItem = ( | |
| id: string; | |
| name: string; | |
| imageUrl: string; | |
| difficulty: 0 | 1 | 2 | 3 | 4; | |
| tags: string[]; | |
| ) => JSX.Element; |


タイトル
概要
変更内容
スクリーンショット
備考
現状はDB変更しなくてもエラー吐かないように追加props部分はオプショナルにしているけど,今後のためにDBの変更・seedの変更をしないといけないね.