From fac22c9c70cfb25d77f10ec8321e0b314dbbbade Mon Sep 17 00:00:00 2001 From: Jordan Wong <42422209+JorWo@users.noreply.github.com> Date: Fri, 31 May 2024 10:38:47 -1000 Subject: [PATCH] Improve file/folder structure (#19) --- ui/jest.config.ts | 2 +- ...enticationService.ts => authentication.ts} | 8 +- ...thorizationService.ts => authorization.ts} | 4 +- ui/src/access/{Role.ts => role.ts} | 0 ...aml11Validator.ts => saml-11-validator.ts} | 2 +- ui/src/access/{Session.ts => session.ts} | 2 +- ui/src/access/{User.ts => user.ts} | 4 +- .../EmailService.ts => actions/email.ts} | 6 +- .../groupings-api.ts} | 6 +- .../http-client.ts} | 6 +- .../_components/after-login.tsx} | 8 +- .../_components/announcements.tsx} | 2 +- .../_components/before-login.tsx} | 2 +- .../_components/login-button.tsx} | 7 +- ui/src/app/{(index) => (home)}/page.tsx | 12 +-- .../footer/Footer.tsx => footer/footer.tsx} | 0 .../timeout-modal.tsx} | 6 +- .../login-button.tsx} | 6 +- .../mobile-navbar.tsx} | 6 +- .../NavLinks.ts => navbar/nav-links.ts} | 2 +- .../navbar/Navbar.tsx => navbar/navbar.tsx} | 36 ++++---- ...foSection.tsx => general-info-section.tsx} | 0 ...Section.tsx => technical-info-section.tsx} | 0 ...ection.tsx => what-happens-if-section.tsx} | 0 ui/src/app/about/page.tsx | 8 +- ui/src/app/api/cas/login/route.ts | 2 +- ui/src/app/api/cas/logout/route.ts | 2 +- ui/src/app/layout.tsx | 4 +- ...roupingsInfo.tsx => uh-groupings-info.tsx} | 0 ui/src/middleware.ts | 4 +- .../groupings-api-results.ts} | 0 ...Service.test.ts => authentication.test.ts} | 8 +- ...nService.test.ts => authorization.test.ts} | 9 +- .../access/{Role.test.ts => role.test.ts} | 4 +- ...ator.test.ts => saml-11-validator.test.ts} | 6 +- .../access/{User.test.ts => user.test.ts} | 6 +- .../email.test.ts} | 10 +- .../groupings-api.test.ts} | 12 +-- .../_components/after-login.test.tsx} | 17 ++-- .../_components/announcements.test.tsx} | 8 +- .../_components/before-login.test.tsx} | 4 +- .../_components/login-button.test.tsx} | 8 +- .../footer.test.tsx} | 2 +- .../_components/layout/navbar/Navbar.test.tsx | 92 ------------------- .../timeout-modal.test.tsx} | 11 ++- .../login-button.test.tsx} | 6 +- .../mobile-navbar.test.tsx} | 29 +++--- ...test.tsx => general-info-section.test.tsx} | 2 +- ...st.tsx => technical-info-section.test.tsx} | 2 +- ...t.tsx => what-happens-if-section.test.tsx} | 2 +- ui/tests/app/api/cas/login/route.test.ts | 4 +- ui/tests/app/api/cas/logout/route.test.ts | 4 +- ...fo.test.tsx => uh-groupings-info.test.tsx} | 2 +- ui/tests/middleware.test.tsx | 6 +- ui/tests/{setupJest.ts => setup-jest.ts} | 2 +- 55 files changed, 156 insertions(+), 247 deletions(-) rename ui/src/access/{AuthenticationService.ts => authentication.ts} (91%) rename ui/src/access/{AuthorizationService.ts => authorization.ts} (96%) rename ui/src/access/{Role.ts => role.ts} (100%) rename ui/src/access/{Saml11Validator.ts => saml-11-validator.ts} (97%) rename ui/src/access/{Session.ts => session.ts} (91%) rename ui/src/access/{User.ts => user.ts} (71%) rename ui/src/{services/EmailService.ts => actions/email.ts} (87%) rename ui/src/{services/GroupingsApiService.ts => actions/groupings-api.ts} (99%) rename ui/src/{services/FetchService.ts => actions/http-client.ts} (98%) rename ui/src/app/{(index)/_components/AfterLogin.tsx => (home)/_components/after-login.tsx} (97%) rename ui/src/app/{(index)/_components/Announcements.tsx => (home)/_components/announcements.tsx} (94%) rename ui/src/app/{(index)/_components/BeforeLogin.tsx => (home)/_components/before-login.tsx} (91%) rename ui/src/app/{(index)/_components/LoginButton.tsx => (home)/_components/login-button.tsx} (81%) rename ui/src/app/{(index) => (home)}/page.tsx (83%) rename ui/src/app/_components/{layout/footer/Footer.tsx => footer/footer.tsx} (100%) rename ui/src/app/_components/{layout/modal/TimeoutModal.tsx => modal/timeout-modal.tsx} (95%) rename ui/src/app/_components/{layout/navbar/LoginButton.tsx => navbar/login-button.tsx} (85%) rename ui/src/app/_components/{layout/navbar/MobileNavbar.tsx => navbar/mobile-navbar.tsx} (95%) rename ui/src/app/_components/{layout/navbar/NavLinks.ts => navbar/nav-links.ts} (93%) rename ui/src/app/_components/{layout/navbar/Navbar.tsx => navbar/navbar.tsx} (66%) rename ui/src/app/about/_components/{GeneralInfoSection.tsx => general-info-section.tsx} (100%) rename ui/src/app/about/_components/{TechnicalInfoSection.tsx => technical-info-section.tsx} (100%) rename ui/src/app/about/_components/{WhatHappensIfSection.tsx => what-happens-if-section.tsx} (100%) rename ui/src/components/{UHGroupingsInfo.tsx => uh-groupings-info.tsx} (100%) rename ui/src/{groupings/GroupingsApiResults.ts => models/groupings-api-results.ts} (100%) rename ui/tests/access/{AuthenticationService.test.ts => authentication.test.ts} (93%) rename ui/tests/access/{AuthorizationService.test.ts => authorization.test.ts} (93%) rename ui/tests/access/{Role.test.ts => role.test.ts} (74%) rename ui/tests/access/{Saml11Validator.test.ts => saml-11-validator.test.ts} (85%) rename ui/tests/access/{User.test.ts => user.test.ts} (80%) rename ui/tests/{services/EmailService.test.ts => actions/email.test.ts} (85%) rename ui/tests/{services/GroupingsApiService.test.ts => actions/groupings-api.test.ts} (99%) rename ui/tests/app/{(index)/_components/AfterLogin.test.tsx => (home)/_components/after-login.test.tsx} (93%) rename ui/tests/app/{(index)/_components/Announcement.test.tsx => (home)/_components/announcements.test.tsx} (82%) rename ui/tests/app/{(index)/_components/BeforeLogin.test.tsx => (home)/_components/before-login.test.tsx} (93%) rename ui/tests/app/{(index)/_components/LoginButton.test.tsx => (home)/_components/login-button.test.tsx} (90%) rename ui/tests/app/_components/{layout/footer/Footer.test.tsx => footer/footer.test.tsx} (92%) delete mode 100644 ui/tests/app/_components/layout/navbar/Navbar.test.tsx rename ui/tests/app/_components/{layout/modal/TimeoutModal.test.tsx => modal/timeout-modal.test.tsx} (93%) rename ui/tests/app/_components/{layout/navbar/LoginButton.test.tsx => navbar/login-button.test.tsx} (92%) rename ui/tests/app/_components/{layout/navbar/MobileNavbar.test.tsx => navbar/mobile-navbar.test.tsx} (78%) rename ui/tests/app/about/_components/{GeneralInfoSection.test.tsx => general-info-section.test.tsx} (94%) rename ui/tests/app/about/_components/{TechnicalInfoSection.test.tsx => technical-info-section.test.tsx} (96%) rename ui/tests/app/about/_components/{WhatHappensIfSection.test.tsx => what-happens-if-section.test.tsx} (94%) rename ui/tests/components/{UHGroupingsInfo.test.tsx => uh-groupings-info.test.tsx} (97%) rename ui/tests/{setupJest.ts => setup-jest.ts} (90%) diff --git a/ui/jest.config.ts b/ui/jest.config.ts index d6c08bc9..e36aab35 100644 --- a/ui/jest.config.ts +++ b/ui/jest.config.ts @@ -19,7 +19,7 @@ const config: Config = { customExportConditions: [] }, setupFilesAfterEnv: [ - '/tests/setupJest.ts' + '/tests/setup-jest.ts' ], moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], moduleDirectories: ['node_modules', ''], diff --git a/ui/src/access/AuthenticationService.ts b/ui/src/access/authentication.ts similarity index 91% rename from ui/src/access/AuthenticationService.ts rename to ui/src/access/authentication.ts index 0ab1d854..a4798066 100644 --- a/ui/src/access/AuthenticationService.ts +++ b/ui/src/access/authentication.ts @@ -3,10 +3,10 @@ import { cookies } from 'next/headers'; import { redirect } from 'next/navigation'; import { IronSession, getIronSession } from 'iron-session'; -import { SessionData, SessionOptions } from './Session'; -import User, { AnonymousUser } from './User'; -import { validateTicket } from './Saml11Validator'; -import { setRoles } from './AuthorizationService'; +import { SessionData, SessionOptions } from './session'; +import User, { AnonymousUser } from './user'; +import { validateTicket } from './saml-11-validator'; +import { setRoles } from './authorization'; import { isDeepStrictEqual } from 'util'; const casUrl = process.env.NEXT_PUBLIC_CAS_URL as string; diff --git a/ui/src/access/AuthorizationService.ts b/ui/src/access/authorization.ts similarity index 96% rename from ui/src/access/AuthorizationService.ts rename to ui/src/access/authorization.ts index c61a14ef..77f8c4da 100644 --- a/ui/src/access/AuthorizationService.ts +++ b/ui/src/access/authorization.ts @@ -1,7 +1,7 @@ 'use server'; -import User from './User'; -import Role from './Role'; +import User from './user'; +import Role from './role'; const apiBaseUrl = process.env.NEXT_PUBLIC_API_2_1_BASE_URL as string; diff --git a/ui/src/access/Role.ts b/ui/src/access/role.ts similarity index 100% rename from ui/src/access/Role.ts rename to ui/src/access/role.ts diff --git a/ui/src/access/Saml11Validator.ts b/ui/src/access/saml-11-validator.ts similarity index 97% rename from ui/src/access/Saml11Validator.ts rename to ui/src/access/saml-11-validator.ts index d046fc2b..c526ac7b 100644 --- a/ui/src/access/Saml11Validator.ts +++ b/ui/src/access/saml-11-validator.ts @@ -1,4 +1,4 @@ -import User, { AnonymousUser } from './User'; +import User, { AnonymousUser } from './user'; import uniqid from 'uniqid'; import { format } from 'util'; import { transform } from 'camaro'; diff --git a/ui/src/access/Session.ts b/ui/src/access/session.ts similarity index 91% rename from ui/src/access/Session.ts rename to ui/src/access/session.ts index 9f37f9c3..5db36db9 100644 --- a/ui/src/access/Session.ts +++ b/ui/src/access/session.ts @@ -1,4 +1,4 @@ -import User from './User'; +import User from './user'; export interface SessionData { user: User; diff --git a/ui/src/access/User.ts b/ui/src/access/user.ts similarity index 71% rename from ui/src/access/User.ts rename to ui/src/access/user.ts index e73b3937..9f309eec 100644 --- a/ui/src/access/User.ts +++ b/ui/src/access/user.ts @@ -1,5 +1,5 @@ -import { MemberResult } from '@/groupings/GroupingsApiResults'; -import Role from './Role'; +import { MemberResult } from '@/models/groupings-api-results'; +import Role from './role'; type User = { roles: Role[] diff --git a/ui/src/services/EmailService.ts b/ui/src/actions/email.ts similarity index 87% rename from ui/src/services/EmailService.ts rename to ui/src/actions/email.ts index 204ec896..3ebf5549 100644 --- a/ui/src/services/EmailService.ts +++ b/ui/src/actions/email.ts @@ -1,8 +1,8 @@ 'use server'; -import { getCurrentUser } from '@/access/AuthenticationService'; -import { ApiError } from '@/groupings/GroupingsApiResults'; -import { postRequest } from './FetchService'; +import { getCurrentUser } from '@/access/authentication'; +import { ApiError } from '@/models/groupings-api-results'; +import { postRequest } from './http-client'; const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL as string; diff --git a/ui/src/services/GroupingsApiService.ts b/ui/src/actions/groupings-api.ts similarity index 99% rename from ui/src/services/GroupingsApiService.ts rename to ui/src/actions/groupings-api.ts index 66ea81a4..620ed5d6 100644 --- a/ui/src/services/GroupingsApiService.ts +++ b/ui/src/actions/groupings-api.ts @@ -1,6 +1,6 @@ 'use server'; -import { getCurrentUser } from '@/access/AuthenticationService'; +import { getCurrentUser } from '@/access/authentication'; import { Announcements, ApiError, @@ -19,7 +19,7 @@ import { GroupingUpdateDescriptionResult, MemberAttributeResults, MembershipResults -} from '../groupings/GroupingsApiResults'; +} from '@/models/groupings-api-results'; import { deleteRequest, deleteRequestAsync, @@ -29,7 +29,7 @@ import { postRequestRetry, putRequest, putRequestAsync -} from './FetchService'; +} from './http-client'; const baseUrl = process.env.NEXT_PUBLIC_API_2_1_BASE_URL as string; diff --git a/ui/src/services/FetchService.ts b/ui/src/actions/http-client.ts similarity index 98% rename from ui/src/services/FetchService.ts rename to ui/src/actions/http-client.ts index 4b2c73dd..8316e942 100644 --- a/ui/src/services/FetchService.ts +++ b/ui/src/actions/http-client.ts @@ -1,8 +1,8 @@ 'use server'; -import { ApiError } from '../groupings/GroupingsApiResults'; -import { getCurrentUser } from '@/access/AuthenticationService'; -import { sendStackTrace } from './EmailService'; +import { ApiError } from '@/models/groupings-api-results'; +import { getCurrentUser } from '@/access/authentication'; +import { sendStackTrace } from './email'; const maxRetries = 3; const baseUrl = process.env.NEXT_PUBLIC_API_2_1_BASE_URL as string; diff --git a/ui/src/app/(index)/_components/AfterLogin.tsx b/ui/src/app/(home)/_components/after-login.tsx similarity index 97% rename from ui/src/app/(index)/_components/AfterLogin.tsx rename to ui/src/app/(home)/_components/after-login.tsx index 2fe623f1..f1bd9542 100644 --- a/ui/src/app/(index)/_components/AfterLogin.tsx +++ b/ui/src/app/(home)/_components/after-login.tsx @@ -1,12 +1,12 @@ -import Role from '@/access/Role'; +import Role from '@/access/role'; import Image from 'next/image'; import { KeyRound } from 'lucide-react'; import Link from 'next/link'; import { Button } from '@/components/ui/button'; -import { getNumberOfGroupings, getNumberOfMemberships } from '@/services/GroupingsApiService'; -import { getCurrentUser } from '@/access/AuthenticationService'; +import { getNumberOfGroupings, getNumberOfMemberships } from '@/actions/groupings-api'; +import { getCurrentUser } from '@/access/authentication'; -const AfterLogin = async ()=>{ +const AfterLogin = async () => { const [currentUser, numberOfGroupings, numberOfMemberships] = await Promise.all([ getCurrentUser(), getNumberOfGroupings(), diff --git a/ui/src/app/(index)/_components/Announcements.tsx b/ui/src/app/(home)/_components/announcements.tsx similarity index 94% rename from ui/src/app/(index)/_components/Announcements.tsx rename to ui/src/app/(home)/_components/announcements.tsx index e3253c78..ac8fe16e 100644 --- a/ui/src/app/(index)/_components/Announcements.tsx +++ b/ui/src/app/(home)/_components/announcements.tsx @@ -1,6 +1,6 @@ import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'; import { AlertCircle } from 'lucide-react'; -import { getAnnouncements } from '@/services/GroupingsApiService'; +import { getAnnouncements } from '@/actions/groupings-api'; const Announcements = async () => { const announcements = await getAnnouncements(); diff --git a/ui/src/app/(index)/_components/BeforeLogin.tsx b/ui/src/app/(home)/_components/before-login.tsx similarity index 91% rename from ui/src/app/(index)/_components/BeforeLogin.tsx rename to ui/src/app/(home)/_components/before-login.tsx index 2a1c0ef1..cca2036b 100644 --- a/ui/src/app/(index)/_components/BeforeLogin.tsx +++ b/ui/src/app/(home)/_components/before-login.tsx @@ -1,6 +1,6 @@ import { Button } from '@/components/ui/button'; import { ArrowRight } from 'lucide-react'; -import UHGroupingsInfo from '@/components/UHGroupingsInfo'; +import UHGroupingsInfo from '@/components/uh-groupings-info'; const BeforeLogin = () => (
diff --git a/ui/src/app/(index)/_components/LoginButton.tsx b/ui/src/app/(home)/_components/login-button.tsx similarity index 81% rename from ui/src/app/(index)/_components/LoginButton.tsx rename to ui/src/app/(home)/_components/login-button.tsx index 544f01c9..997e5284 100644 --- a/ui/src/app/(index)/_components/LoginButton.tsx +++ b/ui/src/app/(home)/_components/login-button.tsx @@ -1,8 +1,9 @@ 'use client'; + import { Button } from '@/components/ui/button'; -import Role from '@/access/Role'; -import User from '@/access/User'; -import { login, logout } from '@/access/AuthenticationService'; +import Role from '@/access/role'; +import User from '@/access/user'; +import { login, logout } from '@/access/authentication'; const LoginButton = ({ currentUser diff --git a/ui/src/app/(index)/page.tsx b/ui/src/app/(home)/page.tsx similarity index 83% rename from ui/src/app/(index)/page.tsx rename to ui/src/app/(home)/page.tsx index 523a51de..61a2bbdd 100644 --- a/ui/src/app/(index)/page.tsx +++ b/ui/src/app/(home)/page.tsx @@ -1,10 +1,10 @@ import Image from 'next/image'; -import BeforeLogin from '@/app/(index)/_components/BeforeLogin'; -import AfterLogin from '@/app/(index)/_components/AfterLogin'; -import { getCurrentUser } from '@/access/AuthenticationService'; -import Role from '@/access/Role'; -import LoginButton from '@/app/(index)/_components/LoginButton'; -import Announcements from '@/app/(index)/_components/Announcements'; +import BeforeLogin from '@/app/(home)/_components/before-login'; +import AfterLogin from '@/app/(home)/_components/after-login'; +import { getCurrentUser } from '@/access/authentication'; +import Role from '@/access/role'; +import LoginButton from '@/app/(home)/_components/login-button'; +import Announcements from '@/app/(home)/_components/announcements'; const Home = async () => { const currentUser = await getCurrentUser(); diff --git a/ui/src/app/_components/layout/footer/Footer.tsx b/ui/src/app/_components/footer/footer.tsx similarity index 100% rename from ui/src/app/_components/layout/footer/Footer.tsx rename to ui/src/app/_components/footer/footer.tsx diff --git a/ui/src/app/_components/layout/modal/TimeoutModal.tsx b/ui/src/app/_components/modal/timeout-modal.tsx similarity index 95% rename from ui/src/app/_components/layout/modal/TimeoutModal.tsx rename to ui/src/app/_components/modal/timeout-modal.tsx index c3479aa2..aecac090 100644 --- a/ui/src/app/_components/layout/modal/TimeoutModal.tsx +++ b/ui/src/app/_components/modal/timeout-modal.tsx @@ -12,9 +12,9 @@ import { AlertDialogCancel } from '@/components/ui/alert-dialog'; import { useIdleTimer } from 'react-idle-timer'; -import { logout } from '@/access/AuthenticationService'; -import User from '@/access/User'; -import Role from '@/access/Role'; +import { logout } from '@/access/authentication'; +import User from '@/access/user'; +import Role from '@/access/role'; const timeout = 1000 * 60 * 30; // Total timeout - 30 minutes in milliseconds const promptBeforeIdle = 1000 * 60 * 5; // Time prior to timeout until modal opens - 5 minutes in milliseconds diff --git a/ui/src/app/_components/layout/navbar/LoginButton.tsx b/ui/src/app/_components/navbar/login-button.tsx similarity index 85% rename from ui/src/app/_components/layout/navbar/LoginButton.tsx rename to ui/src/app/_components/navbar/login-button.tsx index 0059c6a0..fad36e75 100644 --- a/ui/src/app/_components/layout/navbar/LoginButton.tsx +++ b/ui/src/app/_components/navbar/login-button.tsx @@ -1,9 +1,9 @@ 'use client'; import { Button } from '@/components/ui/button'; -import Role from '@/access/Role'; -import User from '@/access/User'; -import { login, logout } from '@/access/AuthenticationService'; +import Role from '@/access/role'; +import User from '@/access/user'; +import { login, logout } from '@/access/authentication'; import { LogInIcon, LogOutIcon } from 'lucide-react'; const LoginButton = ({ diff --git a/ui/src/app/_components/layout/navbar/MobileNavbar.tsx b/ui/src/app/_components/navbar/mobile-navbar.tsx similarity index 95% rename from ui/src/app/_components/layout/navbar/MobileNavbar.tsx rename to ui/src/app/_components/navbar/mobile-navbar.tsx index 3fe018f8..333d5c08 100644 --- a/ui/src/app/_components/layout/navbar/MobileNavbar.tsx +++ b/ui/src/app/_components/navbar/mobile-navbar.tsx @@ -5,11 +5,11 @@ import { SheetContent, SheetTrigger, } from '@/components/ui/sheet' -import User from '@/access/User'; +import User from '@/access/user'; import Link from 'next/link'; -import { NavLinks } from './NavLinks'; +import { NavLinks } from './nav-links'; import { useState } from 'react'; -import Role from '@/access/Role'; +import Role from '@/access/role'; const MobileNavbar = ({ currentUser diff --git a/ui/src/app/_components/layout/navbar/NavLinks.ts b/ui/src/app/_components/navbar/nav-links.ts similarity index 93% rename from ui/src/app/_components/layout/navbar/NavLinks.ts rename to ui/src/app/_components/navbar/nav-links.ts index ad29ae8e..63fb9bdb 100644 --- a/ui/src/app/_components/layout/navbar/NavLinks.ts +++ b/ui/src/app/_components/navbar/nav-links.ts @@ -1,4 +1,4 @@ -import Role from '@/access/Role'; +import Role from '@/access/role'; export const NavLinks = [ { diff --git a/ui/src/app/_components/layout/navbar/Navbar.tsx b/ui/src/app/_components/navbar/navbar.tsx similarity index 66% rename from ui/src/app/_components/layout/navbar/Navbar.tsx rename to ui/src/app/_components/navbar/navbar.tsx index 6810cb8e..87667574 100644 --- a/ui/src/app/_components/layout/navbar/Navbar.tsx +++ b/ui/src/app/_components/navbar/navbar.tsx @@ -1,11 +1,11 @@ import Link from 'next/link'; import Image from 'next/image'; -import LoginButton from './LoginButton'; -import { getCurrentUser } from '@/access/AuthenticationService'; -import MobileNavbar from './MobileNavbar'; -import { NavLinks } from './NavLinks'; -import Role from '@/access/Role'; -import TimeoutModal from '@/app/_components/layout/modal/TimeoutModal'; +import Role from '@/access/role'; +import { getCurrentUser } from '@/access/authentication'; +import { NavLinks } from './nav-links'; +import LoginButton from './login-button'; +import MobileNavbar from './mobile-navbar'; +import TimeoutModal from '../modal/timeout-modal'; const Navbar = async () => { const currentUser = await getCurrentUser(); @@ -18,28 +18,28 @@ const Navbar = async () => { UH Groupings Logo
- UH Groupings Logo
{NavLinks - .filter(navLink => + .filter(navLink => currentUser.roles.includes(Role.ADMIN) || currentUser.roles.includes(navLink.role)) - .map(navLink => - + {navLink.name} )} @@ -51,5 +51,5 @@ const Navbar = async () => { ); } - + export default Navbar; diff --git a/ui/src/app/about/_components/GeneralInfoSection.tsx b/ui/src/app/about/_components/general-info-section.tsx similarity index 100% rename from ui/src/app/about/_components/GeneralInfoSection.tsx rename to ui/src/app/about/_components/general-info-section.tsx diff --git a/ui/src/app/about/_components/TechnicalInfoSection.tsx b/ui/src/app/about/_components/technical-info-section.tsx similarity index 100% rename from ui/src/app/about/_components/TechnicalInfoSection.tsx rename to ui/src/app/about/_components/technical-info-section.tsx diff --git a/ui/src/app/about/_components/WhatHappensIfSection.tsx b/ui/src/app/about/_components/what-happens-if-section.tsx similarity index 100% rename from ui/src/app/about/_components/WhatHappensIfSection.tsx rename to ui/src/app/about/_components/what-happens-if-section.tsx diff --git a/ui/src/app/about/page.tsx b/ui/src/app/about/page.tsx index a2ecbcc7..9ca3404d 100644 --- a/ui/src/app/about/page.tsx +++ b/ui/src/app/about/page.tsx @@ -1,7 +1,7 @@ -import UHGroupingsInfo from '@/components/UHGroupingsInfo'; -import GeneralInfoSection from '@/app/about/_components/GeneralInfoSection'; -import WhatHappensIfSection from '@/app/about/_components/WhatHappensIfSection'; -import TechnicalInfoSection from '@/app/about/_components/TechnicalInfoSection'; +import UHGroupingsInfo from '@/components/uh-groupings-info'; +import GeneralInfoSection from '@/app/about/_components/general-info-section'; +import WhatHappensIfSection from '@/app/about/_components/what-happens-if-section'; +import TechnicalInfoSection from '@/app/about/_components/technical-info-section'; const About = () => (
diff --git a/ui/src/app/api/cas/login/route.ts b/ui/src/app/api/cas/login/route.ts index e1649eaf..cf7d8e4f 100644 --- a/ui/src/app/api/cas/login/route.ts +++ b/ui/src/app/api/cas/login/route.ts @@ -1,6 +1,6 @@ import { redirect } from 'next/navigation'; import type { NextRequest } from 'next/server'; -import { handleLogin } from '@/access/AuthenticationService'; +import { handleLogin } from '@/access/authentication'; const baseUrl = process.env.NEXT_PUBLIC_BASE_URL as string; diff --git a/ui/src/app/api/cas/logout/route.ts b/ui/src/app/api/cas/logout/route.ts index 2d7b4681..6fb133e5 100644 --- a/ui/src/app/api/cas/logout/route.ts +++ b/ui/src/app/api/cas/logout/route.ts @@ -1,5 +1,5 @@ import { redirect } from 'next/navigation'; -import { handleLogout } from '@/access/AuthenticationService'; +import { handleLogout } from '@/access/authentication'; const baseUrl = process.env.NEXT_PUBLIC_BASE_URL as string; diff --git a/ui/src/app/layout.tsx b/ui/src/app/layout.tsx index ea6dc329..fe700bd4 100644 --- a/ui/src/app/layout.tsx +++ b/ui/src/app/layout.tsx @@ -1,8 +1,8 @@ import './globals.css'; import { Source_Sans_3 } from 'next/font/google'; -import Footer from '@/app/_components/layout/footer/Footer'; +import Navbar from './_components/navbar/navbar'; +import Footer from './_components/footer/footer'; import type { Metadata } from 'next'; -import Navbar from '@/app/_components/layout/navbar/Navbar'; const sourceSans3 = Source_Sans_3({ subsets: ['latin'], diff --git a/ui/src/components/UHGroupingsInfo.tsx b/ui/src/components/uh-groupings-info.tsx similarity index 100% rename from ui/src/components/UHGroupingsInfo.tsx rename to ui/src/components/uh-groupings-info.tsx diff --git a/ui/src/middleware.ts b/ui/src/middleware.ts index 81c7dbcb..6b538ac8 100644 --- a/ui/src/middleware.ts +++ b/ui/src/middleware.ts @@ -1,8 +1,8 @@ import { cookies } from 'next/headers'; import { NextResponse, NextRequest } from 'next/server'; import { getIronSession } from 'iron-session'; -import { SessionData, SessionOptions } from './access/Session'; -import Role from './access/Role'; +import { SessionData, SessionOptions } from '@/access/session'; +import Role from '@/access/role'; /** * Next.js middleware function that is called upon visiting a route that matches the config. diff --git a/ui/src/groupings/GroupingsApiResults.ts b/ui/src/models/groupings-api-results.ts similarity index 100% rename from ui/src/groupings/GroupingsApiResults.ts rename to ui/src/models/groupings-api-results.ts diff --git a/ui/tests/access/AuthenticationService.test.ts b/ui/tests/access/authentication.test.ts similarity index 93% rename from ui/tests/access/AuthenticationService.test.ts rename to ui/tests/access/authentication.test.ts index fd936217..19c0478d 100644 --- a/ui/tests/access/AuthenticationService.test.ts +++ b/ui/tests/access/authentication.test.ts @@ -1,6 +1,6 @@ -import { getCurrentUser, login, logout, handleLogin, handleLogout } from '@/access/AuthenticationService'; -import { createMockSession } from '../setupJest'; -import User, { AnonymousUser } from '@/access/User'; +import { getCurrentUser, login, logout, handleLogin, handleLogout } from '@/access/authentication'; +import { createMockSession } from '../setup-jest'; +import User, { AnonymousUser } from '@/access/user'; import { redirect } from 'next/navigation'; import IronSession from 'iron-session'; @@ -9,7 +9,7 @@ const casUrl = process.env.NEXT_PUBLIC_CAS_URL as string; const testUser: User = JSON.parse(process.env.TEST_USER_A as string); const xmlSoapResponse = process.env.XML_SOAP_RESPONSE as string; -describe('AuthenticationService', () => { +describe('authentication', () => { describe('getCurrentUser', () => { diff --git a/ui/tests/access/AuthorizationService.test.ts b/ui/tests/access/authorization.test.ts similarity index 93% rename from ui/tests/access/AuthorizationService.test.ts rename to ui/tests/access/authorization.test.ts index e208770f..579cc4fa 100644 --- a/ui/tests/access/AuthorizationService.test.ts +++ b/ui/tests/access/authorization.test.ts @@ -1,11 +1,10 @@ -import { setRoles } from '@/access/AuthorizationService'; -import Role from '@/access/Role'; -import User, { AnonymousUser } from '@/access/User'; +import { setRoles } from '@/access/authorization'; +import Role from '@/access/role'; +import User, { AnonymousUser } from '@/access/user'; const testUser: User = JSON.parse(process.env.TEST_USER_A as string); -const apiBaseUrl = process.env.NEXT_PUBLIC_API_2_1_BASE_URL as string; -describe('AuthorizationService', () => { +describe('authorization', () => { describe('setRoles', () => { diff --git a/ui/tests/access/Role.test.ts b/ui/tests/access/role.test.ts similarity index 74% rename from ui/tests/access/Role.test.ts rename to ui/tests/access/role.test.ts index 8d37b46f..b5202622 100644 --- a/ui/tests/access/Role.test.ts +++ b/ui/tests/access/role.test.ts @@ -1,6 +1,6 @@ -import Role from '@/access/Role'; +import Role from '@/access/role'; -describe('Role', () => { +describe('role', () => { it('should have the same key and value', () => { for (const [key, value] of Object.entries(Role)) { diff --git a/ui/tests/access/Saml11Validator.test.ts b/ui/tests/access/saml-11-validator.test.ts similarity index 85% rename from ui/tests/access/Saml11Validator.test.ts rename to ui/tests/access/saml-11-validator.test.ts index f8e525aa..97dd313b 100644 --- a/ui/tests/access/Saml11Validator.test.ts +++ b/ui/tests/access/saml-11-validator.test.ts @@ -1,11 +1,11 @@ -import { validateTicket } from '@/access/Saml11Validator'; -import User, { AnonymousUser } from '@/access/User'; +import { validateTicket } from '@/access/saml-11-validator'; +import User, { AnonymousUser } from '@/access/user'; const testUser: User = JSON.parse(process.env.TEST_USER_A as string); const xmlSoapResponse = process.env.XML_SOAP_RESPONSE as string; const xmlSoapResponseRequestDenied = process.env.XML_SOAP_RESPONSE_REQUEST_DENIED as string; -describe('Saml11Validator', () => { +describe('saml-11-validator', () => { describe('validateTicket', () => { diff --git a/ui/tests/access/User.test.ts b/ui/tests/access/user.test.ts similarity index 80% rename from ui/tests/access/User.test.ts rename to ui/tests/access/user.test.ts index 00718823..250dfa96 100644 --- a/ui/tests/access/User.test.ts +++ b/ui/tests/access/user.test.ts @@ -1,7 +1,7 @@ -import Role from '@/access/Role'; -import { AnonymousUser } from '@/access/User'; +import Role from '@/access/role'; +import { AnonymousUser } from '@/access/user'; -describe('User', () => { +describe('user', () => { describe('AnonymousUser', () => { diff --git a/ui/tests/services/EmailService.test.ts b/ui/tests/actions/email.test.ts similarity index 85% rename from ui/tests/services/EmailService.test.ts rename to ui/tests/actions/email.test.ts index 50d2662c..c300a3f3 100644 --- a/ui/tests/services/EmailService.test.ts +++ b/ui/tests/actions/email.test.ts @@ -1,13 +1,13 @@ -import User from '@/access/User'; -import { Feedback, sendFeedback, sendStackTrace } from '@/services/EmailService'; -import * as AuthenticationService from '@/access/AuthenticationService'; +import User from '@/access/user'; +import { Feedback, sendFeedback, sendStackTrace } from '@/actions/email'; +import * as AuthenticationService from '@/access/authentication'; const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL as string; const testUser: User = JSON.parse(process.env.TEST_USER_A as string); -jest.mock('@/access/AuthenticationService'); +jest.mock('@/access/authentication'); -describe('EmailService', () => { +describe('email', () => { const currentUser = testUser; diff --git a/ui/tests/services/GroupingsApiService.test.ts b/ui/tests/actions/groupings-api.test.ts similarity index 99% rename from ui/tests/services/GroupingsApiService.test.ts rename to ui/tests/actions/groupings-api.test.ts index 24e28875..8ee95152 100644 --- a/ui/tests/services/GroupingsApiService.test.ts +++ b/ui/tests/actions/groupings-api.test.ts @@ -34,17 +34,17 @@ import { resetIncludeGroup, resetIncludeGroupAsync, updateDescription -} from '@/services/GroupingsApiService'; -import * as AuthenticationService from '@/access/AuthenticationService'; -import User from '@/access/User'; +} from '@/actions/groupings-api'; +import * as AuthenticationService from '@/access/authentication'; +import User from '@/access/user'; const baseUrl = process.env.NEXT_PUBLIC_API_2_1_BASE_URL as string; const testUser: User = JSON.parse(process.env.TEST_USER_A as string); -jest.mock('@/access/AuthenticationService'); -jest.mock('@/services/EmailService'); +jest.mock('@/access/authentication'); +jest.mock('@/actions/email'); -describe('GroupingsService', () => { +describe('groupings-api', () => { const currentUser = testUser; diff --git a/ui/tests/app/(index)/_components/AfterLogin.test.tsx b/ui/tests/app/(home)/_components/after-login.test.tsx similarity index 93% rename from ui/tests/app/(index)/_components/AfterLogin.test.tsx rename to ui/tests/app/(home)/_components/after-login.test.tsx index 52e6edbf..df651712 100644 --- a/ui/tests/app/(index)/_components/AfterLogin.test.tsx +++ b/ui/tests/app/(home)/_components/after-login.test.tsx @@ -1,15 +1,16 @@ -import Role from '@/access/Role' +import Role from '@/access/role' import { render, screen } from '@testing-library/react'; -import User from '@/access/User'; -import * as GroupingsApiService from '@/services/GroupingsApiService'; -import * as AuthenticationService from '@/access/AuthenticationService'; -import afterLogin from '@/app/(index)/_components/AfterLogin'; +import User from '@/access/user'; +import * as GroupingsApiService from '@/actions/groupings-api'; +import * as AuthenticationService from '@/access/authentication'; +import afterLogin from '@/app/(home)/_components/after-login'; + +jest.mock('@/actions/groupings-api'); +jest.mock('@/access/authentication'); -jest.mock('@/services/GroupingsApiService'); -jest.mock('@/access/AuthenticationService'); const testUser: User = JSON.parse(process.env.TEST_USER_A as string); -describe('AfterLogin', () => { +describe('after-login', () => { const numberOfGroupings = 18; const numberOfMemberships = 17; diff --git a/ui/tests/app/(index)/_components/Announcement.test.tsx b/ui/tests/app/(home)/_components/announcements.test.tsx similarity index 82% rename from ui/tests/app/(index)/_components/Announcement.test.tsx rename to ui/tests/app/(home)/_components/announcements.test.tsx index 093d43ac..c5f85e4a 100644 --- a/ui/tests/app/(index)/_components/Announcement.test.tsx +++ b/ui/tests/app/(home)/_components/announcements.test.tsx @@ -1,8 +1,8 @@ import { render, screen } from '@testing-library/react'; -import Announcements from '@/app/(index)/_components/Announcements'; -import * as GroupingsApiService from '@/services/GroupingsApiService'; +import Announcements from '@/app/(home)/_components/announcements'; +import * as GroupingsApiService from '@/actions/groupings-api'; -jest.mock('@/services/GroupingsApiService'); +jest.mock('@/actions/groupings-api'); const message = 'test announcement'; const message1 = 'test1 announcement'; @@ -16,7 +16,7 @@ const announcements = { ] }; -describe('Announcements Component', () => { +describe('announcements', () => { it('renders announcement correctly', async () => { jest.spyOn(GroupingsApiService, 'getAnnouncements').mockResolvedValue(announcements); render(await Announcements()); diff --git a/ui/tests/app/(index)/_components/BeforeLogin.test.tsx b/ui/tests/app/(home)/_components/before-login.test.tsx similarity index 93% rename from ui/tests/app/(index)/_components/BeforeLogin.test.tsx rename to ui/tests/app/(home)/_components/before-login.test.tsx index 8f134a50..d4e63062 100644 --- a/ui/tests/app/(index)/_components/BeforeLogin.test.tsx +++ b/ui/tests/app/(home)/_components/before-login.test.tsx @@ -1,6 +1,6 @@ import { render, screen } from '@testing-library/react'; -import BeforeLogin from '@/app/(index)/_components/BeforeLogin'; -describe('BeforeLogin Component', () => { +import BeforeLogin from '@/app/(home)/_components/before-login'; +describe('before-login', () => { it('renders UHGroupingsInfo and a button with correct text and link', ()=> { render(); diff --git a/ui/tests/app/(index)/_components/LoginButton.test.tsx b/ui/tests/app/(home)/_components/login-button.test.tsx similarity index 90% rename from ui/tests/app/(index)/_components/LoginButton.test.tsx rename to ui/tests/app/(home)/_components/login-button.test.tsx index 654122af..b29ff683 100644 --- a/ui/tests/app/(index)/_components/LoginButton.test.tsx +++ b/ui/tests/app/(home)/_components/login-button.test.tsx @@ -1,15 +1,15 @@ import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { redirect } from 'next/navigation'; -import User, { AnonymousUser } from '@/access/User'; -import Role from '@/access/Role'; -import LoginButton from '@/app/(index)/_components/LoginButton'; +import User, { AnonymousUser } from '@/access/user'; +import Role from '@/access/role'; +import LoginButton from '@/app/(home)/_components/login-button'; const casUrl = process.env.NEXT_PUBLIC_CAS_URL as string; const baseUrl = process.env.NEXT_PUBLIC_BASE_URL as string; const testUser: User = JSON.parse(process.env.TEST_USER_A as string); -describe('LoginButton Component', () => { +describe('login-button', () => { describe('User is not logged in', () => { it('should render a Login button', () => { diff --git a/ui/tests/app/_components/layout/footer/Footer.test.tsx b/ui/tests/app/_components/footer/footer.test.tsx similarity index 92% rename from ui/tests/app/_components/layout/footer/Footer.test.tsx rename to ui/tests/app/_components/footer/footer.test.tsx index 27be7dbc..b40a5daa 100644 --- a/ui/tests/app/_components/layout/footer/Footer.test.tsx +++ b/ui/tests/app/_components/footer/footer.test.tsx @@ -1,5 +1,5 @@ import { render, screen } from '@testing-library/react'; -import Footer from '@/app/_components/layout/footer/Footer'; +import Footer from '@/app/_components/footer/footer'; describe ('Footer', () => { diff --git a/ui/tests/app/_components/layout/navbar/Navbar.test.tsx b/ui/tests/app/_components/layout/navbar/Navbar.test.tsx deleted file mode 100644 index 3bbba34c..00000000 --- a/ui/tests/app/_components/layout/navbar/Navbar.test.tsx +++ /dev/null @@ -1,92 +0,0 @@ -import User, { AnonymousUser } from '@/access/User'; -import * as AuthenticationService from '@/access/AuthenticationService'; -import { render, screen } from '@testing-library/react'; -import Navbar from '@/app/_components/layout/navbar/Navbar'; -import Role from '@/access/Role'; - -const testUser: User = JSON.parse(process.env.TEST_USER_A as string); - -jest.mock('@/access/AuthenticationService'); - -describe('Navbar', () => { - - describe('User is logged-out', () => { - - it('should render the navbar with only the link to /about', async () => { - jest.spyOn(AuthenticationService, 'getCurrentUser').mockResolvedValue(AnonymousUser); - render(await Navbar()); - - expect(screen.getByRole('navigation')).toBeInTheDocument(); - expect(screen.getAllByRole('img', { name: 'UH Groupings Logo' })[0]) - .toHaveAttribute('src', '/uhgroupings/uh-groupings-logo.svg'); - expect(screen.getAllByRole('link', { name: 'UH Groupings Logo' })[0]).toHaveAttribute('href', '/'); - expect(screen.queryByRole('link', { name: 'Admin' })).not.toBeInTheDocument(); - expect(screen.queryByRole('link', { name: 'Memberships' })).not.toBeInTheDocument(); - expect(screen.queryByRole('link', { name: 'Groupings' })).not.toBeInTheDocument(); - expect(screen.getByRole('link', { name: 'About' })).toHaveAttribute('href', '/about'); - expect(screen.queryByRole('link', { name: 'Feedback' })).not.toBeInTheDocument(); - expect(screen.getByRole('button', { name: 'Login' })).toBeInTheDocument(); - }); - - }); - - describe('User is logged-in', () => { - - beforeEach(() => { - testUser.roles = [Role.ANONYMOUS]; - }) - - it('should render only /memberships, /about, /feedback for the average user', async () => { - testUser.roles.push(Role.UH); - jest.spyOn(AuthenticationService, 'getCurrentUser').mockResolvedValue(testUser); - render(await Navbar()); - - expect(screen.getByRole('navigation')).toBeInTheDocument(); - expect(screen.getAllByRole('img', { name: 'UH Groupings Logo' })[0]) - .toHaveAttribute('src', '/uhgroupings/uh-groupings-logo.svg'); - expect(screen.getAllByRole('link', { name: 'UH Groupings Logo' })[0]).toHaveAttribute('href', '/'); - expect(screen.queryByRole('link', { name: 'Admin' })).not.toBeInTheDocument(); - expect(screen.getByRole('link', { name: 'Memberships' })).toHaveAttribute('href', '/memberships'); - expect(screen.queryByRole('link', { name: 'Groupings' })).not.toBeInTheDocument(); - expect(screen.getByRole('link', { name: 'About' })).toHaveAttribute('href', '/about'); - expect(screen.getByRole('link', { name: 'Feedback' })).toHaveAttribute('href', '/feedback'); - expect(screen.getByRole('button', { name: `Logout (${testUser.uid})` })).toBeInTheDocument(); - }); - - it('should render only /memberships, /groupings, /about, /feedback for an owner of a grouping', async () => { - testUser.roles.push(Role.OWNER, Role.UH); - jest.spyOn(AuthenticationService, 'getCurrentUser').mockResolvedValue(testUser); - render(await Navbar()); - - expect(screen.getByRole('navigation')).toBeInTheDocument(); - expect(screen.getAllByRole('img', { name: 'UH Groupings Logo' })[0]) - .toHaveAttribute('src', '/uhgroupings/uh-groupings-logo.svg'); - expect(screen.getAllByRole('link', { name: 'UH Groupings Logo' })[0]).toHaveAttribute('href', '/'); - expect(screen.queryByRole('link', { name: 'Admin' })).not.toBeInTheDocument(); - expect(screen.getByRole('link', { name: 'Memberships' })).toHaveAttribute('href', '/memberships'); - expect(screen.getByRole('link', { name: 'Groupings' })).toHaveAttribute('href', '/groupings'); - expect(screen.getByRole('link', { name: 'About' })).toHaveAttribute('href', '/about'); - expect(screen.getByRole('link', { name: 'Feedback' })).toHaveAttribute('href', '/feedback'); - expect(screen.getByRole('button', { name: `Logout (${testUser.uid})` })).toBeInTheDocument(); - }); - - it('should render all links for an Admin', async () => { - testUser.roles.push(Role.ADMIN, Role.UH); - jest.spyOn(AuthenticationService, 'getCurrentUser').mockResolvedValue(testUser); - render(await Navbar()); - - expect(screen.getByRole('navigation')).toBeInTheDocument(); - expect(screen.getAllByRole('img', { name: 'UH Groupings Logo' })[0]) - .toHaveAttribute('src', '/uhgroupings/uh-groupings-logo.svg'); - expect(screen.getAllByRole('link', { name: 'UH Groupings Logo' })[0]).toHaveAttribute('href', '/'); - expect(screen.getByRole('link', { name: 'Admin' })).toHaveAttribute('href', '/admin'); - expect(screen.getByRole('link', { name: 'Memberships' })).toHaveAttribute('href', '/memberships'); - expect(screen.getByRole('link', { name: 'Groupings' })).toHaveAttribute('href', '/groupings'); - expect(screen.getByRole('link', { name: 'About' })).toHaveAttribute('href', '/about'); - expect(screen.getByRole('link', { name: 'Feedback' })).toHaveAttribute('href', '/feedback'); - expect(screen.getByRole('button', { name: `Logout (${testUser.uid})` })).toBeInTheDocument(); - }); - - }); - -}); diff --git a/ui/tests/app/_components/layout/modal/TimeoutModal.test.tsx b/ui/tests/app/_components/modal/timeout-modal.test.tsx similarity index 93% rename from ui/tests/app/_components/layout/modal/TimeoutModal.test.tsx rename to ui/tests/app/_components/modal/timeout-modal.test.tsx index 98ea5ba8..d18cb808 100644 --- a/ui/tests/app/_components/layout/modal/TimeoutModal.test.tsx +++ b/ui/tests/app/_components/modal/timeout-modal.test.tsx @@ -1,12 +1,13 @@ -import Role from '@/access/Role'; -import User from '@/access/User'; -import TimeoutModal from '@/app/_components/layout/modal/TimeoutModal'; + +import Role from '@/access/role'; +import User from '@/access/user'; +import TimeoutModal from '@/app/_components/modal/timeout-modal'; import { act, fireEvent, render, screen } from '@testing-library/react'; -import * as AuthenticationService from '@/access/AuthenticationService'; +import * as AuthenticationService from '@/access/authentication'; const testUser: User = JSON.parse(process.env.TEST_USER_A as string); -jest.mock('@/access/AuthenticationService'); +jest.mock('@/access/authentication'); describe('TimeoutModal', () => { diff --git a/ui/tests/app/_components/layout/navbar/LoginButton.test.tsx b/ui/tests/app/_components/navbar/login-button.test.tsx similarity index 92% rename from ui/tests/app/_components/layout/navbar/LoginButton.test.tsx rename to ui/tests/app/_components/navbar/login-button.test.tsx index 70e77f00..4f76e320 100644 --- a/ui/tests/app/_components/layout/navbar/LoginButton.test.tsx +++ b/ui/tests/app/_components/navbar/login-button.test.tsx @@ -1,9 +1,9 @@ import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import Login from '@/app/_components/layout/navbar/LoginButton'; +import Login from '@/app/_components/navbar/login-button'; import { redirect } from 'next/navigation'; -import User, { AnonymousUser } from '@/access/User'; -import Role from '@/access/Role'; +import User, { AnonymousUser } from '@/access/user'; +import Role from '@/access/role'; const casUrl = process.env.NEXT_PUBLIC_CAS_URL as string; const baseUrl = process.env.NEXT_PUBLIC_BASE_URL as string; diff --git a/ui/tests/app/_components/layout/navbar/MobileNavbar.test.tsx b/ui/tests/app/_components/navbar/mobile-navbar.test.tsx similarity index 78% rename from ui/tests/app/_components/layout/navbar/MobileNavbar.test.tsx rename to ui/tests/app/_components/navbar/mobile-navbar.test.tsx index 57759f5d..d9b3ddd6 100644 --- a/ui/tests/app/_components/layout/navbar/MobileNavbar.test.tsx +++ b/ui/tests/app/_components/navbar/mobile-navbar.test.tsx @@ -1,8 +1,7 @@ -import Role from '@/access/Role'; -import User, { AnonymousUser } from '@/access/User'; -import MobileNavbar from '@/app/_components/layout/navbar/MobileNavbar'; -import { render, screen } from '@testing-library/react'; -import userEvent from '@testing-library/user-event'; +import Role from '@/access/role'; +import User, { AnonymousUser } from '@/access/user'; +import MobileNavbar from '@/app/_components/navbar/mobile-navbar'; +import { fireEvent, render, screen } from '@testing-library/react'; const testUser: User = JSON.parse(process.env.TEST_USER_A as string); @@ -14,19 +13,19 @@ describe('MobileNavbar', () => { expect(screen.queryByRole('navigation')).not.toBeInTheDocument(); }); - it('should open the drawer on click', async () => { + it('should open the drawer on click', () => { render(); - await userEvent.click(screen.getByRole('button', { name: 'Open navigation menu' })); + fireEvent.click(screen.getByRole('button', { name: 'Open navigation menu' })); expect(screen.getByRole('navigation')).toBeInTheDocument(); }); describe('User is logged-out', () => { - it('should render the navbar with only the link to /about', async () => { + it('should render the navbar with only the link to /about', () => { render(); - await userEvent.click(screen.getByRole('button', { name: 'Open navigation menu' })); + fireEvent.click(screen.getByRole('button', { name: 'Open navigation menu' })); expect(screen.getByRole('navigation')).toBeInTheDocument(); expect(screen.queryByRole('link', { name: 'Admin' })).not.toBeInTheDocument(); expect(screen.queryByRole('link', { name: 'Memberships' })).not.toBeInTheDocument(); @@ -43,11 +42,11 @@ describe('MobileNavbar', () => { testUser.roles = [Role.ANONYMOUS]; }) - it('should render only /memberships, /about, /feedback for the average user', async () => { + it('should render only /memberships, /about, /feedback for the average user', () => { testUser.roles.push(Role.UH); render(); - await userEvent.click(screen.getByRole('button', { name: 'Open navigation menu' })); + fireEvent.click(screen.getByRole('button', { name: 'Open navigation menu' })); expect(screen.getByRole('navigation')).toBeInTheDocument(); expect(screen.queryByRole('link', { name: 'Admin' })).not.toBeInTheDocument(); expect(screen.getByRole('link', { name: 'Memberships' })).toHaveAttribute('href', '/memberships'); @@ -56,11 +55,11 @@ describe('MobileNavbar', () => { expect(screen.getByRole('link', { name: 'Feedback' })).toHaveAttribute('href', '/feedback'); }); - it('should render only /memberships, /groupings, /about, /feedback for an owner of a grouping', async () => { + it('should render only /memberships, /groupings, /about, /feedback for an owner of a grouping', () => { testUser.roles.push(Role.OWNER, Role.UH); render(); - await userEvent.click(screen.getByRole('button', { name: 'Open navigation menu' })); + fireEvent.click(screen.getByRole('button', { name: 'Open navigation menu' })); expect(screen.getByRole('navigation')).toBeInTheDocument(); expect(screen.queryByRole('link', { name: 'Admin' })).not.toBeInTheDocument(); expect(screen.getByRole('link', { name: 'Memberships' })).toHaveAttribute('href', '/memberships'); @@ -69,11 +68,11 @@ describe('MobileNavbar', () => { expect(screen.getByRole('link', { name: 'Feedback' })).toHaveAttribute('href', '/feedback'); }); - it('should render all links for an Admin', async () => { + it('should render all links for an Admin', () => { testUser.roles.push(Role.ADMIN, Role.UH); render(); - await userEvent.click(screen.getByRole('button', { name: 'Open navigation menu' })); + fireEvent.click(screen.getByRole('button', { name: 'Open navigation menu' })); expect(screen.getByRole('navigation')).toBeInTheDocument(); expect(screen.getByRole('link', { name: 'Admin' })).toHaveAttribute('href', '/admin'); expect(screen.getByRole('link', { name: 'Memberships' })).toHaveAttribute('href', '/memberships'); diff --git a/ui/tests/app/about/_components/GeneralInfoSection.test.tsx b/ui/tests/app/about/_components/general-info-section.test.tsx similarity index 94% rename from ui/tests/app/about/_components/GeneralInfoSection.test.tsx rename to ui/tests/app/about/_components/general-info-section.test.tsx index a35c186a..55e0c577 100644 --- a/ui/tests/app/about/_components/GeneralInfoSection.test.tsx +++ b/ui/tests/app/about/_components/general-info-section.test.tsx @@ -1,5 +1,5 @@ import { render, screen } from '@testing-library/react'; -import GeneralInfoSection from '@/app/about/_components/GeneralInfoSection'; +import GeneralInfoSection from '@/app/about/_components/general-info-section'; describe('GeneralInfoSection', () => { it('should render with question and answer', () => { diff --git a/ui/tests/app/about/_components/TechnicalInfoSection.test.tsx b/ui/tests/app/about/_components/technical-info-section.test.tsx similarity index 96% rename from ui/tests/app/about/_components/TechnicalInfoSection.test.tsx rename to ui/tests/app/about/_components/technical-info-section.test.tsx index 8eb0dcef..0b3fe717 100644 --- a/ui/tests/app/about/_components/TechnicalInfoSection.test.tsx +++ b/ui/tests/app/about/_components/technical-info-section.test.tsx @@ -1,5 +1,5 @@ import { render, screen } from '@testing-library/react'; -import TechnicalInfoSection from '@/app/about/_components/TechnicalInfoSection'; +import TechnicalInfoSection from '@/app/about/_components/technical-info-section'; describe('TechnicalInfoSection', () => { it('should render with name, url, and description', () => { diff --git a/ui/tests/app/about/_components/WhatHappensIfSection.test.tsx b/ui/tests/app/about/_components/what-happens-if-section.test.tsx similarity index 94% rename from ui/tests/app/about/_components/WhatHappensIfSection.test.tsx rename to ui/tests/app/about/_components/what-happens-if-section.test.tsx index 6256a7b0..c20ef455 100644 --- a/ui/tests/app/about/_components/WhatHappensIfSection.test.tsx +++ b/ui/tests/app/about/_components/what-happens-if-section.test.tsx @@ -1,5 +1,5 @@ import { render, screen } from '@testing-library/react'; -import WhatHappensIfSection from '@/app/about/_components/WhatHappensIfSection'; +import WhatHappensIfSection from '@/app/about/_components/what-happens-if-section'; describe('WhatHappensIfSection', () => { it('should render with question and answer', () => { diff --git a/ui/tests/app/api/cas/login/route.test.ts b/ui/tests/app/api/cas/login/route.test.ts index 35e29630..b1e032f5 100644 --- a/ui/tests/app/api/cas/login/route.test.ts +++ b/ui/tests/app/api/cas/login/route.test.ts @@ -1,11 +1,11 @@ import { GET } from '@/app/api/cas/login/route'; import { redirect } from 'next/navigation'; -import { handleLogin } from '@/access/AuthenticationService'; +import { handleLogin } from '@/access/authentication'; import { NextRequest } from 'next/server'; const baseUrl = process.env.NEXT_PUBLIC_BASE_URL as string; -jest.mock('@/access/AuthenticationService'); +jest.mock('@/access/authentication'); describe('/api/cas/login', () => { diff --git a/ui/tests/app/api/cas/logout/route.test.ts b/ui/tests/app/api/cas/logout/route.test.ts index 1374af4b..22625174 100644 --- a/ui/tests/app/api/cas/logout/route.test.ts +++ b/ui/tests/app/api/cas/logout/route.test.ts @@ -1,10 +1,10 @@ import { GET } from '@/app/api/cas/logout/route'; import { redirect } from 'next/navigation'; -import { handleLogout } from '@/access/AuthenticationService'; +import { handleLogout } from '@/access/authentication'; const baseUrl = process.env.NEXT_PUBLIC_BASE_URL as string; -jest.mock('@/access/AuthenticationService'); +jest.mock('@/access/authentication'); describe('/api/cas/logout', () => { diff --git a/ui/tests/components/UHGroupingsInfo.test.tsx b/ui/tests/components/uh-groupings-info.test.tsx similarity index 97% rename from ui/tests/components/UHGroupingsInfo.test.tsx rename to ui/tests/components/uh-groupings-info.test.tsx index a70daa9f..c89f173d 100644 --- a/ui/tests/components/UHGroupingsInfo.test.tsx +++ b/ui/tests/components/uh-groupings-info.test.tsx @@ -1,5 +1,5 @@ import { render, screen } from '@testing-library/react'; -import UHGroupingsInfo from '@/components/UHGroupingsInfo'; +import UHGroupingsInfo from '@/components/uh-groupings-info'; describe('UHGroupings Component', () => { const expectCogs = (size: 'text-[1.2rem]' | 'text-base') => { diff --git a/ui/tests/middleware.test.tsx b/ui/tests/middleware.test.tsx index 6c9cf2e5..51d74916 100644 --- a/ui/tests/middleware.test.tsx +++ b/ui/tests/middleware.test.tsx @@ -1,9 +1,9 @@ import { config, middleware } from '@/middleware'; -import { createMockSession } from './setupJest'; +import { createMockSession } from './setup-jest'; import { NextRequest, NextResponse } from 'next/server'; import IronSession from 'iron-session'; -import User, { AnonymousUser } from '@/access/User'; -import Role from '@/access/Role'; +import User, { AnonymousUser } from '@/access/user'; +import Role from '@/access/role'; const baseUrl = process.env.NEXT_PUBLIC_BASE_URL as string; const testUser: User = JSON.parse(process.env.TEST_USER_A as string); diff --git a/ui/tests/setupJest.ts b/ui/tests/setup-jest.ts similarity index 90% rename from ui/tests/setupJest.ts rename to ui/tests/setup-jest.ts index 186f3753..b11b4b4a 100644 --- a/ui/tests/setupJest.ts +++ b/ui/tests/setup-jest.ts @@ -1,7 +1,7 @@ import '@testing-library/jest-dom'; import { loadEnvConfig } from '@next/env'; import { enableFetchMocks } from 'jest-fetch-mock'; -import User from '@/access/User'; +import User from '@/access/user'; enableFetchMocks(); loadEnvConfig(process.cwd());