-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
55 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:passkit/passkit.dart'; | ||
|
||
PkPass loadSample(PassType type) { | ||
final fileName = switch (type) { | ||
PassType.boardingPass => 'BoardingPass_unsigned', | ||
PassType.coupon => 'Coupon', | ||
PassType.eventTicket => 'Event', | ||
PassType.storeCard => 'StoreCard', | ||
PassType.generic => 'Generic', | ||
PassType.unknown => 'Generic', | ||
}; | ||
final bytes = File('test/sample_passes/$fileName.pkpass').readAsBytesSync(); | ||
return PkPass.fromBytes(bytes); | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,132 +1,56 @@ | ||
import 'package:collection/collection.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:passkit/passkit.dart'; | ||
import 'package:passkit_ui/passkit_ui.dart'; | ||
import 'package:passkit_ui/src/boarding_pass.dart'; | ||
import 'package:passkit_ui/src/coupon.dart'; | ||
import 'package:passkit_ui/src/event_ticket.dart'; | ||
import 'package:passkit_ui/src/generic.dart'; | ||
import 'package:passkit_ui/src/store_card.dart'; | ||
|
||
import '../helpers/helpers.dart'; | ||
|
||
class _FakePkPass extends Fake implements PkPass { | ||
_FakePkPass({required this.type}); | ||
|
||
@override | ||
final PassType type; | ||
|
||
@override | ||
PkPassImage? get icon => _passImage; | ||
|
||
@override | ||
PkPassImage? get logo => _passImage; | ||
|
||
@override | ||
PkPassImage? get footer => _passImage; | ||
|
||
@override | ||
PkPassImage? get strip => _passImage; | ||
|
||
@override | ||
PkPassImage? get background => null; | ||
|
||
@override | ||
PkPassImage? get thumbnail => null; | ||
|
||
@override | ||
PassData get pass { | ||
return PassData( | ||
description: 'description', | ||
formatVersion: 0, | ||
organizationName: 'organizationName', | ||
passTypeIdentifier: 'passTypeIdentifier', | ||
serialNumber: 'serialNumber', | ||
teamIdentifier: 'teamIdentifier', | ||
boardingPass: _passStructure, | ||
coupon: _passStructure, | ||
eventTicket: _passStructure, | ||
generic: _passStructure, | ||
storeCard: _passStructure, | ||
logoText: 'logoText', | ||
); | ||
} | ||
|
||
static final PkPassImage? _passImage = PkPassImage.fromImages( | ||
image1: transparentPixelPng, | ||
image2: transparentPixelPng, | ||
image3: transparentPixelPng, | ||
); | ||
|
||
static final PassStructure _passStructure = PassStructure( | ||
headerFields: [ | ||
FieldDict(key: 'key', label: 'label', value: 'value'), | ||
FieldDict(key: 'key', label: 'label', value: 'value'), | ||
], | ||
primaryFields: [ | ||
FieldDict(key: 'key', label: 'label', value: 'value'), | ||
FieldDict(key: 'key', label: 'label', value: 'value'), | ||
], | ||
secondaryFields: [ | ||
FieldDict(key: 'key', label: 'label', value: 'value'), | ||
FieldDict(key: 'key', label: 'label', value: 'value'), | ||
], | ||
auxiliaryFields: [ | ||
FieldDict(key: 'key', label: 'label', value: 'value'), | ||
FieldDict(key: 'key', label: 'label', value: 'value'), | ||
], | ||
backFields: [ | ||
FieldDict(key: 'key', label: 'label', value: 'value'), | ||
FieldDict(key: 'key', label: 'label', value: 'value'), | ||
], | ||
); | ||
} | ||
import '../helpers/load_sample_passkit_file.dart'; | ||
|
||
void main() { | ||
group('PkPassWidget', () { | ||
final passes = PassType.values.map((type) => _FakePkPass(type: type)); | ||
|
||
final widgets = { | ||
PassType.boardingPass: BoardingPass( | ||
pass: passes.firstWhere((pass) => pass.type == PassType.boardingPass), | ||
), | ||
PassType.coupon: Coupon( | ||
pass: passes.firstWhere((pass) => pass.type == PassType.coupon), | ||
), | ||
PassType.eventTicket: EventTicket( | ||
pass: passes.firstWhere((pass) => pass.type == PassType.eventTicket), | ||
), | ||
PassType.storeCard: StoreCard( | ||
pass: passes.firstWhere((pass) => pass.type == PassType.storeCard), | ||
), | ||
PassType.generic: Generic( | ||
pass: passes.firstWhere((pass) => pass.type == PassType.generic), | ||
), | ||
PassType.unknown: Generic( | ||
pass: passes.firstWhere((pass) => pass.type == PassType.unknown), | ||
), | ||
}; | ||
|
||
final zip = IterableZip([passes, widgets.entries]); | ||
testWidgets( | ||
'renders BoardingPass when type is PassType.boardingPass', | ||
(tester) async { | ||
await tester | ||
.pumpApp(PkPassWidget(pass: loadSample(PassType.boardingPass))); | ||
expect(find.byType(BoardingPass), findsOneWidget); | ||
}, | ||
); | ||
|
||
for (final pair in zip) { | ||
final pass = pair.first as PkPass; | ||
final pkPassWidget = pair.last as MapEntry<PassType, Widget>; | ||
final passType = pass.type; | ||
final widgetType = pkPassWidget.value.runtimeType; | ||
testWidgets( | ||
'renders Coupon when type is PassType.coupon', | ||
(tester) async { | ||
await tester.pumpApp(PkPassWidget(pass: loadSample(PassType.coupon))); | ||
expect(find.byType(Coupon), findsOneWidget); | ||
}, | ||
); | ||
|
||
testWidgets( | ||
'renders $widgetType when type is $passType', | ||
(tester) async { | ||
tester.view.devicePixelRatio = 1.0; | ||
testWidgets( | ||
'renders EventTicket when type is PassType.eventTicket', | ||
(tester) async { | ||
await tester | ||
.pumpApp(PkPassWidget(pass: loadSample(PassType.eventTicket))); | ||
expect(find.byType(EventTicket), findsOneWidget); | ||
}, | ||
); | ||
|
||
await tester.pumpApp(PkPassWidget(pass: pass)); | ||
expect(find.byType(widgetType), findsOneWidget); | ||
testWidgets( | ||
'renders Generic when type is PassType.generic', | ||
(tester) async { | ||
await tester.pumpApp(PkPassWidget(pass: loadSample(PassType.generic))); | ||
expect(find.byType(Generic), findsOneWidget); | ||
}, | ||
); | ||
|
||
tester.view.resetDevicePixelRatio(); | ||
}, | ||
); | ||
} | ||
testWidgets( | ||
'renders Generic when type is PassType.unknown', | ||
(tester) async { | ||
await tester.pumpApp(PkPassWidget(pass: loadSample(PassType.unknown))); | ||
expect(find.byType(Generic), findsOneWidget); | ||
}, | ||
); | ||
}); | ||
} |