Compare commits

..

No commits in common. "db0c2fe051357a24c47153cecb34516589d4a538" and "7e4dbd9e2db4ec78320cc696677c8dc21e17fbc3" have entirely different histories.

2 changed files with 7 additions and 80 deletions

View file

@ -1,75 +0,0 @@
import { fireEvent, render, screen } from '@testing-library/react';
import * as React from 'react';
import { describe, it, vi } from 'vitest';
import { Properties } from './Properties';
describe.concurrent('Properties', () => {
it('No properties', () => {
render(<Properties
properties={undefined}
onChange={() => {}}
/>);
expect(screen.queryByText(/property-/i)).toBeNull();
});
it('Some properties', () => {
const prop = {
id: 'stuff',
parentId: 'parentId',
x: 1,
y: 1
};
const handleChange = vi.fn((key, value) => {
(prop as any)[key] = value;
});
const { container, rerender } = render(<Properties
properties={prop}
onChange={handleChange}
/>);
let propertyId = container.querySelector('#property-id');
let propertyParentId = container.querySelector('#property-parentId');
let propertyX = container.querySelector('#property-x');
let propertyY = container.querySelector('#property-y');
expect(propertyId).toBeDefined();
expect((propertyId as HTMLInputElement).value).toBe('stuff');
expect(propertyParentId).toBeDefined();
expect((propertyParentId as HTMLInputElement).value).toBe('parentId');
expect(propertyX).toBeDefined();
expect((propertyX as HTMLInputElement).value).toBe('1');
expect(propertyY).toBeDefined();
expect((propertyY as HTMLInputElement).value).toBe('1');
fireEvent.change(propertyId as Element, { target: { value: 'stuffed' } });
fireEvent.change(propertyParentId as Element, { target: { value: 'parentedId' } });
fireEvent.change(propertyX as Element, { target: { value: '2' } });
fireEvent.change(propertyY as Element, { target: { value: '2' } });
expect(handleChange).toBeCalledTimes(4);
expect(prop.id).toBe('stuffed');
expect(prop.parentId).toBe('parentedId');
expect(prop.x).toBe('2');
expect(prop.y).toBe('2');
rerender(<Properties
properties={Object.assign({}, prop)}
onChange={handleChange}
/>);
propertyId = container.querySelector('#property-id');
propertyParentId = container.querySelector('#property-parentId');
propertyX = container.querySelector('#property-x');
propertyY = container.querySelector('#property-y');
expect(propertyId).toBeDefined();
expect((propertyId as HTMLInputElement).value).toBe('stuffed');
expect(propertyParentId).toBeDefined();
expect((propertyParentId as HTMLInputElement).value).toBe('parentedId');
expect(propertyX).toBeDefined();
expect((propertyX as HTMLInputElement).value).toBe('2');
expect(propertyY).toBeDefined();
expect((propertyY as HTMLInputElement).value).toBe('2');
});
});

View file

@ -3,8 +3,8 @@ import { describe, test, expect, vi } from 'vitest';
import { findByText, fireEvent, render, screen } from '../../utils/test-utils'; import { findByText, fireEvent, render, screen } from '../../utils/test-utils';
import Sidebar from './Sidebar'; import Sidebar from './Sidebar';
describe.concurrent('Sidebar', () => { describe.concurrent('Sidebar open', () => {
it('Start default', () => { it('Start default', async() => {
const handleClick = vi.fn(); const handleClick = vi.fn();
render( render(
<Sidebar <Sidebar
@ -23,7 +23,7 @@ describe.concurrent('Sidebar', () => {
expect(handleClick).toHaveBeenCalledTimes(1); expect(handleClick).toHaveBeenCalledTimes(1);
}); });
it('Start close', () => { it('Start close', async() => {
render(<Sidebar render(<Sidebar
componentOptions={[]} componentOptions={[]}
isOpen={false} isOpen={false}
@ -36,9 +36,11 @@ describe.concurrent('Sidebar', () => {
expect(stuff).toBeNull(); expect(stuff).toBeNull();
}); });
it('With stuff', () => { it('With stuff', async() => {
const Type = 'stuff'; const Type = 'stuff';
const handleButtonClick = vi.fn(); const handleButtonClick = vi.fn((type: string) => {
expect(type).toBe(Type);
});
render(<Sidebar render(<Sidebar
componentOptions={[ componentOptions={[
{ {