From e5ef4294a9fb02a792df53824eec3eaafd6e9a8b Mon Sep 17 00:00:00 2001 From: teamomiamigo Date: Tue, 3 Dec 2024 16:58:54 -0600 Subject: [PATCH] working to pass all test cases to check on keyboard functionality --- __tests__/AddNoteScreen.test.tsx | 33 +++++++++++++++++++++++++++----- lib/screens/AddNoteScreen.tsx | 11 ++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/__tests__/AddNoteScreen.test.tsx b/__tests__/AddNoteScreen.test.tsx index 5452ac4..9b9a37c 100644 --- a/__tests__/AddNoteScreen.test.tsx +++ b/__tests__/AddNoteScreen.test.tsx @@ -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'; @@ -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(); @@ -124,7 +147,7 @@ describe('AddNoteScreen', () => { const { getByTestId } = render(); // Check if the RichEditor is rendered - expect(getByTestId('TenTapEditor')).toBeTruthy(); + expect(getByTestId('RichEditor')).toBeTruthy(); }); @@ -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(() => { @@ -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(() => { diff --git a/lib/screens/AddNoteScreen.tsx b/lib/screens/AddNoteScreen.tsx index b8e6f05..320f296 100644 --- a/lib/screens/AddNoteScreen.tsx +++ b/lib/screens/AddNoteScreen.tsx @@ -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) { @@ -166,7 +166,7 @@ const AddNoteScreen: React.FC<{ navigation: any, route: any }> = ({ navigation, }, [editor]); return ( - + {/* Top Section with Buttons and Title */} @@ -308,6 +308,11 @@ const AddNoteScreen: React.FC<{ navigation: any, route: any }> = ({ navigation, style={{ flex: 1 }} keyboardVerticalOffset={Platform.OS === "ios" ? 90 : 0} > + = ({ navigation, actions={['bold', 'italic', 'underline', 'bullet_list', 'blockquote', 'indent', 'outdent', 'close_keyboard' ]} /> - +