Files
pipelines/app/test/application/schedules_destination_test.dart
T

72 lines
2.1 KiB
Dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/app_session.dart';
import 'package:pipelines_app/application/schedules_destination.dart';
import 'package:pipelines_app/application/server_endpoint.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
void main() {
testWidgets('a page opened before the connection lists once connected', (
tester,
) async {
final channel = FakeChannel();
final client = PipelinesClient(channelFactory: (_) => channel);
final server = ServerEndpoint.resolve(
base: Uri.parse('http://127.0.0.1:8096/'),
web: true,
);
final session = AppSession(endpoint: server.uri, client: client);
addTearDown(session.dispose);
await tester.pumpWidget(
MaterialApp(
home: SchedulesDestination(
session: session,
server: server,
onBack: () {},
onOpenPipeline: (_) {},
),
),
);
await tester.pump();
expect(
find.text('Connect to the server to see schedules.'),
findsOneWidget,
);
final starting = session.start();
channel.readyCompleter.complete();
await starting;
await tester.pump();
await tester.pump();
expect(find.text('Connect to the server to see schedules.'), findsNothing);
final request = channel.outgoing
.map((frame) => jsonDecode(frame as String) as Map<String, dynamic>)
.lastWhere((frame) => frame['type'] == 'list_schedules');
channel.incoming.add(
jsonEncode({
'id': request['id'],
'type': 'schedules',
'schedules': [
{
'id': 1,
'pipeline_id': 4,
'version': 1,
'name': 'Nightly review',
'enabled': true,
'rule': {'kind': 'interval', 'every_seconds': 3600},
},
],
}),
);
await tester.pump();
await tester.pump();
expect(find.text('Nightly review'), findsOneWidget);
});
}