From 64087477bf9611fe5465a49dd02de6220237ec89 Mon Sep 17 00:00:00 2001 From: Eleni Chappen Date: Wed, 30 Oct 2024 16:34:14 -0500 Subject: [PATCH 01/15] stash: start of authenticated homepage --- __tests__/controllers/controllers.test.js | 78 +++++++++++++++++++ public/img/uswds/usa-icons/assessment.svg | 9 +++ public/img/uswds/usa-icons/help.svg | 9 +++ public/img/uswds/usa-icons/people.svg | 9 +++ src/app/{orgs => }/error.tsx | 0 src/app/layout.js | 6 +- src/app/orgs/layout.tsx | 2 +- src/app/page.tsx | 95 +++++++++++++++++++++++ src/app/{page.js => prototype/page.tsx} | 2 +- src/components/Card/Card.tsx | 17 +++- src/components/PreFooter.tsx | 27 +++++++ src/controllers/controllers.ts | 32 ++++++++ 12 files changed, 279 insertions(+), 7 deletions(-) create mode 100644 public/img/uswds/usa-icons/assessment.svg create mode 100644 public/img/uswds/usa-icons/help.svg create mode 100644 public/img/uswds/usa-icons/people.svg rename src/app/{orgs => }/error.tsx (100%) create mode 100644 src/app/page.tsx rename src/app/{page.js => prototype/page.tsx} (98%) create mode 100644 src/components/PreFooter.tsx diff --git a/__tests__/controllers/controllers.test.js b/__tests__/controllers/controllers.test.js index 37e8ba80..9eb4e47f 100644 --- a/__tests__/controllers/controllers.test.js +++ b/__tests__/controllers/controllers.test.js @@ -1,4 +1,5 @@ import nock from 'nock'; +import { cookies } from 'next/headers'; import { describe, it, expect, beforeEach, afterEach } from '@jest/globals'; import { getEditOrgRoles, @@ -8,6 +9,7 @@ import { getOrgUsagePage, getUser, removeUserFromOrg, + getHomepage, } from '@/controllers/controllers'; import { pollForJobCompletion } from '@/controllers/controller-helpers'; import { mockApps } from '../api/mocks/apps'; @@ -16,6 +18,7 @@ import { mockUsersByOrganization, mockUsersBySpace, } from '../api/mocks/roles'; +import { mockOrgs } from '../api/mocks/organizations'; import { getUserLogonInfo } from '@/api/aws/s3'; /* global jest */ @@ -36,6 +39,9 @@ jest.mock('@/controllers/controller-helpers', () => ({ jest.mock('@/api/aws/s3', () => ({ getUserLogonInfo: jest.fn(), })); +jest.mock('next/headers', () => ({ + cookies: jest.fn(), +})); /* eslint no-undef: "error" */ beforeEach(() => { @@ -579,4 +585,76 @@ describe('controllers tests', () => { ]); }); }); + + describe('getHomepage', () => { + it('sets correct orgs, roles, and user counts', async () => { + // setup + nock(process.env.CF_API_URL) + .get(/organizations/) + .reply(200, mockOrgs); + + nock(process.env.CF_API_URL) + .get(/roles/) + .reply(200, mockRolesFilteredByOrgAndUser); + + cookies.mockImplementation(() => ({ + get: () => ({ value: '{"lastViewedOrgId": null}' }), + })); + // act + const result = await getHomepage(); + // assert orgs + expect(result.payload.orgs.length).toEqual(3); + expect(result.payload.orgs[0].name).toEqual('Org1'); + // assert roles + expect(result.payload.currentUserRoles.length).toEqual(2); + // assert user counts + expect(result.payload.userCounts['orgId2']).toEqual(1); // see mock implementation at top of file + }); + + describe('when a last viewed org id cookie is present', () => { + it('sets current org id to that cookie', async () => { + // setup + nock(process.env.CF_API_URL) + .get(/organizations/) + .reply(200, mockOrgs); + + nock(process.env.CF_API_URL) + .get(/roles/) + .reply(200, mockRolesFilteredByOrgAndUser); + + cookies.mockImplementation(() => ({ + get: () => ({ value: 'f114757b-568a-4291-a389-6b97e6b47c47' }), + })); // guid from mockOrgs + // act + const result = await getHomepage(); + // assert + expect(result.payload.currentOrgId).toEqual( + 'f114757b-568a-4291-a389-6b97e6b47c47' + ); + }); + }); + + describe('when no last viewed org id cookie', () => { + it('sets current org id to first returned org from orgs list', async () => { + // setup + nock(process.env.CF_API_URL) + .get(/organizations/) + .reply(200, mockOrgs); + + nock(process.env.CF_API_URL) + .get(/roles/) + .reply(200, mockRolesFilteredByOrgAndUser); + + cookies.mockImplementation(() => ({ + get: () => ({ value: null }), + })); // guid from mockOrgs + // act + const result = await getHomepage(); + // assert + expect(result.payload.currentOrgId).toEqual( + 'b4b52bd5-4940-456a-9432-90c168af6cf8' + ); + }); + }); + }); }); diff --git a/public/img/uswds/usa-icons/assessment.svg b/public/img/uswds/usa-icons/assessment.svg new file mode 100644 index 00000000..520ad6af --- /dev/null +++ b/public/img/uswds/usa-icons/assessment.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/public/img/uswds/usa-icons/help.svg b/public/img/uswds/usa-icons/help.svg new file mode 100644 index 00000000..3ebf817b --- /dev/null +++ b/public/img/uswds/usa-icons/help.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/public/img/uswds/usa-icons/people.svg b/public/img/uswds/usa-icons/people.svg new file mode 100644 index 00000000..6a805e7b --- /dev/null +++ b/public/img/uswds/usa-icons/people.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/app/orgs/error.tsx b/src/app/error.tsx similarity index 100% rename from src/app/orgs/error.tsx rename to src/app/error.tsx diff --git a/src/app/layout.js b/src/app/layout.js index 03b5e375..12d99530 100644 --- a/src/app/layout.js +++ b/src/app/layout.js @@ -2,6 +2,7 @@ import { Banner } from '@/components/uswds/Banner'; import { Footer } from '@/components/uswds/Footer'; import { Identifier } from '@/components/uswds/Identifier'; import { NavGlobal } from '@/components/NavGlobal/NavGlobal'; +import { PreFooter } from '@/components/PreFooter'; import '@/assets/stylesheets/styles.scss'; @@ -20,8 +21,11 @@ export default function RootLayout({ children }) {
-
{children}
+
+
{children}
+
+