File size: 2,444 Bytes
eff6797
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { describe, it, expect, vi } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/react';
import DatasetTrainingConfigPanel from '../DatasetTrainingConfigPanel';
import { DATASET_PROFILES } from '../../utils/datasetProfiles';

describe('DatasetTrainingConfigPanel', () => {
  it('renders nothing when isOpen is false', () => {
    const { container } = render(
      <DatasetTrainingConfigPanel
        isOpen={false}
        onClose={vi.fn()}
        onLaunch={vi.fn()}
      />
    );
    expect(container).toBeEmptyDOMElement();
  });

  it('renders header, dataset cards, and mode toggles when isOpen is true', () => {
    render(
      <DatasetTrainingConfigPanel
        isOpen={true}
        onClose={vi.fn()}
        onLaunch={vi.fn()}
      />
    );

    expect(screen.getByText(/Configure Training Session/i)).toBeInTheDocument();
    expect(screen.getAllByText(/PaySim Mobile Money/i).length).toBeGreaterThanOrEqual(1);
    expect(screen.getByText(/IEEE-CIS Fraud Detection/i)).toBeInTheDocument();
    expect(screen.getByText(/Elliptic Bitcoin AML Graph/i)).toBeInTheDocument();
    expect(screen.getByText(/European Credit Card Fraud/i)).toBeInTheDocument();

    expect(screen.getByText(/Offline Sandbox Demo/i)).toBeInTheDocument();
    expect(screen.getByText(/Live Backend Engine/i)).toBeInTheDocument();
  });

  it('calls onLaunch with selected dataset and mode when Launch Training is clicked', () => {
    const handleLaunch = vi.fn();
    render(
      <DatasetTrainingConfigPanel
        isOpen={true}
        onClose={vi.fn()}
        onLaunch={handleLaunch}
      />
    );

    // Select Elliptic
    fireEvent.click(screen.getByText(/Elliptic Bitcoin AML Graph/i));

    // Toggle Live Backend Engine mode
    fireEvent.click(screen.getByText(/Live Backend Engine/i));

    // Click Launch
    fireEvent.click(screen.getByText(/Launch Real Training/i));

    expect(handleLaunch).toHaveBeenCalledTimes(1);
    expect(handleLaunch).toHaveBeenCalledWith(DATASET_PROFILES.elliptic, 'real');
  });

  it('calls onClose when close button is clicked', () => {
    const handleClose = vi.fn();
    render(
      <DatasetTrainingConfigPanel
        isOpen={true}
        onClose={handleClose}
        onLaunch={vi.fn()}
      />
    );

    const closeBtn = screen.getByLabelText(/Close config panel/i);
    fireEvent.click(closeBtn);
    expect(handleClose).toHaveBeenCalledTimes(1);
  });
});