Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -757,26 +757,26 @@ packages:
dependency: transitive
description:
name: test
sha256: "77cc98ea27006c84e71a7356cf3daf9ddbde2d91d84f77dbfe64cf0e4d9611ae"
sha256: "54c516bbb7cee2754d327ad4fca637f78abfc3cbcc5ace83b3eda117e42cd71a"
url: "https://pub.dev"
source: hosted
version: "1.28.0"
version: "1.29.0"
test_api:
dependency: transitive
description:
name: test_api
sha256: "19a78f63e83d3a61f00826d09bc2f60e191bf3504183c001262be6ac75589fb8"
sha256: "93167629bfc610f71560ab9312acdda4959de4df6fac7492c89ff0d3886f6636"
url: "https://pub.dev"
source: hosted
version: "0.7.8"
version: "0.7.9"
test_core:
dependency: transitive
description:
name: test_core
sha256: f1072617a6657e5fc09662e721307f7fb009b4ed89b19f47175d11d5254a62d4
sha256: "394f07d21f0f2255ec9e3989f21e54d3c7dc0e6e9dbce160e5a9c1a6be0e2943"
url: "https://pub.dev"
source: hosted
version: "0.6.14"
version: "0.6.15"
typed_data:
dependency: transitive
description:
Expand Down
126 changes: 121 additions & 5 deletions test/viewer/bloc/viewer_bloc_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:ariadne/analyzer/analyzer.dart';
import 'package:ariadne/database/code/code_database.dart' as db;
import 'package:ariadne/node/node.dart';
import 'package:ariadne/viewer/bloc/viewer_bloc.dart';
import 'package:bloc_test/bloc_test.dart';
import 'package:drift/native.dart';
Expand All @@ -13,6 +14,87 @@ void main() {
late MockAnalyzer mockAnalyzer;
late db.CodeDatabase codeDB;

final symbols = [
db.SymbolsCompanion.insert(
name: 'MyClass',
kind: 5,
uri: 'file:///path/to/project/lib/my_class.dart',
rangeStartLine: 2,
rangeStartColumn: 0,
rangeEndLine: 6,
rangeEndColumn: 1,
selectionStartLine: 2,
selectionStartColumn: 15,
selectionEndLine: 2,
selectionEndColumn: 19,
),
db.SymbolsCompanion.insert(
name: 'MyTypeDef',
kind: 19,
uri: 'file:///path/to/project/lib/typedef.dart',
rangeStartLine: 478,
rangeStartColumn: 0,
rangeEndLine: 491,
rangeEndColumn: 6,
selectionStartLine: 478,
selectionStartColumn: 8,
selectionEndLine: 478,
selectionEndColumn: 44,
),
db.SymbolsCompanion.insert(
name: 'main',
kind: 12,
uri: 'file:///path/to/project/lib/main.dart',
rangeStartLine: 11,
rangeStartColumn: 0,
rangeEndLine: 36,
rangeEndColumn: 1,
selectionStartLine: 11,
selectionStartColumn: 5,
selectionEndLine: 11,
selectionEndColumn: 9,
),
db.SymbolsCompanion.insert(
name: 'someMethod',
kind: 6,
uri: 'file:///path/to/project/lib/method.dart',
rangeStartLine: 22,
rangeStartColumn: 2,
rangeEndLine: 95,
rangeEndColumn: 3,
selectionStartLine: 22,
selectionStartColumn: 15,
selectionEndLine: 22,
selectionEndColumn: 20,
),
db.SymbolsCompanion.insert(
name: 'MyEnum',
kind: 10,
uri: 'file:///path/to/project/lib/enums.dart',
rangeStartLine: 2,
rangeStartColumn: 0,
rangeEndLine: 9,
rangeEndColumn: 1,
selectionStartLine: 2,
selectionStartColumn: 5,
selectionEndLine: 2,
selectionEndColumn: 15,
),
db.SymbolsCompanion.insert(
name: 'globalVar',
kind: 13,
uri: 'file:///path/to/project/lib/globals.dart',
rangeStartLine: 3,
rangeStartColumn: 6,
rangeEndLine: 24,
rangeEndColumn: 1,
selectionStartLine: 3,
selectionStartColumn: 6,
selectionEndLine: 3,
selectionEndColumn: 20,
),
];

setUp(() {
mockAnalyzer = MockAnalyzer();
codeDB = db.CodeDatabase.forTesting(NativeDatabase.memory());
Expand All @@ -24,28 +106,62 @@ void main() {
});

blocTest<ViewerBloc, ViewerState>(
'Overview emits [loading, success]',
'Overview emits [loading, success] and state with correct values',
build: () {
codeDB.projectSymbols.insertBatch(symbols: symbols);
return viewerBloc;
},
act: (bloc) => bloc.add(const Overview()),
expect: () => [
const ViewerState().copyWith(status: .loading),
const ViewerState().copyWith(status: .success),
isA<ViewerState>()
.having((s) => s.status, 'status', equals(ViewerStatus.success))
.having((s) => s.symbols.length, 'symbols', equals(symbols.length))
.having((s) => s.nodes.length, 'nodes', equals(symbols.length))
.having((s) => s.classesCount, 'classesCount', equals(1))
.having((s) => s.typeDefsCount, 'typeDefsCount', equals(1))
.having((s) => s.functionsCount, 'functionsCount', equals(1))
.having((s) => s.methodsCount, 'methodsCount', equals(1))
.having((s) => s.enumsCount, 'enumsCount', equals(1))
.having(
(s) => s.globalVariablesCount,
'globalVariablesCount',
equals(1),
),
],
);

blocTest<ViewerBloc, ViewerState>(
'Lists emits [loading, success] and a list of nodes',
'Lists emits [loading, success] and a node with items',
build: () {
codeDB.projectSymbols.insertBatch(symbols: symbols);
return viewerBloc;
},
seed: () {
final symbols = <db.Symbol>[];
codeDB.projectSymbols.all().then((r) => symbols.addAll(r));
return const ViewerState().copyWith(symbols: symbols);
},
act: (bloc) => bloc.add(const Lists(title: 'classes', kind: 5)),
expect: () => [
const ViewerState().copyWith(status: .loading),
isA<ViewerState>()
.having((s) => s.status, 'status', equals(ViewerStatus.loading))
.having((s) => s.symbols, 'symbols', isNotEmpty),
isA<ViewerState>()
.having((s) => s.status, 'status', equals(ViewerStatus.success))
.having((s) => s.nodes, 'nodes', isNotEmpty),
.having((s) => s.nodes.length, 'nodes', equals(1))
.having((s) => s.nodes.first, 'node', isA<ListNode>())
.having((s) => s.nodes.first.id, 'nodeId', equals('list_5'))
.having(
(s) => (s.nodes.first as ListNode).title,
'nodeTitle',
equals('classes'),
)
.having(
(s) => (s.nodes.first as ListNode).kind,
'nodeKind',
equals(5),
),
],
);

Expand Down