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.0 KB
Raw Blame
import type { GalleryBoard } from '@features/gallery/core/types';
import type { TFunction } from 'i18next';

import { describe, expect, it } from 'vitest';

import { getGalleryUploadTargetLabel } from './GalleryUploadButton';

const t = ((key: string, values?: Record<string, unknown>) =>
  values && 'name' in values ? `${key}:${String(values.name)}` : key) as unknown as TFunction;

const board: GalleryBoard = {
  archived: false,
  assetCount: 0,
  assetVideoCount: 0,
  id: 'dogs',
  imageCount: 0,
  kind: 'board',
  name: 'Dogs',
  isInbox: false,
  projectId: null,
  videoCount: 0,
};

describe('getGalleryUploadTargetLabel', () => {
  it('names the selected board', () => {
    expect(getGalleryUploadTargetLabel([board], 'dogs', t)).toEqual({
      isAvailable: true,
      label: 'widgets.gallery.uploadMediaToBoard:Dogs',
    });
  });

  it('falls back to a generic name for an unknown board', () => {
    expect(getGalleryUploadTargetLabel([board], 'missing', t)).toEqual({
      isAvailable: true,
      label: 'widgets.gallery.uploadMediaToBoard:widgets.gallery.selectedBoardFallback',
    });
  });

  it('is unavailable while a search looks in every board, which has no board of its own to upload to', () => {
    expect(getGalleryUploadTargetLabel([board], 'all', t)).toEqual({
      isAvailable: false,
      label: 'widgets.gallery.uploadsUnavailableForAllBoards',
    });
  });

  it('marks date boards unavailable', () => {
    expect(getGalleryUploadTargetLabel([board], 'by_date:2026-09-04', t)).toEqual({
      isAvailable: false,
      label: 'widgets.gallery.uploadsUnavailableForDateBoards',
    });
  });

  it('marks a board the caller may only view unavailable, and says why', () => {
    const viewOnly: GalleryBoard = {
      ...board,
      access: { actions: ['read'], adminOverride: false, generalAccess: 'viewer', role: 'viewer' },
    };

    expect(getGalleryUploadTargetLabel([viewOnly], 'dogs', t)).toEqual({
      isAvailable: false,
      label: 'widgets.gallery.uploadsUnavailableForViewOnlyBoard:Dogs',
    });
  });
});