Skip to content

Commit

Permalink
Only print message on timelineMode change
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmolnar committed Jun 26, 2024
1 parent c72ae71 commit 4766fe0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 40 deletions.
19 changes: 3 additions & 16 deletions lib/src/timeline/timeline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ TimelineMode _globalTimelineMode =
TimelineMode get globalTimelineMode => _globalTimelineMode;

set globalTimelineMode(TimelineMode value) {
// ignore: avoid_print
if (value == _globalTimelineMode) {
// ignore: avoid_print
print('Timeline mode is already set to "${value.name}"');
return;
} else if (_globalTimelineMode != value) {
// ignore: avoid_print
print(value.message);
}
_globalTimelineMode = value;
final test = Invoker.current?.liveTest;
if (test != null) {
Expand Down Expand Up @@ -79,9 +70,6 @@ Timeline get timeline {

// create new timeline
final newTimeline = Timeline();
newTimeline.mode = _globalTimelineMode;
// ignore: avoid_print
print(newTimeline.mode.message);

Invoker.current!.addTearDown(() {
if (!test.state.result.isPassing &&
Expand Down Expand Up @@ -118,20 +106,19 @@ Timeline get timeline {
class Timeline {
final List<TimelineEvent> _events = [];

TimelineMode _mode = TimelineMode.off;
TimelineMode _mode = _globalTimelineMode;

/// The mode of the timeline. Defaults to [TimelineMode.off].
TimelineMode get mode => _mode;

set mode(TimelineMode value) {
if (value == _mode) {
// ignore: avoid_print
print('Timeline mode is already set to "${value.name}"');
return;
}
_mode = value;
// ignore: avoid_print
print(value.message);

_mode = value;
}

/// Adds a screenshot to the timeline.
Expand Down
32 changes: 11 additions & 21 deletions test/timeline/tap/timeline_tap_test_bodies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ Future<void> recordWithoutError({
spotText('Counter: 4').existsOnce();
await act.tap(_subtractButtonSelector);
spotText('Counter: 3').existsOnce();
// Notify that the timeline of this type is already recording.
timeline.mode = TimelineMode.record;
});
expect(output, contains('🔴 - Recording error output timeline'));
expect(output, isNot(contains('🔴 - Recording error output timeline')));
expect(
output,
isNot(contains('Tap ${_addButtonSelector.toStringBreadcrumb()}')),
Expand All @@ -44,7 +42,6 @@ Future<void> recordWithoutError({
output,
isNot(contains('Tap ${_subtractButtonSelector.toStringBreadcrumb()}')),
);
expect(output, contains('Timeline mode is already set to "record"'));
_testTimeLineContent(output: output, eventCount: 0);
}

Expand Down Expand Up @@ -243,21 +240,15 @@ Future<void> liveTurnOffDuringTest({
await act.tap(_subtractButtonSelector);
spotText('Counter: 3').existsOnce();
// Notify that the recording stopped
if (isGlobalMode) {
globalTimelineMode = TimelineMode.off;
} else {
timeline.mode = TimelineMode.off;
}
timeline.mode = TimelineMode.off;
await act.tap(_clearButtonSelector);
spotText('Counter: 0').existsOnce();
// Notify that the recording is already off
if (isGlobalMode) {
globalTimelineMode = TimelineMode.off;
} else {
timeline.mode = TimelineMode.off;
}
});
expect(output, contains('🔴 - Recording live timeline'));
final containsMessage = output.contains('🔴 - Recording live timeline');
// Changes in local test since it's `record` by default. Globally it does not
// change since the global mode is already `live`.
expect(containsMessage, isGlobalMode ? isFalse : isTrue);
expect(output, contains('⏸︎ - Timeline recording is off'));
expect(
output,
contains('Tap ${_addButtonSelector.toStringBreadcrumb()}'),
Expand All @@ -273,7 +264,6 @@ Future<void> liveTurnOffDuringTest({
);
_testTimeLineContent(output: output, eventCount: 2);
expect(output, contains('⏸︎ - Timeline recording is off'));
expect(output, contains('Timeline mode is already set to "off"'));
}

Future<void> liveWithoutError({
Expand All @@ -291,10 +281,11 @@ Future<void> liveWithoutError({
spotText('Counter: 4').existsOnce();
await act.tap(_subtractButtonSelector);
spotText('Counter: 3').existsOnce();
// Notify that the timeline mode is already set to live
timeline.mode = TimelineMode.live;
});
expect(output, contains('🔴 - Recording live timeline'));
final containsMessage = output.contains('🔴 - Recording live timeline');
// Changes in local test since it's `record` by default. Globally it does not
// change since the global mode is already `live`.
expect(containsMessage, isGlobalMode ? isFalse : isTrue);
expect(
output,
contains('Event: Tap ${_addButtonSelector.toStringBreadcrumb()}'),
Expand All @@ -303,7 +294,6 @@ Future<void> liveWithoutError({
output,
contains('Event: Tap ${_subtractButtonSelector.toStringBreadcrumb()}'),
);
expect(output, contains('Timeline mode is already set to "live"'));
_testTimeLineContent(output: output, eventCount: 2);
}

Expand Down
9 changes: 6 additions & 3 deletions test/timeline/timeline_test_shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ const String timelineSeparator =

String localTimelineInitiator(TimelineMode timelineMode) {
return switch (timelineMode) {
TimelineMode.live => 'timeline.mode = TimelineMode.live;',
TimelineMode.record => 'timeline.mode = TimelineMode.record;',
TimelineMode.off => 'timeline.mode = TimelineMode.off;',
TimelineMode.live =>
'timeline.mode = TimelineMode.live;\nexpect(timeline.mode, TimelineMode.live);',
TimelineMode.record =>
'timeline.mode = TimelineMode.record;\nexpect(timeline.mode, TimelineMode.record);',
TimelineMode.off =>
'timeline.mode = TimelineMode.off;\nexpect(timeline.mode, TimelineMode.off);',
};
}

Expand Down

0 comments on commit 4766fe0

Please sign in to comment.