-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
179 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (C) 2018 Alberto Varela Sánchez <alberto@berriart.com> | ||
// Use of this source code is governed by the version 3 of the | ||
// GNU General Public License that can be found in the LICENSE file. | ||
|
||
import '../../../../view/index.dart'; | ||
|
||
abstract class QuestionViewContract { | ||
bool get isColorOk; | ||
bool get isNumberOk; | ||
} | ||
|
||
class QuestionPresenter { | ||
QuestionPresenter(this._view, this._colorAnimator, this._numberAnimator); | ||
|
||
final QuestionAnimator _colorAnimator; | ||
final QuestionAnimator _numberAnimator; | ||
final QuestionViewContract _view; | ||
|
||
void onIsColorOkValueChanged() { | ||
if (!_view.isColorOk) { | ||
_colorAnimator.forward(); | ||
} | ||
} | ||
void onIsNumberOkValueChanged() { | ||
if (!_view.isNumberOk) { | ||
_numberAnimator.forward(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (C) 2018 Alberto Varela Sánchez <alberto@berriart.com> | ||
// Use of this source code is governed by the version 3 of the | ||
// GNU General Public License that can be found in the LICENSE file. | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
import '../styles.dart'; | ||
import 'animator.dart'; | ||
|
||
class QuestionAnimator extends Animator { | ||
QuestionAnimator({ | ||
@required TickerProviderStateMixin vsync, | ||
@required int milliseconds, | ||
@required Function onDismissed, | ||
@required Function listener, | ||
}) : super( | ||
vsync: vsync, | ||
milliseconds: milliseconds, | ||
listener: listener, | ||
) { | ||
_animation = ColorTween(begin: ScreenColors.black, end: ScreenColors.darkRed) | ||
.animate(controller); | ||
|
||
controller.addStatusListener((AnimationStatus status) { | ||
if (status == AnimationStatus.completed) { | ||
controller.reverse(); | ||
} else if (status == AnimationStatus.dismissed) { | ||
controller.stop(); | ||
onDismissed?.call(); | ||
} | ||
}); | ||
} | ||
|
||
Animation _animation; | ||
Animation get animation => _animation; | ||
} |
71 changes: 71 additions & 0 deletions
71
test/screens/game/widgets/question/question_presenter_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (C) 2018 Alberto Varela Sánchez <alberto@berriart.com> | ||
// Use of this source code is governed by the version 3 of the | ||
// GNU General Public License that can be found in the LICENSE file. | ||
|
||
import 'package:test/test.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
|
||
import '../../../../../lib/screens/game/widgets/question/question_presenter.dart'; | ||
import '../../../../../lib/view/index.dart'; | ||
|
||
class MockQuestionView extends Mock implements QuestionViewContract {} | ||
class MockQuestionAnimator extends Mock implements QuestionAnimator {} | ||
|
||
void main() { | ||
MockQuestionView _mockQuestionView; | ||
MockQuestionAnimator _mockNumberQuestionAnimator; | ||
MockQuestionAnimator _mockColorQuestionAnimator; | ||
QuestionPresenter _questionPresenter; | ||
|
||
group('Question Widget:', () { | ||
setUp(() async { | ||
_mockQuestionView = MockQuestionView(); | ||
_mockNumberQuestionAnimator = MockQuestionAnimator(); | ||
_mockColorQuestionAnimator = MockQuestionAnimator(); | ||
_questionPresenter = QuestionPresenter( | ||
_mockQuestionView, | ||
_mockColorQuestionAnimator, | ||
_mockNumberQuestionAnimator); | ||
}); | ||
|
||
group('On "IsColorOk" value changed', () { | ||
test('if it is not ok it highlights the color of the question', () { | ||
when(_mockQuestionView.isColorOk) | ||
.thenReturn(false); | ||
|
||
_questionPresenter.onIsColorOkValueChanged(); | ||
|
||
verify(_mockColorQuestionAnimator.forward()); | ||
}); | ||
|
||
test('if it is ok it does not highlight the color of the question', () { | ||
when(_mockQuestionView.isColorOk) | ||
.thenReturn(true); | ||
|
||
_questionPresenter.onIsColorOkValueChanged(); | ||
|
||
verifyNever(_mockColorQuestionAnimator.forward()); | ||
}); | ||
}); | ||
|
||
group('On "IsNumberOk" value changed', () { | ||
test('if it is not ok it highlights the number of the question', () { | ||
when(_mockQuestionView.isNumberOk) | ||
.thenReturn(false); | ||
|
||
_questionPresenter.onIsNumberOkValueChanged(); | ||
|
||
verify(_mockNumberQuestionAnimator.forward()); | ||
}); | ||
|
||
test('if it is ok it does not highlight the number of the question', () { | ||
when(_mockQuestionView.isNumberOk) | ||
.thenReturn(true); | ||
|
||
_questionPresenter.onIsNumberOkValueChanged(); | ||
|
||
verifyNever(_mockNumberQuestionAnimator.forward()); | ||
}); | ||
}); | ||
}); | ||
} |