diff --git a/__mocks__/expo-image.js b/__mocks__/expo-image.js index 4fd577a9..ac0eec6d 100644 --- a/__mocks__/expo-image.js +++ b/__mocks__/expo-image.js @@ -1 +1,3 @@ -export const Image = ({ source }) => mocked-image; \ No newline at end of file +export const Image = ({ source }) => ( + mocked-image +); diff --git a/jest-setup.js b/jest-setup.js index 21ea206d..d881c1f2 100644 --- a/jest-setup.js +++ b/jest-setup.js @@ -1,9 +1,9 @@ -import 'react-native-gesture-handler/jestSetup'; +import "react-native-gesture-handler/jestSetup"; module.exports = { - moduleDirectories: ['node_modules', 'src'], + moduleDirectories: ["node_modules", "src"], moduleNameMapper: { - '^expo-image$': './__mocks__/expo-image.js', + "^expo-image$": "./__mocks__/expo-image.js", }, }; diff --git a/package-lock.json b/package-lock.json index 5ca8bc4a..7584a2f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,10 +11,12 @@ "@expo/vector-icons": "^13.0.0", "@expo/webpack-config": "^19.0.0", "@react-native-async-storage/async-storage": "1.18.2", + "@shopify/flash-list": "1.4.3", "@testing-library/jest-native": "^5.4.3", "axios": "^1.5.1", "expo": "^49.0.0", "expo-constants": "~14.4.2", + "expo-dev-client": "~2.4.12", "expo-image": "^1.5.1", "expo-image-picker": "~14.3.2", "expo-jwt": "^1.6.5", @@ -24,7 +26,9 @@ "expo-updates": "~0.18.17", "jest": "^29.2.1", "jest-expo": "^49.0.0", + "jest-mock-extended": "^3.0.5", "jest-sonar": "^0.2.16", + "jest-sonar-reporter": "^2.0.0", "react": "18.2.0", "react-dom": "18.2.0", "react-native": "0.72.6", @@ -36,7 +40,8 @@ "react-native-swiper": "^1.6.0", "react-native-toast-message": "^2.1.7", "react-native-vector-icons": "^10.0.0", - "react-native-web": "~0.19.6" + "react-native-web": "~0.19.6", + "ts-jest": "^29.1.1" }, "devDependencies": { "@babel/core": "^7.20.0", @@ -6655,6 +6660,25 @@ "join-component": "^1.1.0" } }, + "node_modules/@shopify/flash-list": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/@shopify/flash-list/-/flash-list-1.4.3.tgz", + "integrity": "sha512-jtIReAbwWzYBV0dQ6Io9wBX+pD0C4qQFMrb5/fkEvX8PYDgBl5KRYvpfr9WLLj8CV2Jsn1X0mYOsB+ysWrI/8g==", + "dependencies": { + "recyclerlistview": "4.2.0", + "tslib": "2.4.0" + }, + "peerDependencies": { + "@babel/runtime": "*", + "react": "*", + "react-native": "*" + } + }, + "node_modules/@shopify/flash-list/node_modules/tslib": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" + }, "node_modules/@sideway/address": { "version": "4.1.4", "resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.4.tgz", @@ -8728,6 +8752,17 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/bs-logger": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", + "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", + "dependencies": { + "fast-json-stable-stringify": "2.x" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -11670,6 +11705,114 @@ "expo": "*" } }, + "node_modules/expo-dev-client": { + "version": "2.4.12", + "resolved": "https://registry.npmjs.org/expo-dev-client/-/expo-dev-client-2.4.12.tgz", + "integrity": "sha512-3+xg0yb/0g6+JQaWq5+xn2uHoOXP4oSX33aWkaZPSNJLoyzfRaHNDF5MLcrMBbEHCw5T5qZRU291K+uQeMMC0g==", + "dependencies": { + "expo-dev-launcher": "2.4.14", + "expo-dev-menu": "3.2.2", + "expo-dev-menu-interface": "1.3.0", + "expo-manifests": "~0.7.0", + "expo-updates-interface": "~0.10.0" + }, + "peerDependencies": { + "expo": "*" + } + }, + "node_modules/expo-dev-launcher": { + "version": "2.4.14", + "resolved": "https://registry.npmjs.org/expo-dev-launcher/-/expo-dev-launcher-2.4.14.tgz", + "integrity": "sha512-SlUf+fEX9sKzDzY1Ui8j5775eLKpO0xPVoI89G7CRsrpUv6ZRvRF836cMFesxkU5d+3bXHpKzDQiEPDSI1G/WQ==", + "dependencies": { + "expo-dev-menu": "3.2.2", + "resolve-from": "^5.0.0", + "semver": "^7.5.3" + }, + "peerDependencies": { + "expo": "*" + } + }, + "node_modules/expo-dev-launcher/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/expo-dev-launcher/node_modules/semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/expo-dev-launcher/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, + "node_modules/expo-dev-menu": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/expo-dev-menu/-/expo-dev-menu-3.2.2.tgz", + "integrity": "sha512-q0IDlCGkZMsDIFV+Mgnz0Q3u/bcnrF8IFMglJ0onF09e5csLk5Ts7hKoQyervOJeThyI402r9OQsFNaru2tgtg==", + "dependencies": { + "expo-dev-menu-interface": "1.3.0", + "semver": "^7.5.3" + }, + "peerDependencies": { + "expo": "*" + } + }, + "node_modules/expo-dev-menu-interface": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/expo-dev-menu-interface/-/expo-dev-menu-interface-1.3.0.tgz", + "integrity": "sha512-WtRP7trQ2lizJJTTFXUSGGn1deIeHaYej0sUynvu/uC69VrSP4EeSnYOxbmEO29kuT/MsQBMGu0P/AkMQOqCOg==", + "peerDependencies": { + "expo": "*" + } + }, + "node_modules/expo-dev-menu/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/expo-dev-menu/node_modules/semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/expo-dev-menu/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, "node_modules/expo-eas-client": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/expo-eas-client/-/expo-eas-client-0.6.0.tgz", @@ -15438,6 +15581,18 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-mock-extended": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/jest-mock-extended/-/jest-mock-extended-3.0.5.tgz", + "integrity": "sha512-/eHdaNPUAXe7f65gHH5urc8SbRVWjYxBqmCgax2uqOBJy8UUcCBMN1upj1eZ8y/i+IqpyEm4Kq0VKss/GCCTdw==", + "dependencies": { + "ts-essentials": "^7.0.3" + }, + "peerDependencies": { + "jest": "^24.0.0 || ^25.0.0 || ^26.0.0 || ^27.0.0 || ^28.0.0 || ^29.0.0", + "typescript": "^3.0.0 || ^4.0.0 || ^5.0.0" + } + }, "node_modules/jest-pnp-resolver": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/jest-pnp-resolver/-/jest-pnp-resolver-1.2.3.tgz", @@ -17262,6 +17417,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" + }, "node_modules/makeerror": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.12.tgz", @@ -20558,6 +20718,20 @@ "node": ">= 4" } }, + "node_modules/recyclerlistview": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/recyclerlistview/-/recyclerlistview-4.2.0.tgz", + "integrity": "sha512-uuBCi0c+ggqHKwrzPX4Z/mJOzsBbjZEAwGGmlwpD/sD7raXixdAbdJ6BTcAmuWG50Cg4ru9p12M94Njwhr/27A==", + "dependencies": { + "lodash.debounce": "4.0.8", + "prop-types": "15.8.1", + "ts-object-utils": "0.0.5" + }, + "peerDependencies": { + "react": ">= 15.2.1", + "react-native": ">= 0.30.0" + } + }, "node_modules/redent": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz", @@ -22461,11 +22635,96 @@ "typescript": ">=4.2.0" } }, + "node_modules/ts-essentials": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/ts-essentials/-/ts-essentials-7.0.3.tgz", + "integrity": "sha512-8+gr5+lqO3G84KdiTSMRLtuyJ+nTBVRKuCrK4lidMPdVeEp0uqC875uE5NMcaA7YYMN7XsNiFQuMvasF8HT/xQ==", + "peerDependencies": { + "typescript": ">=3.7.0" + } + }, "node_modules/ts-interface-checker": { "version": "0.1.13", "resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz", "integrity": "sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==" }, + "node_modules/ts-jest": { + "version": "29.1.1", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.1.tgz", + "integrity": "sha512-D6xjnnbP17cC85nliwGiL+tpoKN0StpgE0TeOjXQTU6MVCfsB4v7aW05CgQ/1OywGb0x/oy9hHFnN+sczTiRaA==", + "dependencies": { + "bs-logger": "0.x", + "fast-json-stable-stringify": "2.x", + "jest-util": "^29.0.0", + "json5": "^2.2.3", + "lodash.memoize": "4.x", + "make-error": "1.x", + "semver": "^7.5.3", + "yargs-parser": "^21.0.1" + }, + "bin": { + "ts-jest": "cli.js" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + }, + "peerDependencies": { + "@babel/core": ">=7.0.0-beta.0 <8", + "@jest/types": "^29.0.0", + "babel-jest": "^29.0.0", + "jest": "^29.0.0", + "typescript": ">=4.3 <6" + }, + "peerDependenciesMeta": { + "@babel/core": { + "optional": true + }, + "@jest/types": { + "optional": true + }, + "babel-jest": { + "optional": true + }, + "esbuild": { + "optional": true + } + } + }, + "node_modules/ts-jest/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/ts-jest/node_modules/semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/ts-jest/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, + "node_modules/ts-object-utils": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/ts-object-utils/-/ts-object-utils-0.0.5.tgz", + "integrity": "sha512-iV0GvHqOmilbIKJsfyfJY9/dNHCs969z3so90dQWsO1eMMozvTpnB1MEaUbb3FYtZTGjv5sIy/xmslEz0Rg2TA==" + }, "node_modules/tsconfig-paths": { "version": "3.14.2", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz", @@ -22616,7 +22875,6 @@ "version": "5.2.2", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", - "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index fec4dbe0..80ce84f5 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,8 @@ "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web", - "test": "jest --passWithNoTests --no-cache --runInBand --detectOpenHandles --coverage --colors", + "test": "jest --passWithNoTests --no-cache --runInBand --detectOpenHandles --coverage --colors", "test:all": "CI=true npm run test -- --coverage", - "lint": "eslint . --fix" }, "dependencies": { @@ -33,7 +32,7 @@ "jest-sonar": "^0.2.16", "jest-mock-extended": "^3.0.5", "jest-sonar-reporter": "^2.0.0", - "ts-jest": "^29.1.1", + "ts-jest": "^29.1.1", "react": "18.2.0", "react-dom": "18.2.0", "react-native": "0.72.6", @@ -45,7 +44,9 @@ "react-native-swiper": "^1.6.0", "react-native-toast-message": "^2.1.7", "react-native-vector-icons": "^10.0.0", - "react-native-web": "~0.19.6" + "react-native-web": "~0.19.6", + "@shopify/flash-list": "1.4.3", + "expo-dev-client": "~2.4.12" }, "devDependencies": { "@babel/core": "^7.20.0", diff --git a/src/app/__tests__/CardIdoso.spec.tsx b/src/app/__tests__/CardIdoso.spec.tsx index 7b604534..7ccb327f 100644 --- a/src/app/__tests__/CardIdoso.spec.tsx +++ b/src/app/__tests__/CardIdoso.spec.tsx @@ -30,7 +30,7 @@ describe("CardIdoso", () => { const pencilIcon = screen.getByTestId("pencil-icon"); fireEvent.press(pencilIcon); - + // eslint-disable-next-line @typescript-eslint/no-var-requires expect(require("expo-router").router.push).toHaveBeenCalledWith({ pathname: "/private/pages/editarIdoso", params: { @@ -50,7 +50,7 @@ describe("CardIdoso", () => { const cardIdosoPressable = screen.getByTestId("cardIdosoPressable"); fireEvent.press(cardIdosoPressable); - + // eslint-disable-next-line @typescript-eslint/no-var-requires expect(require("expo-router").router.push).toHaveBeenCalledWith({ pathname: "/private/tabs/rotinas", }); diff --git a/src/app/__tests__/EmConstrucao.spec.tsx b/src/app/__tests__/EmConstrucao.spec.tsx index 580d33ee..e20bc5ca 100644 --- a/src/app/__tests__/EmConstrucao.spec.tsx +++ b/src/app/__tests__/EmConstrucao.spec.tsx @@ -1,18 +1,17 @@ -import React from 'react'; -import { render } from '@testing-library/react-native'; +import React from "react"; +import { render } from "@testing-library/react-native"; import EmConstrucao from "../components/EmConstrucao"; -describe('EmConstrucao component', () => { - test('renders correctly', () => { +describe("EmConstrucao component", () => { + test("renders correctly", () => { const { getByTestId, getByText } = render(); // Check if the component is rendered - const container = getByTestId('em-construcao-container'); + const container = getByTestId("em-construcao-container"); expect(container).toBeTruthy(); // Check if the text is rendered - const text = getByText('Página em construção!'); + const text = getByText("Página em construção!"); expect(text).toBeTruthy(); }); }); - diff --git a/src/app/__tests__/NaoAutenticado.spec.tsx b/src/app/__tests__/NaoAutenticado.spec.tsx index a2999fa6..00c6a06c 100644 --- a/src/app/__tests__/NaoAutenticado.spec.tsx +++ b/src/app/__tests__/NaoAutenticado.spec.tsx @@ -1,7 +1,6 @@ import React from "react"; import { render, screen } from "@testing-library/react-native"; import NaoAutenticado from "../components/NaoAutenticado"; -import LinkButton from "../components/LinkButton"; describe("NaoAutenticado", () => { it("deve renderizar o componente 'NaoAutenticado' corretamente", () => { diff --git a/src/app/__tests__/UploadImageV2.spec.tsx b/src/app/__tests__/UploadImageV2.spec.tsx index 2997511b..3ea234c9 100644 --- a/src/app/__tests__/UploadImageV2.spec.tsx +++ b/src/app/__tests__/UploadImageV2.spec.tsx @@ -6,16 +6,14 @@ import UploadImageV2 from "../components/UploadImageV2"; jest.mock("expo-image-picker"); import * as ImagePicker from "expo-image-picker"; -const launchImageLibraryAsyncMock = jest - .fn() - .mockResolvedValueOnce({ - assets: [ - { - uri: "fakeImageUri", - base64: "fakeBase64", - }, - ], - }); +const launchImageLibraryAsyncMock = jest.fn().mockResolvedValueOnce({ + assets: [ + { + uri: "fakeImageUri", + base64: "fakeBase64", + }, + ], +}); ImagePicker.launchImageLibraryAsync = launchImageLibraryAsyncMock; @@ -23,7 +21,10 @@ describe("UploadImageV2", () => { it("deve renderizar corretamente e chamar a função de callback ao selecionar uma imagem", async () => { const setPhotoCallbackMock = jest.fn(); const { getByTestId } = render( - + , ); fireEvent.press(getByTestId("uploadImageButton")); diff --git a/src/app/__tests__/cadastrarIdoso.spec.tsx b/src/app/__tests__/cadastrarIdoso.spec.tsx index 5104a1c6..241d4be2 100644 --- a/src/app/__tests__/cadastrarIdoso.spec.tsx +++ b/src/app/__tests__/cadastrarIdoso.spec.tsx @@ -1,29 +1,28 @@ -import React from 'react'; -import { render } from '@testing-library/react-native'; -import CadastrarIdoso from '../private/pages/cadastrarIdoso'; -import AsyncStorage, { AsyncStorageStatic } from '@react-native-async-storage/async-storage'; +import React from "react"; +import { render } from "@testing-library/react-native"; +import CadastrarIdoso from "../private/pages/cadastrarIdoso"; +import AsyncStorage from "@react-native-async-storage/async-storage"; // Mock any dependencies if needed // Mock AsyncStorage -jest.mock('@react-native-async-storage/async-storage', () => ({ - getItem: jest.fn(), - })); - -describe('CadastrarIdoso component', () => { - test('renders correctly', () => { +jest.mock("@react-native-async-storage/async-storage", () => ({ + getItem: jest.fn(), +})); +describe("CadastrarIdoso component", () => { + test("renders correctly", () => { (AsyncStorage.getItem as jest.Mock).mockImplementation((key) => { - if (key === 'usuario') { - return Promise.resolve(JSON.stringify({ id: 1 })); - } else if (key === 'token') { - return Promise.resolve('mockedToken'); - } - return Promise.resolve(null); - }); + if (key === "usuario") { + return Promise.resolve(JSON.stringify({ id: 1 })); + } else if (key === "token") { + return Promise.resolve("mockedToken"); + } + return Promise.resolve(null); + }); const { getByText } = render(); - - const cadastrarButton = getByText('Cadastrar'); + + const cadastrarButton = getByText("Cadastrar"); expect(cadastrarButton).toBeTruthy(); }); -}); \ No newline at end of file +}); diff --git a/src/app/__tests__/criaPublicacao.spec.tsx b/src/app/__tests__/criaPublicacao.spec.tsx index 1096a9ce..d9187dd8 100644 --- a/src/app/__tests__/criaPublicacao.spec.tsx +++ b/src/app/__tests__/criaPublicacao.spec.tsx @@ -1,25 +1,25 @@ -import React from 'react'; -import { render } from '@testing-library/react-native'; -import AsyncStorage, { AsyncStorageStatic } from '@react-native-async-storage/async-storage'; -import CriaPublicacao from '../private/pages/criaPublicacao'; +import React from "react"; +import { render } from "@testing-library/react-native"; +import AsyncStorage from "@react-native-async-storage/async-storage"; +import CriaPublicacao from "../private/pages/criaPublicacao"; // Mock AsyncStorage -jest.mock('@react-native-async-storage/async-storage', () => ({ +jest.mock("@react-native-async-storage/async-storage", () => ({ getItem: jest.fn(), })); -describe('CriaPublicacao', () => { - test('The component rendered', () => { +describe("CriaPublicacao", () => { + test("The component rendered", () => { // Mock the response for AsyncStorage.getItem (AsyncStorage.getItem as jest.Mock).mockImplementation((key) => { - if (key === 'usuario') { + if (key === "usuario") { return Promise.resolve(JSON.stringify({ id: 1 })); - } else if (key === 'token') { - return Promise.resolve('mockedToken'); + } else if (key === "token") { + return Promise.resolve("mockedToken"); } return Promise.resolve(null); }); render(); }); -}); \ No newline at end of file +}); diff --git a/src/app/__tests__/editarIdoso.spec.tsx b/src/app/__tests__/editarIdoso.spec.tsx index 911d1875..3cedc53f 100644 --- a/src/app/__tests__/editarIdoso.spec.tsx +++ b/src/app/__tests__/editarIdoso.spec.tsx @@ -1,14 +1,14 @@ -import '@testing-library/jest-native/extend-expect'; -import { render, fireEvent, waitFor, act } from '@testing-library/react-native'; -import AsyncStorage from '@react-native-async-storage/async-storage'; -import EditarIdoso from '../private/pages/editarIdoso'; +import "@testing-library/jest-native/extend-expect"; +import { render } from "@testing-library/react-native"; +import AsyncStorage from "@react-native-async-storage/async-storage"; +import EditarIdoso from "../private/pages/editarIdoso"; // Mock AsyncStorage para retornar valores específicos durante o teste -jest.mock('@react-native-async-storage/async-storage', () => ({ +jest.mock("@react-native-async-storage/async-storage", () => ({ getItem: jest.fn(), })); -describe('EditarIdoso', () => { +describe("EditarIdoso", () => { const mockUsuario = { id: 123, // outras propriedades do usuário, se necessário @@ -19,9 +19,9 @@ describe('EditarIdoso', () => { AsyncStorage.getItem.mockResolvedValue(JSON.stringify(mockUsuario)); }); - it('renderiza corretamente', () => { + it("renderiza corretamente", () => { render(); - + // Você pode continuar a escrever o teste de renderização aqui }); }); diff --git a/src/app/__tests__/editarPerfil.spec.tsx b/src/app/__tests__/editarPerfil.spec.tsx index c3f28872..dad737a9 100644 --- a/src/app/__tests__/editarPerfil.spec.tsx +++ b/src/app/__tests__/editarPerfil.spec.tsx @@ -1,95 +1,113 @@ -import React from 'react'; -import { render, fireEvent, waitFor, act } from '@testing-library/react-native'; -import EditarPerfil from '../private/pages/editarPerfil'; +import React from "react"; +import { render, fireEvent, waitFor, act } from "@testing-library/react-native"; +import EditarPerfil from "../private/pages/editarPerfil"; -describe('EditarPerfil component', () => { - - test('Atualiza nome com o input', async () => { +describe("EditarPerfil component", () => { + test("Atualiza nome com o input", async () => { const { getByPlaceholderText } = render(); - const nameInput = getByPlaceholderText('Nome completo'); - fireEvent.changeText(nameInput, 'Gustavo A'); + const nameInput = getByPlaceholderText("Nome completo"); + fireEvent.changeText(nameInput, "Gustavo A"); await waitFor(() => { - expect(nameInput.props.value).toBe('Gustavo A'); + expect(nameInput.props.value).toBe("Gustavo A"); }); }); - test('Exibe mensagem de erro ao tentar salvar com nome vazio', async () => { - const { getByText, getByPlaceholderText, queryByText } = render(); - const nameInput = getByPlaceholderText('Nome completo'); - fireEvent.changeText(nameInput, ''); + test("Exibe mensagem de erro ao tentar salvar com nome vazio", async () => { + const { getByText, getByPlaceholderText, queryByText } = render( + , + ); + const nameInput = getByPlaceholderText("Nome completo"); + fireEvent.changeText(nameInput, ""); - const saveButton = getByText('Salvar'); + const saveButton = getByText("Salvar"); fireEvent.press(saveButton); await waitFor(() => { - expect(getByText('Campo obrigatório!')).toBeTruthy(); + expect(getByText("Campo obrigatório!")).toBeTruthy(); }); // Certifique-se de que a mensagem de erro específica não está presente quando não deve ser exibida await waitFor(() => { - expect(queryByText('O nome completo deve ter pelo menos 5 caractéres.')).toBeNull(); - expect(queryByText('O nome completo deve ter no máximo 60 caractéres.')).toBeNull(); + expect( + queryByText("O nome completo deve ter pelo menos 5 caractéres."), + ).toBeNull(); + expect( + queryByText("O nome completo deve ter no máximo 60 caractéres."), + ).toBeNull(); }); }); - test('Exibe mensagem de erro ao tentar salvar com nome muito curto', async () => { - const { getByText, getByPlaceholderText, findByText } = render(); - const nameInput = getByPlaceholderText('Nome completo'); - fireEvent.changeText(nameInput, 'Jo'); + test("Exibe mensagem de erro ao tentar salvar com nome muito curto", async () => { + const { getByText, getByPlaceholderText, findByText } = render( + , + ); + const nameInput = getByPlaceholderText("Nome completo"); + fireEvent.changeText(nameInput, "Jo"); - const saveButton = getByText('Salvar'); + const saveButton = getByText("Salvar"); fireEvent.press(saveButton); await act(async () => { - const errorMessage = await findByText('O nome completo deve ter pelo menos 5 caractéres.'); + const errorMessage = await findByText( + "O nome completo deve ter pelo menos 5 caractéres.", + ); expect(errorMessage).toBeTruthy(); }); }); - test('Exibe mensagem de erro ao tentar salvar com nome muito longo', async () => { - const { getByText, getByPlaceholderText, findByText } = render(); - const nameInput = getByPlaceholderText('Nome completo'); + test("Exibe mensagem de erro ao tentar salvar com nome muito longo", async () => { + const { getByText, getByPlaceholderText, findByText } = render( + , + ); + const nameInput = getByPlaceholderText("Nome completo"); fireEvent.changeText( nameInput, - 'Lorem Ipsum é apenas um texto fictício da indústria de impressão e composição tipográfica.' + "Lorem Ipsum é apenas um texto fictício da indústria de impressão e composição tipográfica.", ); - const saveButton = getByText('Salvar'); + const saveButton = getByText("Salvar"); fireEvent.press(saveButton); await act(async () => { - const errorMessage = await findByText('O nome completo deve ter no máximo 60 caractéres.'); + const errorMessage = await findByText( + "O nome completo deve ter no máximo 60 caractéres.", + ); expect(errorMessage).toBeTruthy(); }); }); - - test('Não exibe mensagem de erro ao salvar com nome válido', async () => { - const { getByText, getByPlaceholderText, queryByText } = render(); - const nameInput = getByPlaceholderText('Nome completo'); - fireEvent.changeText(nameInput, 'Nome Válido'); - - const saveButton = getByText('Salvar'); + + test("Não exibe mensagem de erro ao salvar com nome válido", async () => { + const { getByText, getByPlaceholderText, queryByText } = render( + , + ); + const nameInput = getByPlaceholderText("Nome completo"); + fireEvent.changeText(nameInput, "Nome Válido"); + + const saveButton = getByText("Salvar"); fireEvent.press(saveButton); - + // Certifique-se de que nenhuma mensagem de erro é exibida await waitFor(() => { - expect(queryByText('Campo obrigatório!')).toBeNull(); - expect(queryByText('O nome completo deve ter pelo menos 5 caractéres.')).toBeNull(); - expect(queryByText('O nome completo deve ter no máximo 60 caractéres.')).toBeNull(); + expect(queryByText("Campo obrigatório!")).toBeNull(); + expect( + queryByText("O nome completo deve ter pelo menos 5 caractéres."), + ).toBeNull(); + expect( + queryByText("O nome completo deve ter no máximo 60 caractéres."), + ).toBeNull(); }); }); - - test('Exibe mensagem de confirmação ao apagar conta', async () => { - const { getByText, getByPlaceholderText, findByText } = render(); - const apagarContaButton = getByText('Apagar Conta'); - + + test("Exibe mensagem de confirmação ao apagar conta", async () => { + const { getByText, findByText } = render(); + const apagarContaButton = getByText("Apagar Conta"); + fireEvent.press(apagarContaButton); - + // Aguarde até que a mensagem de confirmação seja encontrada await waitFor(() => { - expect(findByText('Prosseguir com a exclusão da conta?')).toBeTruthy(); + expect(findByText("Prosseguir com a exclusão da conta?")).toBeTruthy(); }); }); - }); diff --git a/src/app/__tests__/editarPublicacao.spec.tsx b/src/app/__tests__/editarPublicacao.spec.tsx index 952f9807..e0f3e78c 100644 --- a/src/app/__tests__/editarPublicacao.spec.tsx +++ b/src/app/__tests__/editarPublicacao.spec.tsx @@ -1,10 +1,9 @@ -import React from 'react'; -import { render } from '@testing-library/react-native'; -import EditarPublicacao from '../private/pages/editarPublicacao'; +import React from "react"; +import { render } from "@testing-library/react-native"; +import EditarPublicacao from "../private/pages/editarPublicacao"; -describe('', () => { - it('renders without crashing', () => { +describe("", () => { + it("renders without crashing", () => { render(); }); - -}); \ No newline at end of file +}); diff --git a/src/app/__tests__/image.helper.spec.tsx b/src/app/__tests__/image.helper.spec.tsx index 984f396b..7b1e8bcb 100644 --- a/src/app/__tests__/image.helper.spec.tsx +++ b/src/app/__tests__/image.helper.spec.tsx @@ -14,19 +14,19 @@ describe("getImageUri", () => { }); it("Imagem ja esta codificada", () => { - - var base64Icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAwBQTFRF7c5J78kt+/Xm78lQ6stH5LI36bQh6rcf7sQp671G89ZZ8c9V8c5U9+u27MhJ/Pjv9txf8uCx57c937Ay5L1n58Nb67si8tVZ5sA68tJX/Pfr7dF58tBG9d5e8+Gc6chN6LM+7spN1pos6rYs6L8+47hE7cNG6bQc9uFj7sMn4rc17cMx3atG8duj+O7B686H7cAl7cEm7sRM26cq/vz5/v767NFY7tJM78Yq8s8y3agt9dte6sVD/vz15bY59Nlb8txY9+y86LpA5LxL67pE7L5H05Ai2Z4m58Vz89RI7dKr+/XY8Ms68dx/6sZE7sRCzIEN0YwZ67wi6rk27L4k9NZB4rAz7L0j5rM66bMb682a5sJG6LEm3asy3q0w3q026sqC8cxJ6bYd685U5a457cIn7MBJ8tZW7c1I7c5K7cQ18Msu/v3678tQ3aMq7tNe6chu6rgg79VN8tNH8c0w57Q83akq7dBb9Nld9d5g6cdC8dyb675F/v327NB6////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/LvB3QAAAMFJREFUeNpiqIcAbz0ogwFKm7GgCjgyZMihCLCkc0nkIAnIMVRw2UhDBGp5fcurGOyLfbhVtJwLdJkY8oscZCsFPBk5spiNaoTC4hnqk801Qi2zLQyD2NlcWWP5GepN5TOtSxg1QwrV01itpECG2kaLy3AYiCWxcRozQWyp9pNMDWePDI4QgVpbx5eo7a+mHFOqAxUQVeRhdrLjdFFQggqo5tqVeSS456UEQgWE4/RBboxyC4AKCEI9Wu9lUl8PEGAAV7NY4hyx8voAAAAASUVORK5CYII=", + ); }); - + it("Imagem vazia", () => { - const result = getImageUri(); - expect(result).toMatch('data:image/png;base64,'); + expect(result).toMatch("data:image/png;base64,"); }); - }); diff --git a/src/app/__tests__/layoutPages.spec.tsx b/src/app/__tests__/layoutPages.spec.tsx index fd77549e..9b83116e 100644 --- a/src/app/__tests__/layoutPages.spec.tsx +++ b/src/app/__tests__/layoutPages.spec.tsx @@ -1,21 +1,21 @@ -import React from 'react'; -import { render } from '@testing-library/react-native'; -import PublicLayout from '../public/_layout'; -import PrivateLayout from '../private/pages/_layout'; +import React from "react"; +import { render } from "@testing-library/react-native"; +import PublicLayout from "../public/_layout"; +import PrivateLayout from "../private/pages/_layout"; // Mock expo-router -jest.mock('expo-router', () => ({ +jest.mock("expo-router", () => ({ Stack: ({ children }: { children: React.ReactNode }) => <>{children}, })); -describe('Layouts', () => { - it('renders PublicLayout correctly', () => { +describe("Layouts", () => { + it("renders PublicLayout correctly", () => { const { toJSON } = render(); expect(toJSON()).toMatchSnapshot(); }); - it('renders PrivateLayout correctly', () => { + it("renders PrivateLayout correctly", () => { const { toJSON } = render(); expect(toJSON()).toMatchSnapshot(); }); -}); \ No newline at end of file +}); diff --git a/src/app/__tests__/listarIdosos.spec.tsx b/src/app/__tests__/listarIdosos.spec.tsx index 094a90ef..3a5530b4 100644 --- a/src/app/__tests__/listarIdosos.spec.tsx +++ b/src/app/__tests__/listarIdosos.spec.tsx @@ -3,8 +3,7 @@ import React from "react"; import { render, waitFor } from "@testing-library/react-native"; import ListarIdosos from "../private/pages/listarIdosos"; import { getAllIdoso } from "../services/idoso.service"; -import AsyncStorage, { AsyncStorageStatic } from '@react-native-async-storage/async-storage'; - +import AsyncStorage from "@react-native-async-storage/async-storage"; // Mockando o módulo dos serviços para substituir as implementações jest.mock("../services/idoso.service"); @@ -13,10 +12,10 @@ describe("ListarIdosos", () => { it("deve chamar a função de getAllIdoso ao montar o componente", async () => { // Simula uma resposta fictícia da API (AsyncStorage.getItem as jest.Mock).mockImplementation((key) => { - if (key === 'usuario') { + if (key === "usuario") { return Promise.resolve(JSON.stringify({ id: 1 })); - } else if (key === 'token') { - return Promise.resolve('mockedToken'); + } else if (key === "token") { + return Promise.resolve("mockedToken"); } return Promise.resolve(null); }); @@ -31,14 +30,19 @@ describe("ListarIdosos", () => { it("deve exibir a lista de idosos após a conclusão da chamada da API", async () => { // Simula uma resposta fictícia da API (AsyncStorage.getItem as jest.Mock).mockImplementation((key) => { - if (key === 'usuario') { + if (key === "usuario") { return Promise.resolve(JSON.stringify({ id: 1 })); - } else if (key === 'token') { - return Promise.resolve('mockedToken'); + } else if (key === "token") { + return Promise.resolve("mockedToken"); } return Promise.resolve(null); }); - (getAllIdoso as jest.Mock).mockResolvedValueOnce({ data: [{ id: 1, nome: "Idoso 1" }, { id: 2, nome: "Idoso 2" }] }); + (getAllIdoso as jest.Mock).mockResolvedValueOnce({ + data: [ + { id: 1, nome: "Idoso 1" }, + { id: 2, nome: "Idoso 2" }, + ], + }); const { getByText } = render(); diff --git a/src/app/__tests__/login-success.spec.tsx b/src/app/__tests__/login-success.spec.tsx index 27d554d6..3da78d40 100644 --- a/src/app/__tests__/login-success.spec.tsx +++ b/src/app/__tests__/login-success.spec.tsx @@ -1,7 +1,6 @@ import React from "react"; import { render, fireEvent, act } from "@testing-library/react-native"; import Login from "../public/login"; -import { router } from "expo-router"; // Mock do AsyncStorage jest.mock("@react-native-async-storage/async-storage", () => ({ @@ -16,7 +15,6 @@ jest.mock("expo-router", () => ({ })); // Mock da função de login // eslint-disable-next-line @typescript-eslint/no-var-requires -const userService = require("../services/user.service"); jest.mock("../services/user.service"); describe("Login Component - Sucesso", () => { diff --git a/src/app/__tests__/visualizarPublicacao.spec.tsx b/src/app/__tests__/visualizarPublicacao.spec.tsx index 7fe47de1..550c3ae9 100644 --- a/src/app/__tests__/visualizarPublicacao.spec.tsx +++ b/src/app/__tests__/visualizarPublicacao.spec.tsx @@ -1,12 +1,12 @@ -import React from 'react'; -import { render } from '@testing-library/react-native'; -import VisualizarPublicacao from '../private/pages/visualizarPublicacao'; +import React from "react"; +import { render } from "@testing-library/react-native"; +import VisualizarPublicacao from "../private/pages/visualizarPublicacao"; -describe('Visualizar publicacao', () => { - it('Rendeziza sem quebrar', () => { +describe("Visualizar publicacao", () => { + it("Rendeziza sem quebrar", () => { render(); }); - it('displays actions correctly for admin', () => { + it("displays actions correctly for admin", () => { const { getByText } = render(, { initialState: { usuario: { @@ -16,6 +16,6 @@ describe('Visualizar publicacao', () => { }, }); - expect(getByText('Apagar')).toBeTruthy(); + expect(getByText("Apagar")).toBeTruthy(); }); -}) +}); diff --git a/src/app/components/MaskHour.tsx b/src/app/components/MaskHour.tsx index a477d074..d75df9c5 100644 --- a/src/app/components/MaskHour.tsx +++ b/src/app/components/MaskHour.tsx @@ -1,40 +1,36 @@ import React from "react"; -import { TextInput, TextInputProps, View } from "react-native"; +import { TextInput, TextInputProps } from "react-native"; interface MaskHourProps extends TextInputProps { - inputMaskChange: (value:string) => unknown; + inputMaskChange: (value: string) => unknown; } export default function MaskInput({ - inputMaskChange, - ...textInput}: Readonly){ - - - function handlechange(text:string){ - const value = MaskHour(text); - inputMaskChange(value); - } - - function MaskHour(value: string){ - value = value.replace(/\D/g, ""); - value = value.replace(/^(\d{2})(\d)/, "$1:$2"); + inputMaskChange, + ...textInput +}: Readonly) { + function handlechange(text: string) { + const value = MaskHour(text); + inputMaskChange(value); + } - if (value[0] > "2") { - value = ""; - } if (value[1] > "9"){ - value = value[0]; - } if (value[3] > "5"){ - value = value[0] + value[1] + value[2]; - } - return value; + function MaskHour(value: string) { + value = value.replace(/\D/g, ""); + value = value.replace(/^(\d{2})(\d)/, "$1:$2"); + if (value[0] > "2") { + value = ""; + } + if (value[1] > "9") { + value = value[0]; } + if (value[3] > "5") { + value = value[0] + value[1] + value[2]; + } + return value; + } - return ( - handlechange(text)} - {...textInput} - /> - ); + return ( + handlechange(text)} {...textInput} /> + ); } - diff --git a/src/app/components/ModalConfirmation.tsx b/src/app/components/ModalConfirmation.tsx index dd383bc3..58944089 100644 --- a/src/app/components/ModalConfirmation.tsx +++ b/src/app/components/ModalConfirmation.tsx @@ -17,31 +17,29 @@ export default function ModalConfirmation({ messageButton, }: Readonly) { return ( - - - - - {message} - - closeModal()} - > - Cancelar - - callbackFn()} - > - {messageButton} - - + + + + {message} + + closeModal()} + > + Cancelar + + callbackFn()} + > + {messageButton} + - - + + ); } diff --git a/src/app/components/Publicacao.tsx b/src/app/components/Publicacao.tsx index 1a7ac4f4..f1886813 100644 --- a/src/app/components/Publicacao.tsx +++ b/src/app/components/Publicacao.tsx @@ -86,12 +86,14 @@ export default function Publicacao({ item, crop }: Readonly) { {getDescricao(item.descricao)} - {item.idUsuarioReporte.length > 0 && ( - - - {item.idUsuarioReporte.length} - - )} + {item.idUsuarioReporte.length > 0 && ( + + + + {item.idUsuarioReporte.length} + + + )} ); diff --git a/src/app/components/PublicacaoVisualizar.tsx b/src/app/components/PublicacaoVisualizar.tsx index ac067a4b..ab201ce8 100644 --- a/src/app/components/PublicacaoVisualizar.tsx +++ b/src/app/components/PublicacaoVisualizar.tsx @@ -48,12 +48,14 @@ export default function PublicacaoVisualizar({ item }: Readonly) { {getFormattedDate(item.dataHora)} - {item.idUsuarioReporte.length > 0 && ( - - - {item.idUsuarioReporte.length} - - )} + {item.idUsuarioReporte.length > 0 && ( + + + + {item.idUsuarioReporte.length} + + + )} ); diff --git a/src/app/components/UploadImageV2.tsx b/src/app/components/UploadImageV2.tsx index c47d9fc7..01f35cd1 100644 --- a/src/app/components/UploadImageV2.tsx +++ b/src/app/components/UploadImageV2.tsx @@ -1,5 +1,5 @@ import React, { useState } from "react"; -import { StyleSheet, Pressable, View, Text } from "react-native"; +import { StyleSheet, Pressable } from "react-native"; import * as ImagePicker from "expo-image-picker"; import Icon from "react-native-vector-icons/MaterialCommunityIcons"; import { getImageUri, noImage } from "../shared/helpers/image.helper"; @@ -13,7 +13,6 @@ interface Props { export default function UploadImageV2({ setPhotoCallback, base64, - }: Readonly) { if (base64) { base64 = getImageUri(base64); @@ -36,7 +35,11 @@ export default function UploadImageV2({ }; return ( - + id !== Number(idUsuario)); + const idRemovido = publicacaoLoaded.idUsuarioReporte.filter( + (id) => id !== Number(idUsuario), + ); const body = { idUsuarioReporte: idRemovido, @@ -125,7 +127,10 @@ export default function VisualizarPublicacao() { updateReporte(publicacaoLoaded, body); }; - const updateReporte =async (publicacaoLoaded: IPublicacaoUsuario, body: Partial) => { + const updateReporte = async ( + publicacaoLoaded: IPublicacaoUsuario, + body: Partial, + ) => { try { const response = await updatePublicacao(publicacaoLoaded.id, body, token); setPublicacao({ @@ -176,30 +181,31 @@ export default function VisualizarPublicacao() { )} - {idUsuario && - publicacao?.idUsuario != idUsuario && ( - setModalVisibleReportar(true)} - style={[styles.actionButton, styles.reportButton]} - > - {showLoadingReportar && ( - - )} + {idUsuario && publicacao?.idUsuario != idUsuario && ( + setModalVisibleReportar(true)} + style={[styles.actionButton, styles.reportButton]} + > + {showLoadingReportar && ( + + )} - {!showLoadingReportar && publicacao?.idUsuarioReporte.includes(idUsuario) && ( + {!showLoadingReportar && + publicacao?.idUsuarioReporte.includes(idUsuario) && ( <> Desfazer )} - {!showLoadingReportar && !publicacao?.idUsuarioReporte.includes(idUsuario) && ( + {!showLoadingReportar && + !publicacao?.idUsuarioReporte.includes(idUsuario) && ( <> Reportar )} - - )} + + )} {idUsuario && publicacao?.idUsuario == idUsuario && ( setModalVisibleReportar(false)} - message= {publicacao?.idUsuarioReporte.includes(Number(idUsuario))? "Desfazer reporte?" : "Reportar publicação?"} - messageButton={publicacao?.idUsuarioReporte.includes(Number(idUsuario))? "Desfazer" : "Reportar"} + message={ + publicacao?.idUsuarioReporte.includes(Number(idUsuario)) + ? "Desfazer reporte?" + : "Reportar publicação?" + } + messageButton={ + publicacao?.idUsuarioReporte.includes(Number(idUsuario)) + ? "Desfazer" + : "Reportar" + } /> ); diff --git a/src/app/services/rotina.service.ts b/src/app/services/rotina.service.ts index 9d2369cd..6263afe8 100644 --- a/src/app/services/rotina.service.ts +++ b/src/app/services/rotina.service.ts @@ -1,5 +1,8 @@ -import { IOrder } from "../interfaces/forum.interface"; -import { IRotina, IRotinaBody, IRotinaFilter } from "../interfaces/rotina.interface"; +import { + IRotina, + IRotinaBody, + IRotinaFilter, +} from "../interfaces/rotina.interface"; import { IResponse } from "../interfaces/response.interface"; const API_URL = process.env.EXPO_PUBLIC_API_URL; @@ -30,12 +33,9 @@ export const postRotina = async ( }; export const getAllRotina = async ( - filter: IRotinaFilter, -) // order: IOrder, - : Promise> => { - const params = `limit=20&offset=0&filter=${JSON.stringify( - filter, - )}`; + filter: IRotinaFilter, // order: IOrder, +): Promise> => { + const params = `limit=20&offset=0&filter=${JSON.stringify(filter)}`; const response = await fetch(`${BASE_URL}?${params}`, { method: "GET", headers: {