import assert from 'node:assert/strict'

import { resolveKnowledgePreviewMode } from '../src/views/scripts/knowledgePreviewMode.js'

function testPrefersOnlyOfficeForSupportedOfficeFileWhenAvailable() {
  const document = {
    extension: 'xlsx',
    previewKind: 'table'
  }

  assert.equal(resolveKnowledgePreviewMode(document, { onlyOfficeAvailable: true }), 'onlyoffice')
}

function testFallsBackToStructuredPreviewForOfficeFileWhenOnlyOfficeUnavailable() {
  const document = {
    extension: 'xlsx',
    previewKind: 'table'
  }

  assert.equal(resolveKnowledgePreviewMode(document, { onlyOfficeAvailable: false }), 'table')
}

function testUsesPreviewKindForNonOnlyOfficeFile() {
  const document = {
    extension: 'pdf',
    previewKind: 'pdf'
  }

  assert.equal(resolveKnowledgePreviewMode(document, { onlyOfficeAvailable: false }), 'pdf')
}

function run() {
  testPrefersOnlyOfficeForSupportedOfficeFileWhenAvailable()
  testFallsBackToStructuredPreviewForOfficeFileWhenOnlyOfficeUnavailable()
  testUsesPreviewKindForNonOnlyOfficeFile()
  console.log('knowledge preview mode tests passed')
}

run()
