Root cause behind most "stuck loading" reports: the backend changed shape (schedules became an array, location_preferences a string) while the mobile parser still hard-cast to Map/int. The TypeError was swallowed by a silent catch that returned null, and screens only handled the success state, so a parse failure rendered as a permanent spinner. Same class of bug appeared across service lists via non-null map lookups and a total absence of request timeouts. Ported from prosappweb: - in-app suggestions (POST /suggestions) - policies/terms from GET /settings/policies - configurable appointment length (slot_duration_minutes) - block/unblock calendar slots (POST /services/block) - GPS city detection on the profile (Nominatim) - server-side professional search with haversine distance - retry cooldown after a rejected professional application Reliability: - parse schedules array (day_of_week 0=Mon) and string location_preferences - read times as wall clock, so 08:00 stays 08:00 across timezones - carry minutes into hours in TimeOfDay.add; a minute-based step used to loop forever and freeze the calendar (covered by test/time_slots_test.dart) - semver update check instead of string equality, which blocked every build that did not exactly match the configured version - request timeouts across all repositories - surface HTTP >= 400 instead of reporting failed writes as success - error states with retry instead of an indefinite shimmer Includes pre-existing uncommitted work from the UI redesign. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
58 lines
2.0 KiB
Dart
58 lines
2.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:prosappco/utils/time_of_day_extension.dart';
|
|
import 'package:prosappco/utils/time_of_day_utils.dart';
|
|
|
|
void main() {
|
|
group('TimeOfDayExtension.add', () {
|
|
test('carries minutes into hours', () {
|
|
expect(const TimeOfDay(hour: 8, minute: 45).add(minute: 45),
|
|
const TimeOfDay(hour: 9, minute: 30));
|
|
});
|
|
|
|
test('does not wrap past midnight, so range loops still terminate', () {
|
|
expect(const TimeOfDay(hour: 23, minute: 30).add(minute: 45).hour, 24);
|
|
});
|
|
});
|
|
|
|
group('TimeOfDayUtils.genRanges', () {
|
|
// Regression: a minute-based step used to leave the hour untouched
|
|
// ("8:90"), so isBefore() never became false and this looped forever,
|
|
// freezing the calendar screen.
|
|
test('minute-based step terminates and lands on real times', () {
|
|
final slots = TimeOfDayUtils.genRanges(
|
|
const TimeOfDay(hour: 8, minute: 0),
|
|
const TimeOfDay(hour: 18, minute: 0),
|
|
stepMinutes: 45,
|
|
);
|
|
|
|
expect(slots.length, 14);
|
|
expect(slots.first, const TimeOfDay(hour: 8, minute: 0));
|
|
expect(slots[1], const TimeOfDay(hour: 8, minute: 45));
|
|
expect(slots[2], const TimeOfDay(hour: 9, minute: 30));
|
|
expect(slots.last, const TimeOfDay(hour: 17, minute: 45));
|
|
expect(slots.every((t) => t.minute < 60), isTrue);
|
|
});
|
|
|
|
test('two-hour step keeps the historical behaviour', () {
|
|
final slots = TimeOfDayUtils.genRanges(
|
|
const TimeOfDay(hour: 8, minute: 0),
|
|
const TimeOfDay(hour: 18, minute: 0),
|
|
stepMinutes: 120,
|
|
);
|
|
|
|
expect(slots.map((t) => t.hour).toList(), [8, 10, 12, 14, 16]);
|
|
});
|
|
|
|
test('end before start yields no slots', () {
|
|
final slots = TimeOfDayUtils.genRanges(
|
|
const TimeOfDay(hour: 18, minute: 0),
|
|
const TimeOfDay(hour: 8, minute: 0),
|
|
stepMinutes: 45,
|
|
);
|
|
|
|
expect(slots, isEmpty);
|
|
});
|
|
});
|
|
}
|