diff --git a/.ollama/ExampleTest.spec.tsx b/.ollama/ExampleTest.spec.tsx index 22572b9..547610e 100644 --- a/.ollama/ExampleTest.spec.tsx +++ b/.ollama/ExampleTest.spec.tsx @@ -10,6 +10,19 @@ import React, { act } from 'react'; import { render, screen } from '@testing-library/react-native' import { MyComponent } from '@/app/component/MyComponent'; +/** + * IMPORTANT NOTE: If you need to use jest mock, remember that + * you cannot include any external components in the mock. + * You absolutely must use `jest.requireActual` to import the + * component *within* the jest.mock callback. +*/ +jest.mock('@/app/component/index.tsx', () => { + // Require-actual the component + const { Text } = jest.requireActual('react-native'); + // Use the component. + return () => Index + }); + describe('Message Component', () => { beforeEach(() => { diff --git a/.vscode/settings.json b/.vscode/settings.json index ceac0b1..7a73a41 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,2 @@ { - "jestTestExplorer.pathToJest": "./node_modules/.bin/jest" } \ No newline at end of file diff --git a/__mocks__/expo-file-system.js b/__mocks__/expo-file-system.js new file mode 100644 index 0000000..806c408 --- /dev/null +++ b/__mocks__/expo-file-system.js @@ -0,0 +1,10 @@ +// __mocks__/expo-file-system.js +export const File = { + // Define the properties and methods you need for your tests + uri: 'file:///path/to/file', +}; + +export const Paths = { + // Define the paths you need for your tests + DOCUMENTS_DIRECTORY: '/path/to/documents', +}; \ No newline at end of file diff --git a/app/_layout.tsx b/app/_layout.tsx index 7c5456c..cbdfbdf 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -5,17 +5,12 @@ import { LanguageSelection } from '@/components/LanguageSelection'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import ConversationThread from '@/components/ConversationThread'; import Home from '.'; +import TTNavStack from '@/components/TTNavStack'; const Stack = createNativeStackNavigator(); export default function Layout() { return ( - - - - - - - + ); } \ No newline at end of file diff --git a/components/TTNavStack.tsx b/components/TTNavStack.tsx new file mode 100644 index 0000000..ceb1a9a --- /dev/null +++ b/components/TTNavStack.tsx @@ -0,0 +1,20 @@ +import * as React from 'react'; +import { NavigationContainer } from '@react-navigation/native'; +import SettingsComponent from '@/components/Settings'; +import { LanguageSelection } from '@/components/LanguageSelection'; +import { createNativeStackNavigator } from '@react-navigation/native-stack'; +import ConversationThread from '@/components/ConversationThread'; + +const Stack = createNativeStackNavigator(); + +export default function TTNavStack() { + return ( + + + + + + + + ); +} \ No newline at end of file diff --git a/components/__tests__/index.spec.tsx b/components/__tests__/index.spec.tsx new file mode 100644 index 0000000..5831151 --- /dev/null +++ b/components/__tests__/index.spec.tsx @@ -0,0 +1,30 @@ +import React from 'react'; +import { fireEvent, render, screen } from '@testing-library/react-native'; +import { NavigationContainer } from '@react-navigation/native'; +import { createStackNavigator } from '@react-navigation/stack'; +import TTNavStack from '../TTNavStack'; + +jest.mock('expo-file-system', () => require('./__mocks__/expo-file-system')); + +const Stack = createStackNavigator(); + +describe('Navigation', () => { + beforeEach(() => { + // Reset the navigation state before each test + jest.clearAllMocks(); + }); + + it('Navigates to ConversationThread on language selection', async () => { + render(); + const languageSelectionText = await screen.findByText("Language Selection"); + fireEvent.press(languageSelectionText); + expect(await screen.findByText("Conversation Thread")).toBeOnTheScreen(); + }); + + it('Navigates to Settings on settings selection', async () => { + render(); + const settingsButton = await screen.findByText("Settings"); + fireEvent.press(settingsButton); + expect(await screen.findByText("Settings")).toBeOnTheScreen(); + }); +}); \ No newline at end of file diff --git a/package.json b/package.json index 7f476d1..da0ed3c 100644 --- a/package.json +++ b/package.json @@ -64,20 +64,10 @@ "transformIgnorePatterns": [ "node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg)" ], - "collectCoverage": true, - "collectCoverageFrom": [ - "**/*.{ts,tsx,js,jsx}", - "!**/coverage/**", - "!**/node_modules/**", - "!**/babel.config.js", - "!**/expo-env.d.ts", - "!**/.expo/**" - ], "automock": false, "setupFilesAfterEnv": [ "/jestSetup.ts" - ], - "testTimeout": 10000 + ] }, "devDependencies": { "@babel/core": "^7.26.7",