Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
haodong404 committed Nov 12, 2024
1 parent 8346749 commit 1049ad9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_modular/src/domain/errors/errors.dart';
import 'package:modular_core/modular_core.dart';
import 'package:result_dart/result_dart.dart';

import '../../../flutter_modular.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import 'package:mocktail/mocktail.dart';
import 'package:modular_core/modular_core.dart';
import 'package:result_dart/result_dart.dart';

import '../../mocks/mocks.dart';
import '../modular_base_test.dart';

class GetRouteMock extends Mock implements GetRoute {}
Expand Down Expand Up @@ -68,6 +67,7 @@ void main() {
when(() => routeMock.uri).thenReturn(Uri.parse('/'));
when(() => routeMock.parent).thenReturn('');
when(() => routeMock.schema).thenReturn('');
when(() => routeMock.name).thenReturn('/');
when(() => getRoute.call(any()))
.thenAnswer((_) async => Success(routeMock));
when(() => getArguments.call())
Expand All @@ -87,6 +87,7 @@ void main() {
when(() => routeMock.uri).thenReturn(Uri.parse('/test'));
when(() => routeMock.parent).thenReturn('/');
when(() => routeMock.schema).thenReturn('/');
when(() => routeMock.name).thenReturn('/test');
when(() => routeMock.middlewares).thenReturn([Guard()]);
when(() => routeMock.copyWith(schema: any(named: 'schema')))
.thenReturn(routeMock);
Expand All @@ -95,6 +96,7 @@ void main() {
when(() => routeParent.uri).thenReturn(Uri.parse('/'));
when(() => routeParent.parent).thenReturn('');
when(() => routeParent.schema).thenReturn('');
when(() => routeParent.name).thenReturn('/');
when(() => routeParent.middlewares).thenReturn([Guard()]);
when(() => routeParent.copyWith(schema: any(named: 'schema')))
.thenReturn(routeParent);
Expand Down Expand Up @@ -125,6 +127,7 @@ void main() {
when(() => routeMock.uri).thenReturn(Uri.parse('/test'));
when(() => routeMock.parent).thenReturn('/');
when(() => routeMock.schema).thenReturn('/');
when(() => routeMock.name).thenReturn('/test');
when(() => routeMock.middlewares).thenReturn([Guard()]);
when(() => routeMock.copyWith(schema: any(named: 'schema')))
.thenReturn(routeMock);
Expand All @@ -133,6 +136,7 @@ void main() {
when(() => routeParent.uri).thenReturn(Uri.parse('/'));
when(() => routeParent.parent).thenReturn('');
when(() => routeParent.schema).thenReturn('');
when(() => routeParent.name).thenReturn('/');
when(() => routeParent.middlewares).thenReturn([Guard()]);
when(() => routeParent.copyWith(schema: any(named: 'schema')))
.thenReturn(routeParent);
Expand Down Expand Up @@ -190,6 +194,7 @@ void main() {
final routeMock = ParallelRouteMock();
when(() => routeMock.uri).thenReturn(Uri.parse('/'));
when(() => routeMock.parent).thenReturn('');
when(() => routeMock.name).thenReturn('/');

when(() => reportPush(routeMock)).thenReturn(const Success(unit));

Expand Down Expand Up @@ -217,6 +222,7 @@ void main() {
.thenReturn(Success(ModularArguments.empty()));
when(() => routeMock.middlewares).thenReturn([Guard(false)]);
when(() => routeMock.uri).thenReturn(Uri.parse('/'));
when(() => routeMock.name).thenReturn('/');

expect(
() =>
Expand All @@ -233,6 +239,7 @@ void main() {
.thenReturn(Success(ModularArguments.empty()));
when(() => routeMock.middlewares).thenReturn([MiddlewareNull()]);
when(() => routeMock.uri).thenReturn(Uri.parse('/'));
when(() => routeMock.name).thenReturn('/');

expect(
() =>
Expand All @@ -253,24 +260,59 @@ void main() {
.thenReturn(Success(ModularArguments.empty()));
when(() => routeMock.middlewares).thenReturn([]);
when(() => routeMock.uri).thenReturn(Uri.parse('/'));
when(() => routeMock.name).thenReturn('/');
when(() => routeMock.parent).thenReturn('');
when(() => routeMock.copyWith(popCallback: any(named: 'popCallback')))
.thenReturn(routeMock);
expect(parser.selectBook('/', popCallback: (r) {}), completes);
});

test('selectRoute with wildcard', () {
test('selectRoute with wildcard', () async {
final routeMock = ParallelRouteMock();
when(() => routeMock.uri).thenReturn(Uri.parse('/'));
when(() => routeMock.parent).thenReturn('');
when(() => routeMock.schema).thenReturn('');
when(() => routeMock.middlewares).thenReturn([]);
when(() => routeMock.uri).thenReturn(Uri.parse('/parent/test'));
when(() => routeMock.parent).thenReturn('/parent');
when(() => routeMock.schema).thenReturn('/parent');
when(() => routeMock.name).thenReturn('/test');
when(() => routeMock.middlewares).thenReturn([Guard()]);
when(() => routeMock.copyWith(schema: any(named: 'schema')))
.thenReturn(routeMock);

final routeMock1 = ParallelRouteMock();
when(() => routeMock1.uri).thenReturn(Uri.parse('/**'));
when(() => routeMock1.parent).thenReturn('');
when(() => routeMock1.schema).thenReturn('');
when(() => routeMock1.name).thenReturn('/**');
when(() => routeMock1.middlewares).thenReturn([Guard()]);
when(() => routeMock1.copyWith(schema: any(named: 'schema')))
.thenReturn(routeMock);

final routeParent = ParallelRouteMock();
when(() => routeParent.uri).thenReturn(Uri.parse('/parent'));
when(() => routeParent.parent).thenReturn('');
when(() => routeParent.schema).thenReturn('');
when(() => routeParent.name).thenReturn('/parent');
when(() => routeParent.middlewares).thenReturn([Guard()]);
when(() => routeParent.copyWith(schema: any(named: 'schema')))
.thenReturn(routeParent);

when(() => reportPush(routeMock)).thenReturn(const Success(unit));
when(() => reportPush(routeMock1)).thenReturn(const Success(unit));
when(() => reportPush(routeParent)).thenReturn(const Success(unit));

when(() => getRoute.call(const RouteParmsDTO(url: '/parent/test')))
.thenAnswer((_) async => Success(routeMock1));
when(() => getRoute.call(const RouteParmsDTO(url: '/parent/test/')))
.thenAnswer((_) async => Success(routeMock));
when(() => getRoute.call(const RouteParmsDTO(url: '/parent')))
.thenAnswer((_) async => Success(routeParent));
when(() => getArguments.call())
.thenReturn(Success(ModularArguments.empty()));

when(() => setArguments.call(any())).thenReturn(const Success(unit));

final moduleMock = ModuleMock();
when(() => routeMock.children)
.thenReturn([ModuleRoute('/test', module: moduleMock)]);
final book = await parser.selectBook('/parent/test');
expect(book.uri.toString(), '/parent/test');
expect(book.chapters().first.name, '/parent');
});
}

Expand Down

0 comments on commit 1049ad9

Please sign in to comment.