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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
import { getGalleryItemDragData } from '@features/gallery/utility';
import { describe, expect, it } from 'vitest';
import { PREVIEW_COMPARE_DROP_DATA, resolvePreviewCompareDrop } from './previewCompareDnd';
const NOTHING_PREVIEWED = null;
describe('resolvePreviewCompareDrop', () => {
it('resolves the first dragged gallery image', () => {
const activeData = getGalleryItemDragData([
{ kind: 'image', name: 'first.png' },
{ kind: 'image', name: 'second.png' },
]);
expect(resolvePreviewCompareDrop(activeData, PREVIEW_COMPARE_DROP_DATA, NOTHING_PREVIEWED)).toEqual({
imageName: 'first.png',
});
});
it('ignores drops that are not on the compare target', () => {
const activeData = getGalleryItemDragData([{ kind: 'image', name: 'first.png' }]);
expect(resolvePreviewCompareDrop(activeData, { kind: 'gallery-board' }, NOTHING_PREVIEWED)).toBeNull();
expect(resolvePreviewCompareDrop(activeData, null, NOTHING_PREVIEWED)).toBeNull();
});
it('ignores non-image, video, mixed, and empty drags', () => {
expect(
resolvePreviewCompareDrop({ kind: 'widget-instance' }, PREVIEW_COMPARE_DROP_DATA, NOTHING_PREVIEWED)
).toBeNull();
expect(
resolvePreviewCompareDrop(
getGalleryItemDragData([{ kind: 'video', name: 'clip.mp4' }]),
PREVIEW_COMPARE_DROP_DATA,
NOTHING_PREVIEWED
)
).toBeNull();
expect(
resolvePreviewCompareDrop(
getGalleryItemDragData([
{ kind: 'image', name: 'still.png' },
{ kind: 'video', name: 'clip.mp4' },
]),
PREVIEW_COMPARE_DROP_DATA,
NOTHING_PREVIEWED
)
).toBeNull();
expect(
resolvePreviewCompareDrop({ items: [], kind: 'gallery-item' }, PREVIEW_COMPARE_DROP_DATA, NOTHING_PREVIEWED)
).toBeNull();
});
it('refuses to compare the previewed image with itself', () => {
const activeData = getGalleryItemDragData([{ kind: 'image', name: 'shown.png' }]);
expect(resolvePreviewCompareDrop(activeData, PREVIEW_COMPARE_DROP_DATA, 'shown.png')).toBeNull();
});
it('still resolves any other image while one is previewed', () => {
const activeData = getGalleryItemDragData([{ kind: 'image', name: 'other.png' }]);
expect(resolvePreviewCompareDrop(activeData, PREVIEW_COMPARE_DROP_DATA, 'shown.png')).toEqual({
imageName: 'other.png',
});
});
it('judges a multi-image drag by the image it would arm', () => {
const leadingIsPreviewed = getGalleryItemDragData([
{ kind: 'image', name: 'shown.png' },
{ kind: 'image', name: 'other.png' },
]);
const trailingIsPreviewed = getGalleryItemDragData([
{ kind: 'image', name: 'other.png' },
{ kind: 'image', name: 'shown.png' },
]);
expect(resolvePreviewCompareDrop(leadingIsPreviewed, PREVIEW_COMPARE_DROP_DATA, 'shown.png')).toBeNull();
expect(resolvePreviewCompareDrop(trailingIsPreviewed, PREVIEW_COMPARE_DROP_DATA, 'shown.png')).toEqual({
imageName: 'other.png',
});
});
});