Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

2.9 KB
Raw Blame
import { describe, expect, it } from 'vitest';

import {
  getNaturalDestination,
  getPlacedWidgetTypeIds,
  getSourceIdForWidgetTypeId,
  getVisibleWidgetTypeIds,
  getWidgetTypeIdForSourceId,
  graphWidgetSources,
  isGraphWidgetTypeId,
} from './graphWidgets';
import { createInitialWorkbenchState, workbenchReducer } from './workbenchState.testing';

const applyPreset = (presetId: string) => {
  const state = workbenchReducer(createInitialWorkbenchState(), { presetId, type: 'applyPreset' });

  return state.projects.find((candidate) => candidate.id === state.activeProjectId)!;
};

describe('graph widget sources', () => {
  it('recognises only the graph-bearing widget types', () => {
    expect(isGraphWidgetTypeId('generate')).toBe(true);
    expect(isGraphWidgetTypeId('canvas')).toBe(true);
    expect(isGraphWidgetTypeId('upscale')).toBe(true);
    expect(isGraphWidgetTypeId('workflow')).toBe(true);
    expect(isGraphWidgetTypeId('gallery')).toBe(false);
    expect(isGraphWidgetTypeId('preview')).toBe(false);
    expect(getSourceIdForWidgetTypeId('gallery')).toBeNull();
    expect(getSourceIdForWidgetTypeId('workflow')).toBe('workflow');
    expect(getWidgetTypeIdForSourceId('upscale')).toBe('upscale');
  });

  // Keep unplaced sources selectable so switching sources does not require manual layout changes.
  it('offers every graph widget as a source', () => {
    expect(graphWidgetSources.map((source) => source.sourceId)).toEqual([
      'generate',
      'canvas',
      'upscale',
      'video',
      'workflow',
    ]);
  });

  it('separates active widgets from placed secondary widgets', () => {
    const project = applyPreset('edit');

    // Edit shows Generate on the left and Canvas in the centre...
    expect([...getVisibleWidgetTypeIds(project)]).toEqual(expect.arrayContaining(['generate', 'canvas']));
    expect(getVisibleWidgetTypeIds(project).has('workflow')).toBe(false);

    expect([...getPlacedWidgetTypeIds(project)]).toEqual(expect.arrayContaining(['generate', 'canvas', 'upscale']));
    expect(getPlacedWidgetTypeIds(project).has('workflow')).toBe(false);
  });

  it('counts a floated widget as both visible and placed', () => {
    let state = workbenchReducer(createInitialWorkbenchState(), { presetId: 'edit', type: 'applyPreset' });
    state = workbenchReducer(state, { instanceId: 'upscale', type: 'floatWidget' });
    const project = state.projects.find((candidate) => candidate.id === state.activeProjectId)!;

    expect(project.floatingWidgets?.upscale).toBeDefined();
    expect(getVisibleWidgetTypeIds(project).has('upscale')).toBe(true);
    expect(getPlacedWidgetTypeIds(project).has('upscale')).toBe(true);
  });

  it('maps each source to its natural output target', () => {
    expect(getNaturalDestination('canvas')).toBe('canvas');
    expect(getNaturalDestination('generate')).toBe('gallery');
    expect(getNaturalDestination('workflow')).toBe('gallery');
  });
});