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

メンター・アドバイザー・管理者はダッシュボードの学習時間の草を非表示にする #4211

Merged

Conversation

Saki-htr
Copy link
Contributor

@Saki-htr Saki-htr commented Feb 12, 2022

issue #4110

変更前

これまで、ダッシュボードの学習時間の草の表示条件は以下のようになっていました。

  • 学習時間が有るユーザーなら全員表示する
  • 学習時間が無ければ、メンターでない場合表示する(メンター以外は学習時間の有無に関わらず表示する)

具体的には、以下の画面になっていました。
  • メンター(mentormentaro):学習時間があるメンターは表示 / ないメンターは非表示
    (以下の画像はありの場合のものです)

前:メンター(yamada)

  • アドバイザー(advijirou):学習時間の有無に関わらず表示

前(草なし):アドバイザー(advijirou)

  • 管理者(adminonly):学習時間の有無に関わらず表示

前:管理者(adminonly)

変更後

以下に変更いたしました。

  • メンター・アドバイザー・管理者の場合、(学習時間の有る無しに関わらず)非表示
  • それ以外のユーザーは(学習時間の有る無しに関わらず)表示

具体的には、以下の画面に変更いたしました。

  • メンター(mentormentaro)

後:メンター

  • アドバイザー(advijirou)

後:アドバイザー

  • 管理者(adminonly)

後:管理者

ご確認いただきたいこと3点

  1. mentormentaroでログインした時、学習時間が有る時も無い時も、ダッシュボードに学習時間の草が無い
  2. advijirouでログインした時、学習時間が有る時も無い時も、ダッシュボードに学習時間の草が無い
  3. adminonlyでログインした時、学習時間が有る時も無い時も、ダッシュボードに学習時間の草が無い

@Saki-htr Saki-htr marked this pull request as ready for review February 13, 2022 06:59
@Saki-htr Saki-htr self-assigned this Feb 13, 2022
@Saki-htr
Copy link
Contributor Author

@tksmasaki さん

お疲れ様です〜
お手すきの際に、こちらのissueのレビューをしていただけましたら幸いです🙏

テストが落ちているのですが、今回のPRで追記したものは通っており、落ちているのは日報のコメントの投稿日時をクリックするとコメントURLがコピーされる機能のテストが落ちる · Issue #4201 · fjordllc/bootcampが原因と思われます。
machidaさんが、依頼時にこの旨を記載すればレビュー依頼してよいと仰っていましたので、こちらの状態でレビュー依頼させていただきます🙇‍♀️
よろしくお願いいたします。

Copy link
Contributor

@tksmasaki tksmasaki left a comment

Choose a reason for hiding this comment

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

@Saki-htr
お疲れさまです。レビュー依頼ありがとうございます!
いくつか気になった点をコメントさせていただきました。分かりづらい点があれば、ご指摘よろしくお願いします🙇‍♂️

@@ -62,7 +62,7 @@ header.page-header
| 内容を更新
- if (current_user.admin? || current_user.adviser?) && @job_seeking_users.present?
= render 'job_seeking_users', users: @job_seeking_users
- if current_user.total_learning_time.positive? || !current_user.mentor?
- unless current_user.mentor? || current_user.adviser? || current_user.admin?
Copy link
Contributor

Choose a reason for hiding this comment

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

この条件を「 student もしくは trainee のみ草を表示する」と読み替えて問題なければ、
if current_user.student_or_trainee?
の方が簡潔かなと思いました。(ニコニコカレンダーの表示条件はそうなっているようです)

参考:bootcampのuserの roleまとめ | FJORD BOOT CAMP(フィヨルドブートキャンプ)

Copy link
Contributor Author

@Saki-htr Saki-htr Feb 28, 2022

Choose a reason for hiding this comment

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

@tksmasaki さん
たしかにその方が簡潔で読みやすいコードになりますね✨ ありがとうございます!
念の為rails consoleで、想定通りにtrue / falseが返ってくるかを確認したところ、大丈夫でした。

# 管理者
User.find_by(login_name: "machida").student_or_trainee? #=>false

User.find_by(login_name: "komagata").student_or_trainee? #=>false

# アドバイザー
User.find_by(login_name: "advijirou").student_or_trainee? #=> false

User.find_by(login_name: "senpai").student_or_trainee? #=> false

#メンター
User.find_by(login_name: "yamada").student_or_trainee?  #=> false

#生徒
User.find_by(login_name: "kensyu").student_or_trainee? #=>true

User.find_by(login_name: "sotugyou").student_or_trainee? #=>true

User.find_by(login_name: "daimyo-kensyu").student_or_trainee? #=>true

また動作確認も行ったところOKでしたので、仰るとおりif current_user.student_or_trainee?に変更いたしました🙆‍♀️
こちらのコミットで修正しました:823567d(草の表示条件を簡潔なものに修正)
条件を忠実に満たすために「管理者・アドバイザー・メンター以外」をそのままコードにすることばかり考えていましたが、読みやすく切り出されたメソッドがないかをモデルで確認することが大事なのですね〜
勉強になりました🙏✨


test 'not show the grass for administrators' do
visit_with_auth '/', 'komagata'
assert_no_text 'ニコニコカレンダー'
Copy link
Contributor

Choose a reason for hiding this comment

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

assert_no_text 'ニコニコカレンダー' → これは '学習時間' との間違えでしょうか?

また、このテストケースは show the grass except for mentors, advisers, and administrators のテストケースと重複している気がしました。別途、管理者の場合のテストを作った目的が何かありますか?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

申し訳ありません🙇‍♀️
既存のニコニコカレンダーのテストをコピーして今回のテストを書いたのですが、「ニコニコカレンダー」を「学習時間」に変更するのを失念しておりました。こちらは削除いたしました🙏

@@ -89,9 +89,26 @@ class HomeTest < ApplicationSystemTestCase
assert_current_path(/niconico_calendar=#{1.month.ago.strftime('%Y-%m')}/)
end

test 'show the grass' do
test 'show the grass except for mentors, advisers, and administrators' do
Copy link
Contributor

Choose a reason for hiding this comment

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

個人的な好みかもしれないですが、草が表示される場合と表示されない場合にテストを分けたほうが、わかりやすいと思いました。
また、そのユーザーに対して、なぜ草が 表示 or 非表示 なのかがテストだけ見ても伝わりにくいので、草が表示されていることを確認するアサーションの前に、そのユーザーのロールを assert したほうが良いのではないかと思いました。(コメントでも十分かもしれないです)

テストのイメージとしては以下のような感じです。

  • show the grass (名前は適当です)

    • 草が表示されるユーザーで該当ページへ
    • そのユーザーのロールをアサーション(もしくはコメント)
    • 表示されることを確認
  • not show the grass

    • 草が表示されないユーザーで該当ページへ
    • そのユーザーのロールをアサーション(もしくはコメント)
    • 表示されないことを確認

Copy link
Contributor Author

Choose a reason for hiding this comment

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

草が表示される場合と表示されない場合にテストを分けたほうが、わかりやすい

たしかにその方が分かりやすいですね〜😄 仰るとおり表示される場合と表示されない場合に分けました!

なぜ草が 表示 or 非表示 なのかがテストだけ見ても伝わりにくいので、草が表示されていることを確認するアサーションの前に、そのユーザーのロールを assert したほうが良いのではないか

たしかに補足がないと「なぜか」が分かりにくいですね〜
tksmasakiさんの日報が0件の場合、日報ダウンロードボタンを非表示に修正 by tksmasaki · Pull Request #4128を参考にさせていただき、コメントで補足を入れてみました! いかがでしょうか〜☺️

ユーザーのロールを assert

すみません、「ユーザーのロールを assert 」とは、具体的にはどのようなコードか分かりませんでした🙏💦
ダッシュボードの左上に表示されるロールをassert_text 'メンター'のように書くということでしょうか??
スクリーンショット 2022-03-01 19 31 26

すみませんが、教えていただけるとありがたいです〜🙇‍♀️

Copy link
Contributor

@tksmasaki tksmasaki Mar 1, 2022

Choose a reason for hiding this comment

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

修正ありがとうございます!

ユーザーのロールを assert

これは 、assert users(:kimura).student? のように書いて、ログインするユーザーのロールを確認するという意図でした。初めからはっきり伝えられず、申し訳ありません。

こうすることでログインするユーザーのロールが明確になってよいと思ったのですが、コメントでもいいかな? それとも、そもそもこれはいらないかな?と、レビュー時に迷った点でもありました。

はっきりとこうした方がよいと提示できず申し訳ありませんが、テスト内容が明確になればよいと思うので、@Saki-htr さんがロールをアサーションする方法のほうが良いと思われたら、そちらに修正していただければと思います🙇‍♂️
このままでもよい思いましたが、確認よろしくお願いいたします🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

教えてくださってありがとうございます!
アサーションとはそういう意味だったのですね〜
勉強になります✨

ロールをアサーションした方が、読んだ方に意図が伝わることに加えて、テストも行えて一石二鳥と考えましたので、ロールをアサーションする方法に変更いたしました🙏

@Saki-htr
Copy link
Contributor Author

Saki-htr commented Feb 16, 2022

@tksmasaki さん
体調が悪い中とても丁寧にレビューしてくださって、ありがとうございます🙏
確認いたします!

@Saki-htr Saki-htr force-pushed the feature/not-display-grass-when-mentors-advisors-and-admins-login branch from 60175bd to 297b328 Compare March 1, 2022 10:08
@Saki-htr
Copy link
Contributor Author

Saki-htr commented Mar 1, 2022

@tksmasaki さん
レビューしていただいてからとても日が経ってしまい、大変申し訳ありません🙇‍♀️
コメントしていただいた点を修正しましたので、ご確認をお願いいたします〜🙏

Copy link
Contributor

@tksmasaki tksmasaki left a comment

Choose a reason for hiding this comment

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

再度コメントしたので、確認よろしくお願いいたします🙏

test 'not show the grass for mentor, adviser, and admin' do
# メンターは学習時間の草を表示しない
visit_with_auth '/', 'mentormentaro'
assert_no_text '学習時間'
Copy link
Contributor

Choose a reason for hiding this comment

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

表示されないこと以外に、表示されるはずのものなども確認するとよさそうです。
例:ダッシュボードが表示されていることを確認する
assert_selector 'h2.page-header__title', text: 'ダッシュボード'

(前回のコメントから時間が空いての追加コメントになってしまい、申し訳ありません🙇‍♂️ 後になってこのことに気づきました...)

参考:システムスペックやフィーチャスペックで「〜が表示されないこと」だけを検証するのはちょっと危険、という話 - Qiita

Copy link
Contributor Author

@Saki-htr Saki-htr Mar 7, 2022

Choose a reason for hiding this comment

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

最近別のissueで、"無い"ことを確認するテストを書く難しさを感じたので勉強になります〜
気づいてくださってありがとうございます🙇‍♀️✨

assert_selector 'h2.page-header__title', text: 'ダッシュボード'に変更させていただきました🙏
assert_no_text '学習時間'をチェックする前にダッシュボードのページにアクセスできているか確認すべきと思ったので、`assert_no_selector 'h2.card-header__title', text: '学習時間'の前に追加しました。

test 'show the grass for student and trainee' do
# 生徒は学習時間の草を表示する
visit_with_auth '/', 'kimura'
assert_text '学習時間'
Copy link
Contributor

Choose a reason for hiding this comment

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

「学習時間」という文字列は、他の箇所にも表示される可能性(お知らせやユーザーの日報の下書きに、「学習時間」が含まれるものが作成されるなど)があるかもしれないので、「学習時間」がカードのタイトルとして使われていることを確認すると良いと思いました。

思いついた修正例

visit_with_auth '/', 'kimura'
assert_selector 'h2.card-header__title', text: '学習時間'

(前回のレビューで言えず申し訳ありません🙇‍♂️)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(前回のレビューで言えず申し訳ありません🙇‍♂️)

とんでもないです!ありがとうございます〜🙏✨

「学習時間」という文字列は、他の箇所にも表示される可能性(お知らせやユーザーの日報の下書きに、「学習時間」が含まれるものが作成されるなど)があるかもしれない

たしかに、セレクタを指定すると確実に「学習時間」を指定できますね。
仰るとおりassert_selector 'h2.card-header__title', text: '学習時間'に変更いたしました。

学習時間の草が「無い」テストにも使った方がより確実だと思いましたので、そちらもassert_no_selector 'h2.card-header__title', text: '学習時間'に変更いたしました。

@Saki-htr Saki-htr force-pushed the feature/not-display-grass-when-mentors-advisors-and-admins-login branch from 0e765d9 to e73ed35 Compare March 7, 2022 12:25
@Saki-htr
Copy link
Contributor Author

Saki-htr commented Mar 7, 2022

@tksmasaki さん
お疲れさまです〜
ご指摘いただいた点を修正しましたので、お手すきの際にご確認いただけますと幸いです🙏

Copy link
Contributor

@tksmasaki tksmasaki left a comment

Choose a reason for hiding this comment

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

@Saki-htr
確認しました! LGTMです🙆‍♂️

#4211 (comment)
説明内のメンターのユーザー例が今は存在しない yamada のままなので、ここは直しておくといいと思います!

@Saki-htr Saki-htr requested a review from komagata March 7, 2022 22:54
@Saki-htr
Copy link
Contributor Author

Saki-htr commented Mar 7, 2022

@tksmasaki
丁寧にレビューしてくださり、ありがとうございました🙇‍♀️

説明内のメンターのユーザー例が今は存在しない yamada のままなので、ここは直しておくといいと思います!

こちら、修正いたしました!

@komagata
お疲れさまです。
チームメンバーのレビューを通りましたので、お手すきの際にレビューしていただけますと幸いです。
よろしくお願いいたします🙏

Comment on lines 91 to 101
test 'show the grass for student and trainee' do
assert users(:kimura).student?
visit_with_auth '/', 'kimura'
assert_selector 'h2.card-header__title', text: '学習時間'
logout

assert users(:kensyu).trainee?
visit_with_auth '/', 'kensyu'
assert_selector 'h2.card-header__title', text: '学習時間'
end
Copy link
Member

Choose a reason for hiding this comment

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

検証するユーザーごとにテスト分けた方がわかりやすいかな〜と思いました。
処理速度としては一回ログアウトしてるのであまり変わらないと思うので。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@komagata
レビューしてくださり、ありがとうございます☺️
仰るとおり、ユーザーごとにテストを分けたほうが読みやすいと思いましたので、ユーザーごとに分けました。
ご確認をお願いいたします〜🙏

@Saki-htr Saki-htr force-pushed the feature/not-display-grass-when-mentors-advisors-and-admins-login branch from 303731f to b2bdbf3 Compare March 13, 2022 12:23
Copy link
Member

@komagata komagata left a comment

Choose a reason for hiding this comment

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

確認しました、OKですー🙆‍♂️

Comment on lines +91 to +121
test 'show the grass for student' do
assert users(:kimura).student?
visit_with_auth '/', 'kimura'
assert_selector 'h2.card-header__title', text: '学習時間'
end

test 'show the grass for trainee' do
assert users(:kensyu).trainee?
visit_with_auth '/', 'kensyu'
assert_selector 'h2.card-header__title', text: '学習時間'
end

test 'not show the grass for mentor' do
assert users(:mentormentaro).mentor?
visit_with_auth '/', 'mentormentaro'
assert_selector 'h2.page-header__title', text: 'ダッシュボード'
assert_no_selector 'h2.card-header__title', text: '学習時間'
end

test 'not show the grass for adviser' do
assert users(:advijirou).adviser?
visit_with_auth '/', 'advijirou'
assert_selector 'h2.page-header__title', text: 'ダッシュボード'
assert_no_selector 'h2.card-header__title', text: '学習時間'
end

test 'not show the grass for admin' do
assert users(:komagata).admin?
visit_with_auth '/', 'komagata'
assert_selector 'h2.page-header__title', text: 'ダッシュボード'
assert_no_selector 'h2.card-header__title', text: '学習時間'
Copy link
Member

Choose a reason for hiding this comment

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

とってもわかりやすくなりました〜👍

@komagata komagata merged commit b6a932f into main Mar 14, 2022
@komagata komagata deleted the feature/not-display-grass-when-mentors-advisors-and-admins-login branch March 14, 2022 14:45
@github-actions github-actions bot mentioned this pull request Mar 14, 2022
32 tasks
@Saki-htr Saki-htr added the 1 label Jul 5, 2022
@Saki-htr Saki-htr removed the 1 label Aug 6, 2022
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.

None yet

3 participants