Fintasys / emoji_picker_flutter

A Flutter package that provides an Emoji picker widget with 1500+ emojis in 8 categories.
MIT License
154 stars 114 forks source link

Widget unit testing with `emoji_picker_flutter` #156

Closed LuchoTurtle closed 5 months ago

LuchoTurtle commented 9 months ago

Hey there! 👋

Thanks for the package, it's mighty useful!

I'm having a bit of trouble widget-testing an application that includes this package. Since there aren't any testing utilities that I can go for, to test my code I'm doing something like this in my test:


    // Set size because it's needed to correctly tap on emoji picker
    await tester.binding.setSurfaceSize(const Size(380, 800));

 // .....

 // Tap on smile category
    await tester.tapAt(const Offset(61, 580));
    await tester.pumpAndSettle();

  // Tap on smile icon
  await tester.tapAt(const Offset(14, 632));
  await tester.pumpAndSettle();

I'm always setting the size of the unit test to always be the same one so it works every time. The thing is, I'm simulating this test on a physical device and everything works out - it clicks on an emoji and it is inserted as text. You can check it in the video below:

https://github.com/dwyl/flutter-wysiwyg-editor-tutorial/assets/17494745/073706e9-2c7d-4942-8a77-8381827f51ca

However, even though all the unit tests pass and the integration tests pass, it seems the callback of the inserted emoji is not covered.

image

Has this happened to y'all? Why is the onEmojiSelected callback not being invoked during unit tests and being covered?

If you're curious, you may see the offending file in https://github.com/dwyl/flutter-wysiwyg-editor-tutorial/pull/9/files#diff-64157eac151a0f2a28dff32d284fc4f62e2eaf53e0dd0a8c1cd31e77f56e700d.

Thank you!

Fintasys commented 8 months ago

Hey @LuchoTurtle, thanks for reporting this issue. The onEmojiSelected callback seems to be invoked but only coverage seems not to be reported 🤔 I don't know what could cause this. I need to setup some widget tests myself and check it. If you find the reason in the meantime please keep me updated 👍

LuchoTurtle commented 8 months ago

Thanks for the reply :)

I've found a way so onEmojiSelected is covered. You can see a simple widget test in https://github.com/dwyl/app/blob/6439db5d922ae5a4a368dfc2bba03040e58db2fc/test/widget/emoji_widget_test.dart.

However, the only way I got this to work is having to disable the "Recents" emojis tab.

Config(recentTabBehavior: RecentTabBehavior.NONE);

This was the only way I could find to find.byText() emojis to tap, thus invoking the onEmojiSelected. Otherwise, even though I scrolled and changed tabs, it wasn't working on tests.

So hopefully this helps people in the future :).

Though it'd be fun to have a neat utility function that would allow us to input emojis without having to go through these hoops. 👀

Fintasys commented 5 months ago

Version 2.0 will include some basic tests. Thanks again @LuchoTurtle for your help 🙏 I will close this issue with the release of version 2.0.