import { describe, it, expect } from 'vitest';
import { renderHook, act } from '@testing-library/react';
import { useScreenerMode } from './useScreenerMode';

describe('useScreenerMode', () => {
  it('초기값은 "form"', () => {
    const { result } = renderHook(() => useScreenerMode());
    expect(result.current.mode).toBe('form');
  });

  it('localStorage 에 저장된 값 복원', () => {
    localStorage.setItem('screener-mode-v1', 'canvas');
    const { result } = renderHook(() => useScreenerMode());
    expect(result.current.mode).toBe('canvas');
  });

  it('손상된 localStorage 는 "form" 으로 fallback', () => {
    localStorage.setItem('screener-mode-v1', 'INVALID_MODE');
    const { result } = renderHook(() => useScreenerMode());
    expect(result.current.mode).toBe('form');
  });

  it('setMode 호출 시 state 와 localStorage 모두 갱신', () => {
    const { result } = renderHook(() => useScreenerMode());
    act(() => result.current.setMode('canvas'));
    expect(result.current.mode).toBe('canvas');
    expect(localStorage.getItem('screener-mode-v1')).toBe('canvas');
  });
});
