Skip to content

Commit

Permalink
Social tests
Browse files Browse the repository at this point in the history
  • Loading branch information
algarfer committed May 1, 2024
1 parent 6629539 commit 0405f63
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 61 deletions.
61 changes: 0 additions & 61 deletions webapp/src/__test__/views/AddUser.draft.js

This file was deleted.

82 changes: 82 additions & 0 deletions webapp/src/__test__/views/Social.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

import { useAuth } from "../../App.jsx";
import '@testing-library/jest-dom';
import Social from '../../views/Social.jsx';
import { screen, waitFor, act } from '@testing-library/react';
import { customRender } from "../utils/customRenderer";
import React from 'react';
// import axios from "axios";

const render = customRender((() => useAuth())())
// jest.mock('axios');
jest.mock('../../App.jsx', () => ({
useAuth: jest.fn().mockReturnValue({
getUser: jest.fn().mockReturnValue({
token: 'testUser',
userId: 'test',
username: 'test'
}),
isAuthenticated: jest.fn().mockReturnValue(true),
logout: jest.fn(),
setUser: jest.fn()
})
}));

describe('Social component', () => {

it('load component', async () => {
await act(async () => render(<Social />));

waitFor(() => {
expect(history.location.pathname).toBe("/social");
expect(screen.getByText(/Friends/i)).toBeInTheDocument();
expect(screen.getByText(/Requests/i)).toBeInTheDocument();
expect(screen.getByText(/Friends Ranking/i)).toBeInTheDocument();
expect(screen.getByText(/Search users/i)).toBeInTheDocument();
})
});

it('Friends menu', async () => {
await act(async () => render(<Social />));

waitFor(() => {
expect(history.location.pathname).toBe("/social");
const friendsBt = screen.getByText(/Friends/i, {selector: "a"})
act(() => friendsBt.click())
waitFor(() => expect(screen.getByText(/Oops, this seems empty .../i)).toBeInTheDocument())
})
});

it('Requests menu', async () => {
await act(() => render(<Social />));

waitFor(() => {
expect(history.location.pathname).toBe("/social");
const friendsBt = screen.getByText(/Requests/i, {selector: "a"})
act(() => friendsBt.click())
waitFor(() => expect(screen.getByText(/Oops, this seems empty .../i)).toBeInTheDocument())
})
});

it('Friends ranking', async () => {
await act(async () => render(<Social />));

waitFor(() => {
expect(history.location.pathname).toBe("/social");
const friendsBt = screen.getByText(/Friends Ranking/i, {selector: "a"})
act(() => friendsBt.click())
waitFor(() => expect(screen.getByText(/No scores to show/i)).toBeInTheDocument())
})
});

it('Friends ranking', async () => {
await act(async () => render(<Social />));

waitFor(() => {
expect(history.location.pathname).toBe("/social");
const friendsBt = screen.getByText(/Search users/i, {selector: "a"})
act(() => friendsBt.click())
waitFor(() => expect(screen.getByText(/Search users/i)).toBeInTheDocument())
})
});
})

0 comments on commit 0405f63

Please sign in to comment.