feat: add TemplateGrid and TitleBar components with tests

- Implemented TemplateGrid component for displaying templates in a grid layout.
- Added calculateCardWidth helper function for dynamic card sizing.
- Created TitleBar component for displaying the title and points with interaction.
- Added unit tests for TemplateGrid and TitleBar components to ensure proper functionality.
- Introduced useStickyTabs and useTabNavigation hooks with tests for managing sticky tab behavior and navigation logic.
- Implemented useTemplateFilter hook for filtering templates based on video content.
- Added comprehensive tests for all new hooks and components to validate behavior and edge cases.
This commit is contained in:
imeepos
2026-01-26 12:43:20 +08:00
parent bf11241d68
commit 2757b68756
23 changed files with 2637 additions and 586 deletions

View File

@@ -2,7 +2,6 @@
jest.mock('react-native', () => {
const React = require('react')
return {
...jest.requireActual('react-native'),
RefreshControl: 'RefreshControl',
ScrollView: 'ScrollView',
FlatList: 'FlatList',
@@ -10,6 +9,8 @@ jest.mock('react-native', () => {
Text: 'Text',
Image: 'Image',
Pressable: 'Pressable',
TouchableOpacity: 'TouchableOpacity',
TextInput: 'TextInput',
Platform: { OS: 'web' },
Animated: {
View: 'Animated.View',
@@ -34,6 +35,14 @@ jest.mock('react-native', () => {
StatusBar: 'StatusBar',
SafeAreaView: 'SafeAreaView',
useSafeAreaInsets: () => ({ top: 0, bottom: 0, left: 0, right: 0 }),
NativeModules: {
DevMenu: {},
SettingsManager: {},
},
Settings: {
get: jest.fn(),
set: jest.fn(),
},
}
})
@@ -75,6 +84,11 @@ jest.mock('expo-image', () => ({
Image: 'Image',
}))
// Mock expo-linear-gradient
jest.mock('expo-linear-gradient', () => ({
LinearGradient: 'LinearGradient',
}))
// Mock react-native-gesture-handler
jest.mock('react-native-gesture-handler', () => {
const { View } = require('react-native')
@@ -177,21 +191,8 @@ jest.mock('@repo/sdk', () => ({
CategoryController: class MockCategoryController {},
}))
// Mock react-native to avoid flow type issues
jest.mock('react-native', () => {
const RN = jest.requireActual('react-native')
return {
...RN,
// Ensure RefreshControl is properly mocked for tests
RefreshControl: 'RefreshControl',
// Mock DevMenu to avoid TurboModuleRegistry errors
NativeModules: {
...RN.NativeModules,
DevMenu: {},
SettingsManager: {},
},
}
})
// Note: The second react-native mock has been removed to avoid circular dependency issues
// The first mock at the top of this file handles all necessary react-native mocking
// Mock DevMenu module
jest.mock('react-native/src/private/devsupport/devmenu/DevMenu', () => ({