import { describe, test } from 'node:test';
import assert from 'node:assert/strict';
import { clipboardAvailable, copyToClipboard } from '../clipboard-helper.mjs';

describe('clipboardAvailable', () => {
  test('returns object with available and platform fields', () => {
    const result = clipboardAvailable();
    assert.equal(typeof result.available, 'boolean');
    assert.equal(typeof result.platform, 'string');
  });

  test('returns available: true on macOS (darwin)', () => {
    if (process.platform !== 'darwin') return;
    const result = clipboardAvailable();
    assert.equal(result.available, true);
    assert.equal(result.platform, 'darwin');
  });

  test('returns a recognized platform string', () => {
    const result = clipboardAvailable();
    assert.ok(
      ['darwin', 'win32', 'linux'].includes(result.platform),
      `Unexpected platform: ${result.platform}`
    );
  });
});

describe('copyToClipboard', () => {
  test('returns object with success and platform fields', () => {
    const result = copyToClipboard('test clipboard text');
    assert.equal(typeof result.success, 'boolean');
    assert.equal(typeof result.platform, 'string');
  });

  test('copies text successfully on macOS', () => {
    if (process.platform !== 'darwin') return;
    const result = copyToClipboard('clipboard-helper test 2026');
    assert.equal(result.success, true);
    assert.equal(result.platform, 'darwin');
  });

  test('handles empty string input gracefully', () => {
    const result = copyToClipboard('');
    assert.equal(result.success, true);
    assert.equal(typeof result.platform, 'string');
  });

  test('handles multiline text', () => {
    const multiline = 'Line 1\nLine 2\nLine 3';
    const result = copyToClipboard(multiline);
    assert.equal(result.success, true);
  });

  test('handles special characters (quotes, ampersands, backticks)', () => {
    const special = 'He said "hello" & she said \'goodbye\' `code` $VAR';
    const result = copyToClipboard(special);
    assert.equal(result.success, true);
  });

  test('handles unicode/emoji text', () => {
    const unicode = '🚀 Thought leadership → impact';
    const result = copyToClipboard(unicode);
    assert.equal(result.success, true);
  });

  test('never throws — always returns a result object', () => {
    assert.doesNotThrow(() => copyToClipboard(null));
    assert.doesNotThrow(() => copyToClipboard(undefined));
    assert.doesNotThrow(() => copyToClipboard(123));
  });

  test('returns success: false for non-string input', () => {
    const result = copyToClipboard(null);
    assert.equal(result.success, false);
  });
});

describe('module exports', () => {
  test('exports clipboardAvailable as a function', () => {
    assert.equal(typeof clipboardAvailable, 'function');
  });

  test('exports copyToClipboard as a function', () => {
    assert.equal(typeof copyToClipboard, 'function');
  });
});
