import { useEffect } from 'react';
import { render } from '@testing-library/react';
import { describe, expect, test } from 'vitest';

let mounts = 0;

const Child = ({ jobId }: { jobId: string }) => {
  useEffect(() => {
    mounts += 1;
  }, []);

  return <span>{jobId}</span>;
};

const Shell = ({ jobId }: { jobId: string }) => (
  <Child key={jobId} jobId={jobId} />
);

describe('workspace shell keyed by job', () => {
  test('remounts when jobId changes', () => {
    mounts = 0;
    const { rerender } = render(<Shell jobId='a' />);
    expect(mounts).toBe(1);

    rerender(<Shell jobId='b' />);
    expect(mounts).toBe(2);
  });
});
