From 38bbbc7360e602b43a53679d2b1f34a0728ea93a Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Mon, 26 Jun 2023 17:59:04 +0200 Subject: [PATCH 1/3] neon: test HexColor --- .../neon/neon/lib/src/utils/hex_color.dart | 14 ++++----- packages/neon/neon/test/hex_color_test.dart | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 packages/neon/neon/test/hex_color_test.dart diff --git a/packages/neon/neon/lib/src/utils/hex_color.dart b/packages/neon/neon/lib/src/utils/hex_color.dart index 2e1e569a..670e28ab 100644 --- a/packages/neon/neon/lib/src/utils/hex_color.dart +++ b/packages/neon/neon/lib/src/utils/hex_color.dart @@ -1,11 +1,11 @@ part of '../../neon.dart'; class HexColor extends Color { - HexColor(final String hexColor) - : super( - int.parse( - hexColor.toUpperCase().replaceAll('#', '').padLeft(8, 'F'), - radix: 16, - ), - ); + HexColor(final String hexColor) : super(_parse(hexColor)); + + static int _parse(final String hexColor) { + final formated = hexColor.toUpperCase().replaceAll('#', '').padLeft(8, 'F'); + + return int.parse(formated, radix: 16); + } } diff --git a/packages/neon/neon/test/hex_color_test.dart b/packages/neon/neon/test/hex_color_test.dart new file mode 100644 index 00000000..c4166ebe --- /dev/null +++ b/packages/neon/neon/test/hex_color_test.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; +import 'package:neon/neon.dart'; +import 'package:test/test.dart'; + +void main() { + group('HexColor', () { + test('White', () { + final color = HexColor('#ffffffff'); + + expect(color.value, equals(Colors.white.value)); + }); + + test('Without alpha', () { + final color = HexColor('#ffffff'); + + expect(color.value, equals(Colors.white.value)); + }); + + test('Without #', () { + final color = HexColor('ffffffff'); + + expect(color.value, equals(Colors.white.value)); + }); + + test('Uppercase', () { + final color = HexColor('#FFFFFFFF'); + + expect(color.value, equals(Colors.white.value)); + }); + }); +} From aed8049aa2294544c4a19d6f219e6982b5869d5f Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Mon, 26 Jun 2023 17:59:04 +0200 Subject: [PATCH 2/3] neon: mark Branding as immutable --- packages/neon/neon/lib/src/utils/branding.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/neon/neon/lib/src/utils/branding.dart b/packages/neon/neon/lib/src/utils/branding.dart index 9b758b17..c0e5607b 100644 --- a/packages/neon/neon/lib/src/utils/branding.dart +++ b/packages/neon/neon/lib/src/utils/branding.dart @@ -1,7 +1,8 @@ part of '../../neon.dart'; +@immutable class Branding { - Branding({ + const Branding({ required this.name, required this.logo, this.legalese, From 528ae8ef7a982972fe83ff2cdf6c4aace91b46da Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Mon, 26 Jun 2023 17:59:05 +0200 Subject: [PATCH 3/3] neon: make GlobalPopups mockable --- packages/neon/neon/lib/src/utils/global_popups.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/neon/neon/lib/src/utils/global_popups.dart b/packages/neon/neon/lib/src/utils/global_popups.dart index 43ac125c..aa79a40f 100644 --- a/packages/neon/neon/lib/src/utils/global_popups.dart +++ b/packages/neon/neon/lib/src/utils/global_popups.dart @@ -1,10 +1,16 @@ part of '../../neon.dart'; class GlobalPopups { - factory GlobalPopups() => _instance ??= GlobalPopups._(); + factory GlobalPopups() => instance ??= GlobalPopups._(); + + @visibleForTesting + factory GlobalPopups.mocked(final GlobalPopups mock) => instance ??= mock; + GlobalPopups._(); - static GlobalPopups? _instance; + @visibleForTesting + static GlobalPopups? instance; + bool _registered = false; void register(final BuildContext context) {