From c4ca3447805ab46b02ea8c9b31b6c06b7e9e7f23 Mon Sep 17 00:00:00 2001 From: Anton Stubenbord Date: Sun, 30 Oct 2022 14:32:27 +0100 Subject: [PATCH] Re-added accidentally removed test --- test/src/bloc/document_cubit_test.dart | 100 ++++++ test/src/bloc/documents_cubit_test.mocks.dart | 293 ------------------ 2 files changed, 100 insertions(+), 293 deletions(-) create mode 100644 test/src/bloc/document_cubit_test.dart delete mode 100644 test/src/bloc/documents_cubit_test.mocks.dart diff --git a/test/src/bloc/document_cubit_test.dart b/test/src/bloc/document_cubit_test.dart new file mode 100644 index 0000000..d18fa4e --- /dev/null +++ b/test/src/bloc/document_cubit_test.dart @@ -0,0 +1,100 @@ +import 'package:bloc_test/bloc_test.dart'; +import 'package:flutter_paperless_mobile/features/documents/bloc/documents_cubit.dart'; +import 'package:flutter_paperless_mobile/features/documents/bloc/documents_state.dart'; +import 'package:flutter_paperless_mobile/features/documents/model/document.model.dart'; +import 'package:flutter_paperless_mobile/features/documents/model/document_filter.dart'; +import 'package:flutter_paperless_mobile/features/documents/model/paged_search_result.dart'; +import 'package:flutter_paperless_mobile/features/documents/repository/document_repository.dart'; +import 'package:flutter_paperless_mobile/features/labels/correspondent/model/correspondent.model.dart'; +import 'package:flutter_paperless_mobile/features/labels/document_type/model/document_type.model.dart'; +import 'package:flutter_paperless_mobile/features/labels/tags/model/tag.model.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; + +import '../../utils.dart'; +@GenerateNiceMocks([MockSpec()]) +import 'document_cubit_test.mocks.dart'; + +void main() async { + TestWidgetsFlutterBinding.ensureInitialized(); + + final List documents = List.unmodifiable( + await loadCollection("test/fixtures/documents/documents.json", DocumentModel.fromJson), + ); + final List tags = List.unmodifiable( + await loadCollection("test/fixtures/tags/tags.json", Tag.fromJson), + ); + final List correspondents = List.unmodifiable( + await loadCollection( + "test/fixtures/correspondents/correspondents.json", Correspondent.fromJson), + ); + final List documentTypes = List.unmodifiable( + await loadCollection("test/fixtures/document_types/document_types.json", DocumentType.fromJson), + ); + + final MockDocumentRepository documentRepository = MockDocumentRepository(); + group("Test DocumentsCubit reloadDocuments", () { + test("Assert correct initial state", () { + expect(DocumentsCubit(documentRepository).state, DocumentsState.initial); + }); + + blocTest( + "Load documents shall emit new state containing the found documents", + setUp: () => when(documentRepository.find(any)).thenAnswer( + (_) async => PagedSearchResult( + count: 10, + next: null, + previous: null, + results: documents, + ), + ), + build: () => DocumentsCubit(documentRepository), + seed: () => DocumentsState.initial, + act: (bloc) => bloc.loadDocuments(), + expect: () => [ + DocumentsState( + isLoaded: true, + value: [ + PagedSearchResult( + count: 10, + next: null, + previous: null, + results: documents, + ), + ], + filter: DocumentFilter.initial) + ], + verify: (bloc) => verify(documentRepository.find(any)).called(1), + ); + + blocTest( + "Reload documents shall emit new state containing the same documents as before", + setUp: () => when(documentRepository.find(any)).thenAnswer( + (_) async => PagedSearchResult( + count: 10, + next: null, + previous: null, + results: documents, + ), + ), + build: () => DocumentsCubit(documentRepository), + seed: () => DocumentsState.initial, + act: (bloc) => bloc.loadDocuments(), + expect: () => [ + DocumentsState( + isLoaded: true, + value: [ + PagedSearchResult( + count: 10, + next: null, + previous: null, + results: documents, + ), + ], + filter: DocumentFilter.initial) + ], + verify: (bloc) => verify(documentRepository.find(any)).called(1), + ); + }); +} diff --git a/test/src/bloc/documents_cubit_test.mocks.dart b/test/src/bloc/documents_cubit_test.mocks.dart deleted file mode 100644 index 53e3340..0000000 --- a/test/src/bloc/documents_cubit_test.mocks.dart +++ /dev/null @@ -1,293 +0,0 @@ -// Mocks generated by Mockito 5.3.2 from annotations -// in flutter_paperless_mobile/test/src/bloc/documents_cubit_test.dart. -// Do not manually edit this file. - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i6; -import 'dart:typed_data' as _i7; - -import 'package:flutter_paperless_mobile/features/documents/model/document.model.dart' - as _i2; -import 'package:flutter_paperless_mobile/features/documents/model/document_filter.dart' - as _i8; -import 'package:flutter_paperless_mobile/features/documents/model/document_meta_data.model.dart' - as _i4; -import 'package:flutter_paperless_mobile/features/documents/model/paged_search_result.dart' - as _i3; -import 'package:flutter_paperless_mobile/features/documents/model/similar_document.model.dart' - as _i9; -import 'package:flutter_paperless_mobile/features/documents/repository/document_repository.dart' - as _i5; -import 'package:mockito/mockito.dart' as _i1; - -// ignore_for_file: type=lint -// 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 -// ignore_for_file: subtype_of_sealed_class - -class _FakeDocumentModel_0 extends _i1.SmartFake implements _i2.DocumentModel { - _FakeDocumentModel_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakePagedSearchResult_1 extends _i1.SmartFake - implements _i3.PagedSearchResult { - _FakePagedSearchResult_1( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeDocumentMetaData_2 extends _i1.SmartFake - implements _i4.DocumentMetaData { - _FakeDocumentMetaData_2( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -/// A class which mocks [DocumentRepository]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockDocumentRepository extends _i1.Mock - implements _i5.DocumentRepository { - @override - _i6.Future create( - _i7.Uint8List? documentBytes, - String? filename, { - required String? title, - int? documentType, - int? correspondent, - List? tags, - DateTime? createdAt, - }) => - (super.noSuchMethod( - Invocation.method( - #create, - [ - documentBytes, - filename, - ], - { - #title: title, - #documentType: documentType, - #correspondent: correspondent, - #tags: tags, - #createdAt: createdAt, - }, - ), - returnValue: _i6.Future.value(), - returnValueForMissingStub: _i6.Future.value(), - ) as _i6.Future); - @override - _i6.Future<_i2.DocumentModel> update(_i2.DocumentModel? doc) => - (super.noSuchMethod( - Invocation.method( - #update, - [doc], - ), - returnValue: _i6.Future<_i2.DocumentModel>.value(_FakeDocumentModel_0( - this, - Invocation.method( - #update, - [doc], - ), - )), - returnValueForMissingStub: - _i6.Future<_i2.DocumentModel>.value(_FakeDocumentModel_0( - this, - Invocation.method( - #update, - [doc], - ), - )), - ) as _i6.Future<_i2.DocumentModel>); - @override - _i6.Future findNextAsn() => (super.noSuchMethod( - Invocation.method( - #findNextAsn, - [], - ), - returnValue: _i6.Future.value(0), - returnValueForMissingStub: _i6.Future.value(0), - ) as _i6.Future); - @override - _i6.Future<_i3.PagedSearchResult> find(_i8.DocumentFilter? filter) => - (super.noSuchMethod( - Invocation.method( - #find, - [filter], - ), - returnValue: _i6.Future<_i3.PagedSearchResult>.value( - _FakePagedSearchResult_1( - this, - Invocation.method( - #find, - [filter], - ), - )), - returnValueForMissingStub: - _i6.Future<_i3.PagedSearchResult>.value( - _FakePagedSearchResult_1( - this, - Invocation.method( - #find, - [filter], - ), - )), - ) as _i6.Future<_i3.PagedSearchResult>); - @override - _i6.Future> findSimilar(int? docId) => - (super.noSuchMethod( - Invocation.method( - #findSimilar, - [docId], - ), - returnValue: _i6.Future>.value( - <_i9.SimilarDocumentModel>[]), - returnValueForMissingStub: - _i6.Future>.value( - <_i9.SimilarDocumentModel>[]), - ) as _i6.Future>); - @override - _i6.Future delete(_i2.DocumentModel? doc) => (super.noSuchMethod( - Invocation.method( - #delete, - [doc], - ), - returnValue: _i6.Future.value(0), - returnValueForMissingStub: _i6.Future.value(0), - ) as _i6.Future); - @override - _i6.Future<_i4.DocumentMetaData> getMetaData(_i2.DocumentModel? document) => - (super.noSuchMethod( - Invocation.method( - #getMetaData, - [document], - ), - returnValue: - _i6.Future<_i4.DocumentMetaData>.value(_FakeDocumentMetaData_2( - this, - Invocation.method( - #getMetaData, - [document], - ), - )), - returnValueForMissingStub: - _i6.Future<_i4.DocumentMetaData>.value(_FakeDocumentMetaData_2( - this, - Invocation.method( - #getMetaData, - [document], - ), - )), - ) as _i6.Future<_i4.DocumentMetaData>); - @override - _i6.Future> bulkDelete(List<_i2.DocumentModel>? models) => - (super.noSuchMethod( - Invocation.method( - #bulkDelete, - [models], - ), - returnValue: _i6.Future>.value([]), - returnValueForMissingStub: _i6.Future>.value([]), - ) as _i6.Future>); - @override - _i6.Future<_i7.Uint8List> getPreview(int? docId) => (super.noSuchMethod( - Invocation.method( - #getPreview, - [docId], - ), - returnValue: _i6.Future<_i7.Uint8List>.value(_i7.Uint8List(0)), - returnValueForMissingStub: - _i6.Future<_i7.Uint8List>.value(_i7.Uint8List(0)), - ) as _i6.Future<_i7.Uint8List>); - @override - String getThumbnailUrl(int? docId) => (super.noSuchMethod( - Invocation.method( - #getThumbnailUrl, - [docId], - ), - returnValue: '', - returnValueForMissingStub: '', - ) as String); - @override - _i6.Future<_i2.DocumentModel> waitForConsumptionFinished( - String? filename, - String? title, - ) => - (super.noSuchMethod( - Invocation.method( - #waitForConsumptionFinished, - [ - filename, - title, - ], - ), - returnValue: _i6.Future<_i2.DocumentModel>.value(_FakeDocumentModel_0( - this, - Invocation.method( - #waitForConsumptionFinished, - [ - filename, - title, - ], - ), - )), - returnValueForMissingStub: - _i6.Future<_i2.DocumentModel>.value(_FakeDocumentModel_0( - this, - Invocation.method( - #waitForConsumptionFinished, - [ - filename, - title, - ], - ), - )), - ) as _i6.Future<_i2.DocumentModel>); - @override - _i6.Future<_i7.Uint8List> download(_i2.DocumentModel? document) => - (super.noSuchMethod( - Invocation.method( - #download, - [document], - ), - returnValue: _i6.Future<_i7.Uint8List>.value(_i7.Uint8List(0)), - returnValueForMissingStub: - _i6.Future<_i7.Uint8List>.value(_i7.Uint8List(0)), - ) as _i6.Future<_i7.Uint8List>); - @override - _i6.Future> autocomplete( - String? query, [ - int? limit = 10, - ]) => - (super.noSuchMethod( - Invocation.method( - #autocomplete, - [ - query, - limit, - ], - ), - returnValue: _i6.Future>.value([]), - returnValueForMissingStub: _i6.Future>.value([]), - ) as _i6.Future>); -}