import 'dart:convert'; import 'dart:io'; import 'package:display/checklist.dart'; import 'package:flutter_test/flutter_test.dart'; Checklist sample() => Checklist.fromJson({ 'id': 'demo', 'version': 2, 'title': 'Demo', 'sections': [ { 'title': 'A', 'steps': [ { 'id': '1', 'title': 'Brake', 'actions': [ {'label': 'brake', 'repeat': 2}, {'label': 'flash', 'point': true}, ], }, { 'id': '2', 'title': 'Gears', 'actions': [ {'label': 'gear 1'}, ], }, ], }, ], }); void main() { test('one button: announce once, start/end spans, repeats numbered, points single', () { final r = ChecklistRun(sample()); expect(r.nextLabel, 'Start brake #1'); expect(r.press(), ['checklist demo v2', '1 brake #1 start']); expect(r.nextLabel, 'End brake #1'); expect(r.press(), ['1 brake #1 end']); expect(r.press(), ['1 brake #2 start']); expect(r.press(), ['1 brake #2 end']); expect(r.nextLabel, 'Mark flash'); expect(r.press(), ['1 flash']); expect(r.nextLabel, 'Next step'); expect(r.press(), isEmpty); expect(r.current.id, '2'); expect(r.press(), ['2 gear 1 start']); expect(r.press(), ['2 gear 1 end']); expect(r.finished, isTrue); expect(r.nextLabel, 'All done'); }); test('leaving an open span aborts it', () { final r = ChecklistRun(sample()); r.press(); expect(r.redo(), ['1 brake #1 abort', '1 redo']); expect(r.inSpan, isFalse); expect(r.nextLabel, 'Start brake #1'); r.press(); expect(r.select(1), ['1 brake #1 abort']); expect(r.current.id, '2'); expect(r.skip(), ['2 skip']); expect(r.finished, isTrue); }); test('the bundled checklists parse, with unique step ids', () { final dir = Directory('assets/contracts/checklists'); final files = dir.listSync().whereType().where((f) => f.path.endsWith('.json')).toList(); expect(files, isNotEmpty); for (final f in files) { final c = Checklist.fromJson(jsonDecode(f.readAsStringSync()) as Map); final ids = c.steps.map((s) => s.id).toList(); expect(ids.toSet().length, ids.length, reason: f.path); expect(c.steps.every((s) => s.actions.isNotEmpty), isTrue, reason: f.path); } }); }