UI test utils

This package presents UI functions that you can invoke to simplify plugin testing. It requires an environment like jest or jasmine that has the beforeEach symbol defined globally.

Installation

These test utils are packed as a part of the @orion/ui module. You only need to import like: import { test-utils you need } from @orion/ui/test-utils on your tests in order to be able to use them.

renderPOSComponent

Plugins use POSComponents to define views inside the application. In your tests, you want to test those POSComponents. The function renderPOSComponent renders a POSComponent of the given name.

Copy
import { renderPOSComponent } from '@orion/ui/test-utils';

function<Helper> renderPOSComponent(
  componentName: string,
  props?: object,
  children?: React.ReactNode,
): RenderResult

Arguments:

  • componentName: is the component name to render,

  • props (optional): props to pass to that component.

  • children (optional): children to pass to that component.

The result is the corresponding object for the render method of the @testing-library/react.

renderPluginComponent

Plugins can define their custom Components to define views inside the application. In your tests, you want to test those Components. The function renderPluginComponent renders a Component registered by a plugin.

Copy
import { renderPluginComponent } from '@orion/ui/test-utils';

function renderPluginComponent(
  plugin: Plugin,
  componentName: string,
  props?: object,
  children?: React.ReactNode,
): RenderResult;

Arguments:

  • plugin: is the instance of the plugin producing the Component.

  • componentName: is the name of the component to render.

  • props (optional): props to pass to that component.

  • children (optional): children to pass to that component.

The result is the corresponding object for the render method of the @testing-library/react.

render

The function render from @orion/ui/test-utils renders a React Element wrapping it inside all the configured Wrappers of the application (e.g., the Store Provider from Redux).

Copy
import { render } from '@orion/ui/test-utils';

function render(ui: React.ReactElement): RenderResult;

Arguments:

  • ui: is the React Element to be rendered inside the Application wrappers

The result is the corresponding object for the render method of the @testing-library/react.

GAST

There is no special function to render GAST. GAST components are POSComponents like the React ones. No special API is required.