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.

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

import { getCanvasGallerySaveErrorAction, withMatchingCanvasProject } from './canvasGallerySaveState';

describe('withMatchingCanvasProject', () => {
  it('does not run save, refresh, or error effects for a mismatched engine and project', () => {
    const save = vi.fn();
    const refresh = vi.fn();
    const recordError = vi.fn();

    const result = withMatchingCanvasProject({ projectId: 'engine-project' }, 'active-project', () => {
      save();
      refresh();
      recordError();
    });

    expect(result).toBeUndefined();
    expect(save).not.toHaveBeenCalled();
    expect(refresh).not.toHaveBeenCalled();
    expect(recordError).not.toHaveBeenCalled();
  });
});

describe('getCanvasGallerySaveErrorAction', () => {
  it('maps a save failure to one localized record with diagnostic context', () => {
    expect(
      getCanvasGallerySaveErrorAction(new Error('backend exploded'), 'project-1', "Couldn't save to gallery")
    ).toEqual({
      area: 'canvas-save-to-gallery',
      context: { error: 'backend exploded' },
      message: "Couldn't save to gallery",
      namespace: 'canvas',
      projectId: 'project-1',
    });
  });

  it('records under the caller-provided area', () => {
    expect(
      getCanvasGallerySaveErrorAction(
        new Error('backend exploded'),
        'project-1',
        "Couldn't create from BBox",
        'canvas-create-from-bbox'
      )
    ).toMatchObject({ area: 'canvas-create-from-bbox', message: "Couldn't create from BBox" });
  });
});