Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/testing mobile #328

Merged
merged 16 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added frontend/occupi-mobile4/jest
Empty file.
Empty file.
Empty file.
16 changes: 8 additions & 8 deletions frontend/occupi-mobile4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
"jest": {
"preset": "jest-expo",
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg|moti|@gluestack-ui/themed|gifted-charts-core)"
"node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg|@gluestack-ui/themed|expo-device)"
],
"collectCoverage": true,
"coverageReporters": [
"lcov",
"text"
],
"coverageDirectory": "coverage"
}
,
"coverageReporters": ["lcov", "text"],
"coverageDirectory": "coverage",
"setupFiles": [
"./node_modules/react-native-gesture-handler/jestSetup.js",
"./jest.setup.js"
]
},
"dependencies": {
"@eva-design/eva": "^2.2.0",
"@expo/vector-icons": "^14.0.0",
Expand Down
25 changes: 13 additions & 12 deletions frontend/occupi-mobile4/screens/Settings/Appearance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const Appearance = () => {
<ScrollView flex={1} backgroundColor={currentTheme === 'dark' ? 'black' : 'white'} px="$4" pt="$16">
<View style={styles.header}>
<Icon
testID="back-button"
as={Feather}
name="chevron-left"
size="xl"
Expand All @@ -103,7 +104,7 @@ const Appearance = () => {
<View mt="$4" flexDirection="column" >
<Text color={currentTheme === 'dark' ? 'white' : 'black'}>Mode</Text>
<View p="$8" justifyContent='space-between' flexDirection='row' borderRadius={18} my="$2" height={hp('28%')} backgroundColor={currentTheme === 'dark' ? '#2C2C2E' : '#F3F3F3'}>
<TouchableOpacity onPress={() => setTheme("light")} style={{ width: wp('25%') }}>
<TouchableOpacity onPress={() => setTheme("light")} style={{ width: wp('25%') }}>
<View alignItems='center'>
<Image
h={hp('18%')}
Expand Down Expand Up @@ -151,55 +152,55 @@ const Appearance = () => {
<Text mt="$2" color={currentTheme === 'dark' ? 'white' : 'black'}>Accent colour</Text>
<View p="$5" borderRadius={18} justifyContent='space-between' my="$2" height={hp('18%')} backgroundColor={currentTheme === 'dark' ? '#2C2C2E' : '#F3F3F3'}>
<View flexDirection="row" justifyContent='space-between'>
<TouchableOpacity onPress={() => setAccentColour("lightgrey")}>
<TouchableOpacity testID={`color-option-${color}`} onPress={() => setAccentColour("lightgrey")}>
<View borderColor='lightgrey' borderRadius="$full" borderWidth={accentColour === 'lightgrey' ? 2 : 0}>
<View w="$12" h="$12" paddingHorizontal={3} borderColor={currentTheme === 'dark' ? '#2C2C2E' : '#F3F3F3'} borderRadius="$full" borderWidth={2.5} name="circle" backgroundColor="lightgrey" />
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => setAccentColour("#FF4343")}>
<TouchableOpacity testID={`color-option-${color}`} onPress={() => setAccentColour("#FF4343")}>
<View borderColor='#FF4343' borderRadius="$full" borderWidth={accentColour === '#FF4343' ? 2 : 0}>
<View w="$12" h="$12" paddingHorizontal={3} borderColor={currentTheme === 'dark' ? '#2C2C2E' : '#F3F3F3'} borderRadius="$full" borderWidth={2.5} name="circle" backgroundColor="#FF4343" />
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => setAccentColour("#FFB443")}>
<TouchableOpacity testID={`color-option-${color}`} onPress={() => setAccentColour("#FFB443")}>
<View borderColor='#FFB443' borderRadius="$full" borderWidth={accentColour === '#FFB443' ? 2 : 0}>
<View w="$12" h="$12" paddingHorizontal={3} borderColor={currentTheme === 'dark' ? '#2C2C2E' : '#F3F3F3'} borderRadius="$full" borderWidth={2.5} name="circle" backgroundColor="#FFB443" />
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => setAccentColour("greenyellow")}>
<TouchableOpacity testID={`color-option-${color}`} onPress={() => setAccentColour("greenyellow")}>
<View borderColor='greenyellow' borderRadius="$full" borderWidth={accentColour === 'greenyellow' ? 2 : 0}>
<View w="$12" h="$12" paddingHorizontal={3} borderColor={currentTheme === 'dark' ? '#2C2C2E' : '#F3F3F3'} borderRadius="$full" borderWidth={2.5} name="circle" backgroundColor="greenyellow" />
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => setAccentColour("#43FF61")}>
<TouchableOpacity testID={`color-option-${color}`} onPress={() => setAccentColour("#43FF61")}>
<View borderColor='#43FF61' borderRadius="$full" borderWidth={accentColour === '#43FF61' ? 2 : 0}>
<View w="$12" h="$12" paddingHorizontal={3} borderColor={currentTheme === 'dark' ? '#2C2C2E' : '#F3F3F3'} borderRadius="$full" borderWidth={2.5} name="circle" backgroundColor="#43FF61" />
</View>
</TouchableOpacity>
</View>
<View flexDirection="row" justifyContent='space-between'>
<TouchableOpacity onPress={() => setAccentColour("#43F4FF")}>
<TouchableOpacity testID={`color-option-${color}`} onPress={() => setAccentColour("#43F4FF")}>
<View borderColor='#43F4FF' borderRadius="$full" borderWidth={accentColour === '#43F4FF' ? 2 : 0}>
<View w="$12" h="$12" paddingHorizontal={3} borderColor={currentTheme === 'dark' ? '#2C2C2E' : '#F3F3F3'} borderRadius="$full" borderWidth={2.5} name="circle" backgroundColor="#43F4FF" />
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => setAccentColour("#4383FF")}>
<TouchableOpacity testID={`color-option-${color}`} onPress={() => setAccentColour("#4383FF")}>
<View borderColor='#4383FF' borderRadius="$full" borderWidth={accentColour === '#4383FF' ? 2 : 0}>
<View w="$12" h="$12" paddingHorizontal={3} borderColor={currentTheme === 'dark' ? '#2C2C2E' : '#F3F3F3'} borderRadius="$full" borderWidth={2.5} name="circle" backgroundColor="#4383FF" />
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => setAccentColour("#AC43FF")}>
<TouchableOpacity testID={`color-option-${color}`} onPress={() => setAccentColour("#AC43FF")}>
<View borderColor='#AC43FF' borderRadius="$full" borderWidth={accentColour === '#AC43FF' ? 2 : 0}>
<View w="$12" h="$12" paddingHorizontal={3} borderColor={currentTheme === 'dark' ? '#2C2C2E' : '#F3F3F3'} borderRadius="$full" borderWidth={2.5} name="circle" backgroundColor="#AC43FF" />
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => setAccentColour("#FF43F7")}>
<TouchableOpacity testID={`color-option-${color}`} onPress={() => setAccentColour("#FF43F7")}>
<View borderColor='#FF43F7' borderRadius="$full" borderWidth={accentColour === '#FF43F7' ? 2 : 0}>
<View w="$12" h="$12" paddingHorizontal={3} borderColor={currentTheme === 'dark' ? '#2C2C2E' : '#F3F3F3'} borderRadius="$full" borderWidth={2.5} name="circle" backgroundColor="#FF43F7" />
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => setAccentColour("purple")}>
<View borderColor='purple' borderRadius="$full" borderWidth={accentColour === 'purple' ? 2 : 0} onPress={() => setAccentColour("#FF4343")}>
<TouchableOpacity testID={`color-option-${color}`} onPress={() => setAccentColour("purple")}>
<View borderColor='purple' borderRadius="$full" borderWidth={accentColour === 'purple' ? 2 : 0} testID={`color-option-${color}`} onPress={() => setAccentColour("#FF4343")}>
<View w="$12" h="$12" paddingHorizontal={3} borderColor={currentTheme === 'dark' ? '#2C2C2E' : '#F3F3F3'} borderRadius="$full" borderWidth={2.5} name="circle" backgroundColor="purple" />
</View>
</TouchableOpacity>
Expand Down
10 changes: 5 additions & 5 deletions frontend/occupi-mobile4/screens/Settings/FAQPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ const FAQPage = () => {
<View key={`section-${sectionIndex}`} style={{ marginBottom: 20, backgroundColor: isDarkMode ? 'black' : 'white'}}>
<Text style={{ fontSize: 19, fontWeight: 'bold', color: isDarkMode ? 'white' : 'black', marginBottom: 10 }}>{section.section}</Text>
{section.questions.map((item, index) => (
<AccordionItem key={`item-${sectionIndex}-${index}`} value={`item-${sectionIndex}-${index}`} style={{ backgroundColor: isDarkMode ? 'black' : 'white'}}>
<AccordionHeader style={{ backgroundColor: isDarkMode ? '#2C2C2E' : '#F3F3F3', borderRadius: 10, marginBottom: 10 }}>
<AccordionItem key={`item-${sectionIndex}-${index}`} value={`item-${sectionIndex}-${index}`}>
<AccordionHeader>
<AccordionTrigger>
<Text style={{ color: isDarkMode ? 'white' : 'black', fontSize: 16, fontWeight: 'bold' }}>{item.question}</Text>
<Text testID={`faq-question-${sectionIndex}-${index}`} style={{ color: isDarkMode ? 'white' : 'black' }}>{item.question}</Text>
</AccordionTrigger>
</AccordionHeader>
<AccordionContent style={{ backgroundColor: isDarkMode ? 'black' : 'white', borderRadius: 10 }}>
<Text style={{ color: isDarkMode ? '#CCCCCC' : '#333333', fontSize: 14 }}>{item.answer}</Text>
<AccordionContent>
<Text testID={`faq-answer-${sectionIndex}-${index}`} style={{ color: isDarkMode ? 'white' : 'black' }}>{item.answer}</Text>
</AccordionContent>
</AccordionItem>
))}
Expand Down
56 changes: 56 additions & 0 deletions frontend/occupi-mobile4/services/__tests__/aimodel-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import axios from 'axios';
import { getPredictions, getDayPredictions, Prediction } from '../aimodel';

jest.mock('axios');

describe('aimodel', () => {
let consoleErrorMock: jest.SpyInstance;

beforeEach(() => {
consoleErrorMock = jest.spyOn(console, 'error').mockImplementation(() => {});
});

afterEach(() => {
consoleErrorMock.mockRestore();
});

describe('getPredictions', () => {
it('should return an array of Prediction objects', async () => {
const mockPredictions: Prediction[] = [
{ value: 123, timestamp: new Date() },
{ value: 456, timestamp: new Date() },
];

(axios.get as jest.Mock).mockResolvedValue({ data: mockPredictions });

const predictions = await getPredictions();
expect(predictions).toEqual(mockPredictions);
});

it('should handle errors and return undefined', async () => {
(axios.get as jest.Mock).mockRejectedValue(new Error('Network error'));

const predictions = await getPredictions();
expect(predictions).toBeUndefined();
});
});

describe('getDayPredictions', () => {
it('should return a Prediction object', async () => {
const mockPrediction: Prediction = { value: 789, timestamp: new Date() };

(axios.get as jest.Mock).mockResolvedValue({ data: mockPrediction });

const prediction = await getDayPredictions();
expect(prediction).toEqual(mockPrediction);
});

it('should handle errors and return undefined', async () => {
(axios.get as jest.Mock).mockRejectedValue(new Error('Network error'));

const prediction = await getDayPredictions();
expect(prediction).toBeUndefined();
});

});
});
Loading
Loading