Skip to content

Commit

Permalink
finish test
Browse files Browse the repository at this point in the history
  • Loading branch information
evan361425 committed May 18, 2024
1 parent ae8ee20 commit 2454b33
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 31 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ test: ## Run tests
.PHONY: test-coverage
test-coverage: ## Run tests with coverage
flutter test --coverage
genhtml coverage/lcov.info -o coverage/html
@genhtml coverage/lcov.info -o coverage/html
@open coverage/html/index.html

##@ Build
.PHONY: bump
Expand Down
2 changes: 1 addition & 1 deletion assets/l10n/en/menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ingredient:
repeat: Product already has the same ingredient, cannot select repeatedly.
amount:
label: Amount Used
helper: |
helper: |-
Default amount used.
If customers are able to adjust the amount,
set different quantities in "Quantity."
Expand Down
4 changes: 2 additions & 2 deletions assets/l10n/en/order_attribute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ mode:
- name
helper:
- statOnly: Normal setting, selecting won't affect the order price.
changePrice: |
changePrice: |-
Selecting this setting may affect the order price.
For example: Takeout +$30, Eco Cup -$5.
changeDiscount: |
changeDiscount: |-
Selecting this setting will affect the total price based on the discount.
For example: Dine-in +10% service charge, Friends & Family Discount -10%.
- Explanation of customer setting categories
Expand Down
4 changes: 2 additions & 2 deletions assets/l10n/en/transit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ GS:
empty: Cannot be Empty
invalid: |-
Invalid text. It must include:
/spreadsheets/d/<ID>/
Or provide the ID directly (combination of letters, numbers, underscores, and hyphens).
/spreadsheets/d/<ID>/
Or provide the ID directly (combination of letters, numbers, underscores, and hyphens).
createSheet: Unable to Create Sheet in Spreadsheet
createSheetHelper: |-
Don't worry, it's usually easy to solve!
Expand Down
2 changes: 1 addition & 1 deletion assets/l10n/zh/global.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ totalCount:
searchCount: 搜尋到 {count} 個結果
dialog:
deletionTitle: 刪除確認通知
deletionContent: |
deletionContent: |-
確定要刪除「{name}」嗎?
{more}此動作將無法復原!
Expand Down
4 changes: 2 additions & 2 deletions assets/l10n/zh/order_attribute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ mode:
changeDiscount: 折扣
helper:
- statOnly: 一般的設定,選取時並不會影響點單價格。
changePrice: |
changePrice: |-
選取設定時,可能會影響價格。
例如:外送 + 30塊錢、環保杯 - 5塊錢。
changeDiscount: |
changeDiscount: |-
選取設定時,會根據折扣影響總價。
例如:內用 + 10% 服務費、親友價 - 10%。
name:
Expand Down
4 changes: 2 additions & 2 deletions assets/l10n/zh/transit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ GS:
empty: 不能為空
invalid: |-
不合法的文字,必須包含:
/spreadsheets/d/<ID>/
或者直接給 ID(英文+數字+底線+減號的組合)
/spreadsheets/d/<ID>/
或者直接給 ID(英文+數字+底線+減號的組合)
createSheet: 無法在試算表中建立表單
createSheetHelper: |-
別擔心,通常都可以簡單解決!
Expand Down
7 changes: 0 additions & 7 deletions evan.dart

This file was deleted.

8 changes: 1 addition & 7 deletions lib/components/style/route_circular_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class RouteCircularButton extends StatelessWidget {

final String? route;

final Map<String, String> routePathParameters;

final bool popTrueShowSuccess;

final VoidCallback? onTap;
Expand All @@ -21,7 +19,6 @@ class RouteCircularButton extends StatelessWidget {
required this.text,
required this.icon,
this.route,
this.routePathParameters = const <String, String>{},
this.popTrueShowSuccess = false,
this.onTap,
});
Expand All @@ -42,10 +39,7 @@ class RouteCircularButton extends StatelessWidget {
),
onPressed: onTap ??
() async {
final result = await context.pushNamed(
route!,
pathParameters: routePathParameters,
);
final result = await context.pushNamed(route!);
if (result == true) {
if (context.mounted) {
showSnackBar(context, S.actSuccess);
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Util {
return Center(child: Text(error.toString()));
}

if (!snapshot.hasData) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(
child: SizedBox(
height: 20,
Expand Down
3 changes: 1 addition & 2 deletions lib/ui/analysis/analysis_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ class _AnalysisViewState extends State<AnalysisView> with AutomaticKeepAliveClie
message: S.analysisChartTutorialContent,
child: RouteCircularButton(
key: const Key('anal.add_chart'),
route: Routes.chartModal,
routePathParameters: const {'id': '_'},
route: Routes.chartNew,
icon: KIcons.add,
text: S.analysisChartTitleCreate,
),
Expand Down
8 changes: 8 additions & 0 deletions test/helpers/util_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:possystem/helpers/util.dart';

void main() {
Expand Down Expand Up @@ -32,6 +33,13 @@ void main() {
expect(date.second, equals(33));
});

test('#formatCompact', () {
initializeDateFormatting('en', null);
DateTimeRange range = Util.getDateRange(now: DateTime.utc(2021, 6, 14), days: 3);

expect(range.formatCompact('en'), equals('20210614 - 20210616'));
});

testWidgets('#handleSnapshot error', (WidgetTester tester) async {
final f = Util.handleSnapshot((context, data) => const SizedBox.shrink());
const err = AsyncSnapshot<String>.withError(ConnectionState.done, 'test');
Expand Down
10 changes: 10 additions & 0 deletions test/ui/analysis/widgets/history_order_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:possystem/models/repository/seller.dart';
import 'package:possystem/routes.dart';
import 'package:possystem/translator.dart';
import 'package:possystem/ui/analysis/widgets/history_order_list.dart';
import 'package:possystem/ui/analysis/widgets/history_order_modal.dart';

import '../../../mocks/mock_cache.dart';
import '../../../mocks/mock_database.dart';
Expand Down Expand Up @@ -194,6 +195,15 @@ void main() {
verify(txn.delete(any, where: anyNamed('where'))).called(4);
});

testWidgets('order not found', (tester) async {
when(database.query(any, where: argThat(equals('id = 666'), named: 'where'))).thenAnswer((_) => Future.value([]));

await tester.pumpWidget(const MaterialApp(home: HistoryOrderModal(666)));
await tester.pumpAndSettle();

expect(find.text(S.analysisHistoryOrderNotFound), findsOneWidget);
});

setUpAll(() {
initializeCache();
initializeTranslator();
Expand Down
7 changes: 7 additions & 0 deletions test/ui/menu/menu_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:possystem/translator.dart';
import 'package:possystem/ui/menu/menu_page.dart';
import 'package:provider/provider.dart';

import '../../mocks/mock_cache.dart';
import '../../mocks/mock_storage.dart';
import '../../test_helpers/file_mocker.dart';
import '../../test_helpers/translator.dart';
Expand Down Expand Up @@ -335,8 +336,14 @@ void main() {
expect(find.byKey(const Key('catalog.c-1')), findsOneWidget);
});

setUp(() async {
await cache.reset();
when(cache.get(any)).thenReturn(true);
});

setUpAll(() {
initializeStorage();
initializeCache();
initializeTranslator();
initializeFileSystem();
});
Expand Down
6 changes: 6 additions & 0 deletions test/ui/order/order_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ void main() {
['p-1', '2'],
['p-2', '2'],
], 36);

// open by tapping snapshot product
await tester.tap(find.byKey(const Key('cart_snapshot.0')));
await tester.pumpAndSettle();

expect(find.byKey(const Key('order.ingredient.pi-2')), findsOneWidget);
});
});

Expand Down
23 changes: 20 additions & 3 deletions test/ui/transit/google_sheet/select_spreadsheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void main() {
)));
}

testWidgets('exporter pick invalid and exist', (tester) async {
testWidgets('exporter pick invalid and exit', (tester) async {
when(cache.get(eCacheKey)).thenReturn('old-id:true:old-name');

await tester.pumpWidget(buildApp());
Expand All @@ -84,10 +84,13 @@ void main() {
expect(editorW.controller?.text, equals('old-id'));

await tester.enterText(editor, 'QQ');
await tester.tap(find.byKey(const Key('text_dialog.confirm')));
await tester.pump();
// not in dialog
expect(find.text(S.transitGSErrorSpreadsheetIdInvalid), findsOneWidget);

await tester.tap(find.byKey(const Key('text_dialog.cancel')));
await tester.pumpAndSettle();
// not in dialog
expect(find.byKey(const Key('text_dialog.cancel')), findsNothing);
});

testWidgets('exporter pick not exist', (tester) async {
Expand Down Expand Up @@ -217,4 +220,18 @@ void main() {
initializeAuth();
});
});

test('GoogleSheetProperties hash code', () {
final a = GoogleSheetProperties(1, 'title');
final b = GoogleSheetProperties(1, 'title');
final c = GoogleSheetProperties(1, 'title2');
final d = GoogleSheetProperties(2, 'title');

expect(a, equals(b));
expect(a.hashCode, equals(b.hashCode));
expect(a, isNot(equals(c)));
expect(a.hashCode, isNot(equals(c.hashCode)));
expect(a, isNot(equals(d)));
expect(a.hashCode, isNot(equals(d.hashCode)));
});
}

0 comments on commit 2454b33

Please sign in to comment.