fluttercommunity / flutter_sticky_headers

Flutter Sticky Headers - Lets you place "sticky headers" into any scrollable content in your Flutter app. No special wrappers or magic required. Maintainer: @slightfoot
https://pub.dev/packages/sticky_headers
MIT License
1.07k stars 130 forks source link

adding tests to StickyHeader and StickyHeaderWidgetBuilder #81

Open henriquezanfa opened 8 months ago

henriquezanfa commented 8 months ago

I want to make it safer to add new features/change the current code. I started adding some tests so we can guarantee that the current state is not lost.

I had trouble validating the stuckAmount on StickyHeaderWidgetBuilder. If someone knows how to properly test it it would be great. What I tried was the following:

...
ListView.builder(
  itemCount: 100,
  itemBuilder: (context, index) {
    return StickyHeaderBuilder(
      builder: (context, stuckAmount) {
        capturedStuckAmount = stuckAmount;
        return SizedBox(
          height: 50.0,
          child: Text('Header #$index'),
        );
      },
      content: SizedBox(
        height: 200.0,
        child: Text('Content #$index'),
      ),
    );
  },
),
...
await tester.drag(find.byType(ListView), const Offset(0.0, -25.0));
await tester.pumpAndSettle();
expect(capturedStuckAmount, -0.5);

but the capturedStuckAmount was now what I expected, I don't know if it is something with tester.drag that I'm not aware of.

Anyway, the other tests are working