Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

1.6 KB
Raw Blame
// @vitest-environment jsdom
import '@testing-library/jest-dom/vitest';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import type { DescriptionSource } from '@mimik/core/guides/types';
import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { StepSourceBadge } from '../StepSourceBadge';

const SOURCES: DescriptionSource[] = ['ai', 'narration', 'heuristic', 'manual'];
const LOCALES = ['en', 'de', 'es', 'fr', 'pt-BR', 'zh-CN', 'ru'];

describe('StepSourceBadge', () => {
  it('says nothing for a step recorded before the field existed', () => {
    const { container } = render(<StepSourceBadge source={undefined} />);
    expect(container).toBeEmptyDOMElement();
  });

  it.each(SOURCES)('renders a label for %s', (source) => {
    render(<StepSourceBadge source={source} />);
    expect(screen.getByText(/.+/)).toBeInTheDocument();
  });

  it('distinguishes a rule-based description from an AI one', () => {
    const { container: ai } = render(<StepSourceBadge source="ai" />);
    const { container: basic } = render(<StepSourceBadge source="heuristic" />);
    expect(ai.textContent).not.toBe(basic.textContent);
    expect(ai.firstElementChild?.className).not.toBe(basic.firstElementChild?.className);
  });

  it('carries a label for every source, in every locale', () => {
    for (const locale of LOCALES) {
      const text = readFileSync(join(process.cwd(), 'packages/locales', `${locale}.yml`), 'utf8');
      for (const key of ['ai', 'voice', 'basic', 'edited', 'hint']) {
        expect(text, `${locale} is missing stepSource.${key}`).toContain(`  ${key}:`);
      }
    }
  });
});