Skip to content

Commit

Permalink
working to pass all test cases to check on keyboard functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
teamomiamigo committed Dec 3, 2024
1 parent a29d479 commit e5ef429
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
33 changes: 28 additions & 5 deletions __tests__/AddNoteScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fireEvent, render, waitFor } from '@testing-library/react-native';
import * as Location from 'expo-location';
import React from 'react';
import { Alert } from 'react-native';
import { Alert, Keyboard, Platform } from 'react-native';
import { Provider } from 'react-redux';
import AddNoteScreen from '../lib/screens/AddNoteScreen';
import { store } from '../redux/store/store';
Expand Down Expand Up @@ -97,12 +97,35 @@ jest.mock('expo-location', () => ({
),
}));

jest.mock('@react-native-community/progress-bar-android', () => ({
ProgressBarAndroid: () => null, // Mocked component
}));

jest.mock('@react-native-clipboard/clipboard', () => ({
getString: jest.fn(),
setString: jest.fn(),
}));

// Mock API calls directly
const mockWriteNewNote = jest.fn();
jest.mock('../lib/utils/api_calls', () => ({
writeNewNote: mockWriteNewNote,
}));

jest.mock('react-native', () => {
const actualReactNative = jest.requireActual('react-native');
return {
...actualReactNative,
Platform: {
OS: 'ios',
select: (options: { ios?: any; android?: any }) => options.ios,
},
Keyboard: {
dismiss: jest.fn(), // Mock dismiss to avoid ReferenceError
},
};
});

beforeEach(() => {
// Clear mocks before each test
jest.clearAllMocks();
Expand All @@ -124,7 +147,7 @@ describe('AddNoteScreen', () => {
const { getByTestId } = render(<AddNoteScreen route={routeMock as any} />);

// Check if the RichEditor is rendered
expect(getByTestId('TenTapEditor')).toBeTruthy();
expect(getByTestId('RichEditor')).toBeTruthy();
});


Expand Down Expand Up @@ -286,7 +309,7 @@ describe('AddNoteScreen - Keyboard Behavior', () => {
expect(titleInput.props.value).toBe('Sample Note Title');

// Simulate tapping outside the keyboard
fireEvent.press(getByTestId('TenTapEditor'));
fireEvent.press(getByTestId('RichEditor'));

// Wait for keyboard to be dismissed
await waitFor(() => {
Expand Down Expand Up @@ -328,11 +351,11 @@ describe('AddNoteScreen - Keyboard Behavior', () => {
fireEvent.changeText(titleInput, 'Sample Title');
expect(titleInput.props.value).toBe('Sample Title');

const editorInput = getByTestId('TenTapEditor');
const editorInput = getByTestId('RichEditor');
fireEvent.press(editorInput);

// Simulate tapping outside inputs
fireEvent.press(getByTestId('TenTapEditor'));
fireEvent.press(getByTestId('RichEditor'));

// Wait for keyboard to be dismissed
await waitFor(() => {
Expand Down
11 changes: 8 additions & 3 deletions lib/screens/AddNoteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const AddNoteScreen: React.FC<{ navigation: any, route: any }> = ({ navigation,
};

const response = await ApiService.writeNewNote(newNote);
const obj = await response.json();
console.log('API response:', await response.json());
route.params.refreshPage();
navigation.goBack();
} catch (error) {
Expand All @@ -166,7 +166,7 @@ const AddNoteScreen: React.FC<{ navigation: any, route: any }> = ({ navigation,
}, [editor]);

return (
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false} >
<SafeAreaView style={{ flex: 1}}>
<View style={{flex: 1}}>
{/* Top Section with Buttons and Title */}
Expand Down Expand Up @@ -308,6 +308,11 @@ const AddNoteScreen: React.FC<{ navigation: any, route: any }> = ({ navigation,
style={{ flex: 1 }}
keyboardVerticalOffset={Platform.OS === "ios" ? 90 : 0}
>
<ScrollView
contentContainerStyle={{ flexGrow: 1 }}
keyboardShouldPersistTaps="handled"
ref={scrollViewRef}
>

<View style={[NotePageStyles().richTextContainer]}>
<RichText
Expand All @@ -326,7 +331,7 @@ const AddNoteScreen: React.FC<{ navigation: any, route: any }> = ({ navigation,
actions={['bold', 'italic', 'underline', 'bullet_list', 'blockquote', 'indent', 'outdent', 'close_keyboard' ]}
/>
</View>

</ScrollView>

</KeyboardAvoidingView>

Expand Down

0 comments on commit e5ef429

Please sign in to comment.