This repository was archived by the owner on Jan 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
tests: add first Unit tests #104
Open
techno-disaster
wants to merge
23
commits into
anitab-org:develop
Choose a base branch
from
techno-disaster:unit-tests
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c3ab2f3
Auth tests
5a3561e
Login tests
a61a8bb
add coverage to gitignore
5cc5799
auth and login event, state tests
b3c5ed9
update github and travis
ce70baf
update github ci
d07e7c5
add codecov
edf975d
add codecov badge
83b101a
coverage tests
d6c8ac3
Update .gitignore
762a5ec
coverage file
ecdd84d
fix gitignore
e97ab52
Merge branch 'develop' into unit-tests
16df874
merge
a0c8935
merge
cd953c5
move to travis?
90a0e28
test readme
99f025b
edit codecov bot reply
d1c8fc7
fix readme
6aee5f1
Update codecov.yml
633df7e
fix on Failure
1c41226
Merge branch 'develop' into unit-tests
ee8c3e7
update tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
| comment: | ||
| layout: "diff, files" | ||
| behavior: new | ||
| require_changes: false # if true: only post the comment if coverage changes | ||
|
|
||
| coverage: | ||
| status: | ||
| project: | ||
| default: | ||
| target: auto # will use the coverage from the base commit | ||
| threshold: 0% | ||
| base: auto |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,87 @@ | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| import 'package:mockito/mockito.dart'; | ||
| import 'package:mentorship_client/remote/repositories/auth_repository.dart'; | ||
| import 'package:mentorship_client/auth/bloc.dart'; | ||
|
|
||
| class MockUserRepository extends Mock implements AuthRepository {} | ||
|
|
||
| void main() { | ||
| AuthBloc authenticationBloc; | ||
| MockUserRepository userRepository; | ||
|
|
||
| setUp(() { | ||
| userRepository = MockUserRepository(); | ||
| authenticationBloc = AuthBloc(userRepository); | ||
| }); | ||
|
|
||
| tearDown(() { | ||
| authenticationBloc?.close(); | ||
| }); | ||
|
|
||
| test('initial state is correct', () { | ||
| expect(authenticationBloc.initialState, AuthUninitialized()); | ||
| }); | ||
|
|
||
| test('close does not emit new states', () { | ||
| expectLater( | ||
| authenticationBloc, | ||
| emitsInOrder([AuthUninitialized(), emitsDone]), | ||
| ); | ||
| authenticationBloc.close(); | ||
| }); | ||
|
|
||
| group('AppStarted', () { | ||
| test('emits [uninitialized, unauthenticated] for invalid token', () { | ||
| final expectedResponse = [ | ||
| AuthUninitialized(), | ||
| AuthUnauthenticated(), | ||
| ]; | ||
|
|
||
| when(userRepository.getToken()).thenAnswer((_) => Future.value(null)); | ||
|
|
||
| expectLater( | ||
| authenticationBloc, | ||
| emitsInOrder(expectedResponse), | ||
| ); | ||
|
|
||
| authenticationBloc.add(AppStarted()); | ||
| }); | ||
| }); | ||
| group('LoggedIn', () { | ||
| test('emits [uninitialized, loading, authenticated] when token is persisted', () { | ||
| final expectedResponse = [ | ||
| AuthUninitialized(), | ||
| AuthInProgress(), | ||
| AuthAuthenticated(), | ||
| ]; | ||
|
|
||
| expectLater( | ||
| authenticationBloc, | ||
| emitsInOrder(expectedResponse), | ||
| ); | ||
|
|
||
| authenticationBloc.add(JustLoggedIn( | ||
| 'instance.token', | ||
| )); | ||
| }); | ||
| }); | ||
| group('LoggedOut', () { | ||
| test('emits [uninitialized, loading, unauthenticated] when token is deleted', () { | ||
| final expectedResponse = [ | ||
| AuthUninitialized(), | ||
| AuthInProgress(), | ||
| AuthUnauthenticated( | ||
| justLoggedOut: true, | ||
| ), | ||
| ]; | ||
|
|
||
| expectLater( | ||
| authenticationBloc, | ||
| emitsInOrder(expectedResponse), | ||
| ); | ||
|
|
||
| authenticationBloc.add(JustLoggedOut()); | ||
| }); | ||
| }); | ||
| } |
This file contains hidden or 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,39 @@ | ||
| import 'package:mentorship_client/auth/bloc.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| void main() { | ||
| group('AppStarted', () { | ||
| group('AppStarted', () { | ||
| test('props are []', () { | ||
| expect(AppStarted().props, []); | ||
| }); | ||
|
|
||
| test('toString is "AppStarted"', () { | ||
| expect(AppStarted().toString(), 'AppStarted'); | ||
| }); | ||
| }); | ||
|
|
||
| group('JustLoggedIn', () { | ||
| test('props are [token]', () { | ||
| expect(JustLoggedIn('token').props, ['token']); | ||
| }); | ||
|
|
||
| test('toString is "LoggedIn { token: token }"', () { | ||
| expect( | ||
| JustLoggedIn('token').toString(), | ||
| 'LoggedIn { token: token }', | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| group('JustLoggedOut', () { | ||
| test('props are []', () { | ||
| expect(JustLoggedOut().props, []); | ||
| }); | ||
|
|
||
| test('toString is "AuthenticationLoggedOut"', () { | ||
| expect(JustLoggedOut().toString(), 'JustLoggedOut'); | ||
| }); | ||
| }); | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.