Sub6Resources / flutter_html

A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)
https://pub.dev/packages/flutter_html
MIT License
1.79k stars 860 forks source link

How to execute Test case for OnLinkTap Method #1189

Closed MageshPandian20 closed 1 year ago

MageshPandian20 commented 1 year ago

HI Team,

I used flutter_html to load html content in my app. It work fine. We currently working on covering test case over all project. When we tried to cover OnLinkTap method in html(), It not covering. We had key to the html widget and in the test case we used tap with key but it not working.

Container( color: Colors.white, padding: EdgeInsets.only(top: 10, right: 10, bottom: 10, left: 10), child: Html( key : Key("html_tap") data: htmlContent, onLinkTap: (link) { -----> Need to cover this block launch(link); }, ))

In Test case :

var foo = find.byKey("html_tap"); await tester.ensureVisible(foo); // <-- here await tester.tap(foo); await tester.pumpAndSettle();

MageshPandian20 commented 1 year ago

@erickok @Sub6Resources Anyone support on this ?. Please confirm we can able to cover test-case for OnLinkTap ?

erickok commented 1 year ago

You code does not work because find.byKey("html_tap"); will find the Html widget and not the link. Perhaps you are looking for AnchorKey.forId(htmlWidgetKey, "#linkYouWantToClick")?

matiasleyba commented 1 year ago

@MageshPandian20 were you able to test ?

Sub6Resources commented 1 year ago

I think the AnchorKey solution should have fixed this? Please ping if not.