---
phase: 08-simplified-permissions
plan: 06
title: Unit Tests for Simplified Permissions
subsystem: tests
tags: [testing, permissions, simplified-mode, xunit]
dependency_graph:
  requires: [08-01, 08-02, 08-03, 08-04, 08-05]
  provides: [test-coverage-simplified-permissions]
  affects: [SharepointToolbox.Tests]
tech_stack:
  added: []
  patterns: [Theory-InlineData-parametric, WeakReferenceMessenger-Reset-isolation, helper-factory-method]
key_files:
  created:
    - SharepointToolbox.Tests/Helpers/PermissionLevelMappingTests.cs
    - SharepointToolbox.Tests/Models/PermissionSummaryBuilderTests.cs
  modified:
    - SharepointToolbox.Tests/ViewModels/PermissionsViewModelTests.cs
decisions:
  - Used CreateViewModelWithResults helper to avoid duplicating mock setup across 4 new ViewModel tests
metrics:
  duration: 104s
  completed: 2026-04-07T12:21:13Z
  tasks_completed: 2
  tasks_total: 2
  tests_added: 17
  tests_total_pass: 203
  tests_total_skip: 22
requirements:
  - SIMP-01
  - SIMP-02
  - SIMP-03
---

# Phase 08 Plan 06: Unit Tests for Simplified Permissions Summary

Unit tests for PermissionLevelMapping (11 known roles + unknown fallback + case insensitivity), PermissionSummaryBuilder (4 risk-level groups + distinct users), and PermissionsViewModel toggle behavior (simplified mode rebuild, detail toggle no-op, summary risk breakdown).

## Task Completion

| Task | Name | Commit | Files |
|------|------|--------|-------|
| 1 | Create PermissionLevelMapping and PermissionSummaryBuilder tests | 0f25fd6 | PermissionLevelMappingTests.cs, PermissionSummaryBuilderTests.cs |
| 2 | Add simplified mode tests to PermissionsViewModelTests | 22a51c0 | PermissionsViewModelTests.cs |

## Test Coverage Added

### PermissionLevelMappingTests (9 methods, 22 test cases with Theory)
- **GetMapping_KnownRoles_ReturnsCorrectRiskLevel** (11 InlineData): All built-in SharePoint roles mapped correctly
- **GetMapping_UnknownRole_ReturnsMediumRiskWithRawName**: Custom roles fall back to Medium with raw name
- **GetMapping_CaseInsensitive**: Mapping works regardless of casing
- **GetMappings_SemicolonDelimited_SplitsAndMaps**: Semicolon-delimited input correctly split
- **GetMappings_EmptyString_ReturnsEmpty**: Empty input handled gracefully
- **GetHighestRisk_MultipleLevels_ReturnsHighest**: High wins over Low
- **GetHighestRisk_SingleReadOnly_ReturnsReadOnly**: Single ReadOnly preserved
- **GetSimplifiedLabels_JoinsLabels**: Labels joined with semicolons

### PermissionSummaryBuilderTests (4 methods)
- **Build_ReturnsAllFourRiskLevels**: Always returns 4 groups even with 1 entry per level
- **Build_EmptyCollection_ReturnsZeroCounts**: Empty input returns 4 groups with count 0
- **Build_CountsDistinctUsers**: 3 entries with 2 distinct users counted correctly
- **SimplifiedPermissionEntry_WrapAll_PreservesInner**: Inner reference preserved, passthrough properties correct

### PermissionsViewModelTests (4 new methods, 5 total)
- **IsSimplifiedMode_Default_IsFalse**: Default state verification
- **IsSimplifiedMode_WhenToggled_RebuildsSimplifiedResults**: Toggle populates SimplifiedResults and Summaries
- **IsDetailView_Toggle_DoesNotChangeCounts**: Detail toggle does not re-compute data
- **Summaries_ContainsCorrectRiskBreakdown**: Risk counts match input entries

## Deviations from Plan

None - plan executed exactly as written.

## Verification

Full test suite: 203 passed, 22 skipped, 0 failed.
