Fakultas Ilmu Komputer UI

index.test.tsx 1.08 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React from 'react';
import { render, waitFor } from 'utils/testing';
import * as ROUTES from 'constants/routes';
import axios from 'axios';

import ClientListAdmin from '.';
import { mockClientList } from '__mocks__/clientList';

jest.mock('axios');
const mockAxios = axios as jest.Mocked<typeof axios>;

describe('ClientListAdmin', () => {
  it('renders correctly', async () => {
    mockAxios.request.mockImplementationOnce(() =>
      Promise.resolve({
        status: 200,
        data: [],
      }),
    );
    render(<ClientListAdmin />, ROUTES.clientListForAdmin);
  });

  it('shows correct client list', async () => {
    mockAxios.request.mockImplementationOnce(() =>
      Promise.resolve({
        status: 200,
        data: mockClientList,
      }),
    );

    const { queryByText, queryAllByText } = render(
      <ClientListAdmin />,
      ROUTES.clientListForAdmin,
    );

    await waitFor(() => expect(queryAllByText(/List Klien/i)).toBeTruthy());

    expect(queryByText(mockClientList[0].user.name)).toBeTruthy();
    expect(queryByText(/Download Csv/i)).toBeTruthy();
  });
});