All files / react/components/SideNav helpers.js

62.5% Statements 10/16
50% Branches 2/4
66.66% Functions 2/3
62.5% Lines 10/16

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    2x                                             2x 1x 1x                     2x 3x 3x 1x 1x   2x        
import { parse, serialize } from "cookie";
 
const handleNavigation = (e, linkCallbackFunction, label) => {
  if (linkCallbackFunction) {
    const { pathname, hash, search } = e.currentTarget;
    e.preventDefault();
    e.stopPropagation();
    linkCallbackFunction(`${pathname}${hash}${search}`);
  }
  window?.utag?.link({
    ga_event_category: "side navbar",
    ga_event_action: "click",
    ga_event_label: label,
    page_title: `${window.document.title}`,
    page_url: `${window.location.pathname}`,
    event: "trackEvent",
  });
};
 
/**
 * Sets the qpp_side_nav_expanded cookie value
 * @param {Document} document object
 * @param {string} value
 * @returns {void}
 */
const setSideNavExpanded = (_document, value) => {
  const secure = _document.location.protocol === "https:";
  _document.cookie = serialize("qpp_side_nav_expanded", value, {
    path: "/",
    secure,
  });
};
 
/**
 * Check if sidenav is expanded
 * @param {Document} document object
 * @returns {boolean}
 */
const isSideNavExpanded = (_document) => {
  const parsedCookies = parse(_document.cookie);
  if (parsedCookies.qpp_side_nav_expanded === undefined) {
    setSideNavExpanded(_document, "true");
    return true;
  }
  return parsedCookies.qpp_side_nav_expanded === "true";
};
 
export { handleNavigation, setSideNavExpanded, isSideNavExpanded };