/**
 * @jest-environment jsdom
 */

// Tests for EmailWrapper container component
describe('EmailWrapper Container Tests', () => {
  // This test verifies that the container passes props from the custom hook to the view component
  it('should pass props from custom hook to view', () => {
    // Mock hook results
    const mockHookResults = {
      templateName: 'Test Template',
      isTemplateNameEmpty: false,
      modeContent: { file: { name: 'test.zip' } },
      modes: ['upload', 'editor'],
      isShowEmailCreate: false,
      emailProps: { location: { pathname: '/email/create' } },
      cmsTemplatesProps: { cmsTemplates: [] },
      uploadButtonLabel: 'Upload',
      onTemplateNameChange: jest.fn(),
      onChange: jest.fn(),
      useFileUpload: jest.fn()
    };

    // Mock view component (captures props)
    let capturedViewProps = null;
    const mockView = jest.fn(props => {
      capturedViewProps = props;
      return null;
    });

    // Mock custom hook
    const mockUseEmailWrapper = jest.fn(() => mockHookResults);

    // Container props
    const containerProps = {
      isUploading: false,
      emailCreateMode: 'editor',
      step: 'modeSelection',
      isFullMode: true,
      EmailLayout: null
    };

    // Simulate the container component behavior
    function simulateContainer() {
      // Get state and handlers from hook
      const hookResults = mockUseEmailWrapper(containerProps);

      // Render view with combined props
      return mockView({
        ...containerProps,
        ...hookResults
      });
    }

    // Run the simulation
    simulateContainer();

    // Verify hook was called with correct props
    expect(mockUseEmailWrapper).toHaveBeenCalledWith(containerProps);

    // Verify view received combined props
    expect(capturedViewProps).toEqual({
      ...containerProps,
      ...mockHookResults
    });

    // Verify specific props
    expect(capturedViewProps.isUploading).toBe(containerProps.isUploading);
    expect(capturedViewProps.emailCreateMode).toBe(containerProps.emailCreateMode);
    expect(capturedViewProps.templateName).toBe(mockHookResults.templateName);
    expect(capturedViewProps.modes).toBe(mockHookResults.modes);
  });

  // This test verifies the pattern is maintainable for future changes
  it('handles adding new hook properties', () => {
    // Mock hook with additional property
    const mockHookWithNewProp = jest.fn(() => ({
      templateName: 'Test',
      newFeature: 'This is a new feature' // New property
    }));

    // Mock view component (captures props)
    let capturedViewProps = null;
    const mockView = jest.fn(props => {
      capturedViewProps = props;
      return null;
    });

    // Simulate container with new hook property
    function simulateContainer() {
      const hookResults = mockHookWithNewProp({});
      return mockView(hookResults);
    }

    // Run the simulation
    simulateContainer();

    // Verify the new property is correctly passed to view
    expect(capturedViewProps.newFeature).toBe('This is a new feature');
  });
});
