This commit implements role-based permission testing and documentation for the beneficiary management system. The role-based UI was already correctly implemented in BeneficiaryMenu.tsx (lines 21-25). This commit adds: - Comprehensive test suite for BeneficiaryMenu role permissions - Test suite for role-based edit modal functionality - Detailed documentation in docs/ROLE_BASED_PERMISSIONS.md - Jest configuration for future testing - testID added to menu button for testing accessibility Role Permission Summary: - Custodian: Full access (all features including remove) - Guardian: Most features (cannot remove beneficiary) - Caretaker: Limited access (dashboard, edit nickname, sensors only) Edit Functionality: - Custodians can edit full profile (name, address, avatar) - Guardians/Caretakers can only edit personal nickname (customName) - Backend validates all permissions server-side for security Tests verify: ✅ Menu items filtered correctly by role ✅ Custodian has full edit capabilities ✅ Guardian/Caretaker limited to nickname editing only ✅ Default role is caretaker (security-first approach) ✅ Navigation routes work correctly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
// Setup testing library
|
|
import '@testing-library/react-native/extend-expect';
|
|
|
|
// Mock Expo modules
|
|
jest.mock('expo-router', () => ({
|
|
router: {
|
|
push: jest.fn(),
|
|
replace: jest.fn(),
|
|
back: jest.fn(),
|
|
setParams: jest.fn(),
|
|
},
|
|
useLocalSearchParams: jest.fn(() => ({})),
|
|
useRouter: jest.fn(() => ({
|
|
push: jest.fn(),
|
|
replace: jest.fn(),
|
|
back: jest.fn(),
|
|
})),
|
|
useSegments: jest.fn(() => []),
|
|
usePathname: jest.fn(() => '/'),
|
|
}));
|
|
|
|
jest.mock('expo-secure-store', () => ({
|
|
getItemAsync: jest.fn(),
|
|
setItemAsync: jest.fn(),
|
|
deleteItemAsync: jest.fn(),
|
|
}));
|
|
|
|
jest.mock('expo-image-picker', () => ({
|
|
requestMediaLibraryPermissionsAsync: jest.fn(() =>
|
|
Promise.resolve({ status: 'granted' })
|
|
),
|
|
launchImageLibraryAsync: jest.fn(() =>
|
|
Promise.resolve({
|
|
canceled: false,
|
|
assets: [{ uri: 'file://test-image.jpg' }],
|
|
})
|
|
),
|
|
}));
|
|
|
|
// Mock native modules
|
|
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
|
|
|
|
// Silence console warnings in tests
|
|
global.console = {
|
|
...console,
|
|
warn: jest.fn(),
|
|
error: jest.fn(),
|
|
};
|