Skip to content

Commit

Permalink
test: render idoso and user information
Browse files Browse the repository at this point in the history
Co-Authored-By: Natalia Rodrigues <Natytotherodrigues@gmail.com>
  • Loading branch information
GabrielSMonteiro and Natyrodrigues committed Sep 19, 2024
1 parent 3418a7b commit 747d829
Showing 1 changed file with 40 additions and 12 deletions.
52 changes: 40 additions & 12 deletions src/app/__tests__/registros.spec.tsx
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 />);
  });
});

0 comments on commit 747d829

Please sign in to comment.