This commit is contained in:
parent
2c7a1bc96c
commit
126b34fda4
1 changed files with 47 additions and 6 deletions
|
@ -1,19 +1,60 @@
|
|||
import * as React from 'react';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { render, screen } from '../../utils/test-utils';
|
||||
import { describe, test, expect, vi } from 'vitest';
|
||||
import { findByText, fireEvent, render, screen } from '../../utils/test-utils';
|
||||
import Sidebar from './Sidebar';
|
||||
|
||||
describe('Sidebar test', () => {
|
||||
test('Start empty', () => {
|
||||
describe.concurrent('Sidebar open', () => {
|
||||
it('Start default', async() => {
|
||||
const handleClick = vi.fn();
|
||||
render(
|
||||
<Sidebar
|
||||
componentOptions={[]}
|
||||
isOpen={true}
|
||||
onClick={() => {}}
|
||||
onClick={handleClick}
|
||||
buttonOnClick={() => {}}
|
||||
/>
|
||||
);
|
||||
const stuff = screen.queryByText(/stuff/i);
|
||||
const close = screen.getByText(/close/i);
|
||||
|
||||
expect(screen.getByText(/Components/i)).toBeDefined();
|
||||
expect(screen.getByText(/Components/i).classList.contains('left-0')).toBeDefined();
|
||||
expect(stuff).toBeNull();
|
||||
fireEvent.click(close);
|
||||
expect(handleClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('Start close', async() => {
|
||||
render(<Sidebar
|
||||
componentOptions={[]}
|
||||
isOpen={false}
|
||||
onClick={() => {}}
|
||||
buttonOnClick={() => {}}
|
||||
/>);
|
||||
|
||||
const stuff = screen.queryByText(/stuff/i);
|
||||
expect(screen.getByText(/Components/i).classList.contains('-left-64')).toBeDefined();
|
||||
expect(stuff).toBeNull();
|
||||
});
|
||||
|
||||
it('With stuff', async() => {
|
||||
const handleButtonClick = vi.fn();
|
||||
render(<Sidebar
|
||||
componentOptions={[
|
||||
{
|
||||
Type: 'stuff',
|
||||
Width: 30,
|
||||
Height: 30,
|
||||
Style: {}
|
||||
}
|
||||
]}
|
||||
isOpen={true}
|
||||
onClick={() => {}}
|
||||
buttonOnClick={handleButtonClick}
|
||||
/>);
|
||||
const stuff = screen.getByText(/stuff/i);
|
||||
|
||||
expect(stuff).toBeDefined();
|
||||
fireEvent.click(stuff);
|
||||
expect(handleButtonClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue