Skip to content

Commit

Permalink
Arreglado un test de GroupDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
iyanfdezz committed Apr 16, 2024
1 parent 0fb5aa9 commit 68def40
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
8 changes: 4 additions & 4 deletions webapp/src/pages/Social/GroupDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ const GroupDetails = () => {
const response = await fetch(
`${apiEndpoint}/group/${encodeURIComponent(groupName)}`
);
// if (!response.status === 200) {
// throw new Error("Network response was not ok");
// }
if (!response.status === 200) {
throw new Error("Network response was not ok");
}
const data = await response.json();
setGroup(data.group);
setGroup(data);
setError(null);
} catch (error) {
setError(error);
Expand Down
42 changes: 18 additions & 24 deletions webapp/src/pages/Social/GroupDetails.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ const mockNavigate = jest.fn();
useNavigate: () => mockNavigate,
}));

const checks = (async () => {
await waitFor(() => {
expect(screen.getByText('Detalles del grupo exampleGroup')).toBeInTheDocument();
expect(screen.getByText('Avatar')).toBeInTheDocument();
expect(screen.getByText('Nombre')).toBeInTheDocument();
const viewProfile = screen.getAllByText('Ver perfil');
expect(viewProfile).toHaveLength(3);
expect(screen.getByTestId('user-avatar-user1')).toBeInTheDocument();
expect(screen.getByTestId('user-avatar-user2')).toBeInTheDocument();
expect(screen.getByText('user1')).toBeInTheDocument();
expect(screen.getByText('user2')).toBeInTheDocument();
});
});

describe('GroupDetails', () => {
beforeEach(() => {
localStorage.clear();
Expand All @@ -61,45 +75,25 @@ describe('GroupDetails', () => {
it('renders group details when data is fetched', async () => {

jest.spyOn(global, "fetch").mockResolvedValue({
ok: true,
status: 200,
json: jest.fn().mockResolvedValueOnce(groupData),
});

renderComponentWithRouter();

await waitFor(() => {
expect(screen.getByText('Detalles del grupo exampleGroup')).toBeInTheDocument();
expect(screen.getByText('Avatar')).toBeInTheDocument();
expect(screen.getByText('Nombre')).toBeInTheDocument();
const viewProfile = screen.getAllByText('Ver perfil');
expect(viewProfile).toHaveLength(3);
expect(screen.getByTestId('user-avatar-user1')).toBeInTheDocument();
expect(screen.getByTestId('user-avatar-user2')).toBeInTheDocument();
expect(screen.getByText('user1')).toBeInTheDocument();
expect(screen.getByText('user2')).toBeInTheDocument();
});
checks();
});

it('redirects to user profile when view profile link is clicked', async () => {

jest.spyOn(global, "fetch").mockResolvedValue({
ok: true,
status: 200,
json: jest.fn().mockResolvedValueOnce(groupData),
});

renderComponentWithRouter();

await waitFor(() => {
expect(screen.getByText('Detalles del grupo exampleGroup')).toBeInTheDocument();
expect(screen.getByText('Avatar')).toBeInTheDocument();
expect(screen.getByText('Nombre')).toBeInTheDocument();
const viewProfile = screen.getAllByText('Ver perfil');
expect(viewProfile).toHaveLength(3);
expect(screen.getByTestId('user-avatar-user1')).toBeInTheDocument();
expect(screen.getByTestId('user-avatar-user2')).toBeInTheDocument();
expect(screen.getByText('user1')).toBeInTheDocument();
expect(screen.getByText('user2')).toBeInTheDocument();
});


const viewProfileButtons = screen.getByTestId('view-profile-button-user1');

Expand Down

0 comments on commit 68def40

Please sign in to comment.