forked from fga-eps-mds/2023-2-GEROcuidado-Front
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: render idoso and user information
Co-Authored-By: Natalia Rodrigues <Natytotherodrigues@gmail.com>
- Loading branch information
1 parent
3418a7b
commit 747d829
Showing
1 changed file
with
40 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,44 @@ | ||
import React from "react"; | ||
import { render, waitFor } from "@testing-library/react-native"; | ||
import Registros from "../private/tabs/registros"; | ||
import AsyncStorage from "@react-native-async-storage/async-storage/jest/async-storage-mock"; | ||
import React from 'react'; | ||
import { render, waitFor, fireEvent } from '@testing-library/react-native'; | ||
import Registros from '../private/tabs/registros'; | ||
import AsyncStorage from '@react-native-async-storage/async-storage'; | ||
import { IIdoso } from '../interfaces/idoso.interface'; | ||
import { IMetrica } from '../interfaces/metricas.interface'; | ||
import { Q } from '@nozbe/watermelondb'; | ||
import database from '../db'; | ||
import { getAllMetrica } from '../services/metrica.service'; | ||
import Toast from 'react-native-toast-message'; | ||
|
||
describe("Registros", () => { | ||
it("renderiza corretamente", async () => { | ||
await waitFor(() => render(<Registros />)); | ||
}); | ||
// Mocking the necessary components and services | ||
jest.mock('@react-native-async-storage/async-storage', () => ({ | ||
getItem: jest.fn(), | ||
})); | ||
|
||
jest.mock('../db', () => ({ | ||
get: jest.fn().mockReturnValue({ | ||
query: jest.fn().mockReturnValue({ | ||
fetch: jest.fn(), | ||
}), | ||
}), | ||
})); | ||
|
||
jest.mock('react-native-toast-message'); | ||
|
||
it("renderiza corretamente com user id", async () => { | ||
AsyncStorage.setItem("usuario", JSON.stringify({ id: 1 })); | ||
describe('Registros', () => { | ||
const mockUser = { id: 'user1', nome: 'User Test' }; | ||
const mockIdoso: IIdoso = { id: 'idoso1', nome: 'Idoso Test', foto: null }; | ||
const mockMetricas: IMetrica[] = [{ _raw: { idoso_id: 'idoso1' } }]; | ||
|
||
await waitFor(() => render(<Registros />)); | ||
beforeEach(() => { | ||
// Clear mocks before each test | ||
jest.clearAllMocks(); | ||
}); | ||
}); | ||
|
||
it('should render the user and idoso information when both are available', async () => { | ||
(AsyncStorage.getItem as jest.Mock) | ||
.mockResolvedValueOnce(JSON.stringify(mockUser)) // Mocking user | ||
.mockResolvedValueOnce(JSON.stringify(mockIdoso)); // Mocking idoso | ||
|
||
const { getByText, getByTestId } = render(<Registros />); | ||
}); | ||
}); |