| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import 'package:flutter_test/flutter_test.dart';
- import 'package:mebarista/models/machine_state.dart';
- void main() {
- group('MachineState.copyWith', () {
- test('updates only specified fields', () {
- final original = MachineState(
- temperature: 95.0,
- targetTemperature: 100.0,
- wakeupTime: '07:00',
- shutdownEnabled: false,
- );
- final updated = original.copyWith(
- temperature: 96.5,
- shutdownEnabled: true,
- );
- expect(updated.temperature, 96.5);
- expect(updated.shutdownEnabled, isTrue);
- expect(updated.targetTemperature, 100.0);
- expect(updated.wakeupTime, '07:00');
- });
- test('keeps list reference unless replaced', () {
- final history = <double>[92.0, 93.0, 94.0];
- final original = MachineState(temperatureHistory: history);
- final unchanged = original.copyWith();
- final replaced = original.copyWith(temperatureHistory: [95.0]);
- expect(identical(unchanged.temperatureHistory, history), isTrue);
- expect(replaced.temperatureHistory, [95.0]);
- });
- test('preserves telemetry metadata and explicitly clears last sample', () {
- final timestamp = DateTime(2026, 10, 6);
- final state = MachineState(
- lastTelemetryAt: timestamp,
- telemetryStale: false,
- transportName: 'BLE',
- firmwareUpdateStatus: 'Ready',
- );
- final updated = state.copyWith(temperature: 99);
- expect(updated.lastTelemetryAt, timestamp);
- expect(updated.telemetryStale, isFalse);
- expect(updated.transportName, 'BLE');
- expect(updated.firmwareUpdateStatus, 'Ready');
- expect(
- updated.copyWith(clearLastTelemetry: true).lastTelemetryAt,
- isNull,
- );
- });
- });
- }
|