svg-layout-designer-react/src/Components/Sidebar/Sidebar.test.tsx
Eric Nguyen d9e06537e8
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Merged PR 16: Transform every single class components into functional component
This improve greatly the performance and the code cleaning.
It allows us to separate the inseparable class methods into modules functions
2022-08-09 15:15:56 +00:00

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);
});
});