Skip to content

Commit

Permalink
Merge pull request #11 from Moises088/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Moises088 committed Dec 5, 2022
2 parents 917cfd3 + e773222 commit 0f8cd9f
Show file tree
Hide file tree
Showing 53 changed files with 1,329 additions and 175 deletions.
19 changes: 11 additions & 8 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import FinancesProvider from './src/contexts/financesContext';
import ThemeProvider from './src/contexts/themeContext';
import Routes from './src/routes/index.routes';
import * as Updates from 'expo-updates';
import DebtsProvider from './src/contexts/debtsContext';

export default function App() {

React.useEffect(() => {
updateApp()
}, [])

const updateApp = async () => {
const updateApp = async () => {
try {
const { isAvailable } = await Updates.checkForUpdateAsync();
if (isAvailable) {
Expand All @@ -24,17 +25,19 @@ export default function App() {
} catch (err) {
}
}

return (
<AuthProvider>
<ThemeProvider>
<FinancesProvider>
<BudgetsProvider>
<NavigationContainer>
<Routes />
<StatusBar backgroundColor='#141b26' style='light' />
</NavigationContainer>
</BudgetsProvider>
<DebtsProvider>
<BudgetsProvider>
<NavigationContainer>
<Routes />
<StatusBar backgroundColor='#141b26' style='light' />
</NavigationContainer>
</BudgetsProvider>
</DebtsProvider>
</FinancesProvider>
</ThemeProvider>
</AuthProvider>
Expand Down
25 changes: 2 additions & 23 deletions __mocks__/asynstorage.mock.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
import AsyncStorageMock from '@react-native-async-storage/async-storage/jest/async-storage-mock';
import { ASYNC_BUDGETS, ASYNC_CATEGORIES, ASYNC_FINANCES, ASYNC_WALLETS } from '../src/constants/storage.constant';
import { BudgetEntity } from '../src/interfaces/services/budget.interface';
import { CategoryEntity } from '../src/interfaces/services/category.interface';
import { FinanceEntity } from '../src/interfaces/services/finance.interface';
import { WalletEntity } from '../src/interfaces/services/wallet.interface';
import { AsyncMock, ASYNC_BUDGETS, ASYNC_CATEGORIES, ASYNC_DEBTS, ASYNC_FINANCES, ASYNC_WALLETS } from '../src/constants/storage.constant';

jest.mock('@react-native-async-storage/async-storage', () =>
require('@react-native-async-storage/async-storage/jest/async-storage-mock')
);

type MockProps = {
ASYNC_CATEGORIES: CategoryEntity[];
ASYNC_WALLETS: WalletEntity[];
ASYNC_FINANCES: FinanceEntity[];
ASYNC_BUDGETS: BudgetEntity[];
}

export const AsyncMock: MockProps = {
ASYNC_CATEGORIES: [{ id: 1, name: 'Bike', color: '#d44', icon: 'biking' }],
ASYNC_WALLETS: [{ name: 'Principal', id: 1 }],
ASYNC_FINANCES: [
{ id: 1, categoryId: 1, walletId: 1, createdAt: '2022-11-10 00:00:00', isPaid: true, name: 'Conta', paidAt: '2022-11-10 00:00:00', value: 20.00, type: 'EXPENSE' },
{ id: 2, categoryId: 1, walletId: 1, createdAt: '2022-11-11 00:00:00', isPaid: true, name: 'Conta1', paidAt: '2022-11-11 00:00:00', value: 10.00, type: 'INCOME' },
],
ASYNC_BUDGETS: [
{ id: 1, month: "11", year: "2022", value: 100.50, createdAt: "2022-11-10 00:00:00", categories: [{ categoryId: 1, total: 10 }, { categoryId: 2, total: 90.50 }] }
]
}

AsyncStorageMock.getItem = jest.fn((key, callback): Promise<string | null> => {
if (key == ASYNC_CATEGORIES) return new Promise(resolve => resolve(JSON.stringify(AsyncMock["ASYNC_CATEGORIES"])))
if (key == ASYNC_WALLETS) return new Promise(resolve => resolve(JSON.stringify(AsyncMock["ASYNC_WALLETS"])))
if (key == ASYNC_FINANCES) return new Promise(resolve => resolve(JSON.stringify(AsyncMock["ASYNC_FINANCES"])))
if (key == ASYNC_BUDGETS) return new Promise(resolve => resolve(JSON.stringify(AsyncMock["ASYNC_BUDGETS"])))
if (key == ASYNC_DEBTS) return new Promise(resolve => resolve(JSON.stringify(AsyncMock["ASYNC_DEBTS"])))
return new Promise(resolve => resolve(JSON.stringify([])));
});

Expand Down
2 changes: 1 addition & 1 deletion __tests__/services/budget.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AsyncMock } from "../../src/constants/storage.constant";
import { BudgetDto } from "../../src/interfaces/services/budget.interface";
import { AppBudgetService } from "../../src/services/budget";
import { AsyncMock } from "../../__mocks__/asynstorage.mock";

const budget: BudgetDto = { month: "12", year: "2022", total: "10,50", categories: [{ categoryId: 1, total: 10 }] };
const sameBudget = AsyncMock['ASYNC_BUDGETS'][0];
Expand Down
2 changes: 1 addition & 1 deletion __tests__/services/category.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AsyncMock } from "../../src/constants/storage.constant";
import { CategoryDto } from "../../src/interfaces/services/category.interface";
import { AppCategoryService } from "../../src/services/category";
import { AsyncMock } from "../../__mocks__/asynstorage.mock";

const category: CategoryDto = { color: "#3f93eb", icon: "dumbbel", name: "Academia" }
const sameCategory: CategoryDto = AsyncMock['ASYNC_CATEGORIES'][0];
Expand Down
52 changes: 52 additions & 0 deletions __tests__/services/debts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { AsyncMock } from "../../src/constants/storage.constant";
import { DebtsDto } from "../../src/interfaces/services/debts.interface";
import { AppDebtsService } from "../../src/services/debts";

const debt: DebtsDto = { total: 100, totalPerMonth: 10, paidMonthAt: "11-10", type: "INVOICE", institutionId: 1 }
const sameDebt = AsyncMock['ASYNC_DEBTS'][0];

describe("services/debt", () => {
describe("method find", () => {
it("find debts and result must be DebtsDto array", async () => {
const debts = await AppDebtsService.find();
expect(debts).toEqual(
expect.arrayContaining([
expect.objectContaining({ ...sameDebt, id: 1 })
])
)
})
});

describe("method findOne", () => {
it("find where id = 1 result must be DebtsDto", async () => {
const debt = await AppDebtsService.findOne(1);
expect(debt).toEqual({ ...sameDebt, id: 1 })
})

it("find where id = 2 result must be undefined", async () => {
const debt = await AppDebtsService.findOne(2);
expect(debt).toBeUndefined()
})
});

describe("method create", () => {
it("create new debt and result must be { id: 2, ...debt }", async () => {
const newDebt = await AppDebtsService.create(debt);

expect(newDebt.id).toEqual(2);
expect(newDebt.total).toEqual(100);
expect(newDebt.totalPerMonth).toEqual(10);
expect(newDebt.institutionId).toEqual(1);
expect(newDebt.institutionName).toBeUndefined();
expect(newDebt.paidMonthAt).toEqual("11-10");
expect(newDebt.type).toEqual("INVOICE");
})
});

describe("method delete", () => {
it("id 1", async () => {
const debts = await AppDebtsService.delete(1);
expect(debts.length).toBe(0);
})
})
})
13 changes: 8 additions & 5 deletions __tests__/services/finance.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { AsyncMock } from "../../src/constants/storage.constant";
import { FinanceDto } from "../../src/interfaces/services/finance.interface";
import { AppBalanceService } from "../../src/services/balance";
import { AppFinanceService } from "../../src/services/finance";
import { getPipeTransformDateStringNumber, getPipeTransformDateStringPT } from "../../src/utils/date.util";
import { AsyncMock } from "../../__mocks__/asynstorage.mock";

const sameFinance = AsyncMock['ASYNC_FINANCES'][0];

Expand Down Expand Up @@ -38,7 +39,8 @@ describe("services/finance", () => {
name: 'Conta',
paid: getPipeTransformDateStringNumber('10/11/2022'),
money: "R$20,50",
type: 'INCOME'
type: 'INCOME',
billId: 0
}
const newfinance = await AppFinanceService.create(finance);
expect(newfinance.id).toEqual(3);
Expand All @@ -51,7 +53,7 @@ describe("services/finance", () => {

describe("method getFinancesBalance", () => {
it("get balance nov 2022", async () => {
const balance = await AppFinanceService.getFinancesBalance('11', '2022', 1);
const balance = await AppBalanceService.getFinancesBalance('11', '2022', 1);
expect(balance.total).toEqual(-10);
expect(balance.totalExpense).toEqual(20);
expect(balance.totalIncome).toEqual(10);
Expand All @@ -63,7 +65,7 @@ describe("services/finance", () => {
})

it("get balance withou params", async () => {
const balance = await AppFinanceService.getFinancesBalance('', '', 0);
const balance = await AppBalanceService.getFinancesBalance('', '', 0);
expect(balance.total).toEqual(0);
expect(balance.totalExpense).toEqual(0);
expect(balance.totalIncome).toEqual(0);
Expand All @@ -80,7 +82,8 @@ describe("services/finance", () => {
name: "Updated",
paid: "2022-27-11 00:00:00",
type: "INCOME",
description: "Test"
description: "Test",
billId: 0
}

it("update id 1", async () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/services/wallet.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AsyncMock } from "../../src/constants/storage.constant";
import { WalletDto, WalletEntity } from "../../src/interfaces/services/wallet.interface";
import { AppWalletService } from "../../src/services/wallet";
import { AsyncMock } from "../../__mocks__/asynstorage.mock";

const wallet: WalletDto = { name: "Secundária" };
const sameWallet: WalletDto = AsyncMock['ASYNC_WALLETS'][0];
Expand Down
Binary file added assets/institutions/bb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/institutions/caixa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/institutions/cielo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/institutions/default.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/institutions/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/institutions/inter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/institutions/itau.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/institutions/mastercard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/institutions/nubank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions src/components/debts/debts-card/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React from 'react';
import { View, Text, TouchableOpacity, Animated, Image } from 'react-native';
import { ThemeContext } from '../../../contexts/themeContext';
import { FontAwesome5 } from '@expo/vector-icons';
import { styles } from './styles';
import { DebtsInstitution } from '../../../interfaces/services/debts.interface';

const DebtsCard: React.FC<{ institution: DebtsInstitution | undefined }> = ({ institution }) => {

const spinValue = React.useRef(new Animated.Value(0)).current;
const spin = spinValue.interpolate({
inputRange: [0, 1, 2, 3, 4, 5, 6],
outputRange: ['0deg', '30deg', '60deg', '90deg', '-30deg', '-60deg', '0deg']
})

const { theme } = React.useContext(ThemeContext);
const style = styles(theme);

const [backgroundColor, setBackgroundColor] = React.useState("#FFF")
const [image, setImage] = React.useState()

React.useEffect(() => {
animated()
}, [institution])

const animated = () => {
setTimeout(() => {
if (institution?.color) {
setBackgroundColor(institution.color)
setImage(institution.logo)
}
}, 450);

Animated.sequence([
Animated.timing(spinValue, {
toValue: 3,
duration: 450,
useNativeDriver: true,
}),
Animated.timing(spinValue, {
toValue: 6,
duration: 450,
useNativeDriver: true,
})
]).start()
}

return (
<Animated.View style={[
style.container,
{
transform: [{ rotateY: spin }],
backgroundColor
}
]}>
<View style={style.containerLogo}>
{image && (
<Image source={image} style={style.image} />
)}
</View>
<View style={style.containerTitle}>
<Text style={[style.title, { color: institution?.color != "#FFF" ? "#FFF" : "#000" }]}>
FATURA
</Text>
</View>
</Animated.View>
)
}
export default DebtsCard;
34 changes: 34 additions & 0 deletions src/components/debts/debts-card/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { StyleSheet } from 'react-native';
import { WINDOW_WIDTH } from '../../../constants/screen.contants';
import { ThemesConfig } from '../../../interfaces/screens/themes.interace';

export const styles = (theme: ThemesConfig) => {
return StyleSheet.create({
container: {
width: "100%",
height: 150,
borderRadius: 15,
backgroundColor: 'red',
padding: 10
},
containerLogo: {
flex: 1,
justifyContent: "center",
alignItems: "flex-end",
},
containerTitle: {
flex: 1,
justifyContent: "flex-end"
},
title: {
fontSize: 15,
fontWeight: "bold",
letterSpacing: 1
},
image: {
maxWidth: 90,
maxHeight: 70,
marginTop: 10
}
})
};
Loading

0 comments on commit 0f8cd9f

Please sign in to comment.