import { describe, it, expect, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import StorageBrowser from '../StorageBrowser.vue'

const globalStubs = {
  BreadcrumbBar: true,
  SearchBar: true,
  SortControls: true,
  DropZone: true,
  UploadProgress: true,
  TopicBadge: true,
  AppIcon: true,
  EmptyState: true,
}

function mountBrowser(mode, breadcrumb = []) {
  setActivePinia(createPinia())
  return mount(StorageBrowser, {
    props: {
      mode,
      breadcrumb,
      documents: [],
      folders: [],
      files: [],
      topicColorFn: () => '#000',
      loading: false,
    },
    global: { stubs: globalStubs },
  })
}

describe('Gap 2: showSearch visible at root for local and cloud modes', () => {
  it("mode='local', breadcrumb=[] → showSearch is true (root-level local)", () => {
    const w = mountBrowser('local', [])
    expect(w.vm.showSearch).toBe(true)
  })

  it("mode='local', breadcrumb=[{name:'Folder'}] → showSearch is true (non-root local)", () => {
    const w = mountBrowser('local', [{ name: 'Folder' }])
    expect(w.vm.showSearch).toBe(true)
  })

  it("mode='cloud', breadcrumb=[] → showSearch is true (cloud root)", () => {
    const w = mountBrowser('cloud', [])
    expect(w.vm.showSearch).toBe(true)
  })

  it("mode='shared' → showSearch is false", () => {
    const w = mountBrowser('shared', [])
    expect(w.vm.showSearch).toBe(false)
  })
})
