A better state and alerts
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:awesome_snackbar_content/awesome_snackbar_content.dart';
|
||||
|
||||
import 'package:tasq/models/notification_item.dart';
|
||||
import 'package:tasq/models/office.dart';
|
||||
@@ -48,6 +50,73 @@ class FakeNotificationsController implements NotificationsController {
|
||||
Future<void> markReadForTask(String taskId) async {}
|
||||
}
|
||||
|
||||
// test doubles for controllers that allow us to intercept create operations
|
||||
class _FakeTicketsController implements TicketsController {
|
||||
Future<void> Function({
|
||||
required String subject,
|
||||
required String description,
|
||||
required String officeId,
|
||||
})?
|
||||
onCreate;
|
||||
|
||||
@override
|
||||
Future<void> createTicket({
|
||||
required String subject,
|
||||
required String description,
|
||||
required String officeId,
|
||||
}) async {
|
||||
if (onCreate != null) {
|
||||
await onCreate!(
|
||||
subject: subject,
|
||||
description: description,
|
||||
officeId: officeId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
||||
}
|
||||
|
||||
class _FakeTasksController implements TasksController {
|
||||
Future<void> Function({
|
||||
required String title,
|
||||
required String description,
|
||||
String? officeId,
|
||||
String? ticketId,
|
||||
String? requestType,
|
||||
String? requestTypeOther,
|
||||
String? requestCategory,
|
||||
})?
|
||||
onCreate;
|
||||
|
||||
@override
|
||||
Future<void> createTask({
|
||||
required String title,
|
||||
required String description,
|
||||
String? officeId,
|
||||
String? ticketId,
|
||||
String? requestType,
|
||||
String? requestTypeOther,
|
||||
String? requestCategory,
|
||||
}) async {
|
||||
if (onCreate != null) {
|
||||
await onCreate!(
|
||||
title: title,
|
||||
description: description,
|
||||
officeId: officeId,
|
||||
ticketId: ticketId,
|
||||
requestType: requestType,
|
||||
requestTypeOther: requestTypeOther,
|
||||
requestCategory: requestCategory,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
|
||||
}
|
||||
|
||||
void main() {
|
||||
final now = DateTime(2026, 2, 10, 12, 0, 0);
|
||||
final office = Office(id: 'office-1', name: 'HQ');
|
||||
@@ -247,6 +316,182 @@ void main() {
|
||||
find.text('Assign at least one office to the team'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.byType(AwesomeSnackbarContent), findsOneWidget);
|
||||
expect(find.byIcon(Icons.warning_amber_rounded), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Office creation shows descriptive success message', (
|
||||
tester,
|
||||
) async {
|
||||
await _setSurfaceSize(tester, const Size(600, 800));
|
||||
await _pumpScreen(
|
||||
tester,
|
||||
const OfficesScreen(),
|
||||
overrides: baseOverrides(),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byType(FloatingActionButton));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.enterText(find.byType(TextField).first, 'PACD');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Create'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.textContaining('PACD'), findsOneWidget);
|
||||
expect(find.byType(AwesomeSnackbarContent), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Ticket creation message includes subject', (tester) async {
|
||||
await _setSurfaceSize(tester, const Size(600, 800));
|
||||
await _pumpScreen(
|
||||
tester,
|
||||
const TicketsListScreen(),
|
||||
overrides: baseOverrides(),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byType(FloatingActionButton));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextField, 'Subject'),
|
||||
'Test ticket',
|
||||
);
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextField, 'Description'),
|
||||
'Desc',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Create'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.textContaining('Test ticket'), findsOneWidget);
|
||||
expect(find.byType(AwesomeSnackbarContent), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Ticket dialog shows spinner while saving', (tester) async {
|
||||
final fake = _FakeTicketsController();
|
||||
final completer = Completer<void>();
|
||||
fake.onCreate =
|
||||
({
|
||||
required String subject,
|
||||
required String description,
|
||||
required String officeId,
|
||||
}) async {
|
||||
await completer.future;
|
||||
};
|
||||
|
||||
await _setSurfaceSize(tester, const Size(600, 800));
|
||||
await _pumpScreen(
|
||||
tester,
|
||||
const TicketsListScreen(),
|
||||
overrides: [
|
||||
...baseOverrides(),
|
||||
ticketsControllerProvider.overrideWithValue(fake),
|
||||
],
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byType(FloatingActionButton));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextField, 'Subject'),
|
||||
'Spinner test',
|
||||
);
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextField, 'Description'),
|
||||
'Help',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Create'));
|
||||
await tester.pump(); // start saving
|
||||
expect(find.byType(CircularProgressIndicator), findsOneWidget);
|
||||
|
||||
completer.complete();
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
|
||||
testWidgets('Task creation message includes title', (tester) async {
|
||||
await _setSurfaceSize(tester, const Size(600, 800));
|
||||
await _pumpScreen(
|
||||
tester,
|
||||
const TasksListScreen(),
|
||||
overrides: baseOverrides(),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byType(FloatingActionButton));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextField, 'Task title'),
|
||||
'Do work',
|
||||
);
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextField, 'Description'),
|
||||
'Details',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Create'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.textContaining('Do work'), findsOneWidget);
|
||||
expect(find.byType(AwesomeSnackbarContent), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Task dialog shows spinner while saving', (tester) async {
|
||||
final fake = _FakeTasksController();
|
||||
final completer = Completer<void>();
|
||||
fake.onCreate =
|
||||
({
|
||||
required String title,
|
||||
required String description,
|
||||
String? officeId,
|
||||
String? ticketId,
|
||||
String? requestType,
|
||||
String? requestTypeOther,
|
||||
String? requestCategory,
|
||||
}) async {
|
||||
await completer.future;
|
||||
};
|
||||
|
||||
await _setSurfaceSize(tester, const Size(600, 800));
|
||||
await _pumpScreen(
|
||||
tester,
|
||||
const TasksListScreen(),
|
||||
overrides: [
|
||||
...baseOverrides(),
|
||||
tasksControllerProvider.overrideWithValue(fake),
|
||||
],
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.byType(FloatingActionButton));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextField, 'Task title'),
|
||||
'Saving test',
|
||||
);
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextField, 'Description'),
|
||||
'Stuff',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Create'));
|
||||
await tester.pump();
|
||||
expect(find.byType(CircularProgressIndicator), findsOneWidget);
|
||||
|
||||
completer.complete();
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
|
||||
testWidgets('Add Team dialog: opening Offices dropdown does not overflow', (
|
||||
|
||||
Reference in New Issue
Block a user