Skip to content

Commit

Permalink
tests for category
Browse files Browse the repository at this point in the history
  • Loading branch information
LegendAF committed Sep 28, 2024
1 parent fffba73 commit a98c751
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Tenor Flutter

This package integrates [Tenor GIF search](https://tenor.com/) into [Flutter](https://flutter.dev/) by utilizing the [tenor_dart](https://pub.dev/packages/tenor_dart) package to communicate directly with the [Tenor API V2](https://developers.google.com/tenor/guides/quickstart) via [http](https://pub.dev/packages/http).

The package currently provides an opinionated yet customizable UI experience for searching and selecting from a list of GIFs/Stickers from the Tenor GIF search API.

<p align="center">
<a href="https://pub.dartlang.org/packages/tenor_flutter"><img src="https://img.shields.io/pub/v/tenor_flutter.svg" alt="Tenor Flutter Pub Package" /></a>
<a href="https://github.com/Flyclops/tenor_flutter/actions/workflows/main.yml"><img src="https://github.com/flyclops/tenor_flutter/actions/workflows/main.yml/badge.svg" alt="Build Status" /></a>
Expand All @@ -12,6 +8,10 @@ The package currently provides an opinionated yet customizable UI experience for
<a href="https://github.com/Flyclops/tenor_flutter/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-BSD_3--Clause-blue.svg" alt="License BSD 3-Clause" /></a>
</p>

This package integrates [Tenor GIF search](https://tenor.com/) into [Flutter](https://flutter.dev/) by utilizing the [tenor_dart](https://pub.dev/packages/tenor_dart) package to communicate directly with the [Tenor API V2](https://developers.google.com/tenor/guides/quickstart) via [http](https://pub.dev/packages/http).

The package currently provides an opinionated yet customizable UI experience for searching and selecting from a list of GIFs/Stickers from the Tenor GIF search API.

<p align="center"><img src="https://github.com/flyclops/tenor_flutter/raw/main/example/assets/demo.gif" width="200" alt="Tenor Flutter Demo"/></p>

<p align="center"><strong><sup>Show some ❤️ and <a href="https://github.com/flyclops/tenor_flutter">star the repo</a> to support this package.</sup></strong></p>
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/category.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TenorCategoryWidget extends StatelessWidget {
child: Stack(
fit: StackFit.expand,
children: [
if (tenorCategoryImage != null)
if (tenorCategoryImage != null && tenorCategoryImage.isNotEmpty)
ExtendedImage.network(
tenorCategoryImage,
cache: true,
Expand Down
56 changes: 56 additions & 0 deletions test/components/category_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:tenor_flutter/src/components/components.dart';
import 'package:tenor_flutter/src/tools/debouncer.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tenor_flutter/tenor_flutter.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();

group('Category Widget >', () {
testWidgets('If TenorCategory is null, find nothing', (tester) async {
await tester.pumpWidget(
const TenorCategoryWidget(),
);

expect(find.byType(GestureDetector), findsNothing);
});

testWidgets('Make sure it renders and is tappable', (tester) async {
// track if the tap was tapped
bool hasTapped = false;

// category to populate with
final tenorCategoryTest = TenorCategory(
name: 'test',
searchTerm: 'test search term',
path: 'path/to/category',
image: 'https://flyclops.com/images/logo.png',
);

// display the category widget
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: TenorCategoryWidget(
category: tenorCategoryTest,
onTap: (tenorCategory) {
expect(tenorCategory, tenorCategoryTest);
hasTapped = true;
},
),
),
);

// it should not have been tapped at this point
expect(hasTapped, false);

// tap it
await tester.tap(find.byType(GestureDetector));

// make sure the tap went through
expect(hasTapped, true);
});
});
}

0 comments on commit a98c751

Please sign in to comment.