From b5dcde1389ae79a37fd68a8826709f36072d274e Mon Sep 17 00:00:00 2001 From: Aadeesh11 Date: Sun, 5 Dec 2021 16:10:13 +0530 Subject: [PATCH] Fixes: #149 Enabled non_constant_identifier_names rule --- analysis_options.yaml | 2 +- lib/services/database_service.dart | 4 +- lib/services/ib_engine_service.dart | 10 +-- lib/ui/views/profile/edit_profile_view.dart | 6 +- .../views/profile/user_favourites_view.dart | 2 +- lib/ui/views/profile/user_projects_view.dart | 2 +- lib/ui/views/projects/edit_project_view.dart | 6 +- .../projects/featured_projects_view.dart | 2 +- .../views/projects/project_details_view.dart | 36 +++++----- lib/utils/unicode_map.dart | 2 +- .../profile/edit_profile_viewmodel.dart | 10 +-- lib/viewmodels/profile/profile_viewmodel.dart | 10 +-- .../profile/user_favourites_viewmodel.dart | 10 +-- .../profile/user_projects_viewmodel.dart | 10 +-- .../projects/edit_project_viewmodel.dart | 10 +-- .../projects/featured_projects_viewmodel.dart | 10 +-- .../projects/project_details_viewmodel.dart | 68 +++++++++---------- .../profile/edit_profile_view_test.dart | 2 +- test/ui_tests/profile/profile_view_test.dart | 4 +- .../profile/user_favourites_view_test.dart | 2 +- .../profile/user_projects_view_test.dart | 2 +- .../projects/featured_projects_view_test.dart | 2 +- .../profile/edit_profile_viewmodel_test.dart | 6 +- .../profile/profile_viewmodel_test.dart | 6 +- .../user_favourites_viewmodel_test.dart | 10 +-- .../profile/user_projects_viewmodel_test.dart | 10 +-- .../projects/edit_project_viewmodel_test.dart | 6 +- .../featured_projects_viewmodel_test.dart | 8 +-- .../project_details_viewmodel_test.dart | 41 +++++------ 29 files changed, 150 insertions(+), 149 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index e84b1918..7c3f3a84 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -10,7 +10,7 @@ linter: avoid_redundant_argument_values: false - non_constant_identifier_names: false + non_constant_identifier_names: true constant_identifier_names: false diff --git a/lib/services/database_service.dart b/lib/services/database_service.dart index 65f47f05..5367453e 100644 --- a/lib/services/database_service.dart +++ b/lib/services/database_service.dart @@ -8,7 +8,7 @@ enum DatabaseBox { IB, } -List DatabaseAdapters = [ +List databaseAdapters = [ IbRawPageDataAdapter(), ]; @@ -38,7 +38,7 @@ class DatabaseServiceImpl implements DatabaseService { } // Register Adapters for Hive - for (var adapter in DatabaseAdapters) { + for (var adapter in databaseAdapters) { Hive.registerAdapter(adapter); } } diff --git a/lib/services/ib_engine_service.dart b/lib/services/ib_engine_service.dart index 72e8acaf..20ff2ba4 100644 --- a/lib/services/ib_engine_service.dart +++ b/lib/services/ib_engine_service.dart @@ -161,11 +161,11 @@ class IbEngineServiceImpl implements IbEngineService { var toc = []; for (var li in element.children) { - var eff_index = num ? index.toString() : String.fromCharCode(index); + var effIndex = num ? index.toString() : String.fromCharCode(index); if (li.getElementsByTagName('ol').isNotEmpty) { toc.add( IbTocItem( - leading: '$eff_index.', + leading: '$effIndex.', content: li.firstChild.text, items: _parseToc(li.children[1], num: !num), ), @@ -173,7 +173,7 @@ class IbEngineServiceImpl implements IbEngineService { } else { toc.add( IbTocItem( - leading: '$eff_index.', + leading: '$effIndex.', content: li.text, ), ); @@ -191,7 +191,7 @@ class IbEngineServiceImpl implements IbEngineService { var toc = []; for (var li in element.children) { - var eff_index = num ? index.toString() : String.fromCharCode(index); + var effIndex = num ? index.toString() : String.fromCharCode(index); var sublist = []; for (var node in li.nodes) { @@ -206,7 +206,7 @@ class IbEngineServiceImpl implements IbEngineService { toc.add( IbTocItem( - leading: '$eff_index.', + leading: '$effIndex.', content: root ? li.nodes[0].text.trim() : li.text.trim(), items: sublist.isNotEmpty ? sublist : null, ), diff --git a/lib/ui/views/profile/edit_profile_view.dart b/lib/ui/views/profile/edit_profile_view.dart index 0a6b35a1..620f2d4d 100644 --- a/lib/ui/views/profile/edit_profile_view.dart +++ b/lib/ui/views/profile/edit_profile_view.dart @@ -108,17 +108,17 @@ class _EditProfileViewState extends State { _dialogService.popDialog(); - if (_model.isSuccess(_model.UPDATE_PROFILE)) { + if (_model.isSuccess(_model.updateProfileKey)) { await Future.delayed(const Duration(seconds: 1)); Get.back(result: _model.updatedUser); SnackBarUtils.showDark( 'Profile Updated', 'Your profile was successfully updated.', ); - } else if (_model.isError(_model.UPDATE_PROFILE)) { + } else if (_model.isError(_model.updateProfileKey)) { SnackBarUtils.showDark( 'Error', - _model.errorMessageFor(_model.UPDATE_PROFILE), + _model.errorMessageFor(_model.updateProfileKey), ); } } diff --git a/lib/ui/views/profile/user_favourites_view.dart b/lib/ui/views/profile/user_favourites_view.dart index 20923535..768dc832 100644 --- a/lib/ui/views/profile/user_favourites_view.dart +++ b/lib/ui/views/profile/user_favourites_view.dart @@ -31,7 +31,7 @@ class _UserFavouritesViewState extends State builder: (context, model, child) { final _items = []; - if (model.isSuccess(model.FETCH_USER_FAVOURITES)) { + if (model.isSuccess(model.fetchUserFavouritesKey)) { for (var project in model.userFavourites) { _items.add( ProjectCard( diff --git a/lib/ui/views/profile/user_projects_view.dart b/lib/ui/views/profile/user_projects_view.dart index fa7e2997..7ab2fa98 100644 --- a/lib/ui/views/profile/user_projects_view.dart +++ b/lib/ui/views/profile/user_projects_view.dart @@ -28,7 +28,7 @@ class _UserProjectsViewState extends State builder: (context, model, child) { final _items = []; - if (model.isSuccess(model.FETCH_USER_PROJECTS)) { + if (model.isSuccess(model.fetchUserProjectsKey)) { for (var project in model.userProjects) { _items.add( ProjectCard( diff --git a/lib/ui/views/projects/edit_project_view.dart b/lib/ui/views/projects/edit_project_view.dart index 695dbbb3..713f8c50 100644 --- a/lib/ui/views/projects/edit_project_view.dart +++ b/lib/ui/views/projects/edit_project_view.dart @@ -127,17 +127,17 @@ class _EditProjectViewState extends State { _dialogService.popDialog(); - if (_model.isSuccess(_model.UPDATE_PROJECT)) { + if (_model.isSuccess(_model.updateProjectKey)) { await Future.delayed(const Duration(seconds: 1)); Get.back(result: _model.updatedProject); SnackBarUtils.showDark( 'Project Updated', 'The project was successfully updated.', ); - } else if (_model.isError(_model.UPDATE_PROJECT)) { + } else if (_model.isError(_model.updateProjectKey)) { SnackBarUtils.showDark( 'Error', - _model.errorMessageFor(_model.UPDATE_PROJECT), + _model.errorMessageFor(_model.updateProjectKey), ); } } diff --git a/lib/ui/views/projects/featured_projects_view.dart b/lib/ui/views/projects/featured_projects_view.dart index e2241213..a19c0f4c 100644 --- a/lib/ui/views/projects/featured_projects_view.dart +++ b/lib/ui/views/projects/featured_projects_view.dart @@ -30,7 +30,7 @@ class _FeaturedProjectsViewState extends State { builder: (context, model, child) { final _items = []; - if (model.isSuccess(model.FETCH_FEATURED_PROJECTS)) { + if (model.isSuccess(model.fetchFeaturedProjectsKey)) { for (var project in model.featuredProjects) { _items.add( FeaturedProjectCard( diff --git a/lib/ui/views/projects/project_details_view.dart b/lib/ui/views/projects/project_details_view.dart index 422c0fb6..f2c9852e 100644 --- a/lib/ui/views/projects/project_details_view.dart +++ b/lib/ui/views/projects/project_details_view.dart @@ -51,9 +51,9 @@ class _ProjectDetailsViewState extends State { void onShareButtonPressed() { final RenderBox box = context.findRenderObject(); - var URL = + var url = 'https://circuitverse.org/users/${widget.project.relationships.author.data.id}/projects/${widget.project.id}'; - Share.share(URL, + Share.share(url, sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size); } @@ -253,13 +253,13 @@ class _ProjectDetailsViewState extends State { _dialogService.popDialog(); - if (_model.isSuccess(_model.FORK_PROJECT)) { + if (_model.isSuccess(_model.forkProjectKey)) { await Get.toNamed(ProjectDetailsView.id, arguments: _model.forkedProject); - } else if (_model.isError(_model.FORK_PROJECT)) { + } else if (_model.isError(_model.forkProjectKey)) { SnackBarUtils.showDark( 'Error', - _model.errorMessageFor(_model.FORK_PROJECT), + _model.errorMessageFor(_model.forkProjectKey), ); } } @@ -294,15 +294,15 @@ class _ProjectDetailsViewState extends State { Future onStarProjectPressed() async { await _model.toggleStarForProject(_recievedProject.id); - if (_model.isSuccess(_model.TOGGLE_STAR)) { + if (_model.isSuccess(_model.toggleStarKey)) { SnackBarUtils.showDark( 'Project ${_model.isProjectStarred ? 'Starred' : 'Unstarred'}', 'You have successfully ${_model.isProjectStarred ? 'stared' : 'unstarred'} the project', ); - } else if (_model.isError(_model.TOGGLE_STAR)) { + } else if (_model.isError(_model.toggleStarKey)) { SnackBarUtils.showDark( 'Error', - _model.errorMessageFor(_model.TOGGLE_STAR), + _model.errorMessageFor(_model.toggleStarKey), ); } } @@ -335,16 +335,16 @@ class _ProjectDetailsViewState extends State { _dialogService.popDialog(); - if (_model.isSuccess(_model.ADD_COLLABORATORS) && + if (_model.isSuccess(_model.addCollaboratorsKey) && _model.addedCollaboratorsSuccessMessage.isNotEmpty) { SnackBarUtils.showDark( 'Collaborators Added', _model.addedCollaboratorsSuccessMessage, ); - } else if (_model.isError(_model.ADD_COLLABORATORS)) { + } else if (_model.isError(_model.addCollaboratorsKey)) { SnackBarUtils.showDark( 'Error', - _model.errorMessageFor(_model.ADD_COLLABORATORS), + _model.errorMessageFor(_model.addCollaboratorsKey), ); } } @@ -466,16 +466,16 @@ class _ProjectDetailsViewState extends State { _dialogService.popDialog(); - if (_model.isSuccess(_model.DELETE_PROJECT)) { + if (_model.isSuccess(_model.deleteProjectKey)) { Get.back(result: true); SnackBarUtils.showDark( 'Project Deleted', 'Project is successfully deleted.', ); - } else if (_model.isError(_model.DELETE_PROJECT)) { + } else if (_model.isError(_model.deleteProjectKey)) { SnackBarUtils.showDark( 'Error', - _model.errorMessageFor(_model.DELETE_PROJECT), + _model.errorMessageFor(_model.deleteProjectKey), ); } } @@ -516,15 +516,15 @@ class _ProjectDetailsViewState extends State { _dialogService.popDialog(); - if (_model.isSuccess(_model.DELETE_COLLABORATORS)) { + if (_model.isSuccess(_model.deleteCollaboartorsKey)) { SnackBarUtils.showDark( 'Collaborator Deleted', 'Collaborator was successfully deleted.', ); - } else if (_model.isError(_model.DELETE_COLLABORATORS)) { + } else if (_model.isError(_model.deleteCollaboartorsKey)) { SnackBarUtils.showDark( 'Error', - _model.errorMessageFor(_model.DELETE_COLLABORATORS), + _model.errorMessageFor(_model.deleteCollaboartorsKey), ); } } @@ -634,7 +634,7 @@ class _ProjectDetailsViewState extends State { ), ); - if (_model.isSuccess(_model.FETCH_PROJECT_DETAILS) && + if (_model.isSuccess(_model.fetchProjectDetailsKey) && _model.collaborators.isNotEmpty) { _items.add(const Divider()); diff --git a/lib/utils/unicode_map.dart b/lib/utils/unicode_map.dart index 4d29684b..24bc223d 100644 --- a/lib/utils/unicode_map.dart +++ b/lib/utils/unicode_map.dart @@ -1,5 +1,5 @@ /// Unicode Map for Subscript and Subscript character -var UnicodeMap = { +const UnicodeMap = { ' ': [' ', ' '], '0': ['\u2070', '\u2080'], '1': ['\u00B9', '\u2081'], diff --git a/lib/viewmodels/profile/edit_profile_viewmodel.dart b/lib/viewmodels/profile/edit_profile_viewmodel.dart index 4fe9954c..9443c235 100644 --- a/lib/viewmodels/profile/edit_profile_viewmodel.dart +++ b/lib/viewmodels/profile/edit_profile_viewmodel.dart @@ -8,7 +8,7 @@ import 'package:mobile_app/viewmodels/base_viewmodel.dart'; class EditProfileViewModel extends BaseModel { // ViewState Keys - String UPDATE_PROFILE = 'update_profile'; + String updateProfileKey = 'update_profile'; final UsersApi _userApi = locator(); final LocalStorageService _storage = locator(); @@ -24,16 +24,16 @@ class EditProfileViewModel extends BaseModel { Future updateProfile(String name, String educationalInstitute, String country, bool subscribed) async { - setStateFor(UPDATE_PROFILE, ViewState.Busy); + setStateFor(updateProfileKey, ViewState.Busy); try { updatedUser = await _userApi.updateProfile( name, educationalInstitute, country, subscribed); _storage.currentUser = _updatedUser; - setStateFor(UPDATE_PROFILE, ViewState.Success); + setStateFor(updateProfileKey, ViewState.Success); } on Failure catch (f) { - setStateFor(UPDATE_PROFILE, ViewState.Error); - setErrorMessageFor(UPDATE_PROFILE, f.message); + setStateFor(updateProfileKey, ViewState.Error); + setErrorMessageFor(updateProfileKey, f.message); } } } diff --git a/lib/viewmodels/profile/profile_viewmodel.dart b/lib/viewmodels/profile/profile_viewmodel.dart index 08654565..502e71f4 100644 --- a/lib/viewmodels/profile/profile_viewmodel.dart +++ b/lib/viewmodels/profile/profile_viewmodel.dart @@ -7,7 +7,7 @@ import 'package:mobile_app/viewmodels/base_viewmodel.dart'; class ProfileViewModel extends BaseModel { // ViewState Keys - String FETCH_USER_PROFILE = 'fetch_user_profile'; + String fetchUserProfileKey = 'fetch_user_profile'; final UsersApi _usersApi = locator(); @@ -21,14 +21,14 @@ class ProfileViewModel extends BaseModel { } Future fetchUserProfile(String userId) async { - setStateFor(FETCH_USER_PROFILE, ViewState.Busy); + setStateFor(fetchUserProfileKey, ViewState.Busy); try { user = await _usersApi.fetchUser(userId); - setStateFor(FETCH_USER_PROFILE, ViewState.Success); + setStateFor(fetchUserProfileKey, ViewState.Success); } on Failure catch (f) { - setStateFor(FETCH_USER_PROFILE, ViewState.Error); - setErrorMessageFor(FETCH_USER_PROFILE, f.message); + setStateFor(fetchUserProfileKey, ViewState.Error); + setErrorMessageFor(fetchUserProfileKey, f.message); } } } diff --git a/lib/viewmodels/profile/user_favourites_viewmodel.dart b/lib/viewmodels/profile/user_favourites_viewmodel.dart index b3d8f67b..78d43e7b 100644 --- a/lib/viewmodels/profile/user_favourites_viewmodel.dart +++ b/lib/viewmodels/profile/user_favourites_viewmodel.dart @@ -8,7 +8,7 @@ import 'package:mobile_app/viewmodels/base_viewmodel.dart'; class UserFavouritesViewModel extends BaseModel { // ViewState Keys - String FETCH_USER_FAVOURITES = 'fetch_user_favourites'; + String fetchUserFavouritesKey = 'fetch_user_favourites'; final ProjectsApi _projectsApi = locator(); final LocalStorageService _localStorageService = @@ -48,7 +48,7 @@ class UserFavouritesViewModel extends BaseModel { ); } else { // Set State as busy only very first time.. - setStateFor(FETCH_USER_FAVOURITES, ViewState.Busy); + setStateFor(fetchUserFavouritesKey, ViewState.Busy); // fetch projects for the very first time.. previousUserFavouritesBatch = await _projectsApi.getUserFavourites( userId ?? _localStorageService.currentUser.data.id); @@ -56,10 +56,10 @@ class UserFavouritesViewModel extends BaseModel { userFavourites.addAll(previousUserFavouritesBatch.data); - setStateFor(FETCH_USER_FAVOURITES, ViewState.Success); + setStateFor(fetchUserFavouritesKey, ViewState.Success); } on Failure catch (f) { - setStateFor(FETCH_USER_FAVOURITES, ViewState.Error); - setErrorMessageFor(FETCH_USER_FAVOURITES, f.message); + setStateFor(fetchUserFavouritesKey, ViewState.Error); + setErrorMessageFor(fetchUserFavouritesKey, f.message); } } } diff --git a/lib/viewmodels/profile/user_projects_viewmodel.dart b/lib/viewmodels/profile/user_projects_viewmodel.dart index ddce81b7..ecbe4d6f 100644 --- a/lib/viewmodels/profile/user_projects_viewmodel.dart +++ b/lib/viewmodels/profile/user_projects_viewmodel.dart @@ -8,7 +8,7 @@ import 'package:mobile_app/viewmodels/base_viewmodel.dart'; class UserProjectsViewModel extends BaseModel { // ViewState Keys - String FETCH_USER_PROJECTS = 'fetch_user_projects'; + String fetchUserProjectsKey = 'fetch_user_projects'; final ProjectsApi _projectsApi = locator(); final LocalStorageService _localStorageService = @@ -48,16 +48,16 @@ class UserProjectsViewModel extends BaseModel { ); } else { // Set State as busy only very first time.. - setStateFor(FETCH_USER_PROJECTS, ViewState.Busy); + setStateFor(fetchUserProjectsKey, ViewState.Busy); // fetch projects for the very first time.. previousUserProjectsBatch = await _projectsApi.getUserProjects( userId ?? _localStorageService.currentUser.data.id); } userProjects.addAll(previousUserProjectsBatch.data); - setStateFor(FETCH_USER_PROJECTS, ViewState.Success); + setStateFor(fetchUserProjectsKey, ViewState.Success); } on Failure catch (f) { - setStateFor(FETCH_USER_PROJECTS, ViewState.Error); - setErrorMessageFor(FETCH_USER_PROJECTS, f.message); + setStateFor(fetchUserProjectsKey, ViewState.Error); + setErrorMessageFor(fetchUserProjectsKey, f.message); } } } diff --git a/lib/viewmodels/projects/edit_project_viewmodel.dart b/lib/viewmodels/projects/edit_project_viewmodel.dart index 3e70167e..cc542be6 100644 --- a/lib/viewmodels/projects/edit_project_viewmodel.dart +++ b/lib/viewmodels/projects/edit_project_viewmodel.dart @@ -7,7 +7,7 @@ import 'package:mobile_app/viewmodels/base_viewmodel.dart'; class EditProjectViewModel extends BaseModel { // ViewState Keys - String UPDATE_PROJECT = 'update_project'; + String updateProjectKey = 'update_project'; final ProjectsApi _projectsApi = locator(); @@ -27,7 +27,7 @@ class EditProjectViewModel extends BaseModel { String description, List tagsList, }) async { - setStateFor(UPDATE_PROJECT, ViewState.Busy); + setStateFor(updateProjectKey, ViewState.Busy); try { updatedProject = await _projectsApi.updateProject( id, @@ -37,10 +37,10 @@ class EditProjectViewModel extends BaseModel { tagsList: tagsList, ); - setStateFor(UPDATE_PROJECT, ViewState.Success); + setStateFor(updateProjectKey, ViewState.Success); } on Failure catch (f) { - setStateFor(UPDATE_PROJECT, ViewState.Error); - setErrorMessageFor(UPDATE_PROJECT, f.message); + setStateFor(updateProjectKey, ViewState.Error); + setErrorMessageFor(updateProjectKey, f.message); } } } diff --git a/lib/viewmodels/projects/featured_projects_viewmodel.dart b/lib/viewmodels/projects/featured_projects_viewmodel.dart index 1a141f48..c2fee274 100644 --- a/lib/viewmodels/projects/featured_projects_viewmodel.dart +++ b/lib/viewmodels/projects/featured_projects_viewmodel.dart @@ -7,7 +7,7 @@ import 'package:mobile_app/viewmodels/base_viewmodel.dart'; class FeaturedProjectsViewModel extends BaseModel { // ViewState Keys - String FETCH_FEATURED_PROJECTS = 'fetch_featured_projects'; + String fetchFeaturedProjectsKey = 'fetch_featured_projects'; final ProjectsApi _projectsApi = locator(); @@ -40,17 +40,17 @@ class FeaturedProjectsViewModel extends BaseModel { ); } else { // Set State as busy only very first time.. - setStateFor(FETCH_FEATURED_PROJECTS, ViewState.Busy); + setStateFor(fetchFeaturedProjectsKey, ViewState.Busy); // fetch projects for the very first time.. previousFeaturedProjectsBatch = await _projectsApi.getFeaturedProjects( size: size, ); } featuredProjects.addAll(previousFeaturedProjectsBatch.data); - setStateFor(FETCH_FEATURED_PROJECTS, ViewState.Success); + setStateFor(fetchFeaturedProjectsKey, ViewState.Success); } on Failure catch (f) { - setStateFor(FETCH_FEATURED_PROJECTS, ViewState.Error); - setErrorMessageFor(FETCH_FEATURED_PROJECTS, f.message); + setStateFor(fetchFeaturedProjectsKey, ViewState.Error); + setErrorMessageFor(fetchFeaturedProjectsKey, f.message); } } } diff --git a/lib/viewmodels/projects/project_details_viewmodel.dart b/lib/viewmodels/projects/project_details_viewmodel.dart index cdc95eba..ba18a4e2 100644 --- a/lib/viewmodels/projects/project_details_viewmodel.dart +++ b/lib/viewmodels/projects/project_details_viewmodel.dart @@ -9,12 +9,12 @@ import 'package:mobile_app/viewmodels/base_viewmodel.dart'; class ProjectDetailsViewModel extends BaseModel { // ViewState Keys - String FETCH_PROJECT_DETAILS = 'fetch_project_details'; - String FORK_PROJECT = 'fork_project'; - String TOGGLE_STAR = 'toggle_star'; - String DELETE_PROJECT = 'delete_project'; - String ADD_COLLABORATORS = 'add_collaborators'; - String DELETE_COLLABORATORS = 'delete_collaborators'; + String fetchProjectDetailsKey = 'fetch_project_details'; + String forkProjectKey = 'fork_project'; + String toggleStarKey = 'toggle_star'; + String deleteProjectKey = 'delete_project'; + String addCollaboratorsKey = 'add_collaborators'; + String deleteCollaboartorsKey = 'delete_collaborators'; final ProjectsApi _projectsApi = locator(); final CollaboratorsApi _collaboratorsApi = locator(); @@ -76,20 +76,20 @@ class ProjectDetailsViewModel extends BaseModel { } Future fetchProjectDetails(String projectId) async { - setStateFor(FETCH_PROJECT_DETAILS, ViewState.Busy); + setStateFor(fetchProjectDetailsKey, ViewState.Busy); try { project = await _projectsApi.getProjectDetails(projectId); collaborators = _project.collaborators; - setStateFor(FETCH_PROJECT_DETAILS, ViewState.Success); + setStateFor(fetchProjectDetailsKey, ViewState.Success); } on Failure catch (f) { - setStateFor(FETCH_PROJECT_DETAILS, ViewState.Error); - setErrorMessageFor(FETCH_PROJECT_DETAILS, f.message); + setStateFor(fetchProjectDetailsKey, ViewState.Error); + setErrorMessageFor(fetchProjectDetailsKey, f.message); } } Future addCollaborators(String projectId, String emails) async { - setStateFor(ADD_COLLABORATORS, ViewState.Busy); + setStateFor(addCollaboratorsKey, ViewState.Busy); try { var addedCollaborators = await _collaboratorsApi.addCollaborators(projectId, emails); @@ -111,15 +111,15 @@ class ProjectDetailsViewModel extends BaseModel { await _collaboratorsApi.fetchProjectCollaborators(projectId); collaborators = _collaborators.data; - setStateFor(ADD_COLLABORATORS, ViewState.Success); + setStateFor(addCollaboratorsKey, ViewState.Success); } on Failure catch (f) { - setStateFor(ADD_COLLABORATORS, ViewState.Error); - setErrorMessageFor(ADD_COLLABORATORS, f.message); + setStateFor(addCollaboratorsKey, ViewState.Error); + setErrorMessageFor(addCollaboratorsKey, f.message); } } Future deleteCollaborator(String projectId, String collaboratorId) async { - setStateFor(DELETE_COLLABORATORS, ViewState.Busy); + setStateFor(deleteCollaboartorsKey, ViewState.Busy); try { var _isDeleted = await _collaboratorsApi.deleteCollaborator(projectId, collaboratorId); @@ -130,58 +130,58 @@ class ProjectDetailsViewModel extends BaseModel { notifyListeners(); if (_isDeleted) { - setStateFor(DELETE_COLLABORATORS, ViewState.Success); + setStateFor(deleteCollaboartorsKey, ViewState.Success); } else { - setStateFor(DELETE_COLLABORATORS, ViewState.Error); + setStateFor(deleteCollaboartorsKey, ViewState.Error); setErrorMessageFor( - DELETE_COLLABORATORS, 'Collaborator can\'t be deleted'); + deleteCollaboartorsKey, 'Collaborator can\'t be deleted'); } } on Failure catch (f) { - setStateFor(DELETE_COLLABORATORS, ViewState.Error); - setErrorMessageFor(DELETE_COLLABORATORS, f.message); + setStateFor(deleteCollaboartorsKey, ViewState.Error); + setErrorMessageFor(deleteCollaboartorsKey, f.message); } } Future forkProject(String toBeForkedProjectId) async { - setStateFor(FORK_PROJECT, ViewState.Busy); + setStateFor(forkProjectKey, ViewState.Busy); try { forkedProject = await _projectsApi.forkProject(toBeForkedProjectId); - setStateFor(FORK_PROJECT, ViewState.Success); + setStateFor(forkProjectKey, ViewState.Success); } on Failure catch (f) { - setStateFor(FORK_PROJECT, ViewState.Error); - setErrorMessageFor(FORK_PROJECT, f.message); + setStateFor(forkProjectKey, ViewState.Error); + setErrorMessageFor(forkProjectKey, f.message); } } Future toggleStarForProject(String projectId) async { - setStateFor(TOGGLE_STAR, ViewState.Busy); + setStateFor(toggleStarKey, ViewState.Busy); try { var _toggleMessage = await _projectsApi.toggleStarProject(projectId); isProjectStarred = _toggleMessage.contains('Starred') ? true : false; isProjectStarred ? starCount++ : starCount--; - setStateFor(TOGGLE_STAR, ViewState.Success); + setStateFor(toggleStarKey, ViewState.Success); } on Failure catch (f) { - setStateFor(TOGGLE_STAR, ViewState.Error); - setErrorMessageFor(TOGGLE_STAR, f.message); + setStateFor(toggleStarKey, ViewState.Error); + setErrorMessageFor(toggleStarKey, f.message); } } Future deleteProject(String projectId) async { - setStateFor(DELETE_PROJECT, ViewState.Busy); + setStateFor(deleteProjectKey, ViewState.Busy); try { var _isDeleted = await _projectsApi.deleteProject(projectId); if (_isDeleted) { - setStateFor(DELETE_PROJECT, ViewState.Success); + setStateFor(deleteProjectKey, ViewState.Success); } else { - setStateFor(DELETE_PROJECT, ViewState.Error); - setErrorMessageFor(DELETE_PROJECT, 'Project cannot be deleted'); + setStateFor(deleteProjectKey, ViewState.Error); + setErrorMessageFor(deleteProjectKey, 'Project cannot be deleted'); } } on Failure catch (f) { - setStateFor(DELETE_PROJECT, ViewState.Error); - setErrorMessageFor(DELETE_PROJECT, f.message); + setStateFor(deleteProjectKey, ViewState.Error); + setErrorMessageFor(deleteProjectKey, f.message); } } } diff --git a/test/ui_tests/profile/edit_profile_view_test.dart b/test/ui_tests/profile/edit_profile_view_test.dart index 16b75da5..b55bd3e1 100644 --- a/test/ui_tests/profile/edit_profile_view_test.dart +++ b/test/ui_tests/profile/edit_profile_view_test.dart @@ -90,7 +90,7 @@ void main() { when(_editProfileViewModel.updateProfile(any, any, any, any)) .thenReturn(null); when(_editProfileViewModel - .isSuccess(_editProfileViewModel.UPDATE_PROFILE)) + .isSuccess(_editProfileViewModel.updateProfileKey)) .thenReturn(true); // Pump Edit Profile View diff --git a/test/ui_tests/profile/profile_view_test.dart b/test/ui_tests/profile/profile_view_test.dart index c60eb9c2..438e4246 100644 --- a/test/ui_tests/profile/profile_view_test.dart +++ b/test/ui_tests/profile/profile_view_test.dart @@ -40,7 +40,7 @@ void main() { when(_profileViewModel.fetchUserProfile(any)).thenReturn(null); - when(_profileViewModel.isSuccess(_profileViewModel.FETCH_USER_PROFILE)) + when(_profileViewModel.isSuccess(_profileViewModel.fetchUserProfileKey)) .thenReturn(true); when(_profileViewModel.user).thenReturn(user); @@ -50,7 +50,7 @@ void main() { when(_userProjectsViewModel.fetchUserProjects()).thenReturn(null); when(_userProjectsViewModel - .isSuccess(_userProjectsViewModel.FETCH_USER_PROJECTS)) + .isSuccess(_userProjectsViewModel.fetchUserProjectsKey)) .thenReturn(false); await tester.pumpWidget( diff --git a/test/ui_tests/profile/user_favourites_view_test.dart b/test/ui_tests/profile/user_favourites_view_test.dart index 225408e9..346ce087 100644 --- a/test/ui_tests/profile/user_favourites_view_test.dart +++ b/test/ui_tests/profile/user_favourites_view_test.dart @@ -39,7 +39,7 @@ void main() { when(_userFavoritesViewModel.fetchUserFavourites()).thenReturn(null); when(_userFavoritesViewModel - .isSuccess(_userFavoritesViewModel.FETCH_USER_FAVOURITES)) + .isSuccess(_userFavoritesViewModel.fetchUserFavouritesKey)) .thenReturn(true); when(_userFavoritesViewModel.userFavourites).thenAnswer((_) => projects); diff --git a/test/ui_tests/profile/user_projects_view_test.dart b/test/ui_tests/profile/user_projects_view_test.dart index 1cf2751a..6cf2b2cd 100644 --- a/test/ui_tests/profile/user_projects_view_test.dart +++ b/test/ui_tests/profile/user_projects_view_test.dart @@ -38,7 +38,7 @@ void main() { when(_userProjectsViewModel.fetchUserProjects()).thenReturn(null); when(_userProjectsViewModel - .isSuccess(_userProjectsViewModel.FETCH_USER_PROJECTS)) + .isSuccess(_userProjectsViewModel.fetchUserProjectsKey)) .thenReturn(true); when(_userProjectsViewModel.userProjects).thenAnswer((_) => projects); diff --git a/test/ui_tests/projects/featured_projects_view_test.dart b/test/ui_tests/projects/featured_projects_view_test.dart index b49775a6..c46c8e6e 100644 --- a/test/ui_tests/projects/featured_projects_view_test.dart +++ b/test/ui_tests/projects/featured_projects_view_test.dart @@ -39,7 +39,7 @@ void main() { when(model.fetchFeaturedProjects()).thenReturn(null); - when(model.isSuccess(model.FETCH_FEATURED_PROJECTS)) + when(model.isSuccess(model.fetchFeaturedProjectsKey)) .thenAnswer((_) => true); when(model.featuredProjects).thenAnswer((_) => projects); diff --git a/test/viewmodel_tests/profile/edit_profile_viewmodel_test.dart b/test/viewmodel_tests/profile/edit_profile_viewmodel_test.dart index f65350ec..2816433d 100644 --- a/test/viewmodel_tests/profile/edit_profile_viewmodel_test.dart +++ b/test/viewmodel_tests/profile/edit_profile_viewmodel_test.dart @@ -31,7 +31,7 @@ void main() { // verify _user is stored in localStorage.. verify(_mockLocalStorageService.currentUser = _user); - expect(_model.stateFor(_model.UPDATE_PROFILE), ViewState.Success); + expect(_model.stateFor(_model.updateProfileKey), ViewState.Success); // verify profile is updated.. expect(_model.updatedUser, _user); @@ -47,8 +47,8 @@ void main() { await _model.updateProfile('Test User', 'Gurukul', 'India', true); // verify Error ViewState with proper error message.. - expect(_model.stateFor(_model.UPDATE_PROFILE), ViewState.Error); - expect(_model.errorMessageFor(_model.UPDATE_PROFILE), + expect(_model.stateFor(_model.updateProfileKey), ViewState.Error); + expect(_model.errorMessageFor(_model.updateProfileKey), 'Some Error Occurred!'); // verify user is not populated on failure diff --git a/test/viewmodel_tests/profile/profile_viewmodel_test.dart b/test/viewmodel_tests/profile/profile_viewmodel_test.dart index 94e03cea..b301b7c7 100644 --- a/test/viewmodel_tests/profile/profile_viewmodel_test.dart +++ b/test/viewmodel_tests/profile/profile_viewmodel_test.dart @@ -26,7 +26,7 @@ void main() { // verify API call is made.. verify(_mockUsersApi.fetchUser('1')); - expect(_model.stateFor(_model.FETCH_USER_PROFILE), ViewState.Success); + expect(_model.stateFor(_model.fetchUserProfileKey), ViewState.Success); // verify profile/user is populated.. expect(_model.user, _user); @@ -41,8 +41,8 @@ void main() { await _model.fetchUserProfile('1'); // verify Error ViewState with proper error message.. - expect(_model.stateFor(_model.FETCH_USER_PROFILE), ViewState.Error); - expect(_model.errorMessageFor(_model.FETCH_USER_PROFILE), + expect(_model.stateFor(_model.fetchUserProfileKey), ViewState.Error); + expect(_model.errorMessageFor(_model.fetchUserProfileKey), 'Some Error Occurred!'); // verify user is not populated on failure diff --git a/test/viewmodel_tests/profile/user_favourites_viewmodel_test.dart b/test/viewmodel_tests/profile/user_favourites_viewmodel_test.dart index 60de14a2..9589e9e7 100644 --- a/test/viewmodel_tests/profile/user_favourites_viewmodel_test.dart +++ b/test/viewmodel_tests/profile/user_favourites_viewmodel_test.dart @@ -45,7 +45,7 @@ void main() { verify(_mockProjectsApi.getUserFavourites('1')); expect( - _model.stateFor(_model.FETCH_USER_FAVOURITES), ViewState.Success); + _model.stateFor(_model.fetchUserFavouritesKey), ViewState.Success); expect(_model.previousUserFavouritesBatch, _projects); expect(deepEq(_model.userFavourites, _projects.data), true); }); @@ -63,7 +63,7 @@ void main() { // verify API call to page 2 is made verify(_mockProjectsApi.getUserFavourites('1', page: 2)); expect( - _model.stateFor(_model.FETCH_USER_FAVOURITES), ViewState.Success); + _model.stateFor(_model.fetchUserFavouritesKey), ViewState.Success); expect(_model.previousUserFavouritesBatch, _projects); }); @@ -82,7 +82,7 @@ void main() { // verify API call is made with _currentUser.data.id i.e '1'.. verify(_mockProjectsApi.getUserFavourites('1')); expect( - _model.stateFor(_model.FETCH_USER_FAVOURITES), ViewState.Success); + _model.stateFor(_model.fetchUserFavouritesKey), ViewState.Success); expect(_model.previousUserFavouritesBatch, _projects); expect(deepEq(_model.userFavourites, _projects.data), true); }); @@ -96,8 +96,8 @@ void main() { await _model.fetchUserFavourites(userId: '1'); // verify Error ViewState with proper error message.. - expect(_model.stateFor(_model.FETCH_USER_FAVOURITES), ViewState.Error); - expect(_model.errorMessageFor(_model.FETCH_USER_FAVOURITES), + expect(_model.stateFor(_model.fetchUserFavouritesKey), ViewState.Error); + expect(_model.errorMessageFor(_model.fetchUserFavouritesKey), 'Some Error Occurred!'); }); }); diff --git a/test/viewmodel_tests/profile/user_projects_viewmodel_test.dart b/test/viewmodel_tests/profile/user_projects_viewmodel_test.dart index fcda1306..d440eeb5 100644 --- a/test/viewmodel_tests/profile/user_projects_viewmodel_test.dart +++ b/test/viewmodel_tests/profile/user_projects_viewmodel_test.dart @@ -44,7 +44,7 @@ void main() { await _model.fetchUserProjects(userId: '1'); verify(_mockProjectsApi.getUserProjects('1')); - expect(_model.stateFor(_model.FETCH_USER_PROJECTS), ViewState.Success); + expect(_model.stateFor(_model.fetchUserProjectsKey), ViewState.Success); expect(_model.previousUserProjectsBatch, _projects); expect(deepEq(_model.userProjects, _projects.data), true); }); @@ -61,7 +61,7 @@ void main() { // verify API call to page 2 is made verify(_mockProjectsApi.getUserProjects('1', page: 2)); - expect(_model.stateFor(_model.FETCH_USER_PROJECTS), ViewState.Success); + expect(_model.stateFor(_model.fetchUserProjectsKey), ViewState.Success); expect(_model.previousUserProjectsBatch, _projects); }); @@ -79,7 +79,7 @@ void main() { // verify API call is made with _currentUser.data.id i.e '1'.. verify(_mockProjectsApi.getUserProjects('1')); - expect(_model.stateFor(_model.FETCH_USER_PROJECTS), ViewState.Success); + expect(_model.stateFor(_model.fetchUserProjectsKey), ViewState.Success); expect(_model.previousUserProjectsBatch, _projects); expect(deepEq(_model.userProjects, _projects.data), true); }); @@ -93,8 +93,8 @@ void main() { await _model.fetchUserProjects(userId: '1'); // verify Error ViewState with proper error message.. - expect(_model.stateFor(_model.FETCH_USER_PROJECTS), ViewState.Error); - expect(_model.errorMessageFor(_model.FETCH_USER_PROJECTS), + expect(_model.stateFor(_model.fetchUserProjectsKey), ViewState.Error); + expect(_model.errorMessageFor(_model.fetchUserProjectsKey), 'Some Error Occurred!'); }); }); diff --git a/test/viewmodel_tests/projects/edit_project_viewmodel_test.dart b/test/viewmodel_tests/projects/edit_project_viewmodel_test.dart index fa45edb6..4914d6cc 100644 --- a/test/viewmodel_tests/projects/edit_project_viewmodel_test.dart +++ b/test/viewmodel_tests/projects/edit_project_viewmodel_test.dart @@ -37,7 +37,7 @@ void main() { projectAccessType: 'Public', description: 'description', tagsList: [])); - expect(_model.stateFor(_model.UPDATE_PROJECT), ViewState.Success); + expect(_model.stateFor(_model.updateProjectKey), ViewState.Success); // verify project is updated.. expect(_model.updatedProject, _project); @@ -59,8 +59,8 @@ void main() { tagsList: []); // verify Error ViewState with proper error message.. - expect(_model.stateFor(_model.UPDATE_PROJECT), ViewState.Error); - expect(_model.errorMessageFor(_model.UPDATE_PROJECT), + expect(_model.stateFor(_model.updateProjectKey), ViewState.Error); + expect(_model.errorMessageFor(_model.updateProjectKey), 'Some Error Occurred!'); // verify project is not populated on failure diff --git a/test/viewmodel_tests/projects/featured_projects_viewmodel_test.dart b/test/viewmodel_tests/projects/featured_projects_viewmodel_test.dart index 4c84abbc..4876aaad 100644 --- a/test/viewmodel_tests/projects/featured_projects_viewmodel_test.dart +++ b/test/viewmodel_tests/projects/featured_projects_viewmodel_test.dart @@ -27,7 +27,7 @@ void main() { verify(_mockProjectsApi.getFeaturedProjects()); expect( - _model.stateFor(_model.FETCH_FEATURED_PROJECTS), ViewState.Success); + _model.stateFor(_model.fetchFeaturedProjectsKey), ViewState.Success); expect(_model.previousFeaturedProjectsBatch, _projects); expect(deepEq(_model.featuredProjects, _projects.data), true); }); @@ -45,7 +45,7 @@ void main() { // verify API call to page 2 is made verify(_mockProjectsApi.getFeaturedProjects(page: 2)); expect( - _model.stateFor(_model.FETCH_FEATURED_PROJECTS), ViewState.Success); + _model.stateFor(_model.fetchFeaturedProjectsKey), ViewState.Success); expect(_model.previousFeaturedProjectsBatch, _projects); }); @@ -59,8 +59,8 @@ void main() { // verify Error ViewState with proper error message.. expect( - _model.stateFor(_model.FETCH_FEATURED_PROJECTS), ViewState.Error); - expect(_model.errorMessageFor(_model.FETCH_FEATURED_PROJECTS), + _model.stateFor(_model.fetchFeaturedProjectsKey), ViewState.Error); + expect(_model.errorMessageFor(_model.fetchFeaturedProjectsKey), 'Some Error Occurred!'); }); }); diff --git a/test/viewmodel_tests/projects/project_details_viewmodel_test.dart b/test/viewmodel_tests/projects/project_details_viewmodel_test.dart index 427fa866..d4326f39 100644 --- a/test/viewmodel_tests/projects/project_details_viewmodel_test.dart +++ b/test/viewmodel_tests/projects/project_details_viewmodel_test.dart @@ -35,7 +35,7 @@ void main() { // verify API call is made.. verify(_mockProjectsApi.getProjectDetails('1')); expect( - _model.stateFor(_model.FETCH_PROJECT_DETAILS), ViewState.Success); + _model.stateFor(_model.fetchProjectDetailsKey), ViewState.Success); // verify project data is populated.. expect(_model.project, _project); @@ -51,8 +51,8 @@ void main() { await _model.fetchProjectDetails('1'); // verify Error ViewState with proper error message.. - expect(_model.stateFor(_model.FETCH_PROJECT_DETAILS), ViewState.Error); - expect(_model.errorMessageFor(_model.FETCH_PROJECT_DETAILS), + expect(_model.stateFor(_model.fetchProjectDetailsKey), ViewState.Error); + expect(_model.errorMessageFor(_model.fetchProjectDetailsKey), 'Some Error Occurred!'); }); }); @@ -75,7 +75,7 @@ void main() { verify(_mockCollaboratorsApi.addCollaborators( '1', 'test@test.com,existing@test.com,invalid@test.com')); verify(_mockCollaboratorsApi.fetchProjectCollaborators('1')); - expect(_model.stateFor(_model.ADD_COLLABORATORS), ViewState.Success); + expect(_model.stateFor(_model.addCollaboratorsKey), ViewState.Success); expect(_model.addedCollaboratorsSuccessMessage, 'test@test.com was/were added existing@test.com is/are existing invalid@test.com is/are invalid'); @@ -93,8 +93,8 @@ void main() { '1', 'test@test.com,existing@test.com,invalid@test.com'); // verify Error ViewState with proper error message.. - expect(_model.stateFor(_model.ADD_COLLABORATORS), ViewState.Error); - expect(_model.errorMessageFor(_model.ADD_COLLABORATORS), + expect(_model.stateFor(_model.addCollaboratorsKey), ViewState.Error); + expect(_model.errorMessageFor(_model.addCollaboratorsKey), 'Some Error Occurred!'); }); }); @@ -111,7 +111,8 @@ void main() { // verify API call is made.. verify(_mockCollaboratorsApi.deleteCollaborator('1', '1')); - expect(_model.stateFor(_model.DELETE_COLLABORATORS), ViewState.Success); + expect( + _model.stateFor(_model.deleteCollaboartorsKey), ViewState.Success); // verify collaborator is deleted.. expect( @@ -131,8 +132,8 @@ void main() { await _model.deleteCollaborator('1', '1'); // verify Error ViewState with proper error message.. - expect(_model.stateFor(_model.DELETE_COLLABORATORS), ViewState.Error); - expect(_model.errorMessageFor(_model.DELETE_COLLABORATORS), + expect(_model.stateFor(_model.deleteCollaboartorsKey), ViewState.Error); + expect(_model.errorMessageFor(_model.deleteCollaboartorsKey), 'Some Error Occurred!'); }); }); @@ -148,7 +149,7 @@ void main() { // verify API call is made.. verify(_mockProjectsApi.forkProject('1')); - expect(_model.stateFor(_model.FORK_PROJECT), ViewState.Success); + expect(_model.stateFor(_model.forkProjectKey), ViewState.Success); // verify forkedProject data is populated.. expect(_model.forkedProject, _project); @@ -163,8 +164,8 @@ void main() { await _model.forkProject('1'); // verify Error ViewState with proper error message.. - expect(_model.stateFor(_model.FORK_PROJECT), ViewState.Error); - expect(_model.errorMessageFor(_model.FORK_PROJECT), + expect(_model.stateFor(_model.forkProjectKey), ViewState.Error); + expect(_model.errorMessageFor(_model.forkProjectKey), 'Some Error Occurred!'); }); }); @@ -180,7 +181,7 @@ void main() { // verify API call is made.. verify(_mockProjectsApi.toggleStarProject('1')); - expect(_model.stateFor(_model.TOGGLE_STAR), ViewState.Success); + expect(_model.stateFor(_model.toggleStarKey), ViewState.Success); // verify starCount to increment by 1.. expect(_model.starCount, 1); @@ -196,7 +197,7 @@ void main() { // verify API call is made.. verify(_mockProjectsApi.toggleStarProject('1')); - expect(_model.stateFor(_model.TOGGLE_STAR), ViewState.Success); + expect(_model.stateFor(_model.toggleStarKey), ViewState.Success); // verify starCount to decrement by 1.. expect(_model.starCount, -1); @@ -211,9 +212,9 @@ void main() { await _model.toggleStarForProject('1'); // verify Error ViewState with proper error message.. - expect(_model.stateFor(_model.TOGGLE_STAR), ViewState.Error); - expect( - _model.errorMessageFor(_model.TOGGLE_STAR), 'Some Error Occurred!'); + expect(_model.stateFor(_model.toggleStarKey), ViewState.Error); + expect(_model.errorMessageFor(_model.toggleStarKey), + 'Some Error Occurred!'); }); }); @@ -229,7 +230,7 @@ void main() { // verify API call is made.. verify(_mockProjectsApi.deleteProject('1')); - expect(_model.stateFor(_model.DELETE_PROJECT), ViewState.Success); + expect(_model.stateFor(_model.deleteProjectKey), ViewState.Success); }); test('When called & service returns error', () async { @@ -242,8 +243,8 @@ void main() { await _model.deleteProject('1'); // verify Error ViewState with proper error message.. - expect(_model.stateFor(_model.DELETE_PROJECT), ViewState.Error); - expect(_model.errorMessageFor(_model.DELETE_PROJECT), + expect(_model.stateFor(_model.deleteProjectKey), ViewState.Error); + expect(_model.errorMessageFor(_model.deleteProjectKey), 'Some Error Occurred!'); }); });