|
| 1 | +import 'package:flutter_test/flutter_test.dart'; |
| 2 | +import 'package:on_time_front/data/models/get_preparation_step_response_model.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + group('PreparationResponseModelListExtension', () { |
| 6 | + test('orders preparation steps by nextPreparationId chain', () { |
| 7 | + final models = [ |
| 8 | + GetPreparationStepResponseModel( |
| 9 | + id: 'third', |
| 10 | + preparationName: 'Put on shoes', |
| 11 | + preparationTime: 3, |
| 12 | + nextPreparationId: null, |
| 13 | + ), |
| 14 | + GetPreparationStepResponseModel( |
| 15 | + id: 'first', |
| 16 | + preparationName: 'Shower', |
| 17 | + preparationTime: 10, |
| 18 | + nextPreparationId: 'second', |
| 19 | + ), |
| 20 | + GetPreparationStepResponseModel( |
| 21 | + id: 'second', |
| 22 | + preparationName: 'Get dressed', |
| 23 | + preparationTime: 5, |
| 24 | + nextPreparationId: 'third', |
| 25 | + ), |
| 26 | + ]; |
| 27 | + |
| 28 | + final preparation = models.toPreparationEntity(); |
| 29 | + |
| 30 | + expect( |
| 31 | + preparation.preparationStepList.map((step) => step.id), |
| 32 | + ['first', 'second', 'third'], |
| 33 | + ); |
| 34 | + }); |
| 35 | + |
| 36 | + test('keeps unlinked steps instead of dropping them', () { |
| 37 | + final models = [ |
| 38 | + GetPreparationStepResponseModel( |
| 39 | + id: 'first', |
| 40 | + preparationName: 'Shower', |
| 41 | + preparationTime: 10, |
| 42 | + nextPreparationId: 'second', |
| 43 | + ), |
| 44 | + GetPreparationStepResponseModel( |
| 45 | + id: 'second', |
| 46 | + preparationName: 'Get dressed', |
| 47 | + preparationTime: 5, |
| 48 | + nextPreparationId: null, |
| 49 | + ), |
| 50 | + GetPreparationStepResponseModel( |
| 51 | + id: 'unlinked', |
| 52 | + preparationName: 'Pack bag', |
| 53 | + preparationTime: 2, |
| 54 | + nextPreparationId: null, |
| 55 | + ), |
| 56 | + ]; |
| 57 | + |
| 58 | + final preparation = models.toPreparationEntity(); |
| 59 | + |
| 60 | + expect( |
| 61 | + preparation.preparationStepList.map((step) => step.id), |
| 62 | + ['first', 'second', 'unlinked'], |
| 63 | + ); |
| 64 | + }); |
| 65 | + }); |
| 66 | +} |
0 commit comments