Skip to content

UKHSA-Internal/hpub-webapp-frontend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3,539 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Health Publication Frontend Documentation

Overview

This is the frontend application for the Health Publication platform, built using React with TypeScript support. The project consumes backend APIs and serves both the admin and public user interfaces. It supports CI/CD deployments to environments including dev, test, uat, preprod, and prod.

The application is integrated with Azure B2C for authentication and uses Redux for state management. Cypress is used for E2E testing.


Environments & Configuration

All environments are configured using public/env-config.js and .env files as needed.

Available Environments

  • dev
  • test
  • uat
  • preprod
  • prod

Environment-specific variables are injected during the build process using a script (see env-config.template.js).


CI/CD Deployment

Deployment is managed via GitHub Actions, and changes to main or tagged releases automatically trigger deployments to the appropriate environment on AWS S3 or CloudFront.

Pipeline Steps:

  1. Build

    • Installs dependencies and builds the static site with Vite.
  2. Test

    • Runs Jest unit tests and Cypress E2E tests.
  3. Deploy

    • Pushes the build artifacts to S3.
    • Invalidate CloudFront cache.

Running the Health Publications Frontend Code

Prerequisites

Ensure you have the following installed:

  • Node.js version 24 (Latest LTS)
  • npm (comes with Node.js)

Setup Instructions

  1. Clone the Repository
git clone <repository-url>
cd <repository-folder>
  1. Create the env-config.js File

Assume the AWS role for the desired environment, then run:

make env ENV=<env>

This command generates an env-config.js file in the public/ directory.

The file will be automatically populated with environment variables retrieved from the ECS task definition.

  1. Install Dependencies
npm install
  1. Run the Development Server
npm run dev

App will be available at: http://localhost:5173

Note
We have identified an issue where the application does not render correctly in Google Chrome on macOS.
Please use an alternative browser such as Safari, Firefox, or Microsoft Edge.

Running Unit Tests

To run all tests:

npm run test

To run a specific test file:

npm test [file]

Project Structure

Top-Level Folders

  • .github/ – GitHub Actions and workflows
  • src/ – Main frontend source code
  • public/ – Static assets and environment config loader
  • cypress/ – Cypress E2E test config and specs
  • docs/ – Project-level documentation

Key Subdirectories

  • src/components/ – React components (atoms, molecules, organisms)
  • src/pages/ – Route-based page components
  • src/redux/ – Feature-based state slices
  • src/services/ – API client and authentication logic
  • src/utils/ – Shared utility functions
  • src/hooks/ – Custom React hooks
  • src/layouts/ – Page layouts
  • src/context/ – Context providers
  • src/types/ – TypeScript types and interfaces

Public Assets

  • public/env-config.js – Injects runtime environment variables

Testing

Unit Tests (Jest)

npm run test

E2E Tests (Cypress)

npx cypress open

E2E test specs are located in:

  • automation_tests/e2e/

Building for Production

npm run build

Outputs static files to the dist/ directory. These files are then deployed via CI to S3 + CloudFront.


Linting & Formatting

ESLint

npm run lint

Prettier

npm run format

ESLint has been temporarily disabled during migration from the duplicate-feature branch. To re-enable linting, add the following to package.json:

"lint-staged": {
  "*.{js,jsx,ts,tsx,css,html}": [
    "prettier --write .",
    "eslint . --fix"
  ]
}

Pre-commit hooks are enforced using husky and lint-staged.


Authentication

Azure B2C is used for authentication. Configuration lives in:

  • src/msalInstance.tsx
  • src/authConfig.tsx

Protected routes are managed via ProtectedRoute.tsx.


Additional Notes

  • Ensure the env-config.js file is properly configured before starting the app.
  • Check for dependency issues if errors occur during startup.
  • Use the same AWS session credentials during build and test workflows.
  • Postman collections for backend APIs are available for reference.

Helpful Commands

# Build & serve locally
npm run preview

# Run Jest tests with coverage
npm run test:coverage

# Run specific Cypress test
npx cypress run --spec "automation_tests/e2e/HPUB-472_Empty_Basket_Guest.cy.ts"

Deployment Troubleshooting

  • Verify contents of public/env-config.js
  • Check GitHub Actions for CI pipeline logs
  • Validate CloudFront cache invalidation

General Information

This project uses Vite with hot module reloading and supports both Babel and SWC-based plugins:


Contacts