Skip to content

Commit

Permalink
e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyokone committed Sep 11, 2024
1 parent fbde378 commit 8ab5265
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:integration_test/integration_test.dart';

import 'generation_e2e.dart';
import 'instance_e2e.dart';
import 'listen_e2e.dart';
import 'query_e2e.dart';

bool kUseFDCEmulator = true;
Expand Down Expand Up @@ -40,5 +41,6 @@ void main() {
runInstanceTests();
runQueryTests();
runGenerationTest();
runListenTests();
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2020, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:firebase_data_connect/firebase_data_connect.dart';
import 'package:firebase_data_connect_example/generated/movies.dart';
import 'package:flutter_test/flutter_test.dart';

import 'query_e2e.dart';

void runListenTests() {
group(
'$FirebaseDataConnect.instance listen',
() {
// ignore: unused_local_variable
late FirebaseDataConnect fdc;

setUpAll(() async {
fdc = FirebaseDataConnect.instanceFor(
connectorConfig: MoviesConnector.connectorConfig,
);
});

setUp(() async {
await deleteAllMovies();
});

testWidgets('should be able to listen to the list of movies',
(WidgetTester tester) async {
final value = await MoviesConnector.instance.listMovies.ref().execute();

final result = value.data;
expect(result.movies.length, 0);

bool hasBeenListened = false;
int count = 0;

final listener = MoviesConnector.instance.listMovies
.ref()
.subscribe()
.listen((value) {
if (count == 0) {
final result = value.data;
expect(result.movies.length, 0);
} else {
final result = value.data;
expect(result.movies.length, 1);
expect(result.movies[0].title, 'The Matrix');
hasBeenListened = true;
}
count++;
});

MutationRef ref = MoviesConnector.instance.createMovie.ref(
genre: 'Action',
title: 'The Matrix',
releaseYear: 1999,
rating: 4.5,
);

await ref.execute();

QueryRef ref2 = MoviesConnector.instance.listMovies.ref();
ref2.execute();

await Future.delayed(const Duration(seconds: 1));

listener.cancel();

expect(hasBeenListened, true);
});
},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void runQueryTests() {
expect(result.movies.length, 0);
});

testWidgets('can add a movie and delete it', (WidgetTester tester) async {
testWidgets('can add a movie', (WidgetTester tester) async {
MutationRef ref = MoviesConnector.instance.createMovie.ref(
genre: 'Action',
title: 'The Matrix',
Expand Down Expand Up @@ -99,6 +99,7 @@ void runQueryTests() {
final result3 = value3.data;
expect(result3.movies.length, 1);
expect(result3.movies[0].directed_by.length, 1);
expect(result3.movies[0].directed_by[0].name, 'Keanu Reeves');
});

testWidgets('can delete a movie', (WidgetTester tester) async {
Expand Down

0 comments on commit 8ab5265

Please sign in to comment.