From e504dfef66a050df6e88e121e0fa7a2dcb159a58 Mon Sep 17 00:00:00 2001 From: Chad Elliott Date: Mon, 11 Nov 2024 13:23:41 -0600 Subject: [PATCH 1/7] Adding some missing tests. --- .../EarnedCertificationsTable.jsx | 6 +- .../reviews/periods/ReviewPeriods.jsx | 3 +- .../volunteer/VolunteerTables.test.jsx | 24 + .../VolunteerTables.test.jsx.snap | 168 ++++ .../pages/CertificationReportPage.test.jsx | 34 + web-ui/src/pages/CheckinsReportPage.test.jsx | 35 + web-ui/src/pages/EmailPage.test.jsx | 37 + web-ui/src/pages/KudosPage.test.jsx | 65 ++ web-ui/src/pages/ManageKudosPage.jsx | 22 +- web-ui/src/pages/ManageKudosPage.test.jsx | 34 + web-ui/src/pages/MeritReportPage.jsx | 1 + web-ui/src/pages/MeritReportPage.test.jsx | 34 + web-ui/src/pages/ProfilePage.test.jsx | 34 + .../src/pages/ReceivedRequestsPage.test.jsx | 24 + web-ui/src/pages/ReviewsPage.test.jsx | 38 + .../CertificationReportPage.test.jsx.snap | 145 ++++ .../CheckinsReportPage.test.jsx.snap | 214 +++++ .../__snapshots__/EmailPage.test.jsx.snap | 305 +++++++ .../__snapshots__/KudosPage.test.jsx.snap | 126 +++ .../ManageKudosPage.test.jsx.snap | 163 ++++ .../MeritReportPage.test.jsx.snap | 273 +++++++ .../__snapshots__/ProfilePage.test.jsx.snap | 746 ++++++++++++++++++ .../ReceivedRequestsPage.test.jsx.snap | 288 +++++++ .../__snapshots__/ReviewsPage.test.jsx.snap | 107 +++ 24 files changed, 2920 insertions(+), 6 deletions(-) create mode 100644 web-ui/src/components/volunteer/VolunteerTables.test.jsx create mode 100644 web-ui/src/components/volunteer/__snapshots__/VolunteerTables.test.jsx.snap create mode 100644 web-ui/src/pages/CertificationReportPage.test.jsx create mode 100644 web-ui/src/pages/CheckinsReportPage.test.jsx create mode 100644 web-ui/src/pages/EmailPage.test.jsx create mode 100644 web-ui/src/pages/KudosPage.test.jsx create mode 100644 web-ui/src/pages/ManageKudosPage.test.jsx create mode 100644 web-ui/src/pages/MeritReportPage.test.jsx create mode 100644 web-ui/src/pages/ProfilePage.test.jsx create mode 100644 web-ui/src/pages/ReceivedRequestsPage.test.jsx create mode 100644 web-ui/src/pages/ReviewsPage.test.jsx create mode 100644 web-ui/src/pages/__snapshots__/CertificationReportPage.test.jsx.snap create mode 100644 web-ui/src/pages/__snapshots__/CheckinsReportPage.test.jsx.snap create mode 100644 web-ui/src/pages/__snapshots__/EmailPage.test.jsx.snap create mode 100644 web-ui/src/pages/__snapshots__/KudosPage.test.jsx.snap create mode 100644 web-ui/src/pages/__snapshots__/ManageKudosPage.test.jsx.snap create mode 100644 web-ui/src/pages/__snapshots__/MeritReportPage.test.jsx.snap create mode 100644 web-ui/src/pages/__snapshots__/ProfilePage.test.jsx.snap create mode 100644 web-ui/src/pages/__snapshots__/ReceivedRequestsPage.test.jsx.snap create mode 100644 web-ui/src/pages/__snapshots__/ReviewsPage.test.jsx.snap diff --git a/web-ui/src/components/certifications/EarnedCertificationsTable.jsx b/web-ui/src/components/certifications/EarnedCertificationsTable.jsx index a13b67e8a..814a62ec8 100644 --- a/web-ui/src/components/certifications/EarnedCertificationsTable.jsx +++ b/web-ui/src/components/certifications/EarnedCertificationsTable.jsx @@ -94,7 +94,7 @@ const EarnedCertificationsTable = ({ }); if (res.error) return; - const certs = res.payload.data; + const certs = res.payload.data ?? []; setCertifications(certs.sort((c1, c2) => c1.name.localeCompare(c2.name))); const certMap = certs.reduce((map, cert) => { @@ -114,7 +114,7 @@ const EarnedCertificationsTable = ({ }); if (res.error) return; - let earned = res.payload.data; + let earned = res.payload.data ?? []; if (onlyMe) { earned = earned.filter(cert => cert.memberId === currentUser.id); } @@ -512,7 +512,7 @@ const EarnedCertificationsTable = ({ }); if (res.error) return; - const newEarned = res.payload.data; + const newEarned = res.payload.data ?? []; setEarnedCertifications(earned => { if (id) { const index = earned.findIndex(c => c.id === id); diff --git a/web-ui/src/components/reviews/periods/ReviewPeriods.jsx b/web-ui/src/components/reviews/periods/ReviewPeriods.jsx index 4d30109ce..b62d2e980 100644 --- a/web-ui/src/components/reviews/periods/ReviewPeriods.jsx +++ b/web-ui/src/components/reviews/periods/ReviewPeriods.jsx @@ -399,9 +399,8 @@ const ReviewPeriods = ({ onPeriodSelected, mode }) => { : aName.localeCompare(b.name)); }) .map((period) => ( -
+
{ + snapshot( + + + + + + ); +}); diff --git a/web-ui/src/components/volunteer/__snapshots__/VolunteerTables.test.jsx.snap b/web-ui/src/components/volunteer/__snapshots__/VolunteerTables.test.jsx.snap new file mode 100644 index 000000000..91bfa13eb --- /dev/null +++ b/web-ui/src/components/volunteer/__snapshots__/VolunteerTables.test.jsx.snap @@ -0,0 +1,168 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`renders correctly 1`] = ` +
+
+
+
+
+
+ + +
+ +
+
+
+
+
+
+ + + + + + + + + + + +
+ Member + 🔼 + + Organization + + Start Date + + End Date + + Actions +
+
+

+ The administrator may edit organizations to ensure accuracy. +

+
+
+
+ +
+
+`; diff --git a/web-ui/src/pages/CertificationReportPage.test.jsx b/web-ui/src/pages/CertificationReportPage.test.jsx new file mode 100644 index 000000000..1e821f18a --- /dev/null +++ b/web-ui/src/pages/CertificationReportPage.test.jsx @@ -0,0 +1,34 @@ +import React from 'react'; +import CertificationReportPage from './CertificationReportPage'; +import { AppContextProvider } from '../context/AppContext'; +import { BrowserRouter } from 'react-router-dom'; + +const userStateWithPermission = { + state: { + userProfile: { + name: 'Mitch Hedberg', + role: ['MEMBER'], + permissions: [{ permission: 'CAN_MANAGE_EARNED_CERTIFICATIONS' }], + } + } +}; + +it('renders correctly', () => { + snapshot( + + + + + + ); +}); + +it('renders an error if user does not have appropriate permission', () => { + snapshot( + + + + + + ); +}); diff --git a/web-ui/src/pages/CheckinsReportPage.test.jsx b/web-ui/src/pages/CheckinsReportPage.test.jsx new file mode 100644 index 000000000..4299d3318 --- /dev/null +++ b/web-ui/src/pages/CheckinsReportPage.test.jsx @@ -0,0 +1,35 @@ +import React from 'react'; +import CheckinsReportPage from './CheckinsReportPage'; +import { AppContextProvider } from '../context/AppContext'; +import { BrowserRouter } from 'react-router-dom'; + +const userStateWithPermission = { + state: { + userProfile: { + name: 'Mitch Hedberg', + role: ['MEMBER'], + permissions: [{ permission: 'CAN_VIEW_CHECKINS_REPORT' }], + }, + terminatedMembers: [], + } +}; + +it('renders correctly', () => { + snapshot( + + + + + + ); +}); + +it('renders an error if user does not have appropriate permission', () => { + snapshot( + + + + + + ); +}); diff --git a/web-ui/src/pages/EmailPage.test.jsx b/web-ui/src/pages/EmailPage.test.jsx new file mode 100644 index 000000000..7ee3c50bf --- /dev/null +++ b/web-ui/src/pages/EmailPage.test.jsx @@ -0,0 +1,37 @@ +import React from 'react'; +import EmailPage from './EmailPage'; +import { AppContextProvider } from '../context/AppContext'; +import { BrowserRouter } from 'react-router-dom'; + +window.scrollTo = vi.fn(); + +const userStateWithPermission = { + state: { + userProfile: { + name: 'Mitch Hedberg', + role: ['MEMBER'], + permissions: [{ permission: 'CAN_SEND_EMAIL' }], + }, + terminatedMembers: [], + } +}; + +it('renders correctly', () => { + snapshot( + + + + + + ); +}); + +it('renders an error if user does not have appropriate permission', () => { + snapshot( + + + + + + ); +}); diff --git a/web-ui/src/pages/KudosPage.test.jsx b/web-ui/src/pages/KudosPage.test.jsx new file mode 100644 index 000000000..05f4a5a49 --- /dev/null +++ b/web-ui/src/pages/KudosPage.test.jsx @@ -0,0 +1,65 @@ +import React from 'react'; +import KudosPage from './KudosPage'; +import { AppContextProvider } from '../context/AppContext'; +import { http, HttpResponse } from 'msw'; +import { setupServer } from 'msw/node'; +import { BrowserRouter } from 'react-router-dom'; + +window.snackDispatch = vi.fn(); + +const userStateWithPermission = { + state: { + csrf: 'csrf', + userProfile: { + id: 'current-id', + name: 'Mitch Hedberg', + role: ['MEMBER'], + permissions: [{ permission: '' }], + }, + teams: [], + memberProfiles: [ + { + id: 'some-id', + firstName: 'First', + lastName: 'Last', + }, + { + id: 'other-id', + firstName: 'First', + lastName: 'Last', + }, + ], + } +}; + +const server = setupServer( + http.get('http://localhost:8080/services/kudos', ({ request }) => { + return HttpResponse.json([ + { + id: 'kudos-id', + message: 'You are great!', + senderId: 'some-id', + recipientTeam: null, + dateCreated: [2024, 11, 11], + dateApproved: [2024, 11, 11], + recipientMembers: [ + {id: 'current-id'}, + ], + }, + ]); + }), +); + +beforeAll(() => server.listen({ onUnhandledRequest(request, print) {} })); +afterEach(() => server.resetHandlers()); +afterAll(() => server.close()); + +it('renders correctly', () => { + snapshot( + + + + + + ); +}); diff --git a/web-ui/src/pages/ManageKudosPage.jsx b/web-ui/src/pages/ManageKudosPage.jsx index e495efb5f..4d4aa468d 100644 --- a/web-ui/src/pages/ManageKudosPage.jsx +++ b/web-ui/src/pages/ManageKudosPage.jsx @@ -63,6 +63,20 @@ const ManageKudosPage = () => { const [approvedKudosLoading, setApprovedKudosLoading] = useState(true); const [kudosTab, setKudosTab] = useState("PENDING"); const [timeRange, setTimeRange] = useState(DateRange.TWO_WEEKS); + const [pendingSort, setPendingSort] = useState(SortOption.OLDEST); + + const sortPendingKudos = (pending) => { + return pending.sort((a, b) => { + const l = pendingSort === SortOption.NEWEST ? a : b; + const r = pendingSort === SortOption.NEWEST ? b : a; + for(let i = 0; i < l.dateCreated.length; i++) { + if (l.dateCreated[i] != r.dateCreated[i]) { + return r.dateCreated[i] - l.dateCreated[i]; + } + } + return 0; + }); + }; const loadPendingKudos = useCallback(async () => { setPendingKudosLoading(true); @@ -85,11 +99,15 @@ const ManageKudosPage = () => { useEffect(() => { loadPendingKudos().then(data => { if (data) { - setPendingKudos(data); + setPendingKudos(sortPendingKudos(data)); } }); }, [csrf, dispatch, loadPendingKudos]); + useEffect(() => { + setPendingKudos(sortPendingKudos([...pendingKudos])); + }, [pendingSort]); + const handleTabChange = useCallback((event, newTab) => { switch (newTab) { case "PENDING": @@ -141,6 +159,8 @@ const ManageKudosPage = () => { select label="Sort by" variant="outlined" + value={pendingSort} + onChange={(event) => setPendingSort(event.target.value)} > Newest Oldest diff --git a/web-ui/src/pages/ManageKudosPage.test.jsx b/web-ui/src/pages/ManageKudosPage.test.jsx new file mode 100644 index 000000000..920f23c05 --- /dev/null +++ b/web-ui/src/pages/ManageKudosPage.test.jsx @@ -0,0 +1,34 @@ +import React from 'react'; +import ManageKudosPage from './ManageKudosPage'; +import { AppContextProvider } from '../context/AppContext'; +import { BrowserRouter } from 'react-router-dom'; + +const userStateWithPermission = { + state: { + userProfile: { + name: 'Mitch Hedberg', + role: ['MEMBER'], + permissions: [{ permission: 'CAN_ADMINISTER_KUDOS' }], + } + } +}; + +it('renders correctly', () => { + snapshot( + + + + + + ); +}); + +it('renders an error if user does not have appropriate permission', () => { + snapshot( + + + + + + ); +}); diff --git a/web-ui/src/pages/MeritReportPage.jsx b/web-ui/src/pages/MeritReportPage.jsx index f49fb7e70..4ce703b94 100644 --- a/web-ui/src/pages/MeritReportPage.jsx +++ b/web-ui/src/pages/MeritReportPage.jsx @@ -564,6 +564,7 @@ const MeritReportPage = () => { option.name || ""} value={reviewPeriodId} onChange={onReviewPeriodChange} renderInput={params => ( diff --git a/web-ui/src/pages/MeritReportPage.test.jsx b/web-ui/src/pages/MeritReportPage.test.jsx new file mode 100644 index 000000000..0012ead96 --- /dev/null +++ b/web-ui/src/pages/MeritReportPage.test.jsx @@ -0,0 +1,34 @@ +import React from 'react'; +import MeritReportPage from './MeritReportPage'; +import { AppContextProvider } from '../context/AppContext'; +import { BrowserRouter } from 'react-router-dom'; + +const userStateWithPermission = { + state: { + userProfile: { + name: 'Mitch Hedberg', + role: ['MEMBER'], + permissions: [{ permission: 'CAN_CREATE_MERIT_REPORT' }], + } + } +}; + +it('renders correctly', () => { + snapshot( + + + + + + ); +}); + +it('renders an error if user does not have appropriate permission', () => { + snapshot( + + + + + + ); +}); diff --git a/web-ui/src/pages/ProfilePage.test.jsx b/web-ui/src/pages/ProfilePage.test.jsx new file mode 100644 index 000000000..a5ef9e2ca --- /dev/null +++ b/web-ui/src/pages/ProfilePage.test.jsx @@ -0,0 +1,34 @@ +import React from 'react'; +import ProfilePage from './ProfilePage'; +import { AppContextProvider } from '../context/AppContext'; +import { BrowserRouter } from 'react-router-dom'; + +const userProfile = { + id: 'member-id', + name: 'Mitch Hedberg', + role: ['MEMBER'], + workEmail: 'hedbergm@objectcomputing.com', + title: 'Strategic Placement Specialist', + location: 'Roseville, Minnesota', + memberProfile: { + id: 'member-id', + bioText: 'Died too young.', + }, +}; + +const userStateWithPermission = { + state: { + memberProfiles: [ userProfile ], + userProfile: userProfile, + } +}; + +it('renders correctly', () => { + snapshot( + + + + + + ); +}); diff --git a/web-ui/src/pages/ReceivedRequestsPage.test.jsx b/web-ui/src/pages/ReceivedRequestsPage.test.jsx new file mode 100644 index 000000000..e8aae9149 --- /dev/null +++ b/web-ui/src/pages/ReceivedRequestsPage.test.jsx @@ -0,0 +1,24 @@ +import React from 'react'; +import ReceivedRequestsPage from './ReceivedRequestsPage'; +import { AppContextProvider } from '../context/AppContext'; +import { BrowserRouter } from 'react-router-dom'; + + +const initialState = { + state: { + userProfile: { + name: 'Mitch Hedberg', + role: ['MEMBER'], + }, + }, +}; + +it('renders correctly', () => { + snapshot( + + + + + + ); +}); diff --git a/web-ui/src/pages/ReviewsPage.test.jsx b/web-ui/src/pages/ReviewsPage.test.jsx new file mode 100644 index 000000000..be95217b1 --- /dev/null +++ b/web-ui/src/pages/ReviewsPage.test.jsx @@ -0,0 +1,38 @@ +import React from 'react'; +import ReviewsPage from './ReviewsPage'; +import { AppContextProvider } from '../context/AppContext'; +import { BrowserRouter } from 'react-router-dom'; + +window.snackDispatch = vi.fn(); + +const initialState = { + state: { + userProfile: { + name: 'Mitch Hedberg', + role: ['MEMBER'], + }, + // Review Period 2 should be listed before Review Period 1 because it's OPEN + reviewPeriods: [ + { + id: 'a44fc66a-86b0-4f15-8459-e7d4b4ecc330', + name: 'Review Period 1', + reviewStatus: 'CLOSED', + }, + { + id: 'a44fc66a-86b0-4f15-8459-e7d4b4ecc331', + name: 'Review Period 2', + reviewStatus: 'OPEN', + }, + ], + }, +}; + +it('renders correctly', () => { + snapshot( + + + + + + ); +}); diff --git a/web-ui/src/pages/__snapshots__/CertificationReportPage.test.jsx.snap b/web-ui/src/pages/__snapshots__/CertificationReportPage.test.jsx.snap new file mode 100644 index 000000000..3aa7fb840 --- /dev/null +++ b/web-ui/src/pages/__snapshots__/CertificationReportPage.test.jsx.snap @@ -0,0 +1,145 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`renders an error if user does not have appropriate permission 1`] = ` +
+

+ You do not have permission to view this page. +

+
+`; + +exports[`renders correctly 1`] = ` +
+
+ +
+
+
+
+
+ +
+
+
+

+ Earned Certifications +

+
+
+
+
+ + + + + + + + + + + + + + +
+ Member + 🔼 + + Name + + Description + + Earned On + + Expiration + + Validation Image + + Badge + + Actions +
+ +
+
+
+
+
+
+`; diff --git a/web-ui/src/pages/__snapshots__/CheckinsReportPage.test.jsx.snap b/web-ui/src/pages/__snapshots__/CheckinsReportPage.test.jsx.snap new file mode 100644 index 000000000..5d5ddc2f5 --- /dev/null +++ b/web-ui/src/pages/__snapshots__/CheckinsReportPage.test.jsx.snap @@ -0,0 +1,214 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`renders an error if user does not have appropriate permission 1`] = ` +
+

+ You do not have permission to view this page. +

+
+`; + +exports[`renders correctly 1`] = ` +
+
+
+
+
+ +
+
+ Select PDLs +
+
+ ( + 0 + ) +
+
+
+
+
+
+ + +
+
+
+
+
+
+ +
+ + Q4 2024 + +
+ +
+
+
+
+ Start of Quarter +
+
+ Tue Oct 01 2024 +
+
+
+
+ End of Quarter +
+
+ Tue Dec 31 2024 +
+
+
+
+
+
+

+ No PDLs selected +

+

+ Please select some PDLs using the Member Selector. +

+
+
+
+
+`; diff --git a/web-ui/src/pages/__snapshots__/EmailPage.test.jsx.snap b/web-ui/src/pages/__snapshots__/EmailPage.test.jsx.snap new file mode 100644 index 000000000..94d95652a --- /dev/null +++ b/web-ui/src/pages/__snapshots__/EmailPage.test.jsx.snap @@ -0,0 +1,305 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`renders an error if user does not have appropriate permission 1`] = ` +
+

+ You do not have permission to view this page. +

+
+`; + +exports[`renders correctly 1`] = ` +
+ +
+`; diff --git a/web-ui/src/pages/__snapshots__/KudosPage.test.jsx.snap b/web-ui/src/pages/__snapshots__/KudosPage.test.jsx.snap new file mode 100644 index 000000000..e9ba24daa --- /dev/null +++ b/web-ui/src/pages/__snapshots__/KudosPage.test.jsx.snap @@ -0,0 +1,126 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`renders correctly 1`] = ` +
+
+
+ +
+
+
+
+
+ + +
+ +
+
+
+
+ +
+`; diff --git a/web-ui/src/pages/__snapshots__/ManageKudosPage.test.jsx.snap b/web-ui/src/pages/__snapshots__/ManageKudosPage.test.jsx.snap new file mode 100644 index 000000000..65f1090a7 --- /dev/null +++ b/web-ui/src/pages/__snapshots__/ManageKudosPage.test.jsx.snap @@ -0,0 +1,163 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`renders an error if user does not have appropriate permission 1`] = ` +
+

+ You do not have permission to view this page. +

+
+`; + +exports[`renders correctly 1`] = ` +
+
+
+
+
+
+ + +
+ +
+
+
+ +
+ + + + +
+
+
+
+ +
+`; diff --git a/web-ui/src/pages/__snapshots__/MeritReportPage.test.jsx.snap b/web-ui/src/pages/__snapshots__/MeritReportPage.test.jsx.snap new file mode 100644 index 000000000..d837e9309 --- /dev/null +++ b/web-ui/src/pages/__snapshots__/MeritReportPage.test.jsx.snap @@ -0,0 +1,273 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`renders an error if user does not have appropriate permission 1`] = ` +
+

+ You do not have permission to view this page. +

+
+`; + +exports[`renders correctly 1`] = ` +
+
+ + + +
+ +
+
+
+
+ +
+
+ Selected Members +
+
+ ( + 0 + ) +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+ +
+ + +
+ +
+
+
+
+ +
+
+`; diff --git a/web-ui/src/pages/__snapshots__/ProfilePage.test.jsx.snap b/web-ui/src/pages/__snapshots__/ProfilePage.test.jsx.snap new file mode 100644 index 000000000..257c38b7c --- /dev/null +++ b/web-ui/src/pages/__snapshots__/ProfilePage.test.jsx.snap @@ -0,0 +1,746 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`renders correctly 1`] = ` +
+
+
+
+ Profile +
+
+
+
+
+ +
+
+

+ Mitch Hedberg +

+

+ Strategic Placement Specialist +

+
+
+

+ + hedbergm@objectcomputing.com + +
+ Location: + Roseville, Minnesota +
+ Supervisor: +
+ Current PDL: +
+

+
+
+
+
+
+
+
+
+
+ +
+
+
+

+ Bio +

+
+
+
+
+
+ +