Fakultas Ilmu Komputer UI

index.test.tsx 1009 Bytes
Newer Older
1
import React from 'react';
2
import { render, fireEvent, waitFor } from 'utils/testing';
3
4
5
6
7
8
import * as ROUTES from 'constants/routes';

import LogoutButton from '.';

describe('LogoutButton', () => {
  const userContextMock = {
9
10
11
    user: {
      id: 1,
    },
12
13
14
15
    isAuthenticated: true,
    logout: jest.fn(),
  };

16
17
18
19
  it('renders nothing when user is not authenticated', () => {
    render(<LogoutButton />, ROUTES.initial);
  });

20
  it('renders correctly', () => {
21
    render(<LogoutButton />, ROUTES.checkout, { userContext: userContextMock });
22
23
24
  });

  it('calls logout and redirects to initial page when clicked', async () => {
25
26
    const { getByTestId, queryByText } = render(
      <LogoutButton />,
27
      ROUTES.checkout,
28
29
30
      {
        userContext: userContextMock,
      },
31
32
33
34
35
    );

    const logoutButton = getByTestId('logoutButton');
    expect(logoutButton).toBeTruthy();
    await waitFor(() => fireEvent.press(logoutButton));
36
37

    expect(queryByText(/konsultasi sekarang/i)).toBeTruthy();
38
39
  });
});