FunctionEditor.test.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { render, screen } from '@testing-library/react';
  2. import React from 'react';
  3. import { FuncInstance } from '../gfunc';
  4. import { FunctionEditor } from './FunctionEditor';
  5. function mockFunctionInstance(name: string, unknown?: boolean): FuncInstance {
  6. const def = {
  7. category: 'category',
  8. defaultParams: [],
  9. fake: false,
  10. name: name,
  11. params: [],
  12. unknown: unknown,
  13. };
  14. return new FuncInstance(def);
  15. }
  16. describe('FunctionEditor', () => {
  17. it('should display a defined function with name and no icon', () => {
  18. render(
  19. <FunctionEditor
  20. func={mockFunctionInstance('foo')}
  21. onMoveLeft={() => {}}
  22. onMoveRight={() => {}}
  23. onRemove={() => {}}
  24. />
  25. );
  26. expect(screen.getByText('foo')).toBeInTheDocument();
  27. expect(screen.queryByTestId('warning-icon')).not.toBeInTheDocument();
  28. });
  29. it('should display an unknown function with name and warning icon', () => {
  30. render(
  31. <FunctionEditor
  32. func={mockFunctionInstance('bar', true)}
  33. onMoveLeft={jest.fn()}
  34. onMoveRight={jest.fn()}
  35. onRemove={jest.fn()}
  36. />
  37. );
  38. expect(screen.getByText('bar')).toBeInTheDocument();
  39. expect(screen.getByTestId('warning-icon')).toBeInTheDocument();
  40. });
  41. });