Skip to content
Open
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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"lint:quiet": "eslint . --ext js,jsx,mjs,ts,tsx --quiet",
"prepare": "husky install",
"precommit": "npm run lint:fix && npm run format",
"prepush": "npm run lint"
"prepush": "npm run lint",
"test": "yarn workspace mobile test"
},
"workspaces": {
"packages": [
Expand Down Expand Up @@ -44,6 +45,6 @@
"@types/react": "^18.0.27",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.3",
"lerna": "^6.5.1"
"lerna": "^6.6.1"
}
}
1 change: 1 addition & 0 deletions packages/database-watermelon/jest_setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jest.mock('@nozbe/watermelondb/adapters/sqlite', () => '@nozbe/watermelondb/adapters/sqlite')
30 changes: 25 additions & 5 deletions packages/domain/__tests__/domain.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
'use strict'
import { act, create } from 'react-test-renderer'
import { DomainModule, YourFirstUseCase, YourFirstUseCaseParams } from 'domain-layer'
import { Obsidian } from 'di'
import { FirstModel } from 'shared'

import data from '../lib/domain'
import { expect, test } from '@jest/globals'
describe('YourFirstUseCase', () => {
describe('Testing verify method', () => {
it('should return true if emailOrPhone and password are provided', () => {
const params = new YourFirstUseCaseParams({ emailOrPhone: 'mailto:test@example.com', password: 'password' })
expect(params.verify()).toBe(true)
})

test('Hello from domain', () => {
expect(data()).toBe('Hello from domain')
it('should return false if emailOrPhone is not provided', () => {
const params = new YourFirstUseCaseParams({ emailOrPhone: '', password: 'password' })
expect(params.verify()).toBe(false)
})

it('should return false if password is not provided', () => {
const params = new YourFirstUseCaseParams({ emailOrPhone: 'mailto:test@example.com', password: '' })
expect(params.verify()).toBe(false)
})

it('should return false if both emailOrPhone and password are not provided', () => {
const params = new YourFirstUseCaseParams({ emailOrPhone: '', password: '' })
expect(params.verify()).toBe(false)
})
})
})
8 changes: 8 additions & 0 deletions packages/domain/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
// eslint-disable-next-line no-undef
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
setupFiles: ['../database-watermelon/jest_setup.ts'],
transformIgnorePatterns: ['../../node_modules/@nozbe']
}
12 changes: 9 additions & 3 deletions packages/domain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,21 @@
},
"scripts": {
"tsc": "tsc",
"test": "jest --verbose ./__tests__/domain.test.ts"
"test": "jest"
},
"bugs": {
"url": "https://github.com/NeoSOFT-Technologies/mobile-react-native/issues"
},
"dependencies": {
"@jest/globals": "^29.4.2",
"di": "^0.0.1",
"jest": "^29.4.2",
"shared": "^0.0.1"
"react-test-renderer": "^18.2.0",
"shared": "^0.0.1",
"typescript": "^5.0.4"
},
"devDependencies": {
"@types/jest": "^29.5.1",
"jest": "^29.5.0",
"ts-jest": "^29.1.0"
}
}
11 changes: 6 additions & 5 deletions packages/domain/src/usecases/your_first_usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class YourFirstUseCase extends FutureUseCase<YourFirstUseCaseParams, Firs
}

async execute(params: YourFirstUseCaseParams): Promise<FirstModel> {
if (params.verify) {
if (params.verify()) {
return await this.yourFirstRepository.yourFirstFunction({
userName: params.emailOrPhone,
password: params.password
Expand All @@ -25,18 +25,19 @@ export class YourFirstUseCaseParams extends Params {
readonly emailOrPhone: string
readonly password: string

constructor(params: IYourFirstParams) {
constructor(params?: IYourFirstParams) {
super({})
this.emailOrPhone = params.emailOrPhone
this.password = params.password
}

verify(): boolean {
return true
if (this.emailOrPhone == '' || this.password == '') return false
else return true
}
}

export interface IYourFirstParams {
emailOrPhone: string
password: string
emailOrPhone?: string
password?: string
}
14 changes: 0 additions & 14 deletions packages/mobile/__tests__/App-test.tsx

This file was deleted.

143 changes: 143 additions & 0 deletions packages/mobile/__tests__/__snapshots__/first-screen-test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `
<View
style={
{
"backgroundColor": "#0E1824",
"height": 1334,
"width": 750,
}
}
>
<View
style={
[
{
"borderRadius": 45,
"height": "75%",
},
{
"backgroundColor": undefined,
},
]
}
>
<Text
style={
[
{
"fontFamily": "Poppins-Regular",
"fontSize": 28,
"marginTop": "10%",
"textAlign": "center",
},
{
"color": undefined,
},
]
}
testID="Login_Hello_String"
>
Hello
</Text>
<Text
style={
[
{
"fontFamily": "Poppins-Regular",
"fontSize": 22,
"marginTop": "2%",
"textAlign": "center",
},
{
"color": undefined,
},
]
}
>
MY APP
</Text>
<Image
resizeMode="contain"
source={
{
"testUri": "../../../src/assets/images/car.png",
}
}
style={
{
"alignSelf": "center",
"bottom": 30,
"height": 350,
"position": "absolute",
"right": -100,
"width": 350,
}
}
/>
</View>
<View
style={
{
"height": "25%",
"justifyContent": "flex-end",
"paddingBottom": 40,
}
}
>
<LinearGradient
colors={
[
undefined,
undefined,
]
}
style={
{
"alignSelf": "center",
"borderRadius": 15,
"height": 50,
"justifyContent": "center",
"width": "80%",
}
}
>
<View
accessible={true}
collapsable={false}
focusable={false}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
{
"opacity": 1,
}
}
>
<Text
style={
[
{
"fontFamily": "Poppins-Regular",
"fontSize": 24,
"textAlign": "center",
},
{
"color": undefined,
},
]
}
>
getStarted
</Text>
</View>
</LinearGradient>
</View>
</View>
`;
28 changes: 28 additions & 0 deletions packages/mobile/__tests__/first-screen-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import renderer, { act, create } from 'react-test-renderer'
import FirstScreen from '../src/feature/firstscreen/first_screen'

// for rendering of screen

// creating tree for test case of that file

let tree: any
act(() => {
tree = create(<FirstScreen />)
})

// test case to see that app is render correctly
test('renders correctly', () => {
const tree = renderer.create(<FirstScreen />).toJSON()
expect(tree).toMatchSnapshot()
})
// test case for render without crashing
test('render without crashing', () => {
const res = tree.root.children
expect(res).toBeTruthy()
})

// test case to see if text is present there
test('on render of the app there should be a text hello on top', () => {
const res = tree.root.children
expect(res).toBeTruthy()
})
6 changes: 6 additions & 0 deletions packages/mobile/jestSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react'
import { useTheme } from './src/theme/themeprovider'
jest.mock('react-native-linear-gradient', () => 'LinearGradient')
jest.mock('./src/theme/themeprovider', () => ({
useTheme: () => ({ state: 'mocked_value' })
}))
6 changes: 4 additions & 2 deletions packages/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@react-navigation/native-stack": "^6.9.7",
"babel-plugin-parameter-decorator": "^1.0.16",
"foundation": "^0.0.1",
"jest": "^29.4.2",
"localisation": "^0.0.1",
"lodash": "^4.17.21",
"presentation": "^0.0.1",
Expand All @@ -53,7 +52,7 @@
"@typescript-eslint/parser": "^5.51.0",
"babel-jest": "^29.4.2",
"eslint": "^8.31.0",
"jest": "^29.4.2",
"jest": "^29.5.0",
"metro-react-native-babel-preset": "0.75.0",
"react-test-renderer": "18.2.0",
"typescript": "^4.8.3"
Expand All @@ -73,6 +72,9 @@
},
"jest": {
"preset": "react-native",
"setupFiles": [
"./jestSetup.ts"
],
"moduleFileExtensions": [
"ts",
"tsx",
Expand Down
8 changes: 5 additions & 3 deletions packages/mobile/src/feature/firstscreen/first_screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ const FirstScreen = () => {
const { theme, isDark } = useTheme()
return (
<View style={style.mainView}>
<View style={[style.secView, { backgroundColor: theme.secondaryColor }]}>
<Text style={[style.uberText, { color: theme.textColor }]}>{`${i18n.t('anotherString')}`}</Text>
<Text style={[style.getText, { color: theme.textColor }]}>{i18n.t('appName')}</Text>
<View style={[style.secView, { backgroundColor: theme?.secondaryColor }]}>
<Text style={[style.uberText, { color: theme?.textColor }]} testID="Login_Hello_String">{`${i18n.t(
'anotherString'
)}`}</Text>
<Text style={[style.getText, { color: theme?.textColor }]}>{i18n.t('appName')}</Text>
<Image source={isDark ? Images.carBlack : Images.car} style={style.carStyle} resizeMode="contain" />
</View>
<View style={style.thirdView}>
Expand Down
6 changes: 3 additions & 3 deletions packages/mobile/src/widgets/app_button/app_button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export type AppButtonProps = {
const AppButton = ({ loadingState, value, saveData }: AppButtonProps) => {
const { theme } = useTheme()
return (
<LinearGradient colors={[theme.primaryColor, theme.primaryColor]} style={style.buttonView}>
<LinearGradient colors={[theme?.primaryColor, theme?.primaryColor]} style={style.buttonView}>
<TouchableOpacity onPress={saveData}>
{loadingState ? (
<ActivityIndicator color={theme.activityColor} />
<ActivityIndicator color={theme?.activityColor} />
) : (
<Text style={[style.buttonText, { color: theme.textColor }]}>{i18n.t(value)}</Text>
<Text style={[style.buttonText, { color: theme?.textColor }]}>{i18n.t(value)}</Text>
)}
</TouchableOpacity>
</LinearGradient>
Expand Down
4 changes: 2 additions & 2 deletions packages/mobile/src/widgets/app_input/app_input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const AppInput = ({ placeholderText, value, setData, secure }: AppInputProps) =>
const { theme } = useTheme()
return (
<TextInput
style={[style.inputStyle, { color: theme.textColor, borderBottomColor: theme.borderColor }]}
style={[style.inputStyle, { color: theme?.textColor, borderBottomColor: theme?.borderColor }]}
placeholder={i18n.t(placeholderText)}
placeholderTextColor={theme.textColor}
placeholderTextColor={theme?.textColor}
value={value}
onChangeText={(e: string) => setData(e)}
secureTextEntry={secure}
Expand Down
Loading