import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import AgGridAdapter from '../AgGridAdapter.vue'

const columns = [{ field: 'id', header: 'ID' }]

describe('AgGridAdapter', () => {
  it('suppresses the stale empty overlay when rows are present', () => {
    const wrapper = mount(AgGridAdapter, {
      props: { rows: [{ id: 'T01' }], columns },
      global: {
        stubs: {
          AgGridVue: {
            props: ['suppressNoRowsOverlay'],
            template: '<div data-test="grid" :data-suppress-no-rows-overlay="String(suppressNoRowsOverlay)" />'
          }
        }
      }
    })

    expect(wrapper.get('[data-test="grid"]').attributes('data-suppress-no-rows-overlay')).toBe('true')
  })

  it('keeps the empty overlay available when there are no rows', () => {
    const wrapper = mount(AgGridAdapter, {
      props: { rows: [], columns },
      global: {
        stubs: {
          AgGridVue: {
            props: ['suppressNoRowsOverlay'],
            template: '<div data-test="grid" :data-suppress-no-rows-overlay="String(suppressNoRowsOverlay)" />'
          }
        }
      }
    })

    expect(wrapper.get('[data-test="grid"]').attributes('data-suppress-no-rows-overlay')).toBe('false')
  })
})
