All files / components/Nav AppNavbar.js

100% Statements 1/1
100% Branches 18/18
100% Functions 1/1
100% Lines 1/1

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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171                        372x                                                                                                                                                                                                                                                                                                                            
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";
import headerImg from "../../../assets/header-logo-240.png";
 
export default function AppNavbar({
  currentUser,
  systemInfo,
  doLogout,
  currentUrl = window.location.href,
}) {
  return (
    <>
      {(currentUrl.startsWith("http://localhost:3000") ||
        currentUrl.startsWith("http://127.0.0.1:3000")) && (
        <AppNavbarLocalhost url={currentUrl} />
      )}
      <Navbar
        expand="xl"
        variant="dark"
        className="color-nav"
        sticky="top"
        data-testid="AppNavbar"
      >
        <Container>
          <img
            data-testid="AppNavbarImage"
            src={headerImg}
            alt=""
            style={{ width: 80, height: 80, marginRight: 10 }}
          />
          <Navbar.Brand as={Link} to="/">
            UCSB Courses Search
          </Navbar.Brand>
 
          <Navbar.Toggle />
 
          <>
            {/* be sure that each NavDropdown has a unique id and data-testid  */}
          </>
 
          <Navbar.Collapse className="justify-content-between">
            <Nav className="me-auto">
              {systemInfo?.springH2ConsoleEnabled && (
                <>
                  <Nav.Link href="/h2-console/index.html">H2Console </Nav.Link>
                </>
              )}
              {systemInfo?.showSwaggerUILink && (
                <>
                  <Nav.Link href="/swagger-ui/index.html">Swagger</Nav.Link>
                </>
              )}
            </Nav>
 
            <Nav className="mr-auto">
              {hasRole(currentUser, "ROLE_USER") && (
                <Nav.Link
                  href="/personalschedules/list"
                  data-testid="appnavbar-personalschedules-list"
                >
                  Personal Schedules
                </Nav.Link>
              )}
              <Nav.Link href="/" data-testid="appnavbar-mainsearch-list">
                Main Search
              </Nav.Link>
              {hasRole(currentUser, "ROLE_USER") && (
                <Nav.Link
                  href="/courses/list"
                  data-testid="appnavbar-courses-list"
                >
                  Courses
                </Nav.Link>
              )}
            </Nav>
 
            <Nav className="mr-auto">
              <NavDropdown
                title="Other Searches"
                id="appnavbar-course-infos-dropdown"
                data-testid="appnavbar-course-infos-dropdown"
              >
                <NavDropdown.Item
                  href="/coursedescriptions/search"
                  data-testid="appnavbar-course-descriptions-search"
                >
                  Course Descriptions
                </NavDropdown.Item>
                <NavDropdown.Item
                  href="/courseovertime/search"
                  data-testid="appnavbar-course-over-time-search"
                >
                  Course History
                </NavDropdown.Item>
                <NavDropdown.Item
                  href="/courseovertime/buildingsearch"
                  data-testid="appnavbar-course-over-time-buildings-search"
                >
                  Course Location History
                </NavDropdown.Item>
                <NavDropdown.Item
                  href="/courseovertime/instructorsearch"
                  data-testid="appnavbar-course-over-time-instructor-search"
                >
                  Search by Instructor
                </NavDropdown.Item>
              </NavDropdown>
            </Nav>
 
            <Nav className="mr-auto">
              {hasRole(currentUser, "ROLE_ADMIN") && (
                <NavDropdown
                  title="Admin"
                  id="appnavbar-admin-dropdown"
                  data-testid="appnavbar-admin-dropdown"
                >
                  <NavDropdown.Item
                    href="/admin/users"
                    data-testid="appnavbar-admin-users"
                  >
                    Users
                  </NavDropdown.Item>
                  <NavDropdown.Item
                    href="/admin/personalschedule"
                    data-testid="appnavbar-admin-personalschedule"
                  >
                    Personal Schedules
                  </NavDropdown.Item>
                  <NavDropdown.Item
                    href="/admin/loadsubjects"
                    data-testid="appnavbar-admin-loadsubjects"
                  >
                    Load Subjects
                  </NavDropdown.Item>
                  <NavDropdown.Item
                    href="/admin/jobs"
                    data-testid="appnavbar-admin-jobs"
                  >
                    Manage Jobs
                  </NavDropdown.Item>
                  <NavDropdown.Item
                    href="/developer"
                    data-testid="appnavbar-developer"
                  >
                    Developer Info
                  </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}>Log Out</Button>
                </>
              ) : (
                <Button href="/oauth2/authorization/google">Log In</Button>
              )}
            </Nav>
          </Navbar.Collapse>
        </Container>
      </Navbar>
    </>
  );
}