Skip to content

Commit

Permalink
Adding test. #1
Browse files Browse the repository at this point in the history
  • Loading branch information
caduandrade committed Sep 25, 2023
1 parent e4538d8 commit 602378f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/src/layout/layout_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class LayoutParser {
/// V1:1:1(1;I;.2;;100;5;my_id;7;my_name;8;my_value;T;;F)
String stringify(
{required DockingLayout layout,
IdToString? idToString,
ValueToString? valueToString}) {
IdToString? idToString,
ValueToString? valueToString}) {
final List<DockingArea> areas = layout.layoutAreas();

String str = 'V1:${areas.length}:';
Expand Down Expand Up @@ -197,6 +197,9 @@ class LayoutParser {
List<String> indexes = [];
for (int i = 0; i < parent.childrenCount; i++) {
final DockingArea child = parent.childAt(i);
if (child.index == -1) {
throw StateError('Child does not belong to any layout.');
}
indexes.add(child.index.toString());
}
return indexes.join(',');
Expand Down
5 changes: 5 additions & 0 deletions test/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ Matcher dockingAreaInSomeLayoutException() {
x is ArgumentError &&
x.message == "DockingArea already belongs to some layout."));
}

Matcher childNotBelongAnyLayoutException() {
return throwsA(predicate((x) =>
x is StateError && x.message == "Child does not belong to any layout."));
}
35 changes: 35 additions & 0 deletions test/layout_stringify_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:docking/docking.dart';
import 'package:flutter_test/flutter_test.dart';

import 'exceptions.dart';
import 'utils.dart';

void main() {
final LayoutParser parser = LayoutParser();

group('LayoutParser - stringify', () {
test('stringifyParent', () {
DockingItem itemA = dockingItem('a');
DockingItem itemB = dockingItem('b');
DockingItem itemC = dockingItem('c');
DockingItem itemD = dockingItem('d');
DockingItem itemE = dockingItem('e');
DockingRow row = DockingRow([itemB, itemC]);
DockingTabs tabs = DockingTabs([itemD, itemE]);
DockingColumn column = DockingColumn([itemA, row, tabs]);

expect(() => parser.stringifyParent(parent: column),
childNotBelongAnyLayoutException());
expect(() => parser.stringifyParent(parent: row),
childNotBelongAnyLayoutException());
expect(() => parser.stringifyParent(parent: tabs),
childNotBelongAnyLayoutException());

DockingLayout(root: column);

expect(parser.stringifyParent(parent: column), '2,3,6');
expect(parser.stringifyParent(parent: row), '4,5');
expect(parser.stringifyParent(parent: tabs), '7,8');
});
});
}

0 comments on commit 602378f

Please sign in to comment.