From c505cfb78c4bcbd71284f9aa45ce3dd130d179ca Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 3 Nov 2021 12:17:52 -0400 Subject: [PATCH] mic tests --- test/Screens/Mic/Mic_test.dart | 72 +++++ test/Screens/Mic/Mic_test.mocks.dart | 419 +++++++++++++++++++++++++++ 2 files changed, 491 insertions(+) create mode 100644 test/Screens/Mic/Mic_test.dart create mode 100644 test/Screens/Mic/Mic_test.mocks.dart diff --git a/test/Screens/Mic/Mic_test.dart b/test/Screens/Mic/Mic_test.dart new file mode 100644 index 0000000..4a9b1df --- /dev/null +++ b/test/Screens/Mic/Mic_test.dart @@ -0,0 +1,72 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mobx/mobx.dart' show ObservableList; +import 'package:mockito/mockito.dart'; +import 'package:provider/provider.dart'; +import 'package:untitled3/Model/Setting.dart'; +import 'package:untitled3/Observables/MenuObservable.dart'; +import 'package:untitled3/Observables/MicObservable.dart'; +import 'package:untitled3/Observables/NoteObservable.dart'; +import 'package:untitled3/Observables/ScreenNavigator.dart'; +import 'package:untitled3/Observables/SettingObservable.dart'; +import 'package:untitled3/Screens/Mic/Mic.dart'; +import 'package:untitled3/generated/i18n.dart'; +import 'package:mockito/annotations.dart'; +import 'Mic_test.mocks.dart'; + +Widget createWidgetForTesting( + {required Widget child, + required MockSettingObserver mockObs, + required MenuObserver menuObs, + required MicObserver micObs, + required NoteObserver noteObs, + required MainNavObserver mainNavObs}) { + final i18n = I18n.delegate; + when(mockObs.userSettings).thenReturn(new Setting()); + + return MultiProvider( + providers: [ + Provider(create: (_) => micObs), + Provider(create: (_) => mockObs), + Provider(create: (_) => menuObs), + Provider(create: (_) => noteObs), + Provider(create: (_) => mainNavObs) + ], + child: MaterialApp( + home: child, + localizationsDelegates: [ + i18n, + ], + )); +} + +@GenerateMocks( + [SettingObserver, MenuObserver, MicObserver, NoteObserver, MainNavObserver]) +void main() { + group('Mic - Widget', () { + testWidgets('Settings Widget Finds All Default Text', + (WidgetTester tester) async { + final mockObs = MockSettingObserver(); + final menuObs = MockMenuObserver(); + final micObs = MockMicObserver(); + when(micObs.messageInputText).thenReturn('input text'); + final obs = ObservableList(); + obs.insert(0, 'input text'); + when(micObs.systemUserMessage).thenAnswer((_) => obs); + + final noteObs = MockNoteObserver(); + final mainNavObs = MockMainNavObserver(); + await tester.pumpWidget(createWidgetForTesting( + child: new SpeechScreen(), + mockObs: mockObs, + menuObs: menuObs, + micObs: micObs, + noteObs: noteObs, + mainNavObs: mainNavObs)); + await tester.pumpAndSettle(); + final inputFinder = find.text('input text'); + expect(inputFinder, findsOneWidget); + + }); + }); +} diff --git a/test/Screens/Mic/Mic_test.mocks.dart b/test/Screens/Mic/Mic_test.mocks.dart new file mode 100644 index 0000000..8894dc4 --- /dev/null +++ b/test/Screens/Mic/Mic_test.mocks.dart @@ -0,0 +1,419 @@ +// Mocks generated by Mockito 5.0.16 from annotations +// in untitled3/test/Screens/Mic/Mic_test.dart. +// Do not manually edit this file. + +import 'dart:async' as _i11; +import 'dart:ui' as _i9; + +import 'package:mobx/mobx.dart' as _i4; +import 'package:mockito/mockito.dart' as _i1; +import 'package:untitled3/generated/i18n.dart' as _i10; +import 'package:untitled3/Model/NLUResponse.dart' as _i5; +import 'package:untitled3/Model/Note.dart' as _i14; +import 'package:untitled3/Model/Setting.dart' as _i2; +import 'package:untitled3/Observables/MenuObservable.dart' as _i7; +import 'package:untitled3/Observables/MicObservable.dart' as _i8; +import 'package:untitled3/Observables/NoteObservable.dart' as _i12; +import 'package:untitled3/Observables/ScreenNavigator.dart' as _i15; +import 'package:untitled3/Observables/SettingObservable.dart' as _i6; +import 'package:untitled3/Services/NLU/Bot/NLULibService.dart' as _i3; +import 'package:untitled3/Utility/Constant.dart' as _i13; + +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types + +class _FakeSetting_0 extends _i1.Fake implements _i2.Setting {} + +class _FakeNLULibService_1 extends _i1.Fake implements _i3.NLULibService {} + +class _FakeObservableList_2 extends _i1.Fake + implements _i4.ObservableList {} + +class _FakeNLUResponse_3 extends _i1.Fake implements _i5.NLUResponse {} + +/// A class which mocks [SettingObserver]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockSettingObserver extends _i1.Mock implements _i6.SettingObserver { + MockSettingObserver() { + _i1.throwOnMissingStub(this); + } + + @override + String get currentScreen => + (super.noSuchMethod(Invocation.getter(#currentScreen), returnValue: '') + as String); + @override + set currentScreen(String? _currentScreen) => + super.noSuchMethod(Invocation.setter(#currentScreen, _currentScreen), + returnValueForMissingStub: null); + @override + _i2.Setting get userSettings => + (super.noSuchMethod(Invocation.getter(#userSettings), + returnValue: _FakeSetting_0()) as _i2.Setting); + @override + set userSettings(_i2.Setting? _userSettings) => + super.noSuchMethod(Invocation.setter(#userSettings, _userSettings), + returnValueForMissingStub: null); + @override + void saveSetting() => super.noSuchMethod(Invocation.method(#saveSetting, []), + returnValueForMissingStub: null); + @override + void initSettings(dynamic settings) => + super.noSuchMethod(Invocation.method(#initSettings, [settings]), + returnValueForMissingStub: null); + @override + void changeScreen(String? name) => + super.noSuchMethod(Invocation.method(#changeScreen, [name]), + returnValueForMissingStub: null); + @override + void setIsFirstRun(bool? value) => + super.noSuchMethod(Invocation.method(#setIsFirstRun, [value]), + returnValueForMissingStub: null); + @override + String toString() => super.toString(); +} + +/// A class which mocks [MenuObserver]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockMenuObserver extends _i1.Mock implements _i7.MenuObserver { + MockMenuObserver() { + _i1.throwOnMissingStub(this); + } + + @override + set currentScreen(dynamic _currentScreen) => + super.noSuchMethod(Invocation.setter(#currentScreen, _currentScreen), + returnValueForMissingStub: null); + @override + String get focusedIcon => + (super.noSuchMethod(Invocation.getter(#focusedIcon), returnValue: '') + as String); + @override + set focusedIcon(String? _focusedIcon) => + super.noSuchMethod(Invocation.setter(#focusedIcon, _focusedIcon), + returnValueForMissingStub: null); + @override + void changeScreen(dynamic screen) => + super.noSuchMethod(Invocation.method(#changeScreen, [screen]), + returnValueForMissingStub: null); + @override + String toString() => super.toString(); +} + +/// A class which mocks [MicObserver]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockMicObserver extends _i1.Mock implements _i8.MicObserver { + MockMicObserver() { + _i1.throwOnMissingStub(this); + } + + @override + _i3.NLULibService get nluLibService => + (super.noSuchMethod(Invocation.getter(#nluLibService), + returnValue: _FakeNLULibService_1()) as _i3.NLULibService); + @override + set nluLibService(_i3.NLULibService? _nluLibService) => + super.noSuchMethod(Invocation.setter(#nluLibService, _nluLibService), + returnValueForMissingStub: null); + @override + String get messageInputText => + (super.noSuchMethod(Invocation.getter(#messageInputText), returnValue: '') + as String); + @override + set messageInputText(String? _messageInputText) => super.noSuchMethod( + Invocation.setter(#messageInputText, _messageInputText), + returnValueForMissingStub: null); + @override + bool get micIsExpectedToListen => + (super.noSuchMethod(Invocation.getter(#micIsExpectedToListen), + returnValue: false) as bool); + @override + set micIsExpectedToListen(bool? _micIsExpectedToListen) => super.noSuchMethod( + Invocation.setter(#micIsExpectedToListen, _micIsExpectedToListen), + returnValueForMissingStub: null); + @override + bool get expectingUserFollowupResponse => + (super.noSuchMethod(Invocation.getter(#expectingUserFollowupResponse), + returnValue: false) as bool); + @override + set expectingUserFollowupResponse(bool? _expectingUserFollowupResponse) => + super.noSuchMethod( + Invocation.setter( + #expectingUserFollowupResponse, _expectingUserFollowupResponse), + returnValueForMissingStub: null); + @override + double get speechConfidence => (super + .noSuchMethod(Invocation.getter(#speechConfidence), returnValue: 0.0) + as double); + @override + set speechConfidence(double? _speechConfidence) => super.noSuchMethod( + Invocation.setter(#speechConfidence, _speechConfidence), + returnValueForMissingStub: null); + @override + _i4.ObservableList get systemUserMessage => + (super.noSuchMethod(Invocation.getter(#systemUserMessage), + returnValue: _FakeObservableList_2()) + as _i4.ObservableList); + @override + set systemUserMessage(_i4.ObservableList? _systemUserMessage) => + super.noSuchMethod( + Invocation.setter(#systemUserMessage, _systemUserMessage), + returnValueForMissingStub: null); + @override + set mainNavObserver(dynamic _mainNavObserver) => + super.noSuchMethod(Invocation.setter(#mainNavObserver, _mainNavObserver), + returnValueForMissingStub: null); + @override + set noteObserver(dynamic _noteObserver) => + super.noSuchMethod(Invocation.setter(#noteObserver, _noteObserver), + returnValueForMissingStub: null); + @override + set locale(_i9.Locale? _locale) => + super.noSuchMethod(Invocation.setter(#locale, _locale), + returnValueForMissingStub: null); + @override + set lastNluMessage(_i5.NLUResponse? _lastNluMessage) => + super.noSuchMethod(Invocation.setter(#lastNluMessage, _lastNluMessage), + returnValueForMissingStub: null); + @override + set followUpTypesForMsgSent(_i8.FollowUpTypes? _followUpTypesForMsgSent) => + super.noSuchMethod( + Invocation.setter(#followUpTypesForMsgSent, _followUpTypesForMsgSent), + returnValueForMissingStub: null); + @override + set i18n(_i10.I18n? _i18n) => + super.noSuchMethod(Invocation.setter(#i18n, _i18n), + returnValueForMissingStub: null); + @override + _i5.NLUResponse get nluCreateNote => + (super.noSuchMethod(Invocation.getter(#nluCreateNote), + returnValue: _FakeNLUResponse_3()) as _i5.NLUResponse); + @override + set nluCreateNote(_i5.NLUResponse? _nluCreateNote) => + super.noSuchMethod(Invocation.setter(#nluCreateNote, _nluCreateNote), + returnValueForMissingStub: null); + @override + int get index => + (super.noSuchMethod(Invocation.getter(#index), returnValue: 0) as int); + @override + set index(int? _index) => + super.noSuchMethod(Invocation.setter(#index, _index), + returnValueForMissingStub: null); + @override + _i11.Future toggleListeningMode() => (super.noSuchMethod( + Invocation.method(#toggleListeningMode, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) as _i11.Future); + @override + void setLocale(dynamic mlocale) => + super.noSuchMethod(Invocation.method(#setLocale, [mlocale]), + returnValueForMissingStub: null); + @override + void setI18n(dynamic mi18n) => + super.noSuchMethod(Invocation.method(#setI18n, [mi18n]), + returnValueForMissingStub: null); + @override + void addUserMessage(String? userMsg) => + super.noSuchMethod(Invocation.method(#addUserMessage, [userMsg]), + returnValueForMissingStub: null); + @override + void addSystemMessage(_i5.NLUResponse? nluResponse) => + super.noSuchMethod(Invocation.method(#addSystemMessage, [nluResponse]), + returnValueForMissingStub: null); + @override + void addFollowUpMessage(String? message, List? responsOptions, + _i8.FollowUpTypes? followupType) => + super.noSuchMethod( + Invocation.method( + #addFollowUpMessage, [message, responsOptions, followupType]), + returnValueForMissingStub: null); + @override + void setNoteObserver(dynamic observer) => + super.noSuchMethod(Invocation.method(#setNoteObserver, [observer]), + returnValueForMissingStub: null); + @override + void setMainNavObserver(dynamic observer) => + super.noSuchMethod(Invocation.method(#setMainNavObserver, [observer]), + returnValueForMissingStub: null); + @override + void clearMsgTextInput() => + super.noSuchMethod(Invocation.method(#clearMsgTextInput, []), + returnValueForMissingStub: null); + @override + void setVoiceMsgTextInput(dynamic value) => + super.noSuchMethod(Invocation.method(#setVoiceMsgTextInput, [value]), + returnValueForMissingStub: null); + @override + _i11.Future fufillNLUTask(_i5.NLUResponse? nluResponse) => + (super.noSuchMethod(Invocation.method(#fufillNLUTask, [nluResponse]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) + as _i11.Future); + @override + void processFollowups( + dynamic userSelection, _i8.FollowUpTypes? followUpType) => + super.noSuchMethod( + Invocation.method(#processFollowups, [userSelection, followUpType]), + returnValueForMissingStub: null); + @override + String toString() => super.toString(); +} + +/// A class which mocks [NoteObserver]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockNoteObserver extends _i1.Mock implements _i12.NoteObserver { + MockNoteObserver() { + _i1.throwOnMissingStub(this); + } + + @override + _i13.NOTE_SCREENS get currentScreen => + (super.noSuchMethod(Invocation.getter(#currentScreen), + returnValue: _i13.NOTE_SCREENS.NOTE) as _i13.NOTE_SCREENS); + @override + set currentScreen(_i13.NOTE_SCREENS? _currentScreen) => + super.noSuchMethod(Invocation.setter(#currentScreen, _currentScreen), + returnValueForMissingStub: null); + @override + set currNoteForDetails(_i14.TextNote? _currNoteForDetails) => super + .noSuchMethod(Invocation.setter(#currNoteForDetails, _currNoteForDetails), + returnValueForMissingStub: null); + @override + List<_i14.TextNote> get usersNotes => + (super.noSuchMethod(Invocation.getter(#usersNotes), + returnValue: <_i14.TextNote>[]) as List<_i14.TextNote>); + @override + set usersNotes(List<_i14.TextNote>? _usersNotes) => + super.noSuchMethod(Invocation.setter(#usersNotes, _usersNotes), + returnValueForMissingStub: null); + @override + Set<_i14.TextNote> get checkListNotes => + (super.noSuchMethod(Invocation.getter(#checkListNotes), + returnValue: <_i14.TextNote>{}) as Set<_i14.TextNote>); + @override + set checkListNotes(Set<_i14.TextNote>? _checkListNotes) => + super.noSuchMethod(Invocation.setter(#checkListNotes, _checkListNotes), + returnValueForMissingStub: null); + @override + bool get newNoteIsCheckList => + (super.noSuchMethod(Invocation.getter(#newNoteIsCheckList), + returnValue: false) as bool); + @override + set newNoteIsCheckList(bool? _newNoteIsCheckList) => super.noSuchMethod( + Invocation.setter(#newNoteIsCheckList, _newNoteIsCheckList), + returnValueForMissingStub: null); + @override + String get newNoteEventDate => + (super.noSuchMethod(Invocation.getter(#newNoteEventDate), returnValue: '') + as String); + @override + set newNoteEventDate(String? _newNoteEventDate) => super.noSuchMethod( + Invocation.setter(#newNoteEventDate, _newNoteEventDate), + returnValueForMissingStub: null); + @override + String get newNoteEventTime => + (super.noSuchMethod(Invocation.getter(#newNoteEventTime), returnValue: '') + as String); + @override + set newNoteEventTime(String? _newNoteEventTime) => super.noSuchMethod( + Invocation.setter(#newNoteEventTime, _newNoteEventTime), + returnValueForMissingStub: null); + @override + void addNote(_i14.TextNote? note) => + super.noSuchMethod(Invocation.method(#addNote, [note]), + returnValueForMissingStub: null); + @override + void deleteNote(_i14.TextNote? note) => + super.noSuchMethod(Invocation.method(#deleteNote, [note]), + returnValueForMissingStub: null); + @override + _i11.Future setCurrNoteIdForDetails(dynamic noteId) => + (super.noSuchMethod(Invocation.method(#setCurrNoteIdForDetails, [noteId]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()) + as _i11.Future); + @override + void setNotes(dynamic notes) => + super.noSuchMethod(Invocation.method(#setNotes, [notes]), + returnValueForMissingStub: null); + @override + List<_i14.TextNote> onSearchNote(String? searchQuery) => + (super.noSuchMethod(Invocation.method(#onSearchNote, [searchQuery]), + returnValue: <_i14.TextNote>[]) as List<_i14.TextNote>); + @override + void setCheckList(dynamic listOfNotes) => + super.noSuchMethod(Invocation.method(#setCheckList, [listOfNotes]), + returnValueForMissingStub: null); + @override + void clearCheckList() => + super.noSuchMethod(Invocation.method(#clearCheckList, []), + returnValueForMissingStub: null); + @override + void changeScreen(_i13.NOTE_SCREENS? name) => + super.noSuchMethod(Invocation.method(#changeScreen, [name]), + returnValueForMissingStub: null); + @override + void setNewNoteAIsCheckList(bool? value) => + super.noSuchMethod(Invocation.method(#setNewNoteAIsCheckList, [value]), + returnValueForMissingStub: null); + @override + void setNewNoteEventDate(String? value) => + super.noSuchMethod(Invocation.method(#setNewNoteEventDate, [value]), + returnValueForMissingStub: null); + @override + void setNewNoteEventTime(String? value) => + super.noSuchMethod(Invocation.method(#setNewNoteEventTime, [value]), + returnValueForMissingStub: null); + @override + String toString() => super.toString(); +} + +/// A class which mocks [MainNavObserver]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockMainNavObserver extends _i1.Mock implements _i15.MainNavObserver { + MockMainNavObserver() { + _i1.throwOnMissingStub(this); + } + + @override + set currentScreen(dynamic _currentScreen) => + super.noSuchMethod(Invocation.setter(#currentScreen, _currentScreen), + returnValueForMissingStub: null); + @override + String get screenTitle => + (super.noSuchMethod(Invocation.getter(#screenTitle), returnValue: '') + as String); + @override + set screenTitle(String? _screenTitle) => + super.noSuchMethod(Invocation.setter(#screenTitle, _screenTitle), + returnValueForMissingStub: null); + @override + set focusedNavBtn(dynamic _focusedNavBtn) => + super.noSuchMethod(Invocation.setter(#focusedNavBtn, _focusedNavBtn), + returnValueForMissingStub: null); + @override + void changeScreen(dynamic screen) => + super.noSuchMethod(Invocation.method(#changeScreen, [screen]), + returnValueForMissingStub: null); + @override + void setTitle(String? title) => + super.noSuchMethod(Invocation.method(#setTitle, [title]), + returnValueForMissingStub: null); + @override + void setFocusedBtn(dynamic focusedBtn) => + super.noSuchMethod(Invocation.method(#setFocusedBtn, [focusedBtn]), + returnValueForMissingStub: null); + @override + String toString() => super.toString(); +}