Skip to content

Commit 5298700

Browse files
authored
Merge branch 'main' into task/RPE-127/Add-simple-logger-for-BE-log-messages
2 parents 0ef6950 + b5a3271 commit 5298700

File tree

2 files changed

+208
-0
lines changed

2 files changed

+208
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import React from 'react';
2+
import { render, screen, fireEvent } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
import FleModal from '../../components/ModalWindows/FleModal';
5+
import { FieldType } from '../../utils/common';
6+
7+
const mockCloseModal = jest.fn();
8+
const mockOnSubmit = jest.fn();
9+
10+
const mockDefaultValue = {
11+
name: 'Test Name',
12+
lut6: 32,
13+
flip_flop: 16,
14+
clock: 'Clock1',
15+
toggle_rate: 1.5,
16+
glitch_factor: 'Factor1',
17+
clock_enable_rate: 50,
18+
};
19+
20+
const mockClocks = ['Clock1', 'Clock2'];
21+
const mockGlitchFactor = ['Factor1', 'Factor2'];
22+
23+
jest.mock('../../ClockSelectionProvider', () => ({
24+
useClockSelection: () => ({
25+
clocks: mockClocks,
26+
}),
27+
}));
28+
29+
jest.mock('../../GlobalStateProvider', () => ({
30+
useGlobalState: () => ({
31+
GetOptions: (option) => (option === 'Glitch_Factor' ? mockGlitchFactor : []),
32+
}),
33+
}));
34+
35+
describe('FleModal Component', () => {
36+
beforeEach(() => {
37+
render(
38+
<FleModal
39+
title="Test Fle Modal"
40+
defaultValue={mockDefaultValue}
41+
closeModal={mockCloseModal}
42+
onSubmit={mockOnSubmit}
43+
/>
44+
);
45+
});
46+
47+
it('renders the modal with the correct title', () => {
48+
expect(screen.getByText('Test Fle Modal')).toBeInTheDocument();
49+
});
50+
51+
it('renders the Name/Hierarchy field with correct default value', () => {
52+
const nameInput = screen.getByDisplayValue('Test Name');
53+
expect(nameInput).toBeInTheDocument();
54+
});
55+
56+
it('renders the LUT6 field with correct default value', () => {
57+
const lut6Input = screen.getByDisplayValue('32');
58+
expect(lut6Input).toBeInTheDocument();
59+
});
60+
61+
it('renders the FF/Latch field with correct default value', () => {
62+
const ffInput = screen.getByDisplayValue('16');
63+
expect(ffInput).toBeInTheDocument();
64+
});
65+
66+
it('renders the clock select field with correct default value', () => {
67+
const clockSelect = screen.getByDisplayValue('Clock1');
68+
expect(clockSelect).toBeInTheDocument();
69+
});
70+
71+
it('renders the toggle rate field with correct default value', () => {
72+
const toggleRateInput = screen.getByDisplayValue('150.0');
73+
expect(toggleRateInput).toBeInTheDocument();
74+
});
75+
76+
it('renders the clock enable rate field with correct default value', () => {
77+
const clockEnableInput = screen.getByDisplayValue('5000');
78+
expect(clockEnableInput).toBeInTheDocument();
79+
});
80+
81+
82+
it('calls closeModal when the close button is clicked', () => {
83+
const closeButton = screen.getByRole('button', { name: /cancel/i });
84+
fireEvent.click(closeButton);
85+
expect(mockCloseModal).toHaveBeenCalled();
86+
});
87+
88+
it('calls onSubmit with correct data when the form is submitted', () => {
89+
const submitButton = screen.getByRole('button', { name: /ok/i });
90+
fireEvent.click(submitButton);
91+
expect(mockOnSubmit).toHaveBeenCalledWith(mockDefaultValue);
92+
});
93+
94+
it('updates the Name/Hierarchy field when changed', () => {
95+
const nameInput = screen.getByDisplayValue('Test Name');
96+
fireEvent.change(nameInput, { target: { value: 'Updated Name' } });
97+
expect(nameInput.value).toBe('Updated Name');
98+
});
99+
100+
it('updates the LUT6 field when changed', () => {
101+
const lut6Input = screen.getByDisplayValue('32');
102+
fireEvent.change(lut6Input, { target: { value: '64' } });
103+
expect(lut6Input.value).toBe('64');
104+
});
105+
106+
it('updates the clock select field when changed', () => {
107+
const clockSelect = screen.getByDisplayValue('Clock1');
108+
fireEvent.change(clockSelect, { target: { value: 'Clock2' } });
109+
expect(screen.getByDisplayValue('Clock2')).toBeInTheDocument();
110+
});
111+
});
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import React from 'react';
2+
import { render, screen, fireEvent } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
import IOModal from '../../components/ModalWindows/IOModal';
5+
import { FieldType } from '../../utils/common';
6+
7+
const mockCloseModal = jest.fn();
8+
const mockOnSubmit = jest.fn();
9+
10+
const mockDefaultValue = {
11+
name: 'Test Port',
12+
bus_width: 16,
13+
clock: 'Clock1',
14+
duty_cycle: 50,
15+
direction: 'Input',
16+
io_standard: 'Standard1',
17+
drive_strength: 'Strength1',
18+
slew_rate: 'Fast',
19+
differential_termination: 'Termination1',
20+
io_pull_up_down: 'PullUp',
21+
io_data_type: 'Type1',
22+
input_enable_rate: 100,
23+
output_enable_rate: 200,
24+
synchronization: 'Sync1',
25+
toggle_rate: 1.5,
26+
};
27+
28+
const mockClocks = ['Clock1', 'Clock2'];
29+
const mockOptions = {
30+
IO_Direction: ['Input', 'Output'],
31+
IO_Standard: ['Standard1', 'Standard2'],
32+
IO_Drive_Strength: ['Strength1', 'Strength2'],
33+
IO_Slew_Rate: ['Fast', 'Slow'],
34+
IO_differential_termination: ['Termination1', 'Termination2'],
35+
IO_Data_Type: ['Type1', 'Type2'],
36+
IO_Synchronization: ['Sync1', 'Sync2'],
37+
IO_Pull_up_down: ['PullUp', 'PullDown'],
38+
};
39+
40+
jest.mock('../../ClockSelectionProvider', () => ({
41+
useClockSelection: () => ({
42+
clocks: mockClocks,
43+
}),
44+
}));
45+
46+
jest.mock('../../GlobalStateProvider', () => ({
47+
useGlobalState: () => ({
48+
GetOptions: (option) => mockOptions[option],
49+
}),
50+
}));
51+
52+
describe('IOModal Component', () => {
53+
beforeEach(() => {
54+
render(
55+
<IOModal
56+
title="Test IO Modal"
57+
defaultValue={mockDefaultValue}
58+
closeModal={mockCloseModal}
59+
onSubmit={mockOnSubmit}
60+
/>
61+
);
62+
});
63+
64+
it('renders the modal with the correct title', () => {
65+
expect(screen.getByText('Test IO Modal')).toBeInTheDocument();
66+
});
67+
68+
it('calls closeModal when the close button is clicked', () => {
69+
const closeButton = screen.getByRole('button', { name: /cancel/i });
70+
fireEvent.click(closeButton);
71+
expect(mockCloseModal).toHaveBeenCalled();
72+
});
73+
74+
it('calls onSubmit with correct data when the form is submitted', () => {
75+
const submitButton = screen.getByRole('button', { name: /ok/i });
76+
fireEvent.click(submitButton);
77+
expect(mockOnSubmit).toHaveBeenCalledWith(mockDefaultValue);
78+
});
79+
80+
it('updates the RTL Port Name field when changed', () => {
81+
const nameInput = screen.getByDisplayValue('Test Port');
82+
fireEvent.change(nameInput, { target: { value: 'Updated Port' } });
83+
expect(nameInput.value).toBe('Updated Port');
84+
});
85+
86+
it('updates the bus width field when changed', () => {
87+
const busWidthInput = screen.getByDisplayValue('16');
88+
fireEvent.change(busWidthInput, { target: { value: '32' } });
89+
expect(busWidthInput.value).toBe('32');
90+
});
91+
92+
it('updates the clock field when changed', () => {
93+
const clockSelect = screen.getByDisplayValue('Clock1');
94+
fireEvent.change(clockSelect, { target: { value: 'Clock2' } });
95+
expect(screen.getByDisplayValue('Clock2')).toBeInTheDocument();
96+
});
97+
});

0 commit comments

Comments
 (0)