diff --git a/CHANGELOG.md b/CHANGELOG.md index 287dbb7..7a9dd66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## 5.0.1 + +- `Moment.locale`: returns `false` instead of throwing when Moment is not loaded yet. +- `BSDateRangePicker`: removed debug `print`s (config on each render and the selected range on each change). + +- Tests: + - New `bones_ui_bootstrap_unloaded_test.dart`: `Moment.locale` with Moment not loaded. + - VM: no debug prints in `BSDateRangePicker`; stale-library check ignores directories with only hidden files + (e.g. `.DS_Store` left by git when switching branches). + ## 5.0.0 - **Bootstrap 5** (5.3.7). For Bootstrap 4 use version `4.x` (branch `4.x`). diff --git a/lib/src/bones_ui_bootstrap_base.dart b/lib/src/bones_ui_bootstrap_base.dart index 3b1988f..8692960 100644 --- a/lib/src/bones_ui_bootstrap_base.dart +++ b/lib/src/bones_ui_bootstrap_base.dart @@ -271,6 +271,9 @@ class Moment { } /// Sets the locale of [Moment]. + /// + /// Returns `false` if [locale] is empty or if [Moment] is not loaded yet + /// (it triggers [load]; `await Moment.load()` before calling it). static bool locale(String locale) { load(); @@ -279,7 +282,10 @@ class Moment { locale = locale.replaceFirst('_', '-'); - _moment!.callMethod('locale'.toJS, locale.toJS); + var moment = _moment; + if (moment == null) return false; + + moment.callMethod('locale'.toJS, locale.toJS); return true; } diff --git a/lib/src/components/daterangepicker.dart b/lib/src/components/daterangepicker.dart index 1a5181a..d61ed42 100644 --- a/lib/src/components/daterangepicker.dart +++ b/lib/src/components/daterangepicker.dart @@ -249,8 +249,6 @@ class BSDateRangePicker extends UIComponent implements UIField> { if (configLocale.isNotEmpty) 'locale': configLocale, }; - print(config); - JQuery.$( _textElement, ).call('daterangepicker', [config.toJSDeep, _jsQueryCallback.toJS]); @@ -296,8 +294,6 @@ class BSDateRangePicker extends UIComponent implements UIField> { _startTime = startTime; _endTime = endTime; - print('Selected Date Range: $startTime >> $endTime'); - _updateTextElement(); onChange.add(this); diff --git a/pubspec.yaml b/pubspec.yaml index 62b80f0..e54b482 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: bones_ui_bootstrap description: Adds Bootstrap 5 support to Dart package bones_ui, allowing use of Bootstrap components and CSS. -version: 5.0.0 +version: 5.0.1 homepage: https://github.com/Colossus-Services/bones_ui_bootstrap environment: diff --git a/test/bones_ui_bootstrap_consistency_vm_test.dart b/test/bones_ui_bootstrap_consistency_vm_test.dart index 70bdac3..04a799b 100644 --- a/test/bones_ui_bootstrap_consistency_vm_test.dart +++ b/test/bones_ui_bootstrap_consistency_vm_test.dart @@ -95,9 +95,17 @@ void main() { }); test('no stale bundled library versions', () { + // Ignores directories with only hidden files (e.g. `.DS_Store`), left + // behind by git when switching branches: + bool hasFiles(Directory d) => d + .listSync(recursive: true) + .whereType() + .any((f) => !f.uri.pathSegments.last.startsWith('.')); + List dirs(String prefix) => Directory('lib') .listSync() .whereType() + .where(hasFiles) .map((d) => d.uri.pathSegments.where((s) => s.isNotEmpty).last) .where((n) => n.startsWith(prefix)) .toList(); @@ -165,4 +173,11 @@ void main() { } }); }); + + test('no debug prints in BSDateRangePicker', () { + var source = File( + 'lib/src/components/daterangepicker.dart', + ).readAsStringSync(); + expect(source, isNot(contains('print('))); + }); } diff --git a/test/bones_ui_bootstrap_unloaded_test.dart b/test/bones_ui_bootstrap_unloaded_test.dart new file mode 100644 index 0000000..0031ee4 --- /dev/null +++ b/test/bones_ui_bootstrap_unloaded_test.dart @@ -0,0 +1,30 @@ +@TestOn('browser') +library; + +import 'dart:js_interop_unsafe'; + +import 'package:bones_ui_bootstrap/bones_ui_bootstrap.dart'; +import 'package:test/test.dart'; +import 'package:web_utils/web_utils.dart'; + +/// Tests with the JS libraries NOT loaded (nothing is loaded in this file +/// before the checks). +void main() { + group('Without loaded JS libraries', () { + test('nothing loaded', () { + expect(Moment.isLoaded, isFalse); + expect(JQuery.isLoaded, isFalse); + expect(Bootstrap.isLoaded, isFalse); + expect(globalContext['jQuery'], isNull); + }); + + test('Moment.locale: not loaded yet', () async { + expect(Moment.locale(' '), isFalse); + // Triggers the load, but doesn't throw: + expect(Moment.locale('en'), isFalse); + + expect(await Moment.load(), isTrue); + expect(Moment.locale('en'), isTrue); + }); + }); +}