Compare commits

...

2 commits

Author SHA1 Message Date
db0c2fe051 Remove expect calls in callback functions
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-06 16:29:51 +02:00
548b70f951 Added test for properties 2022-08-06 16:29:32 +02:00
2 changed files with 80 additions and 7 deletions

View file

@ -0,0 +1,75 @@
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 Sidebar from './Sidebar';
describe.concurrent('Sidebar open', () => {
it('Start default', async() => {
describe.concurrent('Sidebar', () => {
it('Start default', () => {
const handleClick = vi.fn();
render(
<Sidebar
@ -23,7 +23,7 @@ describe.concurrent('Sidebar open', () => {
expect(handleClick).toHaveBeenCalledTimes(1);
});
it('Start close', async() => {
it('Start close', () => {
render(<Sidebar
componentOptions={[]}
isOpen={false}
@ -36,11 +36,9 @@ describe.concurrent('Sidebar open', () => {
expect(stuff).toBeNull();
});
it('With stuff', async() => {
it('With stuff', () => {
const Type = 'stuff';
const handleButtonClick = vi.fn((type: string) => {
expect(type).toBe(Type);
});
const handleButtonClick = vi.fn();
render(<Sidebar
componentOptions={[
{