All files / components/Nav AppNavbar.jsx

100% Statements 71/71
100% Branches 7/7
100% Functions 1/1
100% Lines 71/71

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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 1221x 1x 1x 1x   1x 206x 206x 206x 206x 206x 206x 206x 206x 206x 206x 206x   206x 206x 206x 206x 206x 206x   206x 206x 206x 206x 206x 206x 206x 206x 206x     206x       206x   206x 206x 206x 206x     206x 206x 206x         206x       206x 206x 206x 206x 206x 206x 206x   206x     206x     206x     206x     206x 206x     206x             206x 206x 161x 161x 161x   161x 161x 161x   161x 161x         206x 206x 206x 206x 206x                   206x  
import { Button, Container, Nav, Navbar, NavDropdown } from "react-bootstrap";
import { Link } from "react-router-dom";
import { hasRole } from "main/utils/currentUser";
import AppNavbarLocalhost from "main/components/Nav/AppNavbarLocalhost";
 
export default function AppNavbar({
  currentUser,
  systemInfo,
  doLogout,
  currentUrl = window.location.href,
}) {
  var oauthLogin = systemInfo?.oauthLogin || "/oauth2/authorization/google";
  return (
    <>
      {(currentUrl.startsWith("http://localhost:3000") ||
        currentUrl.startsWith("http://127.0.0.1:3000")) && (
        <AppNavbarLocalhost url={currentUrl} />
      )}
      <Navbar
        expand="xl"
        variant="dark"
        bg="dark"
        sticky="top"
        data-testid="AppNavbar"
      >
        <Container>
          <Navbar.Brand
            as={Link}
            to="/"
            style={
              // Stryker disable all : don't mutation test CSS
              {
                fontFamily: "Rye",
              }
              // Stryker restore all
            }
          >
            Happy Cows
          </Navbar.Brand>
 
          <Navbar.Toggle />
 
          <Nav className="me-auto">
            {systemInfo?.springH2ConsoleEnabled && (
              <>
                <Nav.Link href="/h2-console">H2Console</Nav.Link>
              </>
            )}
            {systemInfo?.showSwaggerUILink && (
              <>
                <Nav.Link href="/swagger-ui/index.html">Swagger</Nav.Link>
              </>
            )}
          </Nav>
 
          <>
            {/* be sure that each NavDropdown has a unique id and data-testid  */}
          </>
 
          <Navbar.Collapse className="justify-content-between">
            <Nav className="mr-auto">
              {hasRole(currentUser, "ROLE_ADMIN") && (
                <NavDropdown
                  title="Admin"
                  id="appnavbar-admin-dropdown"
                  data-testid="appnavbar-admin-dropdown"
                >
                  <NavDropdown.Item href="/admin/createcommons">
                    Create Commons
                  </NavDropdown.Item>
                  <NavDropdown.Item href="/admin/listcommons">
                    List Commons
                  </NavDropdown.Item>
                  <NavDropdown.Item href="/admin/liststudents">
                    Students
                  </NavDropdown.Item>
                  <NavDropdown.Item href="/admin/listcourses">
                    Courses
                  </NavDropdown.Item>
                  <NavDropdown.Item href="/admin/users">Users</NavDropdown.Item>
                  <NavDropdown.Item href="/admin/jobs">
                    Manage Jobs
                  </NavDropdown.Item>
                  <NavDropdown.Item href="/admin/reports">
                    Instructor Reports
                  </NavDropdown.Item>
                </NavDropdown>
              )}
            </Nav>
 
            <Nav className="ml-auto">
              {currentUser && currentUser.loggedIn ? (
                <>
                  <Navbar.Text className="me-3" as={Link} to="/profile">
                    Welcome, {currentUser.root.user.email}
                  </Navbar.Text>
                  <Button
                    onClick={
                      doLogout
                    } /*Stryker disable next-line all : don't mutation test CSS*/
                    style={{ fontFamily: "Rye" }}
                  >
                    Log Out
                  </Button>
                </>
              ) : (
                <Button
                  href={oauthLogin}
                  /*Stryker disable next-line all : don't mutation test CSS*/
                  style={{ fontFamily: "Rye" }}
                >
                  Log In
                </Button>
              )}
            </Nav>
          </Navbar.Collapse>
        </Container>
      </Navbar>
    </>
  );
}