karibu-testing icon indicating copy to clipboard operation
karibu-testing copied to clipboard

Testing for certain html tags with LitRenderer

Open nbabb opened this issue 1 year ago • 1 comments

I am testing a TreeGrid that uses a LitRenderer. I am calling

GridKt._getFormattedRow()

on my expected row, but am getting back only the extracted text portions. This particular renderer conditionally includes an anchor tag, based on some business logic. When I debug into

Renderers._getPresentationValue

in particular these lines

        val renderedLitTemplateHtml: String = renderLitTemplate(templateExpression, valueProviders, rowObject)
        Jsoup.parse(renderedLitTemplateHtml).textRecursively

I see my html in the rendererdLitTemplateHtml value

<vaadin-grid-tree-toggle @click=${onClick} .leaf=true .expanded=${model.expanded} .level=${model.level}><img src='svg/myobj.svg' alt=''>&nbsp;&nbsp;<span class='tree-node-labels'>     <a href='myobj/2' target='_blank'>FOO</a>     <span class='tree-node-labels-subheader target-node'>Bar</span>     <span class='tree-node-labels-subheader ' hidden=true>Inactive</span></span></vaadin-grid-tree-toggle>

but then the Jsoup parsing returns only a minimal String representation, i.e. FOO Bar Inactive. What I'd like to be able to do is assert on whether there is an anchor tag in the rendereredLitTemplateHtml variable String. Any thoughts on this, other than trying to roll my own method? Thanks!

nbabb avatar May 31 '24 13:05 nbabb

At the moment the text is retrieved recursively and that's pretty much set in stone. Perhaps I could add a config option for Karibu Testing to return the full template html instead?

mvysny avatar May 31 '24 13:05 mvysny