Title: Name of book: Programming Phoenix LiveView
Second to last page on Section 10 - Unit Test Test Survey Results State
testing/pento/test/pento_web/live/survey_results_live_test.exs
test "ratings are filtered by age group", %{
socket: socket,
user: user,
product: product,
user2: user2} do
create_rating(2, user, product)
create_rating(3, user2, product)
socket
|> SurveyResultsLive.assign_age_group_filter()
|> assert_keys(:age_group_filter, "all")
|> update_socket(:age_group_filter, "18 and under")
|> SurveyResultsLive.assign_age_group_filter()
|> assert_keys(:age_group_filter, "18 and under")
|> SurveyResultsLive.assign_gender_filter()
|> SurveyResultsLive.assign_products_with_average_ratings()
|> assert_keys(:products_with_average_ratings, [{"Test Game", 2.0}])
end
Should be updated with “18 and under” on second SurveyResultsLive.assign_age_group_filter()
testing/pento/test/pento_web/live/survey_results_live_test.exs
test "ratings are filtered by age group", %{
socket: socket,
user: user,
product: product,
user2: user2} do
create_rating(2, user, product)
create_rating(3, user2, product)
socket
|> SurveyResultsLive.assign_age_group_filter()
|> assert_keys(:age_group_filter, "all")
|> update_socket(:age_group_filter, "18 and under")
|> SurveyResultsLive.assign_age_group_filter("18 and under")
|> assert_keys(:age_group_filter, "18 and under")
|> SurveyResultsLive.assign_gender_filter()
|> SurveyResultsLive.assign_products_with_average_ratings()
|> assert_keys(:products_with_average_ratings, [{"Test Game", 2.0}])
end