mvysny / karibu-testing

Vaadin Server-Side Browserless Containerless Unit Testing
Apache License 2.0
105 stars 14 forks source link

Testing for certain html tags with LitRenderer #175

Open nbabb opened 1 month ago

nbabb commented 1 month ago

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!

mvysny commented 1 month ago

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?