All files / base/navigation login.ts

100% Statements 10/10
66.66% Branches 4/6
100% Functions 3/3
100% Lines 10/10

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    1x     1x       1x 1x 1x   1x 1x       1x 1x 1x          
export default function setupLogin() {
  // Login
  const notAuthenticatedMenu = document.querySelector(
    ".js-nav-account--notauthenticated"
  ) as HTMLElement;
  const authenticatedMenu = document.querySelector(
    ".js-nav-account--authenticated"
  ) as HTMLElement;
 
  Eif (notAuthenticatedMenu && authenticatedMenu) {
    fetch("/account.json")
      .then((response) => response.json())
      .then((data) => {
        Eif (data.account) {
          const displayName = document.querySelector(
            ".js-account--name"
          ) as HTMLElement;
 
          notAuthenticatedMenu.classList.add("u-hide");
          authenticatedMenu.classList.remove("u-hide");
          displayName.innerHTML = data.account["display-name"];
        }
      });
  }
}