This improve greatly the performance and the code cleaning. It allows us to separate the inseparable class methods into modules functions
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import * as React from 'react';
|
|
import { describe, it, expect, vi } from 'vitest';
|
|
import { fireEvent, render, screen } from '../../utils/test-utils';
|
|
import { Sidebar } from './Sidebar';
|
|
|
|
describe.concurrent('Sidebar', () => {
|
|
it('Start default', () => {
|
|
render(
|
|
<Sidebar
|
|
componentOptions={[]}
|
|
isOpen={true}
|
|
buttonOnClick={() => {}}
|
|
/>
|
|
);
|
|
const stuff = screen.queryByText(/stuff/i);
|
|
|
|
expect(screen.getByText(/Components/i).classList.contains('left-0')).toBeDefined();
|
|
expect(stuff).toBeNull();
|
|
});
|
|
|
|
it('Start close', () => {
|
|
render(<Sidebar
|
|
componentOptions={[]}
|
|
isOpen={false}
|
|
buttonOnClick={() => {}}
|
|
/>);
|
|
|
|
const stuff = screen.queryByText(/stuff/i);
|
|
expect(screen.getByText(/Components/i).classList.contains('-left-64')).toBeDefined();
|
|
expect(stuff).toBeNull();
|
|
});
|
|
|
|
it('With stuff', () => {
|
|
const Type = 'stuff';
|
|
const handleButtonClick = vi.fn();
|
|
render(<Sidebar
|
|
componentOptions={[
|
|
{
|
|
Type,
|
|
Width: 30,
|
|
Height: 30,
|
|
Style: {}
|
|
}
|
|
]}
|
|
isOpen={true}
|
|
buttonOnClick={handleButtonClick}
|
|
/>);
|
|
const stuff = screen.getByText(/stuff/i);
|
|
|
|
expect(stuff).toBeDefined();
|
|
fireEvent.click(stuff);
|
|
expect(handleButtonClick).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|