All files / pages/Reviews ReviewsForMenuItemPage.js

88.88% Statements 8/9
87.5% Branches 7/8
100% Functions 2/2
88.88% Lines 8/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52              23x 23x             23x 13x               10x                   10x   13x       10x                      
import React from "react";
import { useParams } from "react-router";
import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import ReviewTable from "main/components/Reviews/ReviewTable";
import { useBackend } from "main/utils/useBackend";
 
export default function ReviewsForMenuItemPage() {
  const { id } = useParams();
  const { data, isLoading, error } = useBackend(
    // Stryker disable next-line all: don't test internal caching of React Query
    ["reviewsForMenuItem", id],
    // Stryker disable next-line all: default method is get, so replacing with an empty string will do nothing
    { method: "GET", url: `/api/diningcommons/menuitem?id=${id}` },
  );
 
  if (isLoading) {
    return (
      <BasicLayout>
        <p>Loading...</p>
      </BasicLayout>
    );
  }
 
  // Stryker disable next-line all : Don't mutate error block
  Iif (error) {
    return (
      <BasicLayout>
        <p>Error loading reviews.</p>
      </BasicLayout>
    );
  }
 
  const filteredReviews =
    // Stryker disable next-line ArrayDeclaration : Don't mutate fallback array
    (Array.isArray(data?.reviews) ? data.reviews : []).filter(
      (review) =>
        review.reviewerComments !== null &&
        review.reviewerComments !== undefined,
    );
 
  return (
    <BasicLayout>
      <h1>Reviews for Menu Item {id}</h1>
      <ReviewTable
        data={filteredReviews}
        userOptions={false}
        moderatorOptions={false}
      />
    </BasicLayout>
  );
}