new change to use intaleq_map sdk 04-16-4
This commit is contained in:
190
packages/get/test/benchmarks/benckmark_test.dart
Normal file
190
packages/get/test/benchmarks/benckmark_test.dart
Normal file
@@ -0,0 +1,190 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/state_manager.dart';
|
||||
|
||||
int times = 30;
|
||||
|
||||
Future<int> valueNotifier() {
|
||||
final c = Completer<int>();
|
||||
final value = ValueNotifier<int>(0);
|
||||
final timer = Stopwatch();
|
||||
timer.start();
|
||||
|
||||
value.addListener(() {
|
||||
if (times == value.value) {
|
||||
timer.stop();
|
||||
print(
|
||||
"""${value.value} listeners notified | [VALUE_NOTIFIER] time: ${timer.elapsedMicroseconds}ms""");
|
||||
c.complete(timer.elapsedMicroseconds);
|
||||
}
|
||||
});
|
||||
|
||||
for (var i = 0; i < times + 1; i++) {
|
||||
value.value = i;
|
||||
}
|
||||
|
||||
return c.future;
|
||||
}
|
||||
|
||||
Future<int> getValue() {
|
||||
final c = Completer<int>();
|
||||
final value = Value<int>(0);
|
||||
final timer = Stopwatch();
|
||||
timer.start();
|
||||
|
||||
value.addListener(() {
|
||||
if (times == value.value) {
|
||||
timer.stop();
|
||||
print(
|
||||
"""${value.value} listeners notified | [GETX_VALUE] time: ${timer.elapsedMicroseconds}ms""");
|
||||
c.complete(timer.elapsedMicroseconds);
|
||||
}
|
||||
});
|
||||
|
||||
for (var i = 0; i < times + 1; i++) {
|
||||
value.value = i;
|
||||
}
|
||||
|
||||
return c.future;
|
||||
}
|
||||
|
||||
Future<int> stream() {
|
||||
final c = Completer<int>();
|
||||
|
||||
final value = StreamController<int>();
|
||||
final timer = Stopwatch();
|
||||
timer.start();
|
||||
|
||||
value.stream.listen((v) {
|
||||
if (times == v) {
|
||||
timer.stop();
|
||||
print(
|
||||
"""$v listeners notified | [STREAM] time: ${timer.elapsedMicroseconds}ms""");
|
||||
c.complete(timer.elapsedMicroseconds);
|
||||
value.close();
|
||||
}
|
||||
});
|
||||
|
||||
for (var i = 0; i < times + 1; i++) {
|
||||
value.add(i);
|
||||
}
|
||||
|
||||
return c.future;
|
||||
}
|
||||
|
||||
Future<int> getStream() {
|
||||
final c = Completer<int>();
|
||||
|
||||
final value = GetStream<int>();
|
||||
final timer = Stopwatch();
|
||||
timer.start();
|
||||
|
||||
value.listen((v) {
|
||||
if (times == v) {
|
||||
timer.stop();
|
||||
print(
|
||||
"""$v listeners notified | [GET_STREAM] time: ${timer.elapsedMicroseconds}ms""");
|
||||
c.complete(timer.elapsedMicroseconds);
|
||||
}
|
||||
});
|
||||
|
||||
for (var i = 0; i < times + 1; i++) {
|
||||
value.add(i);
|
||||
}
|
||||
|
||||
return c.future;
|
||||
}
|
||||
|
||||
Future<int> miniStream() {
|
||||
final c = Completer<int>();
|
||||
|
||||
final value = MiniStream<int>();
|
||||
final timer = Stopwatch();
|
||||
timer.start();
|
||||
|
||||
value.listen((v) {
|
||||
if (times == v) {
|
||||
timer.stop();
|
||||
print(
|
||||
"""$v listeners notified | [MINI_STREAM] time: ${timer.elapsedMicroseconds}ms""");
|
||||
c.complete(timer.elapsedMicroseconds);
|
||||
}
|
||||
});
|
||||
|
||||
for (var i = 0; i < times + 1; i++) {
|
||||
value.add(i);
|
||||
}
|
||||
|
||||
return c.future;
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('percentage test', () {
|
||||
print('============================================');
|
||||
print('PERCENTAGE TEST');
|
||||
|
||||
const referenceValue = 200;
|
||||
const requestedValue = 100;
|
||||
|
||||
print('''
|
||||
referenceValue is ${calculePercentage(referenceValue, requestedValue)}% more than requestedValue''');
|
||||
expect(calculePercentage(referenceValue, requestedValue), 100);
|
||||
});
|
||||
test('run benchmarks from ValueNotifier', () async {
|
||||
times = 30;
|
||||
print('============================================');
|
||||
print('VALUE_NOTIFIER X GETX_VALUE TEST');
|
||||
print('-----------');
|
||||
await getValue();
|
||||
await valueNotifier();
|
||||
print('-----------');
|
||||
|
||||
times = 30000;
|
||||
final getx = await getValue();
|
||||
final dart = await valueNotifier();
|
||||
print('-----------');
|
||||
|
||||
print('ValueNotifier delay $dart ms to made $times requests');
|
||||
print('GetValue delay $getx ms to made $times requests');
|
||||
print('-----------');
|
||||
print('''
|
||||
GetValue is ${calculePercentage(dart, getx).round()}% faster than Default ValueNotifier with $times requests''');
|
||||
});
|
||||
|
||||
test('run benchmarks from Streams', () async {
|
||||
times = 30;
|
||||
print('============================================');
|
||||
print('DART STREAM X GET_STREAM X GET_MINI_STREAM TEST');
|
||||
print('-----------');
|
||||
var getx = await getStream();
|
||||
var mini = await miniStream();
|
||||
var dart = await stream();
|
||||
print('-----------');
|
||||
print('''
|
||||
GetStream is ${calculePercentage(dart, mini).round()}% faster than Default Stream with $times requests''');
|
||||
print('-----------');
|
||||
|
||||
times = 30000;
|
||||
dart = await stream();
|
||||
getx = await getStream();
|
||||
mini = await miniStream();
|
||||
|
||||
times = 60000;
|
||||
dart = await stream();
|
||||
getx = await getStream();
|
||||
mini = await miniStream();
|
||||
print('-----------');
|
||||
print('dart_stream delay $dart ms to made $times requests');
|
||||
print('getx_stream delay $getx ms to made $times requests');
|
||||
print('getx_mini_stream delay $mini ms to made $times requests');
|
||||
print('-----------');
|
||||
print('''
|
||||
GetStream is ${calculePercentage(dart, mini).round()}% faster than Default Stream with $times requests''');
|
||||
});
|
||||
}
|
||||
|
||||
int calculePercentage(int dart, int getx) {
|
||||
return (dart / getx * 100).round() - 100;
|
||||
}
|
||||
284
packages/get/test/instance/get_instance_test.dart
Normal file
284
packages/get/test/instance/get_instance_test.dart
Normal file
@@ -0,0 +1,284 @@
|
||||
// ignore_for_file: avoid_classes_with_only_static_members
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'util/matcher.dart' as m;
|
||||
|
||||
class Mock {
|
||||
static Future<String> test() async {
|
||||
await Future.delayed(Duration.zero);
|
||||
return 'test';
|
||||
}
|
||||
}
|
||||
|
||||
abstract class MyController extends GetLifeCycle {}
|
||||
|
||||
class DisposableController extends MyController {}
|
||||
|
||||
// ignore: one_member_abstracts
|
||||
abstract class Service {
|
||||
String post();
|
||||
}
|
||||
|
||||
class Api implements Service {
|
||||
@override
|
||||
String post() {
|
||||
return 'test';
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('Get.putAsync test', () async {
|
||||
await Get.putAsync<String>(Mock.test);
|
||||
expect('test', Get.find<String>());
|
||||
Get.reset();
|
||||
});
|
||||
|
||||
test('Get.put test', () async {
|
||||
final instance = Get.put<Controller>(Controller());
|
||||
expect(instance, Get.find<Controller>());
|
||||
Get.reset();
|
||||
});
|
||||
|
||||
test('Get start and delete called just one time', () async {
|
||||
Get
|
||||
..put(Controller())
|
||||
..put(Controller());
|
||||
|
||||
final controller = Get.find<Controller>();
|
||||
expect(controller.init, 1);
|
||||
|
||||
Get
|
||||
..delete<Controller>()
|
||||
..delete<Controller>();
|
||||
expect(controller.close, 1);
|
||||
Get.reset();
|
||||
});
|
||||
|
||||
test('Get.put tag test', () async {
|
||||
final instance = Get.put<Controller>(Controller(), tag: 'one');
|
||||
final instance2 = Get.put<Controller>(Controller(), tag: 'two');
|
||||
expect(instance == instance2, false);
|
||||
expect(Get.find<Controller>(tag: 'one') == Get.find<Controller>(tag: 'two'),
|
||||
false);
|
||||
expect(Get.find<Controller>(tag: 'one') == Get.find<Controller>(tag: 'one'),
|
||||
true);
|
||||
expect(Get.find<Controller>(tag: 'two') == Get.find<Controller>(tag: 'two'),
|
||||
true);
|
||||
Get.reset();
|
||||
});
|
||||
|
||||
test('Get.lazyPut tag test', () async {
|
||||
Get.lazyPut<Controller>(Controller.new, tag: 'one');
|
||||
Get.lazyPut<Controller>(Controller.new, tag: 'two');
|
||||
|
||||
expect(Get.find<Controller>(tag: 'one') == Get.find<Controller>(tag: 'two'),
|
||||
false);
|
||||
expect(Get.find<Controller>(tag: 'one') == Get.find<Controller>(tag: 'one'),
|
||||
true);
|
||||
expect(Get.find<Controller>(tag: 'two') == Get.find<Controller>(tag: 'two'),
|
||||
true);
|
||||
Get.reset();
|
||||
});
|
||||
|
||||
test('Get.lazyPut test', () async {
|
||||
final controller = Controller();
|
||||
Get.lazyPut<Controller>(() => controller);
|
||||
final ct1 = Get.find<Controller>();
|
||||
expect(ct1, controller);
|
||||
Get.reset();
|
||||
});
|
||||
|
||||
test('Get.lazyPut fenix test', () async {
|
||||
Get.lazyPut<Controller>(Controller.new, fenix: true);
|
||||
Get.find<Controller>().increment();
|
||||
|
||||
expect(Get.find<Controller>().count, 1);
|
||||
Get.delete<Controller>();
|
||||
expect(Get.find<Controller>().count, 0);
|
||||
Get.reset();
|
||||
});
|
||||
|
||||
test('Get.lazyPut without fenix', () async {
|
||||
Get.lazyPut<Controller>(Controller.new);
|
||||
Get.find<Controller>().increment();
|
||||
|
||||
expect(Get.find<Controller>().count, 1);
|
||||
Get.delete<Controller>();
|
||||
expect(
|
||||
() => Get.find<Controller>(), throwsA(const m.TypeMatcher<String>()));
|
||||
Get.reset();
|
||||
});
|
||||
|
||||
test('Get.reloadInstance test', () async {
|
||||
Get.lazyPut<Controller>(Controller.new);
|
||||
var ct1 = Get.find<Controller>();
|
||||
ct1.increment();
|
||||
expect(ct1.count, 1);
|
||||
ct1 = Get.find<Controller>();
|
||||
expect(ct1.count, 1);
|
||||
GetInstance().reload<Controller>();
|
||||
ct1 = Get.find<Controller>();
|
||||
expect(ct1.count, 0);
|
||||
Get.reset();
|
||||
});
|
||||
|
||||
test('GetxService test', () async {
|
||||
Get.lazyPut<PermanentService>(PermanentService.new);
|
||||
var sv1 = Get.find<PermanentService>();
|
||||
var sv2 = Get.find<PermanentService>();
|
||||
expect(sv1, sv2);
|
||||
expect(Get.isRegistered<PermanentService>(), true);
|
||||
Get.delete<PermanentService>();
|
||||
expect(Get.isRegistered<PermanentService>(), true);
|
||||
Get.delete<PermanentService>(force: true);
|
||||
expect(Get.isRegistered<PermanentService>(), false);
|
||||
Get.reset();
|
||||
});
|
||||
|
||||
test('Get.lazyPut with abstract class test', () async {
|
||||
final api = Api();
|
||||
Get.lazyPut<Service>(() => api);
|
||||
final ct1 = Get.find<Service>();
|
||||
expect(ct1, api);
|
||||
Get.reset();
|
||||
});
|
||||
|
||||
test('Get.create with abstract class test', () async {
|
||||
Get.create<Service>(Api.new);
|
||||
final ct1 = Get.find<Service>();
|
||||
final ct2 = Get.find<Service>();
|
||||
// expect(ct1 is Service, true);
|
||||
// expect(ct2 is Service, true);
|
||||
expect(ct1 == ct2, false);
|
||||
Get.reset();
|
||||
});
|
||||
|
||||
group('test put, delete and check onInit execution', () {
|
||||
tearDownAll(Get.reset);
|
||||
|
||||
test('Get.put test with init check', () async {
|
||||
final instance = Get.put(DisposableController());
|
||||
expect(instance, Get.find<DisposableController>());
|
||||
expect(instance.initialized, true);
|
||||
});
|
||||
|
||||
test('Get.delete test with disposable controller', () async {
|
||||
// Get.put(DisposableController());
|
||||
expect(await Get.delete<DisposableController>(), true);
|
||||
expect(() => Get.find<DisposableController>(),
|
||||
throwsA(const m.TypeMatcher<String>()));
|
||||
});
|
||||
|
||||
test('Get.put test after delete with disposable controller and init check',
|
||||
() async {
|
||||
final instance = Get.put<DisposableController>(DisposableController());
|
||||
expect(instance, Get.find<DisposableController>());
|
||||
expect(instance.initialized, true);
|
||||
});
|
||||
});
|
||||
|
||||
group('Get.replace test for replacing parent instance that is', () {
|
||||
tearDown(Get.reset);
|
||||
test('temporary', () async {
|
||||
Get.put(DisposableController());
|
||||
Get.replace<DisposableController>(Controller());
|
||||
final instance = Get.find<DisposableController>();
|
||||
expect(instance is Controller, isTrue);
|
||||
expect((instance as Controller).init, greaterThan(0));
|
||||
});
|
||||
|
||||
test('permanent', () async {
|
||||
Get.put(DisposableController(), permanent: true);
|
||||
Get.replace<DisposableController>(Controller());
|
||||
final instance = Get.find<DisposableController>();
|
||||
expect(instance is Controller, isTrue);
|
||||
expect((instance as Controller).init, greaterThan(0));
|
||||
});
|
||||
|
||||
test('tagged temporary', () async {
|
||||
const tag = 'tag';
|
||||
Get.put(DisposableController(), tag: tag);
|
||||
Get.replace<DisposableController>(Controller(), tag: tag);
|
||||
final instance = Get.find<DisposableController>(tag: tag);
|
||||
expect(instance is Controller, isTrue);
|
||||
expect((instance as Controller).init, greaterThan(0));
|
||||
});
|
||||
|
||||
test('tagged permanent', () async {
|
||||
const tag = 'tag';
|
||||
Get.put(DisposableController(), permanent: true, tag: tag);
|
||||
Get.replace<DisposableController>(Controller(), tag: tag);
|
||||
final instance = Get.find<DisposableController>(tag: tag);
|
||||
expect(instance is Controller, isTrue);
|
||||
expect((instance as Controller).init, greaterThan(0));
|
||||
});
|
||||
|
||||
test('a generic parent type', () async {
|
||||
const tag = 'tag';
|
||||
Get.put<MyController>(DisposableController(), permanent: true, tag: tag);
|
||||
Get.replace<MyController>(Controller(), tag: tag);
|
||||
final instance = Get.find<MyController>(tag: tag);
|
||||
expect(instance is Controller, isTrue);
|
||||
expect((instance as Controller).init, greaterThan(0));
|
||||
});
|
||||
});
|
||||
|
||||
group('Get.lazyReplace replaces parent instance', () {
|
||||
tearDown(Get.reset);
|
||||
test('without fenix', () async {
|
||||
Get.put(DisposableController());
|
||||
Get.lazyReplace<DisposableController>(Controller.new);
|
||||
final instance = Get.find<DisposableController>();
|
||||
expect(instance, isA<Controller>());
|
||||
expect((instance as Controller).init, greaterThan(0));
|
||||
});
|
||||
|
||||
test('with fenix', () async {
|
||||
Get.put(DisposableController());
|
||||
Get.lazyReplace<DisposableController>(Controller.new, fenix: true);
|
||||
expect(Get.find<DisposableController>(), isA<Controller>());
|
||||
(Get.find<DisposableController>() as Controller).increment();
|
||||
|
||||
expect((Get.find<DisposableController>() as Controller).count, 1);
|
||||
Get.delete<DisposableController>();
|
||||
expect((Get.find<DisposableController>() as Controller).count, 0);
|
||||
});
|
||||
|
||||
test('with fenix when parent is permanent', () async {
|
||||
Get.put(DisposableController(), permanent: true);
|
||||
Get.lazyReplace<DisposableController>(Controller.new);
|
||||
final instance = Get.find<DisposableController>();
|
||||
expect(instance, isA<Controller>());
|
||||
(instance as Controller).increment();
|
||||
|
||||
expect((Get.find<DisposableController>() as Controller).count, 1);
|
||||
Get.delete<DisposableController>();
|
||||
expect((Get.find<DisposableController>() as Controller).count, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class PermanentService extends GetxService {}
|
||||
|
||||
class Controller extends DisposableController {
|
||||
int init = 0;
|
||||
int close = 0;
|
||||
int count = 0;
|
||||
@override
|
||||
void onInit() {
|
||||
init++;
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
close++;
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
void increment() {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
120
packages/get/test/instance/util/matcher.dart
Normal file
120
packages/get/test/instance/util/matcher.dart
Normal file
@@ -0,0 +1,120 @@
|
||||
// Copyright 2014, the Dart project authors. All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
class FunctionMatcher<T> extends CustomMatcher {
|
||||
final Object Function(T value) _feature;
|
||||
|
||||
FunctionMatcher(String name, this._feature, matcher)
|
||||
: super('`$name`:', '`$name`', matcher);
|
||||
|
||||
@override
|
||||
Object featureValueOf(covariant T actual) => _feature(actual);
|
||||
}
|
||||
|
||||
class HavingMatcher<T> implements TypeMatcher<T> {
|
||||
final TypeMatcher<T> _parent;
|
||||
final List<FunctionMatcher<T>> functionMatchers;
|
||||
|
||||
HavingMatcher(TypeMatcher<T> parent, String description,
|
||||
Object Function(T) feature, dynamic matcher,
|
||||
[Iterable<FunctionMatcher<T>>? existing])
|
||||
: _parent = parent,
|
||||
functionMatchers = [
|
||||
...?existing,
|
||||
FunctionMatcher<T>(description, feature, matcher)
|
||||
];
|
||||
|
||||
@override
|
||||
TypeMatcher<T> having(
|
||||
Object Function(T) feature, String description, dynamic matcher) =>
|
||||
HavingMatcher(_parent, description, feature, matcher, functionMatchers);
|
||||
|
||||
@override
|
||||
bool matches(dynamic item, Map matchState) {
|
||||
for (var matcher in <Matcher>[_parent].followedBy(functionMatchers)) {
|
||||
if (!matcher.matches(item, matchState)) {
|
||||
addStateInfo(matchState, {'matcher': matcher});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Description describeMismatch(
|
||||
dynamic item,
|
||||
Description mismatchDescription,
|
||||
Map matchState,
|
||||
bool verbose,
|
||||
) {
|
||||
var matcher = matchState['matcher'] as Matcher;
|
||||
matcher.describeMismatch(
|
||||
item, mismatchDescription, matchState['state'] as Map, verbose);
|
||||
return mismatchDescription;
|
||||
}
|
||||
|
||||
@override
|
||||
Description describe(Description description) => description
|
||||
.add('')
|
||||
.addDescriptionOf(_parent)
|
||||
.add(' with ')
|
||||
.addAll('', ' and ', '', functionMatchers);
|
||||
}
|
||||
|
||||
class TypeMatcher<T> extends Matcher {
|
||||
const TypeMatcher();
|
||||
|
||||
TypeMatcher<T> having(
|
||||
Object Function(T) feature, String description, dynamic matcher) =>
|
||||
HavingMatcher(this, description, feature, matcher);
|
||||
|
||||
@override
|
||||
Description describe(Description description) {
|
||||
var name = _stripDynamic(T);
|
||||
return description.add("<Instance of '$name'>");
|
||||
}
|
||||
|
||||
@override
|
||||
bool matches(Object? item, Map matchState) => item is T;
|
||||
|
||||
@override
|
||||
Description describeMismatch(
|
||||
dynamic item,
|
||||
Description mismatchDescription,
|
||||
Map matchState,
|
||||
bool verbose,
|
||||
) {
|
||||
var name = _stripDynamic(T);
|
||||
return mismatchDescription.add("is not an instance of '$name'");
|
||||
}
|
||||
}
|
||||
|
||||
String _stripDynamic(Type type) =>
|
||||
type.toString().replaceAll(_dart2DynamicArgs, '');
|
||||
final _dart2DynamicArgs = RegExp('<dynamic(, dynamic)*>');
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../navigation/utils/wrapper.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets("Get.defaultDialog smoke test", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
Wrapper(child: Container()),
|
||||
);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect('covid'.tr, 'Corona Virus');
|
||||
expect('total_confirmed'.tr, 'Total Confirmed');
|
||||
expect('total_deaths'.tr, 'Total Deaths');
|
||||
|
||||
Get.updateLocale(const Locale('pt', 'BR'));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect('covid'.tr, 'Corona Vírus');
|
||||
expect('total_confirmed'.tr, 'Total confirmado');
|
||||
expect('total_deaths'.tr, 'Total de mortes');
|
||||
|
||||
Get.updateLocale(const Locale('en', 'EN'));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect('covid'.tr, 'Corona Virus');
|
||||
expect('total_confirmed'.tr, 'Total Confirmed');
|
||||
expect('total_deaths'.tr, 'Total Deaths');
|
||||
});
|
||||
}
|
||||
71
packages/get/test/navigation/bottomsheet_test.dart
Normal file
71
packages/get/test/navigation/bottomsheet_test.dart
Normal file
@@ -0,0 +1,71 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'utils/wrapper.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets("Get.bottomSheet smoke test", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
Wrapper(child: Container()),
|
||||
);
|
||||
|
||||
Get.bottomSheet(Wrap(
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
leading: const Icon(Icons.music_note),
|
||||
title: const Text('Music'),
|
||||
onTap: () {},
|
||||
),
|
||||
],
|
||||
));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byIcon(Icons.music_note), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("Get.bottomSheet close test", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
Wrapper(child: Container()),
|
||||
);
|
||||
|
||||
Get.bottomSheet(Wrap(
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
leading: const Icon(Icons.music_note),
|
||||
title: const Text('Music'),
|
||||
onTap: () {},
|
||||
),
|
||||
],
|
||||
));
|
||||
|
||||
expect(Get.isBottomSheetOpen, true);
|
||||
|
||||
Get.back();
|
||||
expect(Get.isBottomSheetOpen, false);
|
||||
|
||||
// expect(() => Get.bottomSheet(Container(), isScrollControlled: null),
|
||||
// throwsAssertionError);
|
||||
|
||||
// expect(() => Get.bottomSheet(Container(), isDismissible: null),
|
||||
// throwsAssertionError);
|
||||
|
||||
// expect(() => Get.bottomSheet(Container(), enableDrag: null),
|
||||
// throwsAssertionError);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
|
||||
// testWidgets(
|
||||
// "GetMaterialApp with debugShowMaterialGrid null",
|
||||
// (tester) async {
|
||||
// expect(
|
||||
// () => GetMaterialApp(
|
||||
// debugShowMaterialGrid: null,
|
||||
// ),
|
||||
// throwsAssertionError,
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
}
|
||||
54
packages/get/test/navigation/dialog_test.dart
Normal file
54
packages/get/test/navigation/dialog_test.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'utils/wrapper.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets("Get.defaultDialog smoke test", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
Wrapper(child: Container()),
|
||||
);
|
||||
|
||||
Get.defaultDialog(
|
||||
onConfirm: () => print("Ok"),
|
||||
middleText: "Dialog made in 3 lines of code");
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text("Ok"), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("Get.dialog smoke test", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
Wrapper(child: Container()),
|
||||
);
|
||||
|
||||
Get.dialog(const YourDialogWidget());
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(YourDialogWidget), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("Get.dialog close test", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
Wrapper(child: Container()),
|
||||
);
|
||||
|
||||
Get.dialog(const YourDialogWidget());
|
||||
expect(Get.isDialogOpen, true);
|
||||
Get.back();
|
||||
expect(Get.isDialogOpen, false);
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
}
|
||||
|
||||
class YourDialogWidget extends StatelessWidget {
|
||||
const YourDialogWidget({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container();
|
||||
}
|
||||
}
|
||||
77
packages/get/test/navigation/dispose_dependencies_test.dart
Normal file
77
packages/get/test/navigation/dispose_dependencies_test.dart
Normal file
@@ -0,0 +1,77 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'utils/wrapper.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets("Test dispose dependencies with unnamed routes", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
Wrapper(child: Container()),
|
||||
);
|
||||
|
||||
expect(Get.isRegistered<Controller2>(), false);
|
||||
expect(Get.isRegistered<Controller>(), false);
|
||||
|
||||
Get.to(const First());
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(First), findsOneWidget);
|
||||
|
||||
expect(Get.isRegistered<Controller>(), true);
|
||||
|
||||
Get.to(const Second());
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(Second), findsOneWidget);
|
||||
|
||||
expect(Get.isRegistered<Controller>(), true);
|
||||
expect(Get.isRegistered<Controller2>(), true);
|
||||
|
||||
Get.back();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(First), findsOneWidget);
|
||||
|
||||
expect(Get.isRegistered<Controller>(), true);
|
||||
expect(Get.isRegistered<Controller2>(), false);
|
||||
|
||||
Get.back();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(Get.isRegistered<Controller>(), false);
|
||||
expect(Get.isRegistered<Controller2>(), false);
|
||||
});
|
||||
}
|
||||
|
||||
class Controller extends GetxController {}
|
||||
|
||||
class Controller2 extends GetxController {}
|
||||
|
||||
class First extends StatelessWidget {
|
||||
const First({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Get.put(Controller());
|
||||
return const Center(
|
||||
child: Text("first"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Second extends StatelessWidget {
|
||||
const Second({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Get.put(Controller2());
|
||||
return const Center(
|
||||
child: Text("second"),
|
||||
);
|
||||
}
|
||||
}
|
||||
513
packages/get/test/navigation/get_main_test.dart
Normal file
513
packages/get/test/navigation/get_main_test.dart
Normal file
@@ -0,0 +1,513 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'utils/wrapper.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets("Get.to navigates to provided route", (tester) async {
|
||||
await tester.pumpWidget(Wrapper(child: Container()));
|
||||
|
||||
Get.to(const FirstScreen());
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("Get.toNamed navigates to provided named route", (tester) async {
|
||||
await tester.pumpWidget(GetMaterialApp(
|
||||
initialRoute: '/first',
|
||||
getPages: [
|
||||
GetPage(page: FirstScreen.new, name: '/first'),
|
||||
GetPage(page: SecondScreen.new, name: '/second'),
|
||||
GetPage(page: ThirdScreen.new, name: '/third')
|
||||
],
|
||||
));
|
||||
|
||||
Get.toNamed('/second');
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SecondScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("unknowroute", (tester) async {
|
||||
await tester.pumpWidget(GetMaterialApp(
|
||||
initialRoute: '/first',
|
||||
unknownRoute: GetPage(name: '/404', page: Scaffold.new),
|
||||
getPages: [
|
||||
GetPage(page: FirstScreen.new, name: '/first'),
|
||||
GetPage(page: SecondScreen.new, name: '/second'),
|
||||
GetPage(page: ThirdScreen.new, name: '/third')
|
||||
],
|
||||
));
|
||||
|
||||
Get.toNamed('/secondd');
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(Get.currentRoute, '/404');
|
||||
});
|
||||
|
||||
testWidgets("Get.off navigates to provided route", (tester) async {
|
||||
await tester.pumpWidget(const Wrapper(child: FirstScreen()));
|
||||
|
||||
Get.off(const SecondScreen());
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SecondScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("Get.off removes current route", (tester) async {
|
||||
await tester.pumpWidget(const Wrapper(child: FirstScreen()));
|
||||
|
||||
Get.off(const SecondScreen());
|
||||
Get.back();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets("Get.offNamed navigates to provided named route", (tester) async {
|
||||
await tester.pumpWidget(GetMaterialApp(
|
||||
initialRoute: '/first',
|
||||
getPages: [
|
||||
GetPage(name: '/first', page: FirstScreen.new),
|
||||
GetPage(name: '/second', page: SecondScreen.new),
|
||||
GetPage(name: '/third', page: ThirdScreen.new),
|
||||
],
|
||||
));
|
||||
|
||||
Get.offNamed('/second');
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SecondScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("Get.offNamed removes current route", (tester) async {
|
||||
await tester.pumpWidget(GetMaterialApp(
|
||||
initialRoute: '/first',
|
||||
getPages: [
|
||||
GetPage(name: '/first', page: FirstScreen.new),
|
||||
GetPage(name: '/second', page: SecondScreen.new),
|
||||
GetPage(name: '/third', page: ThirdScreen.new),
|
||||
],
|
||||
));
|
||||
|
||||
Get.offNamed('/second');
|
||||
Get.back();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets("Get.offNamed removes only current route", (tester) async {
|
||||
await tester.pumpWidget(GetMaterialApp(
|
||||
initialRoute: '/first',
|
||||
getPages: [
|
||||
GetPage(name: '/first', page: FirstScreen.new),
|
||||
GetPage(name: '/second', page: SecondScreen.new),
|
||||
GetPage(name: '/third', page: ThirdScreen.new),
|
||||
],
|
||||
));
|
||||
|
||||
Get.toNamed('/second');
|
||||
Get.offNamed('/third');
|
||||
Get.back();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("Get.offAll navigates to provided route", (tester) async {
|
||||
await tester.pumpWidget(const Wrapper(child: FirstScreen()));
|
||||
|
||||
Get.offAll(const SecondScreen());
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SecondScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("Get.offAll removes all previous routes", (tester) async {
|
||||
await tester.pumpWidget(const Wrapper(child: FirstScreen()));
|
||||
|
||||
Get.to(const SecondScreen());
|
||||
Get.offAll(const ThirdScreen());
|
||||
Get.back();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SecondScreen), findsNothing);
|
||||
|
||||
Get.back();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets("Get.offAllNamed navigates to provided named route",
|
||||
(tester) async {
|
||||
await tester.pumpWidget(WrapperNamed(
|
||||
initialRoute: '/first',
|
||||
namedRoutes: [
|
||||
GetPage(page: FirstScreen.new, name: '/first'),
|
||||
GetPage(page: SecondScreen.new, name: '/second'),
|
||||
GetPage(page: ThirdScreen.new, name: '/third')
|
||||
],
|
||||
));
|
||||
|
||||
Get.toNamed('/second');
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SecondScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("Get.offAllNamed removes all previous routes", (tester) async {
|
||||
await tester.pumpWidget(WrapperNamed(
|
||||
initialRoute: '/first',
|
||||
namedRoutes: [
|
||||
GetPage(page: FirstScreen.new, name: '/first'),
|
||||
GetPage(page: SecondScreen.new, name: '/second'),
|
||||
GetPage(page: ThirdScreen.new, name: '/third')
|
||||
],
|
||||
));
|
||||
|
||||
Get.toNamed('/second');
|
||||
Get.offAllNamed('/third');
|
||||
Get.back();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SecondScreen), findsNothing);
|
||||
|
||||
Get.back();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets("Get.offAndToNamed navigates to provided route", (tester) async {
|
||||
await tester.pumpWidget(WrapperNamed(
|
||||
initialRoute: '/first',
|
||||
namedRoutes: [
|
||||
GetPage(page: FirstScreen.new, name: '/first'),
|
||||
GetPage(page: SecondScreen.new, name: '/second'),
|
||||
GetPage(page: ThirdScreen.new, name: '/third')
|
||||
],
|
||||
));
|
||||
|
||||
Get.offAndToNamed('/second');
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SecondScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("Get.offAndToNamed removes previous route", (tester) async {
|
||||
await tester.pumpWidget(WrapperNamed(
|
||||
initialRoute: '/first',
|
||||
namedRoutes: [
|
||||
GetPage(page: FirstScreen.new, name: '/first'),
|
||||
GetPage(page: SecondScreen.new, name: '/second'),
|
||||
GetPage(page: ThirdScreen.new, name: '/third')
|
||||
],
|
||||
));
|
||||
|
||||
Get.offAndToNamed('/second');
|
||||
Get.back();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets("Get.offUntil navigates to provided route", (tester) async {
|
||||
await tester.pumpWidget(Wrapper(child: Container()));
|
||||
|
||||
Get.to(const FirstScreen());
|
||||
|
||||
Get.offUntil(GetPageRoute(page: ThirdScreen.new),
|
||||
(route) => (route as GetPageRoute).routeName == '/FirstScreen');
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(ThirdScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
"Get.offUntil removes previous routes if they don't match predicate",
|
||||
(tester) async {
|
||||
await tester.pumpWidget(Wrapper(child: Container()));
|
||||
|
||||
Get.to(const FirstScreen());
|
||||
Get.to(const SecondScreen());
|
||||
Get.offUntil(GetPageRoute(page: ThirdScreen.new),
|
||||
(route) => (route as GetPageRoute).routeName == '/FirstScreen');
|
||||
Get.back();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SecondScreen), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
"Get.offUntil leaves previous routes that match provided predicate",
|
||||
(tester) async {
|
||||
await tester.pumpWidget(Wrapper(child: Container()));
|
||||
|
||||
Get.to(const FirstScreen());
|
||||
Get.to(const SecondScreen());
|
||||
Get.offUntil(GetPageRoute(page: ThirdScreen.new),
|
||||
(route) => (route as GetPageRoute).routeName == '/FirstScreen');
|
||||
Get.back();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("Get.offNamedUntil navigates to provided route", (tester) async {
|
||||
await tester.pumpWidget(WrapperNamed(
|
||||
initialRoute: '/first',
|
||||
namedRoutes: [
|
||||
GetPage(page: FirstScreen.new, name: '/first'),
|
||||
GetPage(page: SecondScreen.new, name: '/second'),
|
||||
GetPage(page: ThirdScreen.new, name: '/third')
|
||||
],
|
||||
));
|
||||
|
||||
Get.offNamedUntil('/second', ModalRoute.withName('/first'));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SecondScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
"Get.offNamedUntil removes previous routes if they don't match predicate",
|
||||
(tester) async {
|
||||
await tester.pumpWidget(WrapperNamed(
|
||||
initialRoute: '/first',
|
||||
namedRoutes: [
|
||||
GetPage(page: FirstScreen.new, name: '/first'),
|
||||
GetPage(page: SecondScreen.new, name: '/second'),
|
||||
GetPage(page: ThirdScreen.new, name: '/third')
|
||||
],
|
||||
));
|
||||
|
||||
Get.toNamed('/second');
|
||||
Get.offNamedUntil('/third', ModalRoute.withName('/first'));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SecondScreen), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
"Get.offNamedUntil leaves previous routes that match provided predicate",
|
||||
(tester) async {
|
||||
await tester.pumpWidget(WrapperNamed(
|
||||
initialRoute: '/first',
|
||||
namedRoutes: [
|
||||
GetPage(page: FirstScreen.new, name: '/first'),
|
||||
GetPage(page: SecondScreen.new, name: '/second'),
|
||||
GetPage(page: ThirdScreen.new, name: '/third'),
|
||||
],
|
||||
));
|
||||
|
||||
Get.toNamed('/second');
|
||||
Get.offNamedUntil('/third', ModalRoute.withName('/first'));
|
||||
Get.back();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("Get.back navigates back", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const Wrapper(
|
||||
defaultTransition: Transition.circularReveal,
|
||||
child: FirstScreen(),
|
||||
),
|
||||
);
|
||||
|
||||
Get.to(const SecondScreen());
|
||||
Get.back();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
"Get.back with closeOverlays pops both snackbar and current route",
|
||||
(tester) async {
|
||||
await tester.pumpWidget(const Wrapper(child: FirstScreen()));
|
||||
|
||||
Get.to(const SecondScreen());
|
||||
Get.snackbar('title', "message");
|
||||
Get.back(closeOverlays: true);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(Get.isSnackbarOpen, false);
|
||||
expect(find.byType(FirstScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("Get.defaultTransition smoke test", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
Wrapper(
|
||||
defaultTransition: Transition.fadeIn,
|
||||
child: Container(),
|
||||
),
|
||||
);
|
||||
|
||||
Get.to(const FirstScreen());
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Wrapper(
|
||||
defaultTransition: Transition.downToUp,
|
||||
child: Container(),
|
||||
),
|
||||
);
|
||||
|
||||
Get.to(const FirstScreen());
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Wrapper(
|
||||
defaultTransition: Transition.fade,
|
||||
child: Container(),
|
||||
),
|
||||
);
|
||||
|
||||
Get.to(const FirstScreen());
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Wrapper(
|
||||
defaultTransition: Transition.leftToRight,
|
||||
child: Container(),
|
||||
),
|
||||
);
|
||||
|
||||
Get.to(const FirstScreen());
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Wrapper(
|
||||
defaultTransition: Transition.leftToRightWithFade,
|
||||
child: Container(),
|
||||
),
|
||||
);
|
||||
|
||||
Get.to(const FirstScreen());
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Wrapper(
|
||||
defaultTransition: Transition.rightToLeft,
|
||||
child: Container(),
|
||||
),
|
||||
);
|
||||
|
||||
Get.to(const FirstScreen());
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Wrapper(
|
||||
defaultTransition: Transition.rightToLeftWithFade,
|
||||
child: Container(),
|
||||
),
|
||||
);
|
||||
|
||||
Get.to(const FirstScreen());
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Wrapper(
|
||||
defaultTransition: Transition.cupertino,
|
||||
child: Container(),
|
||||
),
|
||||
);
|
||||
|
||||
Get.to(const FirstScreen());
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Wrapper(
|
||||
defaultTransition: Transition.size,
|
||||
child: Container(),
|
||||
),
|
||||
);
|
||||
|
||||
Get.to(const FirstScreen());
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(FirstScreen), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
class FirstScreen extends StatelessWidget {
|
||||
const FirstScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Text('FirstScreen');
|
||||
}
|
||||
}
|
||||
|
||||
class SecondScreen extends StatelessWidget {
|
||||
const SecondScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container();
|
||||
}
|
||||
}
|
||||
|
||||
class ThirdScreen extends StatelessWidget {
|
||||
const ThirdScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container();
|
||||
}
|
||||
}
|
||||
35
packages/get/test/navigation/middleware_test.dart
Normal file
35
packages/get/test/navigation/middleware_test.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'get_main_test.dart';
|
||||
|
||||
class RedirectMiddleware extends GetMiddleware {
|
||||
@override
|
||||
RouteSettings redirect(String? route) => const RouteSettings(name: '/second');
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets("Middleware redirect smoke test", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
GetMaterialApp(
|
||||
initialRoute: '/',
|
||||
getPages: [
|
||||
GetPage(name: '/', page: Container.new),
|
||||
GetPage(
|
||||
name: '/first',
|
||||
page: FirstScreen.new,
|
||||
middlewares: [RedirectMiddleware()]),
|
||||
GetPage(name: '/second', page: SecondScreen.new),
|
||||
GetPage(name: '/third', page: ThirdScreen.new),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Get.toNamed('/first');
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(SecondScreen), findsOneWidget);
|
||||
});
|
||||
}
|
||||
192
packages/get/test/navigation/parse_route_test.dart
Normal file
192
packages/get/test/navigation/parse_route_test.dart
Normal file
@@ -0,0 +1,192 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get/get_navigation/src/root/parse_route.dart';
|
||||
|
||||
void main() {
|
||||
test('Parse Page with children', () {
|
||||
final testParams = {'hi': 'value'};
|
||||
final pageTree = GetPage(
|
||||
name: '/city',
|
||||
page: Container.new,
|
||||
children: [
|
||||
GetPage(
|
||||
name: '/home',
|
||||
page: Container.new,
|
||||
transition: Transition.rightToLeftWithFade,
|
||||
children: [
|
||||
GetPage(
|
||||
name: '/bed-room',
|
||||
transition: Transition.size,
|
||||
page: Container.new,
|
||||
),
|
||||
GetPage(
|
||||
name: '/living-room',
|
||||
transition: Transition.topLevel,
|
||||
page: Container.new,
|
||||
),
|
||||
],
|
||||
),
|
||||
GetPage(
|
||||
name: '/work',
|
||||
transition: Transition.upToDown,
|
||||
page: Container.new,
|
||||
children: [
|
||||
GetPage(
|
||||
name: '/office',
|
||||
transition: Transition.zoom,
|
||||
page: Container.new,
|
||||
children: [
|
||||
GetPage(
|
||||
name: '/pen',
|
||||
transition: Transition.cupertino,
|
||||
page: Container.new,
|
||||
parameters: testParams,
|
||||
),
|
||||
GetPage(
|
||||
name: '/paper',
|
||||
page: Container.new,
|
||||
transition: Transition.downToUp,
|
||||
),
|
||||
],
|
||||
),
|
||||
GetPage(
|
||||
name: '/meeting-room',
|
||||
transition: Transition.fade,
|
||||
page: Container.new,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
final tree = ParseRouteTree(routes: <GetPage>[]);
|
||||
|
||||
tree.addRoute(pageTree);
|
||||
|
||||
// tree.addRoute(pageTree);
|
||||
const searchRoute = '/city/work/office/pen';
|
||||
final match = tree.matchRoute(searchRoute);
|
||||
expect(match, isNotNull);
|
||||
expect(match.route!.name, searchRoute);
|
||||
final testRouteParam = match.route!.parameters!;
|
||||
for (final tParam in testParams.entries) {
|
||||
expect(testRouteParam[tParam.key], tParam.value);
|
||||
}
|
||||
});
|
||||
|
||||
test('Parse Page without children', () {
|
||||
final pageTree = [
|
||||
GetPage(
|
||||
name: '/city', page: Container.new, transition: Transition.cupertino),
|
||||
GetPage(
|
||||
name: '/city/home',
|
||||
page: Container.new,
|
||||
transition: Transition.downToUp),
|
||||
GetPage(
|
||||
name: '/city/home/bed-room',
|
||||
page: Container.new,
|
||||
transition: Transition.fade),
|
||||
GetPage(
|
||||
name: '/city/home/living-room',
|
||||
page: Container.new,
|
||||
transition: Transition.fadeIn),
|
||||
GetPage(
|
||||
name: '/city/work',
|
||||
page: Container.new,
|
||||
transition: Transition.leftToRight),
|
||||
GetPage(
|
||||
name: '/city/work/office',
|
||||
page: Container.new,
|
||||
transition: Transition.leftToRightWithFade),
|
||||
GetPage(
|
||||
name: '/city/work/office/pen',
|
||||
page: Container.new,
|
||||
transition: Transition.native),
|
||||
GetPage(
|
||||
name: '/city/work/office/paper',
|
||||
page: Container.new,
|
||||
transition: Transition.noTransition),
|
||||
GetPage(
|
||||
name: '/city/work/meeting-room',
|
||||
page: Container.new,
|
||||
transition: Transition.rightToLeft),
|
||||
];
|
||||
|
||||
final tree = ParseRouteTree(routes: pageTree);
|
||||
|
||||
// for (var p in pageTree) {
|
||||
// tree.addRoute(p);
|
||||
// }
|
||||
|
||||
const searchRoute = '/city/work/office/pen';
|
||||
final match = tree.matchRoute(searchRoute);
|
||||
expect(match, isNotNull);
|
||||
expect(match.route!.name, searchRoute);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'test params from dynamic route',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(GetMaterialApp(
|
||||
initialRoute: '/first/juan',
|
||||
getPages: [
|
||||
GetPage(page: Container.new, name: '/first/:name'),
|
||||
GetPage(page: Container.new, name: '/second/:id'),
|
||||
GetPage(page: Container.new, name: '/third'),
|
||||
GetPage(page: Container.new, name: '/last/:id/:name/profile')
|
||||
],
|
||||
));
|
||||
|
||||
expect(Get.parameters['name'], 'juan');
|
||||
|
||||
Get.toNamed('/second/1234');
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(Get.parameters['id'], '1234');
|
||||
|
||||
Get.toNamed('/third?name=jonny&job=dev');
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(Get.parameters['name'], 'jonny');
|
||||
expect(Get.parameters['job'], 'dev');
|
||||
|
||||
Get.toNamed('/last/1234/ana/profile');
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(Get.parameters['id'], '1234');
|
||||
expect(Get.parameters['name'], 'ana');
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'params in url by parameters',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(GetMaterialApp(
|
||||
initialRoute: '/first/juan',
|
||||
getPages: [
|
||||
GetPage(page: Container.new, name: '/first/:name'),
|
||||
GetPage(page: Container.new, name: '/italy'),
|
||||
],
|
||||
));
|
||||
|
||||
// Get.parameters = ({"varginias": "varginia", "vinis": "viniiss"});
|
||||
var parameters = <String, String>{
|
||||
"varginias": "varginia",
|
||||
"vinis": "viniiss"
|
||||
};
|
||||
// print("Get.parameters: ${Get.parameters}");
|
||||
parameters.addAll({"a": "b", "c": "d"});
|
||||
Get.toNamed("/italy", parameters: parameters);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
expect(Get.parameters['varginias'], 'varginia');
|
||||
expect(Get.parameters['vinis'], 'viniiss');
|
||||
expect(Get.parameters['a'], 'b');
|
||||
expect(Get.parameters['c'], 'd');
|
||||
},
|
||||
);
|
||||
}
|
||||
102
packages/get/test/navigation/root_widget_test.dart
Normal file
102
packages/get/test/navigation/root_widget_test.dart
Normal file
@@ -0,0 +1,102 @@
|
||||
// import 'package:flutter_test/flutter_test.dart';
|
||||
// import 'package:get/get.dart';
|
||||
|
||||
void main() {
|
||||
// testWidgets(
|
||||
// "GetMaterialApp with routes null",
|
||||
// (tester) async {
|
||||
// expect(
|
||||
// () => GetMaterialApp(
|
||||
// routes: null,
|
||||
// ),
|
||||
// throwsAssertionError);
|
||||
// },
|
||||
// );
|
||||
|
||||
// testWidgets(
|
||||
// "GetMaterialApp with navigatorObservers null",
|
||||
// (tester) async {
|
||||
// expect(
|
||||
// () => GetMaterialApp(
|
||||
// navigatorObservers: null,
|
||||
// ),
|
||||
// throwsAssertionError);
|
||||
// },
|
||||
// );
|
||||
// testWidgets(
|
||||
// "GetMaterialApp with title null",
|
||||
// (tester) async {
|
||||
// expect(
|
||||
// () => GetMaterialApp(
|
||||
// title: null,
|
||||
// ),
|
||||
// throwsAssertionError);
|
||||
// },
|
||||
// );
|
||||
// testWidgets(
|
||||
// "GetMaterialApp with debugShowMaterialGrid null",
|
||||
// (test) async {
|
||||
// expect(
|
||||
// () => GetMaterialApp(
|
||||
// debugShowMaterialGrid: null,
|
||||
// ),
|
||||
// throwsAssertionError,
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// testWidgets(
|
||||
// "GetMaterialApp with showPerformanceOverlay null",
|
||||
// (test) async {
|
||||
// expect(
|
||||
// () => GetMaterialApp(
|
||||
// showPerformanceOverlay: null,
|
||||
// ),
|
||||
// throwsAssertionError,
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// testWidgets(
|
||||
// "GetMaterialApp with showSemanticsDebugger null",
|
||||
// (test) async {
|
||||
// expect(
|
||||
// () => GetMaterialApp(
|
||||
// showSemanticsDebugger: null,
|
||||
// ),
|
||||
// throwsAssertionError,
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// testWidgets(
|
||||
// "GetMaterialApp with debugShowCheckedModeBanner null",
|
||||
// (tester) async {
|
||||
// expect(
|
||||
// () => GetMaterialApp(
|
||||
// debugShowCheckedModeBanner: null,
|
||||
// ),
|
||||
// throwsAssertionError);
|
||||
// },
|
||||
// );
|
||||
|
||||
// testWidgets(
|
||||
// "GetMaterialApp with checkerboardRasterCacheImages null",
|
||||
// (tester) async {
|
||||
// expect(
|
||||
// () => GetMaterialApp(
|
||||
// checkerboardRasterCacheImages: null,
|
||||
// ),
|
||||
// throwsAssertionError);
|
||||
// },
|
||||
// );
|
||||
|
||||
// testWidgets(
|
||||
// "GetMaterialApp with checkerboardOffscreenLayers null",
|
||||
// (tester) async {
|
||||
// expect(
|
||||
// () => GetMaterialApp(
|
||||
// checkerboardOffscreenLayers: null,
|
||||
// ),
|
||||
// throwsAssertionError,
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
}
|
||||
120
packages/get/test/navigation/routes_test.dart
Normal file
120
packages/get/test/navigation/routes_test.dart
Normal file
@@ -0,0 +1,120 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Back swipe dismiss interrupted by route push', (tester) async {
|
||||
// final scaffoldKey = GlobalKey();
|
||||
|
||||
await tester.pumpWidget(
|
||||
GetCupertinoApp(
|
||||
popGesture: true,
|
||||
home: CupertinoPageScaffold(
|
||||
// key: scaffoldKey,
|
||||
child: Center(
|
||||
child: CupertinoButton(
|
||||
onPressed: () {
|
||||
Get.to(() => const CupertinoPageScaffold(
|
||||
child: Center(child: Text('route')),
|
||||
));
|
||||
},
|
||||
child: const Text('push'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Check the basic iOS back-swipe dismiss transition. Dragging the pushed
|
||||
// route halfway across the screen will trigger the iOS dismiss animation
|
||||
|
||||
await tester.tap(find.text('push'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('route'), findsOneWidget);
|
||||
expect(find.text('push'), findsNothing);
|
||||
|
||||
var gesture = await tester.startGesture(const Offset(5, 300));
|
||||
await gesture.moveBy(const Offset(400, 0));
|
||||
await gesture.up();
|
||||
await tester.pump();
|
||||
expect(
|
||||
// The 'route' route has been dragged to the right, halfway across
|
||||
// the screen
|
||||
tester.getTopLeft(find.ancestor(
|
||||
of: find.text('route'),
|
||||
matching: find.byType(CupertinoPageScaffold))),
|
||||
const Offset(400, 0),
|
||||
);
|
||||
expect(
|
||||
// The 'push' route is sliding in from the left.
|
||||
tester
|
||||
.getTopLeft(find.ancestor(
|
||||
of: find.text('push'),
|
||||
matching: find.byType(CupertinoPageScaffold)))
|
||||
.dx,
|
||||
0,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('push'), findsOneWidget);
|
||||
expect(
|
||||
tester.getTopLeft(find.ancestor(
|
||||
of: find.text('push'), matching: find.byType(CupertinoPageScaffold))),
|
||||
Offset.zero,
|
||||
);
|
||||
expect(find.text('route'), findsNothing);
|
||||
|
||||
// Run the dismiss animation 60%, which exposes the route "push" button,
|
||||
// and then press the button.
|
||||
|
||||
await tester.tap(find.text('push'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('route'), findsOneWidget);
|
||||
expect(find.text('push'), findsNothing);
|
||||
|
||||
gesture = await tester.startGesture(const Offset(5, 300));
|
||||
await gesture.moveBy(const Offset(400, 0)); // Drag halfway.
|
||||
await gesture.up();
|
||||
// Trigger the snapping animation.
|
||||
// Since the back swipe drag was brought to >=50% of the screen, it will
|
||||
// self snap to finish the pop transition as the gesture is lifted.
|
||||
//
|
||||
// This drag drop animation is 400ms when dropped exactly halfway
|
||||
// (800 / [pixel distance remaining], see
|
||||
// _CupertinoBackGestureController.dragEnd). It follows a curve that is very
|
||||
// steep initially.
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.getTopLeft(find.ancestor(
|
||||
of: find.text('route'),
|
||||
matching: find.byType(CupertinoPageScaffold))),
|
||||
const Offset(400, 0),
|
||||
);
|
||||
// Let the dismissing snapping animation go 60%.
|
||||
await tester.pump(const Duration(milliseconds: 240));
|
||||
expect(
|
||||
tester
|
||||
.getTopLeft(find.ancestor(
|
||||
of: find.text('route'),
|
||||
matching: find.byType(CupertinoPageScaffold)))
|
||||
.dx,
|
||||
moreOrLessEquals(798, epsilon: 1),
|
||||
);
|
||||
|
||||
// Use the navigator to push a route instead of tapping the 'push' button.
|
||||
// The topmost route (the one that's animating away), ignores input while
|
||||
// the pop is underway because route.navigator.userGestureInProgress.
|
||||
Get.to(() => const CupertinoPageScaffold(
|
||||
child: Center(child: Text('route')),
|
||||
));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('route'), findsOneWidget);
|
||||
expect(find.text('push'), findsNothing);
|
||||
expect(
|
||||
tester
|
||||
.state<NavigatorState>(find.byType(Navigator))
|
||||
.userGestureInProgress,
|
||||
false,
|
||||
);
|
||||
});
|
||||
}
|
||||
247
packages/get/test/navigation/snackbar_test.dart
Normal file
247
packages/get/test/navigation/snackbar_test.dart
Normal file
@@ -0,0 +1,247 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets("test if Get.isSnackbarOpen works with Get.snackbar",
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
GetMaterialApp(
|
||||
popGesture: true,
|
||||
home: ElevatedButton(
|
||||
child: const Text('Open Snackbar'),
|
||||
onPressed: () {
|
||||
Get.snackbar(
|
||||
'title',
|
||||
"message",
|
||||
duration: const Duration(seconds: 1),
|
||||
mainButton:
|
||||
TextButton(onPressed: () {}, child: const Text('button')),
|
||||
isDismissible: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(Get.isSnackbarOpen, false);
|
||||
await tester.tap(find.text('Open Snackbar'));
|
||||
|
||||
expect(Get.isSnackbarOpen, true);
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(Get.isSnackbarOpen, false);
|
||||
});
|
||||
|
||||
testWidgets("Get.rawSnackbar test", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
GetMaterialApp(
|
||||
popGesture: true,
|
||||
home: ElevatedButton(
|
||||
child: const Text('Open Snackbar'),
|
||||
onPressed: () {
|
||||
Get.rawSnackbar(
|
||||
title: 'title',
|
||||
message: "message",
|
||||
onTap: (_) {
|
||||
print('snackbar tapped');
|
||||
},
|
||||
shouldIconPulse: true,
|
||||
icon: const Icon(Icons.alarm),
|
||||
showProgressIndicator: true,
|
||||
duration: const Duration(seconds: 1),
|
||||
isDismissible: true,
|
||||
leftBarIndicatorColor: Colors.amber,
|
||||
overlayBlur: 1.0,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(Get.isSnackbarOpen, false);
|
||||
await tester.tap(find.text('Open Snackbar'));
|
||||
|
||||
expect(Get.isSnackbarOpen, true);
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(Get.isSnackbarOpen, false);
|
||||
});
|
||||
|
||||
testWidgets("test snackbar queue", (tester) async {
|
||||
const messageOne = Text('title');
|
||||
|
||||
const messageTwo = Text('titleTwo');
|
||||
|
||||
await tester.pumpWidget(
|
||||
GetMaterialApp(
|
||||
popGesture: true,
|
||||
home: ElevatedButton(
|
||||
child: const Text('Open Snackbar'),
|
||||
onPressed: () {
|
||||
Get.rawSnackbar(
|
||||
messageText: messageOne, duration: const Duration(seconds: 1));
|
||||
Get.rawSnackbar(
|
||||
messageText: messageTwo, duration: const Duration(seconds: 1));
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(Get.isSnackbarOpen, false);
|
||||
await tester.tap(find.text('Open Snackbar'));
|
||||
expect(Get.isSnackbarOpen, true);
|
||||
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
expect(find.text('title'), findsOneWidget);
|
||||
expect(find.text('titleTwo'), findsNothing);
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
expect(find.text('title'), findsNothing);
|
||||
expect(find.text('titleTwo'), findsOneWidget);
|
||||
Get.closeAllSnackbars();
|
||||
});
|
||||
|
||||
testWidgets("test snackbar dismissible", (tester) async {
|
||||
const dismissDirection = DismissDirection.vertical;
|
||||
const snackBarTapTarget = Key('snackbar-tap-target');
|
||||
|
||||
late final GetSnackBar getBar;
|
||||
|
||||
await tester.pumpWidget(GetMaterialApp(
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) {
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
GestureDetector(
|
||||
key: snackBarTapTarget,
|
||||
onTap: () {
|
||||
getBar = const GetSnackBar(
|
||||
message: 'bar1',
|
||||
duration: Duration(seconds: 2),
|
||||
isDismissible: true,
|
||||
dismissDirection: dismissDirection,
|
||||
);
|
||||
Get.showSnackbar(getBar);
|
||||
},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: const SizedBox(
|
||||
height: 100.0,
|
||||
width: 100.0,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
expect(Get.isSnackbarOpen, false);
|
||||
expect(find.text('bar1'), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(snackBarTapTarget));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(Get.isSnackbarOpen, true);
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
expect(find.byWidget(getBar), findsOneWidget);
|
||||
await tester.ensureVisible(find.byWidget(getBar));
|
||||
await tester.drag(find.byWidget(getBar), const Offset(0.0, 50.0));
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
|
||||
expect(Get.isSnackbarOpen, false);
|
||||
});
|
||||
|
||||
testWidgets("test snackbar onTap", (tester) async {
|
||||
const dismissDirection = DismissDirection.vertical;
|
||||
const snackBarTapTarget = Key('snackbar-tap-target');
|
||||
var counter = 0;
|
||||
|
||||
late final GetSnackBar getBar;
|
||||
|
||||
late final SnackbarController getBarController;
|
||||
|
||||
await tester.pumpWidget(GetMaterialApp(
|
||||
home: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) {
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
GestureDetector(
|
||||
key: snackBarTapTarget,
|
||||
onTap: () {
|
||||
getBar = GetSnackBar(
|
||||
message: 'bar1',
|
||||
onTap: (_) {
|
||||
counter++;
|
||||
},
|
||||
duration: const Duration(seconds: 2),
|
||||
isDismissible: true,
|
||||
dismissDirection: dismissDirection,
|
||||
);
|
||||
getBarController = Get.showSnackbar(getBar);
|
||||
},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: const SizedBox(
|
||||
height: 100.0,
|
||||
width: 100.0,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(Get.isSnackbarOpen, false);
|
||||
expect(find.text('bar1'), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(snackBarTapTarget));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(Get.isSnackbarOpen, true);
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
expect(find.byWidget(getBar), findsOneWidget);
|
||||
await tester.ensureVisible(find.byWidget(getBar));
|
||||
await tester.tap(find.byWidget(getBar));
|
||||
expect(counter, 1);
|
||||
await tester.pump(const Duration(milliseconds: 3000));
|
||||
await getBarController.close(withAnimations: false);
|
||||
});
|
||||
|
||||
testWidgets("Get test actions and icon", (tester) async {
|
||||
const icon = Icon(Icons.alarm);
|
||||
final action = TextButton(onPressed: () {}, child: const Text('button'));
|
||||
|
||||
late final GetSnackBar getBar;
|
||||
|
||||
await tester.pumpWidget(const GetMaterialApp(home: Scaffold()));
|
||||
|
||||
expect(Get.isSnackbarOpen, false);
|
||||
expect(find.text('bar1'), findsNothing);
|
||||
|
||||
getBar = GetSnackBar(
|
||||
message: 'bar1',
|
||||
icon: icon,
|
||||
mainButton: action,
|
||||
leftBarIndicatorColor: Colors.yellow,
|
||||
showProgressIndicator: true,
|
||||
// maxWidth: 100,
|
||||
borderColor: Colors.red,
|
||||
duration: const Duration(seconds: 1),
|
||||
isDismissible: false,
|
||||
);
|
||||
Get.showSnackbar(getBar);
|
||||
|
||||
expect(Get.isSnackbarOpen, true);
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
expect(find.byWidget(getBar), findsOneWidget);
|
||||
expect(find.byWidget(icon), findsOneWidget);
|
||||
expect(find.byWidget(action), findsOneWidget);
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
|
||||
expect(Get.isSnackbarOpen, false);
|
||||
});
|
||||
}
|
||||
73
packages/get/test/navigation/utils/wrapper.dart
Normal file
73
packages/get/test/navigation/utils/wrapper.dart
Normal file
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class Wrapper extends StatelessWidget {
|
||||
final Widget? child;
|
||||
final List<GetPage>? namedRoutes;
|
||||
final String? initialRoute;
|
||||
final Transition? defaultTransition;
|
||||
|
||||
const Wrapper({
|
||||
Key? key,
|
||||
this.child,
|
||||
this.namedRoutes,
|
||||
this.initialRoute,
|
||||
this.defaultTransition,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetMaterialApp(
|
||||
defaultTransition: defaultTransition,
|
||||
initialRoute: initialRoute,
|
||||
translations: WrapperTranslations(),
|
||||
locale: WrapperTranslations.locale,
|
||||
getPages: namedRoutes,
|
||||
home: Scaffold(
|
||||
body: child,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class WrapperNamed extends StatelessWidget {
|
||||
final Widget? child;
|
||||
final List<GetPage>? namedRoutes;
|
||||
final String? initialRoute;
|
||||
final Transition? defaultTransition;
|
||||
|
||||
const WrapperNamed({
|
||||
Key? key,
|
||||
this.child,
|
||||
this.namedRoutes,
|
||||
this.initialRoute,
|
||||
this.defaultTransition,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetMaterialApp(
|
||||
defaultTransition: defaultTransition,
|
||||
initialRoute: initialRoute,
|
||||
getPages: namedRoutes,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class WrapperTranslations extends Translations {
|
||||
static Locale fallbackLocale = const Locale('en', 'US');
|
||||
static Locale? get locale => const Locale('en', 'US');
|
||||
@override
|
||||
Map<String, Map<String, String>> get keys => {
|
||||
'en_US': {
|
||||
'covid': 'Corona Virus',
|
||||
'total_confirmed': 'Total Confirmed',
|
||||
'total_deaths': 'Total Deaths',
|
||||
},
|
||||
'pt_BR': {
|
||||
'covid': 'Corona Vírus',
|
||||
'total_confirmed': 'Total confirmado',
|
||||
'total_deaths': 'Total de mortes',
|
||||
},
|
||||
};
|
||||
}
|
||||
210
packages/get/test/rx/rx_workers_test.dart
Normal file
210
packages/get/test/rx/rx_workers_test.dart
Normal file
@@ -0,0 +1,210 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
void main() {
|
||||
test('once', () async {
|
||||
final count = 0.obs;
|
||||
var result = -1;
|
||||
once(count, (dynamic _) {
|
||||
result = _ as int;
|
||||
});
|
||||
count.value++;
|
||||
await Future.delayed(Duration.zero);
|
||||
expect(1, result);
|
||||
count.value++;
|
||||
await Future.delayed(Duration.zero);
|
||||
expect(1, result);
|
||||
count.value++;
|
||||
await Future.delayed(Duration.zero);
|
||||
expect(1, result);
|
||||
});
|
||||
|
||||
test('ever', () async {
|
||||
final count = 0.obs;
|
||||
var result = -1;
|
||||
ever<int>(count, (value) {
|
||||
result = value;
|
||||
});
|
||||
count.value++;
|
||||
await Future.delayed(Duration.zero);
|
||||
expect(1, result);
|
||||
count.value++;
|
||||
await Future.delayed(Duration.zero);
|
||||
expect(2, result);
|
||||
count.value++;
|
||||
await Future.delayed(Duration.zero);
|
||||
expect(3, result);
|
||||
});
|
||||
|
||||
test('debounce', () async {
|
||||
final count = 0.obs;
|
||||
int? result = -1;
|
||||
debounce(count, (dynamic _) {
|
||||
// print(_);
|
||||
result = _ as int?;
|
||||
}, time: const Duration(milliseconds: 100));
|
||||
|
||||
count.value++;
|
||||
count.value++;
|
||||
count.value++;
|
||||
count.value++;
|
||||
await Future.delayed(Duration.zero);
|
||||
expect(-1, result);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
expect(4, result);
|
||||
});
|
||||
|
||||
test('interval', () async {
|
||||
final count = 0.obs;
|
||||
int? result = -1;
|
||||
interval(count, (dynamic _) {
|
||||
// print(_);
|
||||
result = _ as int?;
|
||||
}, time: const Duration(milliseconds: 100));
|
||||
|
||||
count.value++;
|
||||
await Future.delayed(Duration.zero);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
expect(1, result);
|
||||
count.value++;
|
||||
count.value++;
|
||||
count.value++;
|
||||
await Future.delayed(Duration.zero);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
expect(2, result);
|
||||
count.value++;
|
||||
await Future.delayed(Duration.zero);
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
expect(5, result);
|
||||
});
|
||||
|
||||
test('bindStream test', () async {
|
||||
int? count = 0;
|
||||
final controller = StreamController<int>();
|
||||
final rx = 0.obs;
|
||||
|
||||
rx.listen((value) {
|
||||
count = value;
|
||||
});
|
||||
rx.bindStream(controller.stream);
|
||||
expect(count, 0);
|
||||
controller.add(555);
|
||||
|
||||
await Future.delayed(Duration.zero);
|
||||
expect(count, 555);
|
||||
controller.close();
|
||||
});
|
||||
|
||||
test('Rx same value will not call the same listener when `call`', () async {
|
||||
var reactiveInteger = RxInt(2);
|
||||
var timesCalled = 0;
|
||||
reactiveInteger.listen((newInt) {
|
||||
timesCalled++;
|
||||
});
|
||||
|
||||
// we call 3
|
||||
reactiveInteger.call(3);
|
||||
// then repeat twice
|
||||
reactiveInteger.call(3);
|
||||
reactiveInteger.call(3);
|
||||
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
expect(1, timesCalled);
|
||||
});
|
||||
|
||||
test('Rx different value will call the listener when `trigger`', () async {
|
||||
var reactiveInteger = RxInt(0);
|
||||
var timesCalled = 0;
|
||||
reactiveInteger.listen((newInt) {
|
||||
timesCalled++;
|
||||
});
|
||||
|
||||
// we call 3
|
||||
reactiveInteger.trigger(1);
|
||||
// then repeat twice
|
||||
reactiveInteger.trigger(2);
|
||||
reactiveInteger.trigger(3);
|
||||
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
expect(3, timesCalled);
|
||||
});
|
||||
|
||||
test('Rx same value will call the listener when `trigger`', () async {
|
||||
var reactiveInteger = RxInt(2);
|
||||
var timesCalled = 0;
|
||||
reactiveInteger.listen((newInt) {
|
||||
timesCalled++;
|
||||
});
|
||||
|
||||
// we call 3
|
||||
reactiveInteger.trigger(3);
|
||||
// then repeat twice
|
||||
reactiveInteger.trigger(3);
|
||||
reactiveInteger.trigger(3);
|
||||
reactiveInteger.trigger(1);
|
||||
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
expect(4, timesCalled);
|
||||
});
|
||||
|
||||
test('Rx String with non null values', () async {
|
||||
final reactiveString = Rx<String>("abc");
|
||||
String? currentString;
|
||||
reactiveString.listen((newString) {
|
||||
currentString = newString;
|
||||
});
|
||||
|
||||
expect(reactiveString.endsWith("c"), true);
|
||||
|
||||
// we call 3
|
||||
reactiveString("b");
|
||||
|
||||
await Future.delayed(Duration.zero);
|
||||
expect(currentString, "b");
|
||||
});
|
||||
|
||||
test('Rx String with null values', () async {
|
||||
var reactiveString = Rx<String?>(null);
|
||||
String? currentString;
|
||||
|
||||
reactiveString.listen((newString) {
|
||||
currentString = newString;
|
||||
});
|
||||
|
||||
// we call 3
|
||||
reactiveString("abc");
|
||||
|
||||
await Future.delayed(Duration.zero);
|
||||
expect(reactiveString.endsWith("c"), true);
|
||||
expect(currentString, "abc");
|
||||
});
|
||||
|
||||
test('Number of times "ever" is called in RxList', () async {
|
||||
final list = [1, 2, 3].obs;
|
||||
var count = 0;
|
||||
ever<List<int>>(list, (value) {
|
||||
count++;
|
||||
});
|
||||
|
||||
list.add(4);
|
||||
await Future.delayed(Duration.zero);
|
||||
expect(count, 1);
|
||||
|
||||
count = 0;
|
||||
list.addAll([4, 5]);
|
||||
await Future.delayed(Duration.zero);
|
||||
expect(count, 1);
|
||||
|
||||
count = 0;
|
||||
list.removeWhere((element) => element == 2);
|
||||
await Future.delayed(Duration.zero);
|
||||
expect(count, 1);
|
||||
|
||||
count = 0;
|
||||
list.retainWhere((element) => element == 1);
|
||||
await Future.delayed(Duration.zero);
|
||||
expect(count, 1);
|
||||
});
|
||||
}
|
||||
99
packages/get/test/state_manager/get_mixin_state_test.dart
Normal file
99
packages/get/test/state_manager/get_mixin_state_test.dart
Normal file
@@ -0,0 +1,99 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets("MixinBuilder smoke test", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: MixinBuilder<Controller>(
|
||||
init: Controller(),
|
||||
builder: (controller) {
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
'Count: ${controller.counter.value}',
|
||||
),
|
||||
Text(
|
||||
'Count2: ${controller.count}',
|
||||
),
|
||||
Text(
|
||||
'Double: ${controller.doubleNum.value}',
|
||||
),
|
||||
Text(
|
||||
'String: ${controller.string.value}',
|
||||
),
|
||||
Text(
|
||||
'List: ${controller.list.length}',
|
||||
),
|
||||
Text(
|
||||
'Bool: ${controller.boolean.value}',
|
||||
),
|
||||
Text(
|
||||
'Map: ${controller.map.length}',
|
||||
),
|
||||
TextButton(
|
||||
child: const Text("increment"),
|
||||
onPressed: () => controller.increment(),
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text("Count: 0"), findsOneWidget);
|
||||
expect(find.text("Count2: 0"), findsOneWidget);
|
||||
expect(find.text("Double: 0.0"), findsOneWidget);
|
||||
expect(find.text("String: string"), findsOneWidget);
|
||||
expect(find.text("Bool: true"), findsOneWidget);
|
||||
expect(find.text("List: 0"), findsOneWidget);
|
||||
expect(find.text("Map: 0"), findsOneWidget);
|
||||
|
||||
Controller.to.increment();
|
||||
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text("Count: 1"), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('increment'));
|
||||
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text("Count: 2"), findsOneWidget);
|
||||
});
|
||||
|
||||
// testWidgets(
|
||||
// "MixinBuilder with build null",
|
||||
// (tester) async {
|
||||
// expect(
|
||||
// () => MixinBuilder<Controller>(
|
||||
// init: Controller(),
|
||||
// builder: null,
|
||||
// ),
|
||||
// throwsAssertionError,
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
}
|
||||
|
||||
class Controller extends GetxController {
|
||||
static Controller get to => Get.find();
|
||||
int count = 0;
|
||||
RxInt counter = 0.obs;
|
||||
RxDouble doubleNum = 0.0.obs;
|
||||
RxString string = "string".obs;
|
||||
RxList list = [].obs;
|
||||
RxMap map = {}.obs;
|
||||
RxBool boolean = true.obs;
|
||||
|
||||
void increment() {
|
||||
counter.value++;
|
||||
}
|
||||
|
||||
void increment2() {
|
||||
count++;
|
||||
update();
|
||||
}
|
||||
}
|
||||
67
packages/get/test/state_manager/get_obx_test.dart
Normal file
67
packages/get/test/state_manager/get_obx_test.dart
Normal file
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets("GetxController smoke test", (tester) async {
|
||||
final controller = Get.put(Controller());
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Column(
|
||||
children: [
|
||||
Obx(
|
||||
() => Column(children: [
|
||||
Text('Count: ${controller.counter.value}'),
|
||||
Text('Double: ${controller.doubleNum.value}'),
|
||||
Text('String: ${controller.string.value}'),
|
||||
Text('List: ${controller.list.length}'),
|
||||
Text('Bool: ${controller.boolean.value}'),
|
||||
Text('Map: ${controller.map.length}'),
|
||||
TextButton(
|
||||
onPressed: controller.increment,
|
||||
child: const Text("increment"),
|
||||
),
|
||||
Obx(() => Text('Obx: ${controller.map.length}'))
|
||||
]),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text("Count: 0"), findsOneWidget);
|
||||
expect(find.text("Double: 0.0"), findsOneWidget);
|
||||
expect(find.text("String: string"), findsOneWidget);
|
||||
expect(find.text("Bool: true"), findsOneWidget);
|
||||
expect(find.text("List: 0"), findsOneWidget);
|
||||
expect(find.text("Map: 0"), findsOneWidget);
|
||||
expect(find.text("Obx: 0"), findsOneWidget);
|
||||
|
||||
Controller.to.increment();
|
||||
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text("Count: 1"), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('increment'));
|
||||
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text("Count: 2"), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
class Controller extends GetxController {
|
||||
static Controller get to => Get.find();
|
||||
|
||||
RxInt counter = 0.obs;
|
||||
RxDouble doubleNum = 0.0.obs;
|
||||
RxString string = "string".obs;
|
||||
RxList list = [].obs;
|
||||
RxMap map = {}.obs;
|
||||
RxBool boolean = true.obs;
|
||||
|
||||
void increment() {
|
||||
counter.value++;
|
||||
}
|
||||
}
|
||||
97
packages/get/test/state_manager/get_rxstate_test.dart
Normal file
97
packages/get/test/state_manager/get_rxstate_test.dart
Normal file
@@ -0,0 +1,97 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
void main() {
|
||||
Get.lazyPut<Controller2>(Controller2.new);
|
||||
testWidgets("GetxController smoke test", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: GetX<Controller>(
|
||||
init: Controller(),
|
||||
builder: (controller) {
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
'Count: ${controller.counter.value}',
|
||||
),
|
||||
Text(
|
||||
'Double: ${controller.doubleNum.value}',
|
||||
),
|
||||
Text(
|
||||
'String: ${controller.string.value}',
|
||||
),
|
||||
Text(
|
||||
'List: ${controller.list.length}',
|
||||
),
|
||||
Text(
|
||||
'Bool: ${controller.boolean.value}',
|
||||
),
|
||||
Text(
|
||||
'Map: ${controller.map.length}',
|
||||
),
|
||||
TextButton(
|
||||
child: const Text("increment"),
|
||||
onPressed: () => controller.increment(),
|
||||
),
|
||||
GetX<Controller2>(builder: (controller) {
|
||||
return Text('lazy ${controller.lazy.value}');
|
||||
}),
|
||||
GetX<ControllerNonGlobal>(
|
||||
init: ControllerNonGlobal(),
|
||||
global: false,
|
||||
builder: (controller) {
|
||||
return Text('single ${controller.nonGlobal.value}');
|
||||
})
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text("Count: 0"), findsOneWidget);
|
||||
expect(find.text("Double: 0.0"), findsOneWidget);
|
||||
expect(find.text("String: string"), findsOneWidget);
|
||||
expect(find.text("Bool: true"), findsOneWidget);
|
||||
expect(find.text("List: 0"), findsOneWidget);
|
||||
expect(find.text("Map: 0"), findsOneWidget);
|
||||
|
||||
Controller.to.increment();
|
||||
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text("Count: 1"), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('increment'));
|
||||
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text("Count: 2"), findsOneWidget);
|
||||
expect(find.text("lazy 0"), findsOneWidget);
|
||||
expect(find.text("single 0"), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
class Controller2 extends GetxController {
|
||||
RxInt lazy = 0.obs;
|
||||
}
|
||||
|
||||
class ControllerNonGlobal extends GetxController {
|
||||
RxInt nonGlobal = 0.obs;
|
||||
}
|
||||
|
||||
class Controller extends GetxController {
|
||||
static Controller get to => Get.find();
|
||||
|
||||
RxInt counter = 0.obs;
|
||||
RxDouble doubleNum = 0.0.obs;
|
||||
RxString string = "string".obs;
|
||||
RxList list = [].obs;
|
||||
RxMap map = {}.obs;
|
||||
RxBool boolean = true.obs;
|
||||
|
||||
void increment() {
|
||||
counter.value++;
|
||||
}
|
||||
}
|
||||
107
packages/get/test/state_manager/get_state_test.dart
Normal file
107
packages/get/test/state_manager/get_state_test.dart
Normal file
@@ -0,0 +1,107 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
void main() {
|
||||
Get.lazyPut<Controller2>(Controller2.new);
|
||||
testWidgets("GetxController smoke test", (test) async {
|
||||
await test.pumpWidget(
|
||||
MaterialApp(
|
||||
home: GetBuilder<Controller>(
|
||||
init: Controller(),
|
||||
builder: (controller) => Column(
|
||||
children: [
|
||||
Text(
|
||||
'${controller.counter}',
|
||||
),
|
||||
TextButton(
|
||||
child: const Text("increment"),
|
||||
onPressed: () => controller.increment(),
|
||||
),
|
||||
TextButton(
|
||||
child: const Text("incrementWithId"),
|
||||
onPressed: () => controller.incrementWithId(),
|
||||
),
|
||||
GetBuilder<Controller>(
|
||||
id: '1',
|
||||
didChangeDependencies: (_) {
|
||||
// print("didChangeDependencies called");
|
||||
},
|
||||
builder: (controller) {
|
||||
return Text('id ${controller.counter}');
|
||||
}),
|
||||
GetBuilder<Controller2>(builder: (controller) {
|
||||
return Text('lazy ${controller.test}');
|
||||
}),
|
||||
GetBuilder<ControllerNonGlobal>(
|
||||
init: ControllerNonGlobal(),
|
||||
global: false,
|
||||
builder: (controller) {
|
||||
return Text('single ${controller.nonGlobal}');
|
||||
})
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text("0"), findsOneWidget);
|
||||
|
||||
Controller.to.increment();
|
||||
|
||||
await test.pump();
|
||||
|
||||
expect(find.text("1"), findsOneWidget);
|
||||
|
||||
await test.tap(find.text('increment'));
|
||||
|
||||
await test.pump();
|
||||
|
||||
expect(find.text("2"), findsOneWidget);
|
||||
|
||||
await test.tap(find.text('incrementWithId'));
|
||||
|
||||
await test.pump();
|
||||
|
||||
expect(find.text("id 3"), findsOneWidget);
|
||||
expect(find.text("lazy 0"), findsOneWidget);
|
||||
expect(find.text("single 0"), findsOneWidget);
|
||||
});
|
||||
|
||||
// testWidgets(
|
||||
// "MixinBuilder with build null",
|
||||
// (test) async {
|
||||
// expect(
|
||||
// () => GetBuilder<Controller>(
|
||||
// init: Controller(),
|
||||
// builder: null,
|
||||
// ),
|
||||
// throwsAssertionError,
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
}
|
||||
|
||||
class Controller extends GetxController {
|
||||
static Controller get to => Get.find();
|
||||
|
||||
int counter = 0;
|
||||
|
||||
void increment() {
|
||||
counter++;
|
||||
update();
|
||||
}
|
||||
|
||||
void incrementWithId() {
|
||||
counter++;
|
||||
update(['1']);
|
||||
}
|
||||
}
|
||||
|
||||
class Controller2 extends GetxController {
|
||||
int test = 0;
|
||||
}
|
||||
|
||||
class ControllerNonGlobal extends GetxController {
|
||||
int nonGlobal = 0;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../navigation/utils/wrapper.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets("Get.defaultDialog smoke test", (tester) async {
|
||||
await tester.pumpWidget(Wrapper(child: Container()));
|
||||
final BuildContext context = tester.element(find.byType(Container));
|
||||
|
||||
var mediaQuery = MediaQuery.of(context);
|
||||
expect(mediaQuery, context.mediaQuery);
|
||||
var mediaQuerySize = mediaQuery.size;
|
||||
expect(mediaQuerySize, context.mediaQuerySize);
|
||||
var theme = Theme.of(context);
|
||||
expect(theme, context.theme);
|
||||
var textTheme = theme.textTheme;
|
||||
expect(textTheme, context.textTheme);
|
||||
var devicePixelRatio = mediaQuery.devicePixelRatio;
|
||||
expect(devicePixelRatio, context.devicePixelRatio);
|
||||
var height = mediaQuerySize.height;
|
||||
expect(height, context.height);
|
||||
final heightTransformer =
|
||||
(mediaQuerySize.height - ((mediaQuerySize.height / 100) * 0)) / 1;
|
||||
expect(heightTransformer, context.heightTransformer());
|
||||
var iconColor = theme.iconTheme.color;
|
||||
expect(iconColor, context.iconColor);
|
||||
var isDarkMode = (theme.brightness == Brightness.dark);
|
||||
expect(isDarkMode, context.isDarkMode);
|
||||
var orientation = mediaQuery.orientation;
|
||||
expect(orientation, context.orientation);
|
||||
var isLandscape = orientation == Orientation.landscape;
|
||||
expect(isLandscape, context.isLandscape);
|
||||
var mediaQueryShortestSide = mediaQuerySize.shortestSide;
|
||||
expect(mediaQueryShortestSide, context.mediaQueryShortestSide);
|
||||
var isLargeTablet = (mediaQueryShortestSide >= 720);
|
||||
expect(isLargeTablet, context.isLargeTablet);
|
||||
var isPhone = (mediaQueryShortestSide < 600);
|
||||
expect(isPhone, context.isPhone);
|
||||
var isPortrait = orientation == Orientation.portrait;
|
||||
expect(isPortrait, context.isPortrait);
|
||||
var isSmallTablet = (mediaQueryShortestSide >= 600);
|
||||
expect(isSmallTablet, context.isSmallTablet);
|
||||
var isTablet = isSmallTablet || isLargeTablet;
|
||||
expect(isTablet, context.isTablet);
|
||||
var mediaQueryPadding = mediaQuery.padding;
|
||||
expect(mediaQueryPadding, context.mediaQueryPadding);
|
||||
var mediaQueryViewInsets = mediaQuery.viewInsets;
|
||||
expect(mediaQueryViewInsets, context.mediaQueryViewInsets);
|
||||
var mediaQueryViewPadding = mediaQuery.viewPadding;
|
||||
expect(mediaQueryViewPadding, context.mediaQueryViewPadding);
|
||||
var widthTransformer =
|
||||
(mediaQuerySize.width - ((mediaQuerySize.width / 100) * 0)) / 1;
|
||||
expect(widthTransformer, context.widthTransformer());
|
||||
var ratio = heightTransformer / widthTransformer;
|
||||
expect(ratio, context.ratio());
|
||||
var width = mediaQuerySize.width;
|
||||
expect(width, context.width);
|
||||
var showNavbar = (width > 800);
|
||||
expect(showNavbar, context.showNavbar);
|
||||
var textScaleFactor = mediaQuery.textScaleFactor;
|
||||
expect(textScaleFactor, context.textScaleFactor);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/utils.dart';
|
||||
|
||||
void main() {
|
||||
test('Test for toPrecision on Double', () {
|
||||
var testVar = 5.4545454;
|
||||
expect(testVar.toPrecision(2), equals(5.45));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/utils.dart';
|
||||
|
||||
void main() {
|
||||
test('String test', () {
|
||||
var value = 'string';
|
||||
var expected = '';
|
||||
void logFunction(String prefix, dynamic value, String info,
|
||||
{bool isError = false}) {
|
||||
expected = '$prefix $value $info'.trim();
|
||||
}
|
||||
|
||||
value.printError(logFunction: logFunction);
|
||||
expect(expected, 'Error: String string');
|
||||
});
|
||||
test('Int test', () {
|
||||
var value = 1;
|
||||
var expected = '';
|
||||
void logFunction(String prefix, dynamic value, String info,
|
||||
{bool isError = false}) {
|
||||
expected = '$prefix $value $info'.trim();
|
||||
}
|
||||
|
||||
value.printError(logFunction: logFunction);
|
||||
expect(expected, 'Error: int 1');
|
||||
});
|
||||
test('Double test', () {
|
||||
var value = 1.0;
|
||||
var expected = '';
|
||||
void logFunction(String prefix, dynamic value, String info,
|
||||
{bool isError = false}) {
|
||||
expected = '$prefix $value $info'.trim();
|
||||
}
|
||||
|
||||
value.printError(logFunction: logFunction);
|
||||
expect(expected, 'Error: double 1.0');
|
||||
});
|
||||
}
|
||||
45
packages/get/test/utils/extensions/num_extensions_test.dart
Normal file
45
packages/get/test/utils/extensions/num_extensions_test.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/utils.dart';
|
||||
|
||||
void main() {
|
||||
num x = 5;
|
||||
num y = 7;
|
||||
num z = 5;
|
||||
|
||||
var doubleX = 2.1;
|
||||
var doubleY = 3.1;
|
||||
var doubleZ = 5.0;
|
||||
var pi = 3.14159265359;
|
||||
|
||||
group('num extensions text', () {
|
||||
test('var.isLowerThan(value)', () {
|
||||
expect(x.isLowerThan(y), true);
|
||||
expect(y.isLowerThan(x), false);
|
||||
expect(x.isLowerThan(z), false);
|
||||
expect(doubleX.isLowerThan(doubleY), true);
|
||||
expect(doubleY.isLowerThan(pi), true);
|
||||
expect(x.isLowerThan(doubleX), false);
|
||||
expect(z.isLowerThan(doubleZ), false);
|
||||
});
|
||||
test('var.isGreaterThan(value)', () {
|
||||
expect(x.isGreaterThan(y), false);
|
||||
expect(y.isGreaterThan(x), true);
|
||||
expect(x.isGreaterThan(z), false);
|
||||
expect(doubleX.isGreaterThan(doubleY), false);
|
||||
expect(doubleY.isGreaterThan(pi), false);
|
||||
expect(pi.isGreaterThan(3.14159265359), false);
|
||||
expect(y.isGreaterThan(doubleY), true);
|
||||
expect(z.isGreaterThan(doubleZ), false);
|
||||
});
|
||||
test('var.isEqual(value)', () {
|
||||
expect(x.isEqual(y), false);
|
||||
expect(y.isEqual(x), false);
|
||||
expect(x.isEqual(5), true);
|
||||
expect(y.isEqual(7), true);
|
||||
expect(doubleX.isEqual(doubleY), false);
|
||||
expect(doubleY.isEqual(pi), false);
|
||||
expect(pi.isEqual(3.14159265359), true);
|
||||
expect(z.isEqual(doubleZ), true);
|
||||
});
|
||||
});
|
||||
}
|
||||
719
packages/get/test/utils/extensions/string_extensions_test.dart
Normal file
719
packages/get/test/utils/extensions/string_extensions_test.dart
Normal file
@@ -0,0 +1,719 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/utils.dart';
|
||||
|
||||
void main() {
|
||||
group('String extensions', () {
|
||||
const text = "oi";
|
||||
const digit = "5";
|
||||
const specialCaracters = "#\$!%@";
|
||||
const alphaNumeric = "123asd";
|
||||
const numbers = "123";
|
||||
const letters = "foo";
|
||||
// String notInitializedVar;
|
||||
|
||||
test('var.isNum', () {
|
||||
expect(digit.isNum, true);
|
||||
expect(text.isNum, false);
|
||||
});
|
||||
|
||||
test('var.isNumericOnly', () {
|
||||
expect(numbers.isNumericOnly, true);
|
||||
expect(letters.isNumericOnly, false);
|
||||
expect(specialCaracters.isNumericOnly, false);
|
||||
expect(alphaNumeric.isNumericOnly, false);
|
||||
});
|
||||
|
||||
test('var.isAlphabetOnly', () {
|
||||
expect(alphaNumeric.isAlphabetOnly, false);
|
||||
expect(numbers.isAlphabetOnly, false);
|
||||
expect(letters.isAlphabetOnly, true);
|
||||
});
|
||||
|
||||
test('var.isBool', () {
|
||||
const trueString = 'true';
|
||||
// expect(notInitializedVar.isBool, false);
|
||||
expect(letters.isBool, false);
|
||||
expect(trueString.isBool, true);
|
||||
});
|
||||
|
||||
test('var.isVectorFileName', () {
|
||||
const path = "logo.svg";
|
||||
const fullPath = "C:/Users/Getx/Documents/logo.svg";
|
||||
expect(path.isVectorFileName, true);
|
||||
expect(fullPath.isVectorFileName, true);
|
||||
expect(alphaNumeric.isVectorFileName, false);
|
||||
});
|
||||
|
||||
test('var.isImageFileName', () {
|
||||
const jpgPath = "logo.jpg";
|
||||
const jpegPath = "logo.jpeg";
|
||||
const pngPath = "logo.png";
|
||||
const gifPath = "logo.gif";
|
||||
const bmpPath = "logo.bmp";
|
||||
const svgPath = "logo.svg";
|
||||
|
||||
expect(jpgPath.isImageFileName, true);
|
||||
expect(jpegPath.isImageFileName, true);
|
||||
expect(pngPath.isImageFileName, true);
|
||||
expect(gifPath.isImageFileName, true);
|
||||
expect(bmpPath.isImageFileName, true);
|
||||
expect(svgPath.isImageFileName, false);
|
||||
});
|
||||
|
||||
test('var.isAudioFileName', () {
|
||||
const mp3Path = "logo.mp3";
|
||||
const wavPath = "logo.wav";
|
||||
const wmaPath = "logo.wma";
|
||||
const amrPath = "logo.amr";
|
||||
const oggPath = "logo.ogg";
|
||||
const svgPath = "logo.svg";
|
||||
|
||||
expect(mp3Path.isAudioFileName, true);
|
||||
expect(wavPath.isAudioFileName, true);
|
||||
expect(wmaPath.isAudioFileName, true);
|
||||
expect(amrPath.isAudioFileName, true);
|
||||
expect(oggPath.isAudioFileName, true);
|
||||
expect(svgPath.isAudioFileName, false);
|
||||
});
|
||||
|
||||
test('var.isVideoFileName', () {
|
||||
const mp4Path = "logo.mp4";
|
||||
const aviPath = "logo.avi";
|
||||
const wmvPath = "logo.wmv";
|
||||
const rmvbPath = "logo.rmvb";
|
||||
const mpgPath = "logo.mpg";
|
||||
const mpegPath = "logo.mpeg";
|
||||
const threegpPath = "logo.3gp";
|
||||
const svgPath = "logo.svg";
|
||||
|
||||
expect(mp4Path.isVideoFileName, true);
|
||||
expect(aviPath.isVideoFileName, true);
|
||||
expect(wmvPath.isVideoFileName, true);
|
||||
expect(rmvbPath.isVideoFileName, true);
|
||||
expect(mpgPath.isVideoFileName, true);
|
||||
expect(mpegPath.isVideoFileName, true);
|
||||
expect(threegpPath.isVideoFileName, true);
|
||||
expect(svgPath.isAudioFileName, false);
|
||||
});
|
||||
|
||||
test('var.isTxtFileName', () {
|
||||
const txtPath = 'file.txt';
|
||||
expect(txtPath.isTxtFileName, true);
|
||||
expect(alphaNumeric.isTxtFileName, false);
|
||||
});
|
||||
|
||||
test('var.isDocumentFileName', () {
|
||||
const docPath = "file.doc";
|
||||
const docxPath = "file.docx";
|
||||
|
||||
expect(docPath.isDocumentFileName, true);
|
||||
expect(docxPath.isDocumentFileName, true);
|
||||
expect(alphaNumeric.isDocumentFileName, false);
|
||||
});
|
||||
|
||||
test('var.isExcelFileName', () {
|
||||
const xlsPath = "file.xls";
|
||||
const xlsxPath = "file.xlsx";
|
||||
|
||||
expect(xlsPath.isExcelFileName, true);
|
||||
expect(xlsxPath.isExcelFileName, true);
|
||||
expect(alphaNumeric.isExcelFileName, false);
|
||||
});
|
||||
|
||||
test('var.isPPTFileName', () {
|
||||
const pptPath = "file.ppt";
|
||||
const pptxPath = "file.pptx";
|
||||
|
||||
expect(pptPath.isPPTFileName, true);
|
||||
expect(pptxPath.isPPTFileName, true);
|
||||
expect(alphaNumeric.isPPTFileName, false);
|
||||
});
|
||||
|
||||
test('var.isAPKFileName', () {
|
||||
const apkPath = "file.apk";
|
||||
|
||||
expect(apkPath.isAPKFileName, true);
|
||||
expect(alphaNumeric.isAPKFileName, false);
|
||||
});
|
||||
|
||||
test('var.isPDFFileName', () {
|
||||
const pdfPath = "file.pdf";
|
||||
|
||||
expect(pdfPath.isPDFFileName, true);
|
||||
expect(alphaNumeric.isPDFFileName, false);
|
||||
});
|
||||
test('var.isHTMLFileName', () {
|
||||
const htmlPath = "file.html";
|
||||
|
||||
expect(htmlPath.isHTMLFileName, true);
|
||||
expect(alphaNumeric.isHTMLFileName, false);
|
||||
});
|
||||
test('var.isURL', () {
|
||||
// Url's generated in https://www.randomlists.com/urls
|
||||
final urls = [
|
||||
'http://www.example.com/aunt/babies.aspx#act',
|
||||
'http://adjustment.example.com/bedroom/animal.htm',
|
||||
'http://blade.example.com/arch/basketball',
|
||||
'https://www.example.com/air/advice.php',
|
||||
'http://www.example.com/balance/arch.html?blow=aftermath&bait=bath',
|
||||
'http://authority.example.com/',
|
||||
'http://example.com/advice.html',
|
||||
'https://www.example.com/',
|
||||
'https://www.example.com/bee?act=art&bells=board',
|
||||
'http://example.org/',
|
||||
'https://www.example.com/',
|
||||
'https://example.com/bed',
|
||||
'https://www.example.edu/acoustics',
|
||||
'https://www.example.com/bells',
|
||||
'http://board.example.com/',
|
||||
'http://book.example.com/afterthought?advertisement=ball&birth=argument',
|
||||
'http://birds.example.org/ball.aspx?apparatus=border&brother=aftermath',
|
||||
'https://www.example.org/books/book?bedroom=birds',
|
||||
'http://advice.example.com/',
|
||||
'http://example.com/',
|
||||
'http://example.com/bedroom/alarm',
|
||||
'https://example.com/advice/approval',
|
||||
'http://anger.example.net/?breath=brother&air=bell#ball',
|
||||
'http://appliance.example.com/bee/badge',
|
||||
'http://www.example.org/berry.aspx',
|
||||
'http://example.org/',
|
||||
];
|
||||
|
||||
for (final url in urls) {
|
||||
expect(url.isURL, true);
|
||||
}
|
||||
expect(alphaNumeric.isURL, false);
|
||||
});
|
||||
test('var.isEmail', () {
|
||||
final emails = [
|
||||
'hellfire@comcast.net',
|
||||
'hllam@icloud.com',
|
||||
'tskirvin@live.com',
|
||||
'choset@comcast.net',
|
||||
'parksh@live.com',
|
||||
'kassiesa@yahoo.com',
|
||||
'kramulous@comcast.net',
|
||||
'froodian@me.com',
|
||||
'shawnce@yahoo.ca',
|
||||
'cgreuter@gmail.com',
|
||||
'aprakash@verizon.net',
|
||||
'dhrakar@gmail.com',
|
||||
'wmszeliga@yahoo.ca',
|
||||
'bmorrow@icloud.com',
|
||||
'seurat@comcast.net',
|
||||
'dialworld@yahoo.ca',
|
||||
'johndo@yahoo.ca',
|
||||
'empathy@yahoo.com.pt',
|
||||
'openldap@verizon.net',
|
||||
'elflord@outlook.com',
|
||||
'kaiser@me.com',
|
||||
'carcus@att.net',
|
||||
'garland@hotmail.com',
|
||||
'clkao@yahoo.ca',
|
||||
'daveed@mac.com',
|
||||
'parasite@icloud.com',
|
||||
'drolsky@aol.com',
|
||||
'reziac@outlook.com',
|
||||
'storerm@yahoo.ca',
|
||||
'johnbob@hotmail.com.br',
|
||||
];
|
||||
|
||||
for (final email in emails) {
|
||||
expect(email.isEmail, true);
|
||||
}
|
||||
expect(alphaNumeric.isEmail, false);
|
||||
});
|
||||
test('var.isPhoneNumber', () {
|
||||
final phoneNumbers = [
|
||||
'+1202-555-0145',
|
||||
'+1202-555-0139',
|
||||
'+1202-555-0101',
|
||||
'+1202-555-0136',
|
||||
'+1202-555-0190',
|
||||
'+1202-555-0156',
|
||||
'(738) 952-5253',
|
||||
'(861) 965-1597',
|
||||
'(732) 372-9760',
|
||||
'(532) 766-4719',
|
||||
'(987) 472-7813',
|
||||
'(455) 443-8171',
|
||||
'(915) 685-8658',
|
||||
'(572) 207-1898',
|
||||
'(81) 6 2499-9538',
|
||||
'(31) 32304-4263',
|
||||
'(64) 25242-6375',
|
||||
'(41) 19308-7925',
|
||||
'(67) 61684-0395',
|
||||
'(60) 54706-3569',
|
||||
'(31) 33110055',
|
||||
'(11) 3344-5599',
|
||||
'(31) 977447788',
|
||||
'(31) 66557744',
|
||||
'(21) 946576541',
|
||||
'(11) 3432-3333',
|
||||
'02131973585858'
|
||||
];
|
||||
|
||||
for (final phone in phoneNumbers) {
|
||||
// print('testing $phone');
|
||||
expect(phone.isPhoneNumber, true);
|
||||
}
|
||||
|
||||
const bigRandomNumber = '168468468465241327987624987327987';
|
||||
expect(bigRandomNumber.isPhoneNumber, false);
|
||||
|
||||
expect(alphaNumeric.isPhoneNumber, false);
|
||||
});
|
||||
test('var.isDateTime', () {
|
||||
final dateTimes = [
|
||||
'2003-07-05 05:51:47.000Z',
|
||||
'1991-05-11 11:57:30.000Z',
|
||||
'2002-01-04 10:00:41.000Z',
|
||||
'1995-11-04 19:43:25.000Z',
|
||||
'2006-07-12 20:06:46.000Z',
|
||||
'2000-08-10 00:06:23.000Z',
|
||||
'1998-07-31 10:56:50.000Z',
|
||||
'1995-04-27 11:49:34.000Z',
|
||||
'1998-07-26 15:43:11.000Z',
|
||||
'1999-02-04 10:03:01.000Z',
|
||||
'1998-05-02 12:17:55.000Z',
|
||||
'2013-05-26 10:47:22.000Z',
|
||||
'1991-07-07 20:25:42.000Z',
|
||||
'2018-11-03 09:27:38.000Z',
|
||||
'1992-12-22 08:20:26.000Z',
|
||||
'1997-07-01 23:11:59.000Z',
|
||||
'2012-04-13 16:00:04.000Z',
|
||||
'1997-01-06 18:37:51.000Z',
|
||||
'2008-08-23 11:11:29.000Z',
|
||||
'1996-02-06 03:46:43.000Z',
|
||||
'2016-01-03 10:57:15.000Z',
|
||||
'2014-04-16 17:20:50.000Z',
|
||||
'1994-07-13 03:55:16.000Z',
|
||||
'2004-11-15 03:45:11.000Z',
|
||||
'2007-12-18 18:21:21.000Z',
|
||||
'1995-01-31 03:55:44.000Z',
|
||||
'2013-08-09 04:48:37.000Z',
|
||||
'2001-09-07 17:13:55.000Z',
|
||||
'1993-06-18 13:21:21.000Z',
|
||||
'1991-02-06 03:05:47.000Z',
|
||||
'2000-09-22 18:48:55.000Z',
|
||||
'2000-06-01 02:13:57.000Z',
|
||||
'1991-08-07 21:08:35.000Z',
|
||||
'1998-08-15 07:27:12.000Z',
|
||||
'2002-07-03 10:34:25.000Z',
|
||||
'2013-10-05 00:37:45.000Z',
|
||||
'2012-09-10 20:07:21.000Z',
|
||||
'2017-06-18 14:38:06.000Z',
|
||||
'2000-03-09 11:27:49.000Z',
|
||||
'2016-01-16 22:01:20.000Z',
|
||||
];
|
||||
|
||||
for (final dateTime in dateTimes) {
|
||||
// print('testing $dateTime');
|
||||
expect(dateTime.isDateTime, true);
|
||||
}
|
||||
expect(alphaNumeric.isDateTime, false);
|
||||
});
|
||||
test('var.isMD5', () {
|
||||
final md5s = [
|
||||
'176cfa006065a2a2bd8d3f1f83531b64',
|
||||
'713fca6d088132e863497a79d1bd9572',
|
||||
'7decc2fb2aca5cbd8a2cae5de1b50edb',
|
||||
'85ed9bc4e4a8ae65add67886f5dfe02f',
|
||||
'e4f0097f84a11f0298c83ecf6aa0fec3',
|
||||
'70a2712b47127b431d7119b3a511b145',
|
||||
'dd54069e3f97787e79592f6e3a307e93',
|
||||
'5b64677b69da7370ee69523281ce935c',
|
||||
'6150ce23f4b071e1cde49021b57c5a17',
|
||||
'2781566b09a84a695297482cdcb1ffd0',
|
||||
'54fe4ce16862aac01768b5831390d557',
|
||||
'2747268afaa9898a320b8cc5580f143e',
|
||||
'ce3c2d105fb2740c5bf59347b47603a8',
|
||||
'cccef3bbc8cd2530c6de78af586ebcee',
|
||||
'502115b10c767f50ab55270be095512e',
|
||||
'b084ea385e849eaedf4fefaf6dd5f1a9',
|
||||
'1f167339977225fe63a86388083fc64f',
|
||||
'6abd5f472dba5e4688ad6dd14f975870',
|
||||
'7e7f9ef53fb6e3ce2a4fb56665548eb8',
|
||||
'de134fce82421dd2b3fab751fbfa190d',
|
||||
'b0d8492572a52d1f2360535612c5dc82',
|
||||
];
|
||||
|
||||
for (final md5 in md5s) {
|
||||
expect(md5.isMD5, true);
|
||||
}
|
||||
|
||||
expect(alphaNumeric.isMD5, false);
|
||||
});
|
||||
test('var.isSHA1', () {
|
||||
final sha1s = [
|
||||
'1A310CF5DC8CE513586F74EE19CE90BD4BCC5AED',
|
||||
'B458B077B5075C316CFD03619D627F529A0555BF',
|
||||
'902C6A2850B4348BE445D637689CCAE5C5EF3552',
|
||||
'8DC86C0DD0FD2960D62573AB142F90572A7421D5',
|
||||
'7E18C8EA5F05BB2F385A9E34657B8D439A83BF82',
|
||||
'3EC857A133E801C0B3198371C17C1A3A3D73DFE8',
|
||||
'E32590E41805BEFD524205DAE0A56F429DCCC4E7',
|
||||
'943A9164A126457203680B49F0309B5F15F0117E',
|
||||
'C5E1442484AF49A92E1CC51F95AE4E8305F49DB6',
|
||||
'B0C3B071F8ADBEE2222AA07ECFF51C3C040AA0A0',
|
||||
'722ED6929057BF801F29590C423A40F4EF8C710E',
|
||||
'F484FA4DC5EC1E063F0752112D9BF3B9763D6E41',
|
||||
'2A87522644011223A27FD62C87FA926A1838F271',
|
||||
];
|
||||
|
||||
for (final sha1 in sha1s) {
|
||||
expect(sha1.isSHA1, true);
|
||||
}
|
||||
|
||||
expect(alphaNumeric.isSHA1, false);
|
||||
});
|
||||
test('var.isSHA256', () {
|
||||
final sha256s = [
|
||||
'FC694FFE78167EAE21EA4EBF072D8AB6ECF847162D1F65600BF019BA9805DB2D',
|
||||
'3B64F1C349B548E72688A8EEFFA2F418A62BA2E22CF5BD954B4B1912C963D7FA',
|
||||
'EF69D763148B8A222980BD164943F754937DF12771083889DDB69C18245C2904',
|
||||
'9896D3134156E546FFC003C2C9CFED88D46C2BC214B39CF21192EAAF875A7C0A',
|
||||
'2C70E9735D7DAB56427BAA09E6C63912BEAD9C7938F6B16C4954B78F46D1C3CF',
|
||||
'423E095C8074BC1C440D874D999C18025445CD39211D98362E827E55863DD0B2',
|
||||
'4FCDB44D5521663F713A5821DE9401D64D44050C2AF62EBA758B1D128AC4C279',
|
||||
'BD91C9BBC044C94C283D0DF3AA1E8CDBF1BF35BF325E8196BA15FCA5238A3A40',
|
||||
'7B9434447F3B1236221D40CB707D1909886CC9E8CA25EB18DCCFDC70F0A3AE9F',
|
||||
'FBD3A0B1C5F9906EF3BFB5EDD846F77BA252070E036EC1F4F57BDD912F02987D',
|
||||
'B8369EE116ADE797285DC973DDAA69433F255DC0AEEC7936378D4D08B2A7FDD2',
|
||||
'6B6FE6891A5DFCCF2900A2A1F513196827AF5A95AB2DE1590B878BEFCCF12603',
|
||||
'F2CB3614CD070450912EBEC399C63527D2A839C4E5BB2FE281BA1C5D5EA64257',
|
||||
'822805E8FA05909AD7D3D6DBFBB1AE61D7A3C70209DB2A37C415BD5E11764866',
|
||||
'40DAC792B52101BB1506AD880F0378EFACF46B019427A3D0E01DE2B09B06B6ED',
|
||||
'E765A129579AF2F31C681973844490F8EA146DA8ADC07671F9FB71F0FE10E296',
|
||||
'2B5B6DC7EF398D1420D23327295BCDCDDA8AAEDB7FE6C6129D1D31432B676CB7',
|
||||
'67F20826370162C472791055E10E44624D40E35F29E60592B239692836474323',
|
||||
'BD16B1ED024E353B5B2334201EC63C0B3E181F0DFD226A36825EF18F6A7D8D97',
|
||||
'AC98F969AA56810BE672C770BE30EF79F7F77AE6EFB2A90D56FA2AD5506D8BD7',
|
||||
];
|
||||
|
||||
for (final sha256 in sha256s) {
|
||||
expect(sha256.isSHA256, true);
|
||||
}
|
||||
|
||||
expect(alphaNumeric.isSHA256, false);
|
||||
});
|
||||
test('var.isBinary', () {
|
||||
final binaries = [
|
||||
'00111100',
|
||||
'00001111',
|
||||
'10110110',
|
||||
'01101110',
|
||||
'01110101',
|
||||
'00010100',
|
||||
'11100010',
|
||||
'11000001',
|
||||
'11000110',
|
||||
'11011101',
|
||||
'10001101',
|
||||
'10101110',
|
||||
'11001110',
|
||||
'10001011',
|
||||
'11111101',
|
||||
'11010110',
|
||||
'11110011',
|
||||
'01111010',
|
||||
'11110011',
|
||||
'01000111',
|
||||
];
|
||||
|
||||
for (final binary in binaries) {
|
||||
expect(binary.isBinary, true);
|
||||
}
|
||||
|
||||
expect(alphaNumeric.isBinary, false);
|
||||
});
|
||||
test('var.isIPv4', () {
|
||||
final ipv4s = [
|
||||
'155.162.247.250',
|
||||
'121.99.222.180',
|
||||
'142.197.183.237',
|
||||
'176.60.213.134',
|
||||
'12.190.123.58',
|
||||
'105.75.28.173',
|
||||
'121.120.116.138',
|
||||
'20.195.194.189',
|
||||
'234.171.207.97',
|
||||
'153.122.129.170',
|
||||
'224.226.28.80',
|
||||
'236.196.62.84',
|
||||
'122.71.160.46',
|
||||
'151.24.85.63',
|
||||
'37.109.242.32',
|
||||
'235.47.62.53',
|
||||
'151.1.242.190',
|
||||
'227.197.221.85',
|
||||
'12.118.136.231',
|
||||
'51.73.246.208',
|
||||
];
|
||||
|
||||
for (final ipv4 in ipv4s) {
|
||||
expect(ipv4.isIPv4, true);
|
||||
}
|
||||
|
||||
expect(alphaNumeric.isIPv4, false);
|
||||
});
|
||||
test('var.isIPv6', () {
|
||||
final ipv6s = [
|
||||
'f856:62fc:9091:e649:e928:d771:f40c:1439',
|
||||
'b8d5:3f85:5ae5:c63a:6b5f:f7e6:ea6b:871d',
|
||||
'2f91:979a:90b0:55d1:40b7:3e6f:a210:598e',
|
||||
'd35d:49fc:fbe4:9841:e4d3:f006:b04b:e242',
|
||||
'2e0f:2912:e4e8:33d5:e833:0ac5:c73a:30b3',
|
||||
'6af9:878a:a80f:f520:fc2b:a05c:b0dd:b93f',
|
||||
'3329:1ce5:ab09:0120:945c:057b:ed4a:7869',
|
||||
'b77d:5523:2f1b:ff07:93a5:378f:a9c7:e2f2',
|
||||
'b669:64fa:1be7:af47:28fc:07f4:38bd:ae05',
|
||||
'aa77:1f7e:8539:a01a:706d:6f74:7fc3:8407',
|
||||
'16f9:9bcc:32d6:96de:5087:620b:c0c0:25cb',
|
||||
'baad:273f:7e63:29cd:c742:c1ed:d0f9:062d',
|
||||
'ae62:5b09:05fa:4611:5da9:a40a:f1ef:2a9d',
|
||||
'4d2a:353a:9f6b:2070:9605:ab97:92c0:7956',
|
||||
'bfcb:39f8:5119:458f:85fa:9e54:8c53:acd5',
|
||||
'0c1a:c6f3:06af:9588:23b4:e7fb:c307:febd',
|
||||
'ddaa:3c91:f554:dbe5:8447:9464:a9ae:2200',
|
||||
'8787:c939:5002:a4f6:19b2:6521:4cde:8111',
|
||||
'b515:5c17:6590:46dd:4ca8:1db3:a86c:e006',
|
||||
'1083:d492:f42e:2c99:f050:f67f:07c5:23f9',
|
||||
];
|
||||
|
||||
for (final ipv6 in ipv6s) {
|
||||
expect(ipv6.isIPv6, true);
|
||||
}
|
||||
|
||||
expect(alphaNumeric.isIPv6, false);
|
||||
});
|
||||
test('var.isHexadecimal', () {
|
||||
final hexadecimals = [
|
||||
'#56E97B',
|
||||
'#597E2A',
|
||||
'#F45D5C',
|
||||
'#A350DC',
|
||||
'#2DA48E',
|
||||
'#98CB3C',
|
||||
'#F7DCD1',
|
||||
'#B1F9BE',
|
||||
'#D17855',
|
||||
'#6F35CB',
|
||||
'#DCBE21',
|
||||
'#4C2E46',
|
||||
'#145F3F',
|
||||
'#F9776D',
|
||||
'#62E9DC',
|
||||
'#2F1030',
|
||||
'#C4F888',
|
||||
'#8E6D85',
|
||||
'#8C64CE',
|
||||
'#4DFF4E',
|
||||
];
|
||||
|
||||
for (final hexadecimal in hexadecimals) {
|
||||
expect(hexadecimal.isHexadecimal, true);
|
||||
}
|
||||
|
||||
expect(alphaNumeric.isHexadecimal, false);
|
||||
});
|
||||
test('var.isPalindrom', () {
|
||||
final palindroms = [
|
||||
'Anna',
|
||||
'Civic',
|
||||
'Kayak',
|
||||
'Level',
|
||||
'Madam',
|
||||
'Mom',
|
||||
'Noon',
|
||||
'Racecar',
|
||||
'Radar',
|
||||
'Redder',
|
||||
'Refer',
|
||||
'Repaper',
|
||||
'Don\'t nod.',
|
||||
'I did, did I?',
|
||||
'My gym',
|
||||
'Red rum, sir, is murder',
|
||||
'Step on no pets',
|
||||
'Top spot',
|
||||
'Was it a cat I saw?',
|
||||
'Eva, can I see bees in a cave?',
|
||||
'No lemon, no melon',
|
||||
'A base do teto desaba.',
|
||||
'A cara rajada da jararaca.',
|
||||
'Acuda cadela da Leda caduca.',
|
||||
'A dama admirou o rim da amada.',
|
||||
'A Daniela ama a lei? Nada!',
|
||||
|
||||
// TODO make isPalindrom regex support UTF8 characters
|
||||
// 'Adias a data da saída.',
|
||||
// 'A diva em Argel alegra-me a vida.',
|
||||
// 'A droga do dote é todo da gorda.',
|
||||
// 'A gorda ama a droga.',
|
||||
// 'A grama é amarga.',
|
||||
// 'Aí, Lima falou: “Olá, família!”.',
|
||||
// 'anã',
|
||||
// 'anilina',
|
||||
// 'ata',
|
||||
// 'arara',
|
||||
// 'asa',
|
||||
// 'ele',
|
||||
// 'esse',
|
||||
// 'mamam',
|
||||
// 'matam',
|
||||
// 'metem',
|
||||
// 'mirim',
|
||||
// 'oco',
|
||||
// 'omissíssimo',
|
||||
];
|
||||
for (final palindrom in palindroms) {
|
||||
// print("testing $palindrom");
|
||||
expect(palindrom.isPalindrom, true);
|
||||
}
|
||||
expect(alphaNumeric.isPalindrom, false);
|
||||
});
|
||||
test('var.isPassport', () {
|
||||
final passports = [
|
||||
'12ss46',
|
||||
'jdmg5dg',
|
||||
'5f7fj5d7',
|
||||
'w8a9s6f3z',
|
||||
];
|
||||
|
||||
for (final passport in passports) {
|
||||
expect(passport.isPassport, true);
|
||||
}
|
||||
|
||||
expect(specialCaracters.isPassport, false);
|
||||
});
|
||||
|
||||
test('var.isCurrency', () {
|
||||
final currencies = [
|
||||
'R\$50.58',
|
||||
'\$82.48',
|
||||
'₩54.24',
|
||||
'¥81.04',
|
||||
'€4.06',
|
||||
'₹37.40',
|
||||
'₽18.12',
|
||||
'fr95.15',
|
||||
'R81.04',
|
||||
'9.35USD',
|
||||
'98.48AUD',
|
||||
'29.20NZD',
|
||||
'50.58CAD',
|
||||
'82.48CHF',
|
||||
'54.24GBP',
|
||||
'81.04CNY',
|
||||
'4.06EUR',
|
||||
'37.40JPY',
|
||||
'18.12IDR',
|
||||
'95.15MXN',
|
||||
'81.04NOK',
|
||||
'9.35KRW',
|
||||
'98.48TRY',
|
||||
'29.20INR',
|
||||
];
|
||||
|
||||
for (final currency in currencies) {
|
||||
// print('currency $currency');
|
||||
expect(currency.isCurrency, true);
|
||||
}
|
||||
|
||||
expect(specialCaracters.isCurrency, false);
|
||||
});
|
||||
|
||||
test('var.isCpf', () {
|
||||
final cpfs = [
|
||||
'370.559.380-31',
|
||||
'055.878.430-50',
|
||||
'655.232.870-24',
|
||||
'86497047000',
|
||||
'12341309046',
|
||||
'31496294033',
|
||||
];
|
||||
|
||||
for (final cpf in cpfs) {
|
||||
expect(cpf.isCpf, true);
|
||||
}
|
||||
|
||||
expect(specialCaracters.isCpf, false);
|
||||
});
|
||||
test('var.isCnpj', () {
|
||||
final cnpjs = [
|
||||
'11.066.893/0001-94',
|
||||
'21.883.660/0001-38',
|
||||
'59.705.218/0001-94',
|
||||
];
|
||||
|
||||
for (final cnpj in cnpjs) {
|
||||
expect(cnpj.isCnpj, true);
|
||||
}
|
||||
|
||||
expect(specialCaracters.isCnpj, false);
|
||||
});
|
||||
|
||||
test('var.isCaseInsensitiveContains(string)', () {
|
||||
const phrase = 'Back to Square One';
|
||||
|
||||
expect(phrase.isCaseInsensitiveContains('to'), true);
|
||||
expect(phrase.isCaseInsensitiveContains('square'), true);
|
||||
expect(phrase.isCaseInsensitiveContains('On'), true);
|
||||
expect(phrase.isCaseInsensitiveContains('foo'), false);
|
||||
});
|
||||
|
||||
test('var.isCaseInsensitiveContainsAny(string)', () {
|
||||
const phrase = 'Back to Square One';
|
||||
|
||||
expect(phrase.isCaseInsensitiveContainsAny('to'), true);
|
||||
expect(phrase.isCaseInsensitiveContainsAny('square'), true);
|
||||
expect(phrase.isCaseInsensitiveContainsAny('On'), true);
|
||||
expect(phrase.isCaseInsensitiveContainsAny('foo'), false);
|
||||
expect('to'.isCaseInsensitiveContainsAny(phrase), true);
|
||||
expect('square'.isCaseInsensitiveContainsAny('qu'), true);
|
||||
});
|
||||
|
||||
test('var.capitalize', () {
|
||||
expect('foo bar'.capitalize, 'Foo Bar');
|
||||
expect('FoO bAr'.capitalize, 'Foo Bar');
|
||||
expect('FOO BAR'.capitalize, 'Foo Bar');
|
||||
// expect(null.capitalize, null);
|
||||
expect(''.capitalize, '');
|
||||
expect('foo bar '.capitalize, 'Foo Bar ');
|
||||
});
|
||||
|
||||
test('var.capitalizeFirst', () {
|
||||
expect('foo bar'.capitalizeFirst, 'Foo bar');
|
||||
expect('FoO bAr'.capitalizeFirst, 'Foo bar');
|
||||
expect('FOO BAR'.capitalizeFirst, 'Foo bar');
|
||||
// expect(null.capitalizeFirst, null);
|
||||
expect(''.capitalizeFirst, '');
|
||||
});
|
||||
|
||||
test('var.removeAllWhitespace', () {
|
||||
//late String nullString;
|
||||
expect('foo bar'.removeAllWhitespace, 'foobar');
|
||||
expect('foo'.removeAllWhitespace, 'foo');
|
||||
expect(''.removeAllWhitespace, '');
|
||||
// expect(nullString.removeAllWhitespace, null);
|
||||
});
|
||||
|
||||
test('var.camelCase', () {
|
||||
expect('foo bar'.camelCase, 'fooBar');
|
||||
expect('the fox jumped in the water'.camelCase, 'theFoxJumpedInTheWater');
|
||||
expect('foo_bar'.camelCase, 'fooBar');
|
||||
expect(''.camelCase, null);
|
||||
});
|
||||
|
||||
test('var.numericOnly()', () {
|
||||
expect('date: 2020/09/13, time: 00:00'.numericOnly(), '202009130000');
|
||||
expect(
|
||||
'and 1, and 2, and 1 2 3'.numericOnly(),
|
||||
'12123',
|
||||
);
|
||||
expect(''.numericOnly(), '');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/utils.dart';
|
||||
|
||||
class Foo extends StatelessWidget {
|
||||
const Foo({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('Group test for PaddingX Extension', () {
|
||||
testWidgets('Test of paddingAll', (tester) async {
|
||||
Widget containerTest = const Foo();
|
||||
|
||||
expect(find.byType(Padding), findsNothing);
|
||||
|
||||
await tester.pumpWidget(containerTest.paddingAll(16));
|
||||
|
||||
expect(find.byType(Padding), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Test of paddingOnly', (tester) async {
|
||||
Widget containerTest = const Foo();
|
||||
|
||||
expect(find.byType(Padding), findsNothing);
|
||||
|
||||
await tester.pumpWidget(containerTest.paddingOnly(top: 16));
|
||||
|
||||
expect(find.byType(Padding), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Test of paddingSymmetric', (tester) async {
|
||||
Widget containerTest = const Foo();
|
||||
|
||||
expect(find.byType(Padding), findsNothing);
|
||||
|
||||
await tester.pumpWidget(containerTest.paddingSymmetric(vertical: 16));
|
||||
|
||||
expect(find.byType(Padding), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Test of paddingZero', (tester) async {
|
||||
Widget containerTest = const Foo();
|
||||
|
||||
expect(find.byType(Padding), findsNothing);
|
||||
|
||||
await tester.pumpWidget(containerTest.paddingZero);
|
||||
|
||||
expect(find.byType(Padding), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
group('Group test for MarginX Extension', () {
|
||||
testWidgets('Test of marginAll', (tester) async {
|
||||
Widget containerTest = const Foo();
|
||||
|
||||
await tester.pumpWidget(containerTest.marginAll(16));
|
||||
|
||||
expect(find.byType(Container), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Test of marginOnly', (tester) async {
|
||||
Widget containerTest = const Foo();
|
||||
|
||||
await tester.pumpWidget(containerTest.marginOnly(top: 16));
|
||||
|
||||
expect(find.byType(Container), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Test of marginSymmetric', (tester) async {
|
||||
Widget containerTest = const Foo();
|
||||
|
||||
await tester.pumpWidget(containerTest.marginSymmetric(vertical: 16));
|
||||
|
||||
expect(find.byType(Container), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Test of marginZero', (tester) async {
|
||||
Widget containerTest = const Foo();
|
||||
|
||||
await tester.pumpWidget(containerTest.marginZero);
|
||||
|
||||
expect(find.byType(Container), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
114
packages/get/test/utils/get_utils_test.dart
Normal file
114
packages/get/test/utils/get_utils_test.dart
Normal file
@@ -0,0 +1,114 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class TestClass {
|
||||
final name = "John";
|
||||
}
|
||||
|
||||
class EmptyClass {}
|
||||
|
||||
void main() {
|
||||
dynamic _id(dynamic e) => e;
|
||||
|
||||
test('null isNullOrBlank should be true for null', () {
|
||||
expect(GetUtils.isNullOrBlank(null), true);
|
||||
});
|
||||
|
||||
test('isNullOrBlank should be false for unsupported types', () {
|
||||
expect(GetUtils.isNullOrBlank(5), false);
|
||||
expect(GetUtils.isNullOrBlank(0), false);
|
||||
|
||||
expect(GetUtils.isNullOrBlank(5.0), equals(false));
|
||||
expect(GetUtils.isNullOrBlank(0.0), equals(false));
|
||||
|
||||
TestClass? testClass;
|
||||
expect(GetUtils.isNullOrBlank(testClass), equals(true));
|
||||
expect(GetUtils.isNullOrBlank(TestClass()), equals(false));
|
||||
expect(GetUtils.isNullOrBlank(EmptyClass()), equals(false));
|
||||
});
|
||||
|
||||
test('isNullOrBlank should validate strings', () {
|
||||
expect(GetUtils.isNullOrBlank(""), true);
|
||||
expect(GetUtils.isNullOrBlank(" "), true);
|
||||
|
||||
expect(GetUtils.isNullOrBlank("foo"), false);
|
||||
expect(GetUtils.isNullOrBlank(" foo "), false);
|
||||
|
||||
expect(GetUtils.isNullOrBlank("null"), false);
|
||||
});
|
||||
|
||||
test('isNullOrBlank should validate iterables', () {
|
||||
expect(GetUtils.isNullOrBlank([].map(_id)), true);
|
||||
expect(GetUtils.isNullOrBlank([1].map(_id)), false);
|
||||
});
|
||||
|
||||
test('isNullOrBlank should validate lists', () {
|
||||
expect(GetUtils.isNullOrBlank(const []), true);
|
||||
expect(GetUtils.isNullOrBlank(['oi', 'foo']), false);
|
||||
expect(GetUtils.isNullOrBlank([{}, {}]), false);
|
||||
expect(GetUtils.isNullOrBlank(['foo'][0]), false);
|
||||
});
|
||||
|
||||
test('isNullOrBlank should validate sets', () {
|
||||
expect(GetUtils.isNullOrBlank(<dynamic>{}), true);
|
||||
expect(GetUtils.isNullOrBlank({1}), false);
|
||||
expect(GetUtils.isNullOrBlank({'fluorine', 'chlorine', 'bromine'}), false);
|
||||
});
|
||||
|
||||
test('isNullOrBlank should validate maps', () {
|
||||
expect(GetUtils.isNullOrBlank({}), true);
|
||||
expect(GetUtils.isNullOrBlank({1: 1}), false);
|
||||
expect(GetUtils.isNullOrBlank({"other": "thing"}), false);
|
||||
|
||||
final map = {"foo": 'bar', "one": "um"};
|
||||
expect(GetUtils.isNullOrBlank(map["foo"]), false);
|
||||
expect(GetUtils.isNullOrBlank(map["other"]), true);
|
||||
});
|
||||
group('GetUtils.isLength* functions', () {
|
||||
test('isLengthEqualTo should validate iterable lengths', () {
|
||||
// iterables should cover list and set
|
||||
expect(GetUtils.isLengthEqualTo([].map(_id), 0), true);
|
||||
expect(GetUtils.isLengthEqualTo([1, 2].map(_id), 2), true);
|
||||
|
||||
expect(GetUtils.isLengthEqualTo({}, 0), true);
|
||||
expect(GetUtils.isLengthEqualTo({1: 1, 2: 1}, 2), true);
|
||||
expect(GetUtils.isLengthEqualTo({}, 2), false);
|
||||
|
||||
expect(GetUtils.isLengthEqualTo("", 0), true);
|
||||
expect(GetUtils.isLengthEqualTo("a", 0), false);
|
||||
expect(GetUtils.isLengthEqualTo("a", 1), true);
|
||||
});
|
||||
|
||||
test('isLengthGreaterOrEqual should validate lengths', () {
|
||||
// iterables should cover list and set
|
||||
expect(GetUtils.isLengthGreaterOrEqual([].map(_id), 0), true);
|
||||
expect(GetUtils.isLengthGreaterOrEqual([1, 2].map(_id), 2), true);
|
||||
expect(GetUtils.isLengthGreaterOrEqual([1, 2].map(_id), 1), true);
|
||||
|
||||
expect(GetUtils.isLengthGreaterOrEqual({}, 0), true);
|
||||
expect(GetUtils.isLengthGreaterOrEqual({1: 1, 2: 1}, 1), true);
|
||||
expect(GetUtils.isLengthGreaterOrEqual({1: 1, 2: 1}, 2), true);
|
||||
expect(GetUtils.isLengthGreaterOrEqual({}, 2), false);
|
||||
|
||||
expect(GetUtils.isLengthGreaterOrEqual("", 0), true);
|
||||
expect(GetUtils.isLengthGreaterOrEqual("a", 0), true);
|
||||
expect(GetUtils.isLengthGreaterOrEqual("", 1), false);
|
||||
});
|
||||
|
||||
test('isLengthLessOrEqual should validate lengths', () {
|
||||
// iterables should cover list and set
|
||||
expect(GetUtils.isLengthLessOrEqual([].map(_id), 0), true);
|
||||
expect(GetUtils.isLengthLessOrEqual([1, 2].map(_id), 2), true);
|
||||
expect(GetUtils.isLengthLessOrEqual([1, 2].map(_id), 1), false);
|
||||
|
||||
expect(GetUtils.isLengthLessOrEqual({}, 0), true);
|
||||
expect(GetUtils.isLengthLessOrEqual({1: 1, 2: 1}, 1), false);
|
||||
expect(GetUtils.isLengthLessOrEqual({1: 1, 2: 1}, 3), true);
|
||||
expect(GetUtils.isLengthLessOrEqual({}, 2), true);
|
||||
|
||||
expect(GetUtils.isLengthLessOrEqual("", 0), true);
|
||||
expect(GetUtils.isLengthLessOrEqual("a", 2), true);
|
||||
expect(GetUtils.isLengthLessOrEqual("a", 0), false);
|
||||
});
|
||||
});
|
||||
}
|
||||
16
packages/get/test/utils/platform_test.dart
Normal file
16
packages/get/test/utils/platform_test.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
@TestOn('vm')
|
||||
import 'dart:io';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
void main() {
|
||||
test('Platform test', () {
|
||||
expect(GetPlatform.isAndroid, Platform.isAndroid);
|
||||
expect(GetPlatform.isIOS, Platform.isIOS);
|
||||
expect(GetPlatform.isFuchsia, Platform.isFuchsia);
|
||||
expect(GetPlatform.isLinux, Platform.isLinux);
|
||||
expect(GetPlatform.isMacOS, Platform.isMacOS);
|
||||
expect(GetPlatform.isWindows, Platform.isWindows);
|
||||
expect(GetPlatform.isWeb, false);
|
||||
});
|
||||
}
|
||||
16
packages/get/test/utils/platform_web_test.dart
Normal file
16
packages/get/test/utils/platform_web_test.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
@TestOn('browser')
|
||||
import 'dart:io';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
void main() {
|
||||
test('Platform test', () {
|
||||
expect(GetPlatform.isAndroid, Platform.isAndroid);
|
||||
expect(GetPlatform.isIOS, Platform.isIOS);
|
||||
expect(GetPlatform.isFuchsia, Platform.isFuchsia);
|
||||
expect(GetPlatform.isLinux, Platform.isLinux);
|
||||
expect(GetPlatform.isMacOS, Platform.isMacOS);
|
||||
expect(GetPlatform.isWindows, Platform.isWindows);
|
||||
expect(GetPlatform.isWeb, true);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user