From bfaada5b4f03a0f5bae0348271b1df99710abedc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20LUDWIG?= Date: Sat, 16 Mar 2024 00:36:44 +0100 Subject: [PATCH] refactor: project structure --- README.md | 9 +- app.json | 8 +- app/(pages)/habits/index.tsx | 8 +- app/_layout.tsx | 8 +- data/domain/entities/HabitProgressHistory.ts | 18 ---- data/domain/entities/HabitsTracker.ts | 18 ---- .../domain/repositories/GetHabitProgresses.ts | 10 -- docs/CAHIER-DES-CHARGES.md | 2 +- docs/CONVENTIONS.md | 10 +- {data/domain => domain}/entities/Goal.ts | 0 {data/domain => domain}/entities/Habit.ts | 0 domain/entities/HabitHistory.ts | 18 ++++ .../entities/HabitProgress.ts | 0 domain/entities/HabitsTracker.ts | 18 ++++ {data/domain => domain}/entities/User.ts | 0 {data/domain => domain}/entities/_Entity.ts | 0 .../repositories/GetHabitProgressHistory.ts | 10 ++ .../repositories/GetHabitsByUserId.ts | 0 .../use-cases/RetrieveHabitsTracker.ts | 24 ++--- hooks/__tests__/useLocalStorage.test.ts | 93 ------------------ hooks/useLocalStorage.ts | 43 -------- .../index.ts | 17 ++-- .../repositories/supabase/.gitignore | 0 .../repositories/supabase/config.toml | 0 .../supabase/lib/GetHabitProgressHistory.ts | 18 ++-- .../supabase/lib/GetHabitsByUserId.ts | 8 +- .../supabase/lib/_SupabaseRepository.ts | 0 .../20240315152340_initial_schema.sql | 0 .../repositories/supabase/seed.sql | 0 .../repositories/supabase/supabase-types.ts | 0 .../repositories/supabase/supabase.ts | 0 jest.config.json | 4 +- package-lock.json | 59 +++-------- package.json | 5 +- .../assets}/fonts/Canterbury.ttf | Bin .../assets}/fonts/Georama-Black.ttf | Bin .../assets}/fonts/SpaceMono-Regular.ttf | Bin .../assets}/images/Universite-Strasbourg.png | Bin .../assets}/images/adaptive-icon.png | Bin .../assets}/images/favicon.png | Bin .../assets}/images/icon.png | Bin .../assets}/images/splash.png | Bin .../assets}/images/splashscreen.jpg | Bin .../assets}/images/ui-example.png | Bin .../presenters/HabitsTracker.ts | 4 +- .../presenters/_Presenter.ts | 0 .../react/components}/ButtonCustom.tsx | 0 .../react/components}/ExternalLink.tsx | 0 .../react/components}/MonoText.tsx | 0 .../__tests__/ButtonCustom.test.tsx | 2 +- .../__tests__/ExternalLink.test.tsx | 2 +- .../components}/__tests__/MonoText.test.tsx | 2 +- .../__snapshots__/ButtonCustom.test.tsx.snap | 0 .../__snapshots__/ExternalLink.test.tsx.snap | 0 .../__snapshots__/MonoText.test.tsx.snap | 0 .../react/contexts}/HabitsTracker.tsx | 14 +-- .../react/hooks}/__tests__/useBoolean.test.ts | 2 +- .../react/hooks}/useBoolean.ts | 0 .../react/hooks}/usePresenterState.ts | 2 +- tests/jest.setup.ts | 5 - 60 files changed, 135 insertions(+), 306 deletions(-) delete mode 100644 data/domain/entities/HabitProgressHistory.ts delete mode 100644 data/domain/entities/HabitsTracker.ts delete mode 100644 data/domain/repositories/GetHabitProgresses.ts rename {data/domain => domain}/entities/Goal.ts (100%) rename {data/domain => domain}/entities/Habit.ts (100%) create mode 100644 domain/entities/HabitHistory.ts rename {data/domain => domain}/entities/HabitProgress.ts (100%) create mode 100644 domain/entities/HabitsTracker.ts rename {data/domain => domain}/entities/User.ts (100%) rename {data/domain => domain}/entities/_Entity.ts (100%) create mode 100644 domain/repositories/GetHabitProgressHistory.ts rename {data/domain => domain}/repositories/GetHabitsByUserId.ts (100%) rename {data/domain => domain}/use-cases/RetrieveHabitsTracker.ts (62%) delete mode 100644 hooks/__tests__/useLocalStorage.test.ts delete mode 100644 hooks/useLocalStorage.ts rename {data/infrastructure => infrastructure}/index.ts (55%) rename {data/infrastructure => infrastructure}/repositories/supabase/.gitignore (100%) rename {data/infrastructure => infrastructure}/repositories/supabase/config.toml (100%) rename data/infrastructure/repositories/supabase/lib/GetHabitProgresses.ts => infrastructure/repositories/supabase/lib/GetHabitProgressHistory.ts (67%) rename {data/infrastructure => infrastructure}/repositories/supabase/lib/GetHabitsByUserId.ts (83%) rename {data/infrastructure => infrastructure}/repositories/supabase/lib/_SupabaseRepository.ts (100%) rename {data/infrastructure => infrastructure}/repositories/supabase/migrations/20240315152340_initial_schema.sql (100%) rename {data/infrastructure => infrastructure}/repositories/supabase/seed.sql (100%) rename {data/infrastructure => infrastructure}/repositories/supabase/supabase-types.ts (100%) rename {data/infrastructure => infrastructure}/repositories/supabase/supabase.ts (100%) rename {assets => presentation/assets}/fonts/Canterbury.ttf (100%) rename {assets => presentation/assets}/fonts/Georama-Black.ttf (100%) rename {assets => presentation/assets}/fonts/SpaceMono-Regular.ttf (100%) rename {assets => presentation/assets}/images/Universite-Strasbourg.png (100%) rename {assets => presentation/assets}/images/adaptive-icon.png (100%) rename {assets => presentation/assets}/images/favicon.png (100%) rename {assets => presentation/assets}/images/icon.png (100%) rename {assets => presentation/assets}/images/splash.png (100%) rename {assets => presentation/assets}/images/splashscreen.jpg (100%) rename {assets => presentation/assets}/images/ui-example.png (100%) rename data/infrastructure/presenters/HabitsTrackerPresenter.ts => presentation/presenters/HabitsTracker.ts (89%) rename {data/infrastructure => presentation}/presenters/_Presenter.ts (100%) rename {components => presentation/react/components}/ButtonCustom.tsx (100%) rename {components => presentation/react/components}/ExternalLink.tsx (100%) rename {components => presentation/react/components}/MonoText.tsx (100%) rename {components => presentation/react/components}/__tests__/ButtonCustom.test.tsx (77%) rename {components => presentation/react/components}/__tests__/ExternalLink.test.tsx (81%) rename {components => presentation/react/components}/__tests__/MonoText.test.tsx (77%) rename {components => presentation/react/components}/__tests__/__snapshots__/ButtonCustom.test.tsx.snap (100%) rename {components => presentation/react/components}/__tests__/__snapshots__/ExternalLink.test.tsx.snap (100%) rename {components => presentation/react/components}/__tests__/__snapshots__/MonoText.test.tsx.snap (100%) rename {contexts => presentation/react/contexts}/HabitsTracker.tsx (77%) rename {hooks => presentation/react/hooks}/__tests__/useBoolean.test.ts (95%) rename {hooks => presentation/react/hooks}/useBoolean.ts (100%) rename {hooks => presentation/react/hooks}/usePresenterState.ts (85%) delete mode 100644 tests/jest.setup.ts diff --git a/README.md b/README.md index a78e364..34f215b 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,9 @@ Un tracker d'habitudes pour performer au boulot et dans la vie de tous les jours ### Documentation -- [Sujet du projet](./docs/SUJET.md) -- [Cahier des charges](./docs/CAHIER-DES-CHARGES.md) +- [Sujet](./docs/SUJET.md) + [Cahier des charges](./docs/CAHIER-DES-CHARGES.md) - [Modèle Logique des Données (MLD)](./docs/MLD.md) -- [Clean Architecture](./docs/ARCHITECTURE.md) +- [Architecture](./docs/ARCHITECTURE.md) - [Conventions développement informatique](./docs/CONVENTIONS.md) #### Principaux Outils Informatiques Utilisés @@ -26,8 +25,10 @@ Un tracker d'habitudes pour performer au boulot et dans la vie de tous les jours - [React Native](https://reactnative.dev/) + [Expo](https://expo.io/): Framework pour le développement d'applications mobiles. - [TypeScript](https://www.typescriptlang.org/): Langage de programmation. - [React Native Paper](https://callstack.github.io/react-native-paper/): Bibliothèque de composants pour React Native. - - [Supabase](https://supabase.io/): Backend, serveur d'API pour le stockage des données. + ## Développement du projet en local diff --git a/app.json b/app.json index 4f368c9..a1c67b0 100644 --- a/app.json +++ b/app.json @@ -4,11 +4,11 @@ "slug": "p61-project", "version": "1.0.0", "orientation": "portrait", - "icon": "./assets/images/icon.png", + "icon": "./presentation/assets/images/icon.png", "scheme": "p61-project", "userInterfaceStyle": "automatic", "splash": { - "image": "./assets/images/splashscreen.jpg", + "image": "./presentation/assets/images/splashscreen.jpg", "resizeMode": "cover", "backgroundColor": "#74b6cb" }, @@ -18,14 +18,14 @@ }, "android": { "adaptiveIcon": { - "foregroundImage": "./assets/images/adaptive-icon.png", + "foregroundImage": "./presentation/assets/images/adaptive-icon.png", "backgroundColor": "#ffffff" } }, "web": { "bundler": "metro", "output": "static", - "favicon": "./assets/images/favicon.png" + "favicon": "./presentation/assets/images/favicon.png" }, "plugins": ["expo-router"], "experiments": { diff --git a/app/(pages)/habits/index.tsx b/app/(pages)/habits/index.tsx index 4624218..1c5609b 100644 --- a/app/(pages)/habits/index.tsx +++ b/app/(pages)/habits/index.tsx @@ -1,16 +1,14 @@ import { StyleSheet, Text, View } from "react-native" import { SafeAreaView } from "react-native-safe-area-context" -import { useHabitsTracker } from "@/contexts/HabitsTracker" +import { useHabitsTracker } from "@/presentation/react/contexts/HabitsTracker" const HabitsPage: React.FC = () => { - const { habitsTrackerPresenterState } = useHabitsTracker() - const { habitsTracker } = habitsTrackerPresenterState - const { habitProgressHistories } = habitsTracker + const { habitsTracker } = useHabitsTracker() return ( - {habitProgressHistories.map((progressHistory) => { + {habitsTracker.habitsHistory.map((progressHistory) => { const { habit } = progressHistory return ( diff --git a/app/_layout.tsx b/app/_layout.tsx index f053232..92e8c93 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -8,10 +8,10 @@ import { } from "react-native-paper" import { StatusBar } from "expo-status-bar" -import CanterburyFont from "../assets/fonts/Canterbury.ttf" -import GeoramFont from "../assets/fonts/Georama-Black.ttf" -import SpaceMonoFont from "../assets/fonts/SpaceMono-Regular.ttf" -import { HabitsTrackerProvider } from "@/contexts/HabitsTracker" +import CanterburyFont from "../presentation/assets/fonts/Canterbury.ttf" +import GeoramFont from "../presentation/assets/fonts/Georama-Black.ttf" +import SpaceMonoFont from "../presentation/assets/fonts/SpaceMono-Regular.ttf" +import { HabitsTrackerProvider } from "@/presentation/react/contexts/HabitsTracker" export { ErrorBoundary } from "expo-router" diff --git a/data/domain/entities/HabitProgressHistory.ts b/data/domain/entities/HabitProgressHistory.ts deleted file mode 100644 index 125105f..0000000 --- a/data/domain/entities/HabitProgressHistory.ts +++ /dev/null @@ -1,18 +0,0 @@ -import type { Habit } from "./Habit" -import type { HabitProgress } from "./HabitProgress" - -export interface HabitProgressHistoryOptions { - habit: Habit - habitProgresses: HabitProgress[] -} - -export class HabitProgressHistory implements HabitProgressHistoryOptions { - public habit: Habit - public habitProgresses: HabitProgress[] - - public constructor(options: HabitProgressHistoryOptions) { - const { habit, habitProgresses } = options - this.habit = habit - this.habitProgresses = habitProgresses - } -} diff --git a/data/domain/entities/HabitsTracker.ts b/data/domain/entities/HabitsTracker.ts deleted file mode 100644 index 730e83c..0000000 --- a/data/domain/entities/HabitsTracker.ts +++ /dev/null @@ -1,18 +0,0 @@ -import type { HabitProgressHistory } from "./HabitProgressHistory" - -export interface HabitsTrackerOptions { - habitProgressHistories: HabitProgressHistory[] -} - -export class HabitsTracker implements HabitsTrackerOptions { - public habitProgressHistories: HabitProgressHistory[] - - public constructor(options: HabitsTrackerOptions) { - const { habitProgressHistories } = options - this.habitProgressHistories = habitProgressHistories - } - - public static default(): HabitsTracker { - return new HabitsTracker({ habitProgressHistories: [] }) - } -} diff --git a/data/domain/repositories/GetHabitProgresses.ts b/data/domain/repositories/GetHabitProgresses.ts deleted file mode 100644 index dfaef77..0000000 --- a/data/domain/repositories/GetHabitProgresses.ts +++ /dev/null @@ -1,10 +0,0 @@ -import type { Habit } from "../entities/Habit" -import type { HabitProgress } from "../entities/HabitProgress" - -export interface GetHabitProgressesOptions { - habit: Habit -} - -export interface GetHabitProgressesRepository { - execute: (options: GetHabitProgressesOptions) => Promise -} diff --git a/docs/CAHIER-DES-CHARGES.md b/docs/CAHIER-DES-CHARGES.md index 1361b3f..0fa0a81 100644 --- a/docs/CAHIER-DES-CHARGES.md +++ b/docs/CAHIER-DES-CHARGES.md @@ -51,4 +51,4 @@ Vous serez évalués sur les aspects suivants : ## Exemple d’interfaces -![UI Example](../assets/images/ui-example.png) +![UI Example](../presentation/assets/images/ui-example.png) diff --git a/docs/CONVENTIONS.md b/docs/CONVENTIONS.md index 9a3ccfe..ac9f57b 100644 --- a/docs/CONVENTIONS.md +++ b/docs/CONVENTIONS.md @@ -22,15 +22,17 @@ Une pipeline CI ([`.gitlab-ci.yml`](.gitlab-ci.yml)) est en place pour vérifier Le projet suit la convention [GitFlow](https://nvie.com/posts/a-successful-git-branching-model/) reposant sur 2 branches principales: -- `main` (ou `master`): Contient le code de la dernière version stable et déployé en production. +- `main`: Contient le code de la dernière version stable et déployé en production. - `develop`: Contient le code en cours de développement. Les nouvelles fonctionnalités et les correctifs de bugs sont fusionnés ici. +Chaque nouvelle fonctionnalité ou correctif de bug est développé dans une branche dédiée à partir de `develop`, nommée `feat/` ou `fix/`. Une fois le développement terminé, une merge request est créée pour demander une revue de code, et une fois validée, la branche est fusionnée dans `develop`, puis supprimée. + ## Convention des commits Les commits respectent la convention [Conventional Commits](https://www.conventionalcommits.org/) et [Semantic Versioning](https://semver.org/) pour la gestion des versions et des releases en fonction des commits. Les commits doivent être **atomiques** c'est à dire qu'il respecte 3 règles: -- Ne concerne qu'un seul sujet (une fonctionnalité, une correction de bug, etc.) -- Doit avoir un message clair et concis -- Ne doit pas rendre de dépôt "incohérent" (bloque la CI du projet) +- Ne concerne qu'un seul sujet (une fonctionnalité, une correction de bug, etc.). +- Doit avoir un message clair et concis. +- Ne doit pas rendre de dépôt "incohérent" (bloque la CI du projet). diff --git a/data/domain/entities/Goal.ts b/domain/entities/Goal.ts similarity index 100% rename from data/domain/entities/Goal.ts rename to domain/entities/Goal.ts diff --git a/data/domain/entities/Habit.ts b/domain/entities/Habit.ts similarity index 100% rename from data/domain/entities/Habit.ts rename to domain/entities/Habit.ts diff --git a/domain/entities/HabitHistory.ts b/domain/entities/HabitHistory.ts new file mode 100644 index 0000000..a61b31c --- /dev/null +++ b/domain/entities/HabitHistory.ts @@ -0,0 +1,18 @@ +import type { Habit } from "./Habit" +import type { HabitProgress } from "./HabitProgress" + +export interface HabitHistoryOptions { + habit: Habit + progressHistory: HabitProgress[] +} + +export class HabitHistory implements HabitHistoryOptions { + public habit: Habit + public progressHistory: HabitProgress[] + + public constructor(options: HabitHistoryOptions) { + const { habit, progressHistory } = options + this.habit = habit + this.progressHistory = progressHistory + } +} diff --git a/data/domain/entities/HabitProgress.ts b/domain/entities/HabitProgress.ts similarity index 100% rename from data/domain/entities/HabitProgress.ts rename to domain/entities/HabitProgress.ts diff --git a/domain/entities/HabitsTracker.ts b/domain/entities/HabitsTracker.ts new file mode 100644 index 0000000..84e4828 --- /dev/null +++ b/domain/entities/HabitsTracker.ts @@ -0,0 +1,18 @@ +import type { HabitHistory } from "./HabitHistory" + +export interface HabitsTrackerOptions { + habitsHistory: HabitHistory[] +} + +export class HabitsTracker implements HabitsTrackerOptions { + public habitsHistory: HabitHistory[] + + public constructor(options: HabitsTrackerOptions) { + const { habitsHistory } = options + this.habitsHistory = habitsHistory + } + + public static default(): HabitsTracker { + return new HabitsTracker({ habitsHistory: [] }) + } +} diff --git a/data/domain/entities/User.ts b/domain/entities/User.ts similarity index 100% rename from data/domain/entities/User.ts rename to domain/entities/User.ts diff --git a/data/domain/entities/_Entity.ts b/domain/entities/_Entity.ts similarity index 100% rename from data/domain/entities/_Entity.ts rename to domain/entities/_Entity.ts diff --git a/domain/repositories/GetHabitProgressHistory.ts b/domain/repositories/GetHabitProgressHistory.ts new file mode 100644 index 0000000..c3c224f --- /dev/null +++ b/domain/repositories/GetHabitProgressHistory.ts @@ -0,0 +1,10 @@ +import type { Habit } from "../entities/Habit" +import type { HabitProgress } from "../entities/HabitProgress" + +export interface GetHabitProgressHistoryOptions { + habit: Habit +} + +export interface GetHabitProgressHistoryRepository { + execute: (options: GetHabitProgressHistoryOptions) => Promise +} diff --git a/data/domain/repositories/GetHabitsByUserId.ts b/domain/repositories/GetHabitsByUserId.ts similarity index 100% rename from data/domain/repositories/GetHabitsByUserId.ts rename to domain/repositories/GetHabitsByUserId.ts diff --git a/data/domain/use-cases/RetrieveHabitsTracker.ts b/domain/use-cases/RetrieveHabitsTracker.ts similarity index 62% rename from data/domain/use-cases/RetrieveHabitsTracker.ts rename to domain/use-cases/RetrieveHabitsTracker.ts index 23a0bf6..d3fc19c 100644 --- a/data/domain/use-cases/RetrieveHabitsTracker.ts +++ b/domain/use-cases/RetrieveHabitsTracker.ts @@ -1,12 +1,12 @@ -import { HabitProgressHistory } from "../entities/HabitProgressHistory" +import { HabitHistory } from "../entities/HabitHistory" import { HabitsTracker } from "../entities/HabitsTracker" import type { User } from "../entities/User" -import type { GetHabitProgressesRepository } from "../repositories/GetHabitProgresses" +import type { GetHabitProgressHistoryRepository } from "../repositories/GetHabitProgressHistory" import type { GetHabitsByUserIdRepository } from "../repositories/GetHabitsByUserId" export interface RetrieveHabitsTrackerUseCaseDependencyOptions { getHabitsByUserIdRepository: GetHabitsByUserIdRepository - getHabitProgressesRepository: GetHabitProgressesRepository + getHabitProgressHistoryRepository: GetHabitProgressHistoryRepository } export interface RetrieveHabitsTrackerUseCaseOptions { @@ -17,11 +17,12 @@ export class RetrieveHabitsTrackerUseCase implements RetrieveHabitsTrackerUseCaseDependencyOptions { public getHabitsByUserIdRepository: GetHabitsByUserIdRepository - public getHabitProgressesRepository: GetHabitProgressesRepository + public getHabitProgressHistoryRepository: GetHabitProgressHistoryRepository public constructor(options: RetrieveHabitsTrackerUseCaseDependencyOptions) { this.getHabitsByUserIdRepository = options.getHabitsByUserIdRepository - this.getHabitProgressesRepository = options.getHabitProgressesRepository + this.getHabitProgressHistoryRepository = + options.getHabitProgressHistoryRepository } public async execute( @@ -31,15 +32,16 @@ export class RetrieveHabitsTrackerUseCase const habits = await this.getHabitsByUserIdRepository.execute({ userId }) const habitProgressHistories = await Promise.all( habits.map(async (habit) => { - const habitProgresses = await this.getHabitProgressesRepository.execute( - { + const progressHistory = + await this.getHabitProgressHistoryRepository.execute({ habit, - }, - ) - return new HabitProgressHistory({ habit, habitProgresses }) + }) + return new HabitHistory({ habit, progressHistory }) }), ) - const habitsTracker = new HabitsTracker({ habitProgressHistories }) + const habitsTracker = new HabitsTracker({ + habitsHistory: habitProgressHistories, + }) return habitsTracker } } diff --git a/hooks/__tests__/useLocalStorage.test.ts b/hooks/__tests__/useLocalStorage.test.ts deleted file mode 100644 index 3199da7..0000000 --- a/hooks/__tests__/useLocalStorage.test.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { act, renderHook, waitFor } from "@testing-library/react-native" -import AsyncStorage from "@react-native-async-storage/async-storage" - -import { useLocalStorage } from "@/hooks/useLocalStorage" - -describe("hooks/useLocalStorage", () => { - beforeEach(async () => { - jest.clearAllMocks() - await AsyncStorage.clear() - }) - - it("should get the default value", () => { - const key = "key" - const givenDefaultValue = { key: "value" } - const { result } = renderHook(() => { - return useLocalStorage(key, givenDefaultValue) - }) - const [actualValue] = result.current - expect(actualValue).toEqual(givenDefaultValue) - }) - - it("should get the value from the storage", async () => { - const key = "key" - const givenDefaultValue = { someValue: "value" } - const storedValue = { someValue: "value" } - const { result } = renderHook(() => { - return useLocalStorage(key, givenDefaultValue) - }) - await waitFor(() => { - expect(AsyncStorage.getItem).toHaveBeenCalledWith(key) - }) - const [actualValue] = result.current - expect(actualValue).toEqual(storedValue) - }) - - it("should set the value to the storage", async () => { - const key = "key" - const givenDefaultValue = { someValue: "value" } - const storedValue = { someValue: "value" } - const { result } = renderHook(() => { - return useLocalStorage(key, givenDefaultValue) - }) - const [, setValue] = result.current - await act(() => { - setValue(storedValue) - }) - await waitFor(() => { - expect(AsyncStorage.setItem).toHaveBeenCalledWith( - key, - JSON.stringify(storedValue), - ) - }) - }) - - it("should get default value if storage value is not valid JSON", async () => { - console.error = jest.fn() - const key = "key" - const givenDefaultValue = { someValue: "value" } - const storedValue = "{not valid JSON" - await AsyncStorage.setItem(key, storedValue) - const { result } = renderHook(() => { - return useLocalStorage(key, givenDefaultValue) - }) - await waitFor(() => { - expect(AsyncStorage.getItem).toHaveBeenCalledWith(key) - }) - const [actualValue] = result.current - expect(actualValue).toEqual(givenDefaultValue) - }) - - it("should catch the error when setting the value to the storage", async () => { - console.error = jest.fn() - const key = "key" - const givenDefaultValue = { someValue: "value" } - const storedValue = { someValue: "value" } - const error = new Error("error") - ;(AsyncStorage.setItem as jest.Mock).mockRejectedValue(error) - const { result } = renderHook(() => { - return useLocalStorage(key, givenDefaultValue) - }) - const [, setValue] = result.current - await act(() => { - setValue(storedValue) - }) - await waitFor(() => { - expect(AsyncStorage.setItem).toHaveBeenCalledWith( - key, - JSON.stringify(storedValue), - ) - }) - expect(console.error).toHaveBeenCalledWith(error) - }) -}) diff --git a/hooks/useLocalStorage.ts b/hooks/useLocalStorage.ts deleted file mode 100644 index 53a0620..0000000 --- a/hooks/useLocalStorage.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { useCallback, useEffect, useRef, useState } from "react" -import AsyncStorage from "@react-native-async-storage/async-storage" - -type UseLocalStorageResult = [T, React.Dispatch>] - -export const useLocalStorage = ( - key: string, - defaultValue: T, -): UseLocalStorageResult => { - const hasSaved = useRef(false) - const [value, setValue] = useState(defaultValue) - - const getFromLocalStorage = useCallback(async (): Promise => { - const value = await AsyncStorage.getItem(key) - hasSaved.current = true - if (value == null) { - return defaultValue - } - return JSON.parse(value) as T - }, [key, defaultValue]) - - useEffect(() => { - if (!hasSaved.current) { - return - } - AsyncStorage.setItem(key, JSON.stringify(value)).catch((error) => { - console.error(error) - }) - }, [key, value]) - - useEffect(() => { - getFromLocalStorage() - .then((value) => { - setValue(value) - }) - .catch((error) => { - setValue(defaultValue) - console.error(error) - }) - }, [defaultValue, getFromLocalStorage]) - - return [value, setValue] -} diff --git a/data/infrastructure/index.ts b/infrastructure/index.ts similarity index 55% rename from data/infrastructure/index.ts rename to infrastructure/index.ts index 365469c..e681c2e 100644 --- a/data/infrastructure/index.ts +++ b/infrastructure/index.ts @@ -1,19 +1,16 @@ -// export const taskRepository = new TaskLocalStorageRepository() -// export const taskService = new TaskService(taskRepository) -// export const taskPresenter = new TaskPresenter(taskService) - import { RetrieveHabitsTrackerUseCase } from "../domain/use-cases/RetrieveHabitsTracker" -import { HabitsTrackerPresenter } from "./presenters/HabitsTrackerPresenter" -import { GetHabitProgressesSupabaseRepository } from "./repositories/supabase/lib/GetHabitProgresses" +import { HabitsTrackerPresenter } from "../presentation/presenters/HabitsTracker" +import { GetHabitProgressHistorySupabaseRepository } from "./repositories/supabase/lib/GetHabitProgressHistory" import { GetHabitsByUserIdSupabaseRepository } from "./repositories/supabase/lib/GetHabitsByUserId" import { supabaseClient } from "./repositories/supabase/supabase" /** * Repositories */ -const getHabitProgressesRepository = new GetHabitProgressesSupabaseRepository({ - supabaseClient, -}) +const getHabitProgressesRepository = + new GetHabitProgressHistorySupabaseRepository({ + supabaseClient, + }) const getHabitsByUserIdRepository = new GetHabitsByUserIdSupabaseRepository({ supabaseClient, }) @@ -22,7 +19,7 @@ const getHabitsByUserIdRepository = new GetHabitsByUserIdSupabaseRepository({ * Use Cases */ const retrieveHabitsTrackerUseCase = new RetrieveHabitsTrackerUseCase({ - getHabitProgressesRepository, + getHabitProgressHistoryRepository: getHabitProgressesRepository, getHabitsByUserIdRepository, }) diff --git a/data/infrastructure/repositories/supabase/.gitignore b/infrastructure/repositories/supabase/.gitignore similarity index 100% rename from data/infrastructure/repositories/supabase/.gitignore rename to infrastructure/repositories/supabase/.gitignore diff --git a/data/infrastructure/repositories/supabase/config.toml b/infrastructure/repositories/supabase/config.toml similarity index 100% rename from data/infrastructure/repositories/supabase/config.toml rename to infrastructure/repositories/supabase/config.toml diff --git a/data/infrastructure/repositories/supabase/lib/GetHabitProgresses.ts b/infrastructure/repositories/supabase/lib/GetHabitProgressHistory.ts similarity index 67% rename from data/infrastructure/repositories/supabase/lib/GetHabitProgresses.ts rename to infrastructure/repositories/supabase/lib/GetHabitProgressHistory.ts index 17a0154..c2acc5e 100644 --- a/data/infrastructure/repositories/supabase/lib/GetHabitProgresses.ts +++ b/infrastructure/repositories/supabase/lib/GetHabitProgressHistory.ts @@ -1,17 +1,17 @@ -import type { GetHabitProgressesRepository } from "@/data/domain/repositories/GetHabitProgresses" +import type { GetHabitProgressHistoryRepository } from "@/domain/repositories/GetHabitProgressHistory" import { SupabaseRepository } from "./_SupabaseRepository" -import { HabitProgress } from "@/data/domain/entities/HabitProgress" -import type { GoalProgress } from "@/data/domain/entities/Goal" +import { HabitProgress } from "@/domain/entities/HabitProgress" +import type { GoalProgress } from "@/domain/entities/Goal" import { GoalBooleanProgress, GoalNumericProgress, -} from "@/data/domain/entities/Goal" +} from "@/domain/entities/Goal" -export class GetHabitProgressesSupabaseRepository +export class GetHabitProgressHistorySupabaseRepository extends SupabaseRepository - implements GetHabitProgressesRepository + implements GetHabitProgressHistoryRepository { - execute: GetHabitProgressesRepository["execute"] = async (options) => { + execute: GetHabitProgressHistoryRepository["execute"] = async (options) => { const { habit } = options const { data, error } = await this.supabaseClient .from("habits_progresses") @@ -20,7 +20,7 @@ export class GetHabitProgressesSupabaseRepository if (error != null) { throw new Error(error.message) } - const habitProgresses = data.map((item) => { + const habitProgressHistory = data.map((item) => { let goalProgress: GoalProgress | null = null if (habit.goal.isNumeric()) { goalProgress = new GoalNumericProgress({ @@ -44,6 +44,6 @@ export class GetHabitProgressesSupabaseRepository }) return habitProgress }) - return habitProgresses + return habitProgressHistory } } diff --git a/data/infrastructure/repositories/supabase/lib/GetHabitsByUserId.ts b/infrastructure/repositories/supabase/lib/GetHabitsByUserId.ts similarity index 83% rename from data/infrastructure/repositories/supabase/lib/GetHabitsByUserId.ts rename to infrastructure/repositories/supabase/lib/GetHabitsByUserId.ts index c8d5712..704af53 100644 --- a/data/infrastructure/repositories/supabase/lib/GetHabitsByUserId.ts +++ b/infrastructure/repositories/supabase/lib/GetHabitsByUserId.ts @@ -1,8 +1,8 @@ -import type { GetHabitsByUserIdRepository } from "@/data/domain/repositories/GetHabitsByUserId" +import type { GetHabitsByUserIdRepository } from "@/domain/repositories/GetHabitsByUserId" import { SupabaseRepository } from "./_SupabaseRepository" -import { Habit } from "@/data/domain/entities/Habit" -import type { Goal } from "@/data/domain/entities/Goal" -import { GoalBoolean, GoalNumeric } from "@/data/domain/entities/Goal" +import { Habit } from "@/domain/entities/Habit" +import type { Goal } from "@/domain/entities/Goal" +import { GoalBoolean, GoalNumeric } from "@/domain/entities/Goal" export class GetHabitsByUserIdSupabaseRepository extends SupabaseRepository diff --git a/data/infrastructure/repositories/supabase/lib/_SupabaseRepository.ts b/infrastructure/repositories/supabase/lib/_SupabaseRepository.ts similarity index 100% rename from data/infrastructure/repositories/supabase/lib/_SupabaseRepository.ts rename to infrastructure/repositories/supabase/lib/_SupabaseRepository.ts diff --git a/data/infrastructure/repositories/supabase/migrations/20240315152340_initial_schema.sql b/infrastructure/repositories/supabase/migrations/20240315152340_initial_schema.sql similarity index 100% rename from data/infrastructure/repositories/supabase/migrations/20240315152340_initial_schema.sql rename to infrastructure/repositories/supabase/migrations/20240315152340_initial_schema.sql diff --git a/data/infrastructure/repositories/supabase/seed.sql b/infrastructure/repositories/supabase/seed.sql similarity index 100% rename from data/infrastructure/repositories/supabase/seed.sql rename to infrastructure/repositories/supabase/seed.sql diff --git a/data/infrastructure/repositories/supabase/supabase-types.ts b/infrastructure/repositories/supabase/supabase-types.ts similarity index 100% rename from data/infrastructure/repositories/supabase/supabase-types.ts rename to infrastructure/repositories/supabase/supabase-types.ts diff --git a/data/infrastructure/repositories/supabase/supabase.ts b/infrastructure/repositories/supabase/supabase.ts similarity index 100% rename from data/infrastructure/repositories/supabase/supabase.ts rename to infrastructure/repositories/supabase/supabase.ts diff --git a/jest.config.json b/jest.config.json index 69d884b..c950dff 100644 --- a/jest.config.json +++ b/jest.config.json @@ -1,7 +1,7 @@ { "preset": "jest-expo", "roots": ["./"], - "setupFilesAfterEnv": ["/tests/jest.setup.ts"], + "setupFilesAfterEnv": ["@testing-library/react-native/extend-expect"], "fakeTimers": { "enableGlobally": true }, @@ -10,7 +10,7 @@ "coverageReporters": ["text", "text-summary", "cobertura"], "collectCoverageFrom": [ "/**/*.{ts,tsx}", - "!/components/ExternalLink.tsx", + "!/presentation/react/components/ExternalLink.tsx", "!/.expo", "!/app/+html.tsx", "!/app/**/_layout.tsx", diff --git a/package-lock.json b/package-lock.json index b916aca..bf370b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,6 @@ "hasInstallScript": true, "dependencies": { "@expo/vector-icons": "14.0.0", - "@react-native-async-storage/async-storage": "1.21.0", "@react-navigation/native": "6.1.16", "@supabase/supabase-js": "2.39.8", "expo": "50.0.13", @@ -34,7 +33,7 @@ }, "devDependencies": { "@babel/core": "7.24.0", - "@commitlint/cli": "19.1.0", + "@commitlint/cli": "19.2.0", "@commitlint/config-conventional": "19.1.0", "@testing-library/react-native": "12.4.3", "@total-typescript/ts-reset": "0.5.1", @@ -51,7 +50,7 @@ "eslint-plugin-import": "2.29.1", "eslint-plugin-prettier": "5.1.3", "eslint-plugin-promise": "6.1.1", - "eslint-plugin-react": "7.34.0", + "eslint-plugin-react": "7.34.1", "eslint-plugin-react-hooks": "4.6.0", "eslint-plugin-react-native": "4.1.0", "eslint-plugin-unicorn": "51.0.1", @@ -2122,15 +2121,15 @@ } }, "node_modules/@commitlint/cli": { - "version": "19.1.0", - "resolved": "https://registry.npmjs.org/@commitlint/cli/-/cli-19.1.0.tgz", - "integrity": "sha512-SYGm8HGbVzrlSYeB6oo6pG1Ec6bOMJcDsXgNGa4vgZQsPj6nJkcbTWlIRmtmIk0tHi0d5sCljGuQ+g/0NCPv7w==", + "version": "19.2.0", + "resolved": "https://registry.npmjs.org/@commitlint/cli/-/cli-19.2.0.tgz", + "integrity": "sha512-8XnQDMyQR+1/ldbmIyhonvnDS2enEw48Wompo/967fsEvy9Vj5/JbDutzmSBKxANWDVeEbR9QQm0yHpw6ArrFw==", "dev": true, "dependencies": { "@commitlint/format": "^19.0.3", "@commitlint/lint": "^19.1.0", - "@commitlint/load": "^19.1.0", - "@commitlint/read": "^19.0.3", + "@commitlint/load": "^19.2.0", + "@commitlint/read": "^19.2.0", "@commitlint/types": "^19.0.3", "execa": "^8.0.1", "yargs": "^17.0.0" @@ -5292,17 +5291,6 @@ "react": "^16.8 || ^17.0 || ^18.0" } }, - "node_modules/@react-native-async-storage/async-storage": { - "version": "1.21.0", - "resolved": "https://registry.npmjs.org/@react-native-async-storage/async-storage/-/async-storage-1.21.0.tgz", - "integrity": "sha512-JL0w36KuFHFCvnbOXRekqVAUplmOyT/OuCQkogo6X98MtpSaJOKEAeZnYO8JB0U/RIEixZaGI5px73YbRm/oag==", - "dependencies": { - "merge-options": "^3.0.4" - }, - "peerDependencies": { - "react-native": "^0.0.0-0 || >=0.60 <1.0" - } - }, "node_modules/@react-native-community/cli": { "version": "12.3.6", "resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-12.3.6.tgz", @@ -11525,9 +11513,9 @@ } }, "node_modules/eslint-plugin-react": { - "version": "7.34.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.34.0.tgz", - "integrity": "sha512-MeVXdReleBTdkz/bvcQMSnCXGi+c9kvy51IpinjnJgutl3YTHWsDdke7Z1ufZpGfDG8xduBDKyjtB9JH1eBKIQ==", + "version": "7.34.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.34.1.tgz", + "integrity": "sha512-N97CxlouPT1AHt8Jn0mhhN2RrADlUAsk1/atcT2KyA/l9Q/E6ll7OIGwNumFmWfZ9skV3XXccYS19h80rHtgkw==", "dev": true, "dependencies": { "array-includes": "^3.1.7", @@ -13997,11 +13985,11 @@ } }, "node_modules/is-plain-obj": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", - "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz", + "integrity": "sha512-yvkRyxmFKEOQ4pNXCmJG5AEQNlXJS5LaONXo5/cLdTZdWvsZ1ioJEonLGAosKlMWE8lwUy/bJzMjcw8az73+Fg==", "engines": { - "node": ">=8" + "node": ">=0.10.0" } }, "node_modules/is-plain-object": { @@ -17761,17 +17749,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/merge-options": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/merge-options/-/merge-options-3.0.4.tgz", - "integrity": "sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ==", - "dependencies": { - "is-plain-obj": "^2.1.0" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -21261,14 +21238,6 @@ "node": ">=4" } }, - "node_modules/sort-keys/node_modules/is-plain-obj": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz", - "integrity": "sha512-yvkRyxmFKEOQ4pNXCmJG5AEQNlXJS5LaONXo5/cLdTZdWvsZ1ioJEonLGAosKlMWE8lwUy/bJzMjcw8az73+Fg==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/source-map": { "version": "0.7.4", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.4.tgz", diff --git a/package.json b/package.json index bb86556..48d9eb7 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ }, "dependencies": { "@expo/vector-icons": "14.0.0", - "@react-native-async-storage/async-storage": "1.21.0", "@react-navigation/native": "6.1.16", "@supabase/supabase-js": "2.39.8", "expo": "50.0.13", @@ -43,7 +42,7 @@ }, "devDependencies": { "@babel/core": "7.24.0", - "@commitlint/cli": "19.1.0", + "@commitlint/cli": "19.2.0", "@commitlint/config-conventional": "19.1.0", "@testing-library/react-native": "12.4.3", "@total-typescript/ts-reset": "0.5.1", @@ -60,7 +59,7 @@ "eslint-plugin-import": "2.29.1", "eslint-plugin-prettier": "5.1.3", "eslint-plugin-promise": "6.1.1", - "eslint-plugin-react": "7.34.0", + "eslint-plugin-react": "7.34.1", "eslint-plugin-react-hooks": "4.6.0", "eslint-plugin-react-native": "4.1.0", "eslint-plugin-unicorn": "51.0.1", diff --git a/assets/fonts/Canterbury.ttf b/presentation/assets/fonts/Canterbury.ttf similarity index 100% rename from assets/fonts/Canterbury.ttf rename to presentation/assets/fonts/Canterbury.ttf diff --git a/assets/fonts/Georama-Black.ttf b/presentation/assets/fonts/Georama-Black.ttf similarity index 100% rename from assets/fonts/Georama-Black.ttf rename to presentation/assets/fonts/Georama-Black.ttf diff --git a/assets/fonts/SpaceMono-Regular.ttf b/presentation/assets/fonts/SpaceMono-Regular.ttf similarity index 100% rename from assets/fonts/SpaceMono-Regular.ttf rename to presentation/assets/fonts/SpaceMono-Regular.ttf diff --git a/assets/images/Universite-Strasbourg.png b/presentation/assets/images/Universite-Strasbourg.png similarity index 100% rename from assets/images/Universite-Strasbourg.png rename to presentation/assets/images/Universite-Strasbourg.png diff --git a/assets/images/adaptive-icon.png b/presentation/assets/images/adaptive-icon.png similarity index 100% rename from assets/images/adaptive-icon.png rename to presentation/assets/images/adaptive-icon.png diff --git a/assets/images/favicon.png b/presentation/assets/images/favicon.png similarity index 100% rename from assets/images/favicon.png rename to presentation/assets/images/favicon.png diff --git a/assets/images/icon.png b/presentation/assets/images/icon.png similarity index 100% rename from assets/images/icon.png rename to presentation/assets/images/icon.png diff --git a/assets/images/splash.png b/presentation/assets/images/splash.png similarity index 100% rename from assets/images/splash.png rename to presentation/assets/images/splash.png diff --git a/assets/images/splashscreen.jpg b/presentation/assets/images/splashscreen.jpg similarity index 100% rename from assets/images/splashscreen.jpg rename to presentation/assets/images/splashscreen.jpg diff --git a/assets/images/ui-example.png b/presentation/assets/images/ui-example.png similarity index 100% rename from assets/images/ui-example.png rename to presentation/assets/images/ui-example.png diff --git a/data/infrastructure/presenters/HabitsTrackerPresenter.ts b/presentation/presenters/HabitsTracker.ts similarity index 89% rename from data/infrastructure/presenters/HabitsTrackerPresenter.ts rename to presentation/presenters/HabitsTracker.ts index f783211..a0e4802 100644 --- a/data/infrastructure/presenters/HabitsTrackerPresenter.ts +++ b/presentation/presenters/HabitsTracker.ts @@ -1,9 +1,9 @@ -import { HabitsTracker } from "@/data/domain/entities/HabitsTracker" +import { HabitsTracker } from "@/domain/entities/HabitsTracker" import { Presenter } from "./_Presenter" import type { RetrieveHabitsTrackerUseCase, RetrieveHabitsTrackerUseCaseOptions, -} from "@/data/domain/use-cases/RetrieveHabitsTracker" +} from "@/domain/use-cases/RetrieveHabitsTracker" export interface HabitsTrackerPresenterState { habitsTracker: HabitsTracker diff --git a/data/infrastructure/presenters/_Presenter.ts b/presentation/presenters/_Presenter.ts similarity index 100% rename from data/infrastructure/presenters/_Presenter.ts rename to presentation/presenters/_Presenter.ts diff --git a/components/ButtonCustom.tsx b/presentation/react/components/ButtonCustom.tsx similarity index 100% rename from components/ButtonCustom.tsx rename to presentation/react/components/ButtonCustom.tsx diff --git a/components/ExternalLink.tsx b/presentation/react/components/ExternalLink.tsx similarity index 100% rename from components/ExternalLink.tsx rename to presentation/react/components/ExternalLink.tsx diff --git a/components/MonoText.tsx b/presentation/react/components/MonoText.tsx similarity index 100% rename from components/MonoText.tsx rename to presentation/react/components/MonoText.tsx diff --git a/components/__tests__/ButtonCustom.test.tsx b/presentation/react/components/__tests__/ButtonCustom.test.tsx similarity index 77% rename from components/__tests__/ButtonCustom.test.tsx rename to presentation/react/components/__tests__/ButtonCustom.test.tsx index 3af0995..0491962 100644 --- a/components/__tests__/ButtonCustom.test.tsx +++ b/presentation/react/components/__tests__/ButtonCustom.test.tsx @@ -1,6 +1,6 @@ import renderer from "react-test-renderer" -import { ButtonCustom } from "@/components/ButtonCustom" +import { ButtonCustom } from "@/presentation/react/components/ButtonCustom" describe("", () => { it("renders correctly", () => { diff --git a/components/__tests__/ExternalLink.test.tsx b/presentation/react/components/__tests__/ExternalLink.test.tsx similarity index 81% rename from components/__tests__/ExternalLink.test.tsx rename to presentation/react/components/__tests__/ExternalLink.test.tsx index ba2a10f..768dbf4 100644 --- a/components/__tests__/ExternalLink.test.tsx +++ b/presentation/react/components/__tests__/ExternalLink.test.tsx @@ -1,6 +1,6 @@ import renderer from "react-test-renderer" -import { ExternalLink } from "@/components/ExternalLink" +import { ExternalLink } from "@/presentation/react/components/ExternalLink" describe("", () => { it("renders correctly", () => { diff --git a/components/__tests__/MonoText.test.tsx b/presentation/react/components/__tests__/MonoText.test.tsx similarity index 77% rename from components/__tests__/MonoText.test.tsx rename to presentation/react/components/__tests__/MonoText.test.tsx index 722d296..9d9c749 100644 --- a/components/__tests__/MonoText.test.tsx +++ b/presentation/react/components/__tests__/MonoText.test.tsx @@ -1,6 +1,6 @@ import renderer from "react-test-renderer" -import { MonoText } from "@/components/MonoText" +import { MonoText } from "@/presentation/react/components/MonoText" describe("", () => { it("renders correctly", () => { diff --git a/components/__tests__/__snapshots__/ButtonCustom.test.tsx.snap b/presentation/react/components/__tests__/__snapshots__/ButtonCustom.test.tsx.snap similarity index 100% rename from components/__tests__/__snapshots__/ButtonCustom.test.tsx.snap rename to presentation/react/components/__tests__/__snapshots__/ButtonCustom.test.tsx.snap diff --git a/components/__tests__/__snapshots__/ExternalLink.test.tsx.snap b/presentation/react/components/__tests__/__snapshots__/ExternalLink.test.tsx.snap similarity index 100% rename from components/__tests__/__snapshots__/ExternalLink.test.tsx.snap rename to presentation/react/components/__tests__/__snapshots__/ExternalLink.test.tsx.snap diff --git a/components/__tests__/__snapshots__/MonoText.test.tsx.snap b/presentation/react/components/__tests__/__snapshots__/MonoText.test.tsx.snap similarity index 100% rename from components/__tests__/__snapshots__/MonoText.test.tsx.snap rename to presentation/react/components/__tests__/__snapshots__/MonoText.test.tsx.snap diff --git a/contexts/HabitsTracker.tsx b/presentation/react/contexts/HabitsTracker.tsx similarity index 77% rename from contexts/HabitsTracker.tsx rename to presentation/react/contexts/HabitsTracker.tsx index cfd7661..658474b 100644 --- a/contexts/HabitsTracker.tsx +++ b/presentation/react/contexts/HabitsTracker.tsx @@ -3,12 +3,11 @@ import { createContext, useContext, useEffect } from "react" import type { HabitsTrackerPresenter, HabitsTrackerPresenterState, -} from "@/data/infrastructure/presenters/HabitsTrackerPresenter" -import { usePresenterState } from "@/hooks/usePresenterState" -import { habitsTrackerPresenter } from "@/data/infrastructure" +} from "@/presentation/presenters/HabitsTracker" +import { usePresenterState } from "@/presentation/react/hooks/usePresenterState" +import { habitsTrackerPresenter } from "@/infrastructure" -export interface HabitsTrackerContextValue { - habitsTrackerPresenterState: HabitsTrackerPresenterState +export interface HabitsTrackerContextValue extends HabitsTrackerPresenterState { habitsTrackerPresenter: HabitsTrackerPresenter } @@ -36,7 +35,10 @@ export const HabitsTrackerProvider: React.FC = ( return ( {children} diff --git a/hooks/__tests__/useBoolean.test.ts b/presentation/react/hooks/__tests__/useBoolean.test.ts similarity index 95% rename from hooks/__tests__/useBoolean.test.ts rename to presentation/react/hooks/__tests__/useBoolean.test.ts index 95e6337..0277c87 100644 --- a/hooks/__tests__/useBoolean.test.ts +++ b/presentation/react/hooks/__tests__/useBoolean.test.ts @@ -1,6 +1,6 @@ import { act, renderHook } from "@testing-library/react-native" -import { useBoolean } from "@/hooks/useBoolean" +import { useBoolean } from "@/presentation/react/hooks/useBoolean" describe("hooks/useBoolean", () => { beforeEach(() => { diff --git a/hooks/useBoolean.ts b/presentation/react/hooks/useBoolean.ts similarity index 100% rename from hooks/useBoolean.ts rename to presentation/react/hooks/useBoolean.ts diff --git a/hooks/usePresenterState.ts b/presentation/react/hooks/usePresenterState.ts similarity index 85% rename from hooks/usePresenterState.ts rename to presentation/react/hooks/usePresenterState.ts index ca5c2bd..55717ce 100644 --- a/hooks/usePresenterState.ts +++ b/presentation/react/hooks/usePresenterState.ts @@ -1,6 +1,6 @@ import { useEffect, useState } from "react" -import type { Presenter } from "@/data/infrastructure/presenters/_Presenter" +import type { Presenter } from "@/presentation/presenters/_Presenter" export const usePresenterState = (presenter: Presenter): S => { const [state, setState] = useState(presenter.initialState) diff --git a/tests/jest.setup.ts b/tests/jest.setup.ts deleted file mode 100644 index 082878e..0000000 --- a/tests/jest.setup.ts +++ /dev/null @@ -1,5 +0,0 @@ -import "@testing-library/react-native/extend-expect" - -jest.mock("@react-native-async-storage/async-storage", () => { - return require("@react-native-async-storage/async-storage/jest/async-storage-mock") -})