import { GeneratorOptions } from '@teleporthq/teleport-types'
import { resolveHtmlNesting } from '../../src/resolvers/html-nesting'
import { component, element, text } from './mocks'
const NO_OPTIONS: GeneratorOptions = {}
let warnSpy: jest.SpyInstance
const warnings = (): string[] => warnSpy.mock.calls.map((call) => String(call[0]))
beforeEach(() => {
warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => undefined)
})
afterEach(() => {
warnSpy.mockRestore()
})
describe('resolveHtmlNesting — nesting that has no lossless repair', () => {
it('reports a nested anchor and leaves both in place', () => {
const inner = element('a', [text('Details')])
const outer = element('a', [element('div', [inner])])
resolveHtmlNesting(component(outer, 'Product-Card'), NO_OPTIONS)
expect(inner.content.elementType).toBe('a')
expect(warnings()).toEqual([expect.stringContaining(' nested inside another ')])
expect(warnings()[0]).toContain('Product-Card')
})
it('forgets an anchor once a scope boundary hides it from the parser', () => {
const inner = element('a', [text('Details')])
const outer = element('a', [element('table', [element('td', [inner])])])
resolveHtmlNesting(component(outer), NO_OPTIONS)
expect(warnings().filter((message) => message.includes('nested inside another '))).toEqual(
[]
)
})
it('reports a nested form', () => {
const outer = element('form', [element('div', [element('form', [])])])
resolveHtmlNesting(component(outer), NO_OPTIONS)
expect(warnings()).toEqual([expect.stringContaining('