All files / react-app/src/utils crumbs.ts

100% Statements 14/14
100% Branches 9/9
100% Functions 5/5
100% Lines 11/11

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 53                      72x 72x     49x     22x   1x       72x         2x   2x     390x             72x           72x          
import { BreadCrumbConfig } from "@/components";
import { mapActionLabel } from "@/utils";
import { Action } from "shared-types/actions";
import { Authority } from "shared-types/authority";
 
type DetailsAndActionsBreadCrumbsArgs = {
  id: string;
  authority: Authority;
  actionType?: Action;
};
 
export const getDashboardTabForAuthority = (authority: Authority): "spas" | "waivers" => {
  switch (authority) {
    case "CHIP SPA" as Authority:
    case "Medicaid SPA" as Authority:
      return "spas";
    case "1915(b)":
    case "1915(c)":
      return "waivers";
    default:
      throw new Error("Invalid authority");
  }
};
 
export const detailsAndActionsCrumbs = ({
  id,
  authority,
  actionType,
}: DetailsAndActionsBreadCrumbsArgs): BreadCrumbConfig[] => {
  const defaultBreadCrumbs = [dashboardCrumb(authority), detailsCrumb(id, authority)];
 
  return actionType ? [...defaultBreadCrumbs, actionCrumb(actionType, id)] : defaultBreadCrumbs;
};
 
export const dashboardCrumb = (authority?: Authority): BreadCrumbConfig => ({
  displayText: "Dashboard",
  order: 1,
  default: true,
  to: authority ? `/dashboard?tab=${getDashboardTabForAuthority(authority)}` : "/dashboard",
});
 
export const detailsCrumb = (id: string, authority: Authority): BreadCrumbConfig => ({
  displayText: id,
  order: 2,
  to: `/details/${authority}/${id}`,
});
 
export const actionCrumb = (action: Action, id: string): BreadCrumbConfig => ({
  displayText: mapActionLabel(action),
  order: 3,
  to: `/actions/${id}/${action}`,
});