mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-21 23:10:40 +00:00
fixed MeteringScreenLayoutConfigJson
tests
This commit is contained in:
parent
f6a0fc2f52
commit
93d8d46bf0
3 changed files with 70 additions and 34 deletions
|
@ -1,11 +1,17 @@
|
||||||
enum MeteringScreenLayoutFeature { equipmentProfiles, extremeExposurePairs, filmPicker }
|
enum MeteringScreenLayoutFeature {
|
||||||
|
extremeExposurePairs,
|
||||||
|
filmPicker,
|
||||||
|
equipmentProfiles,
|
||||||
|
}
|
||||||
|
|
||||||
typedef MeteringScreenLayoutConfig = Map<MeteringScreenLayoutFeature, bool>;
|
typedef MeteringScreenLayoutConfig = Map<MeteringScreenLayoutFeature, bool>;
|
||||||
|
|
||||||
extension MeteringScreenLayoutConfigJson on MeteringScreenLayoutConfig {
|
extension MeteringScreenLayoutConfigJson on MeteringScreenLayoutConfig {
|
||||||
static MeteringScreenLayoutConfig fromJson(Map<String, dynamic> data) => data.map(
|
static MeteringScreenLayoutConfig fromJson(Map<String, dynamic> data) =>
|
||||||
(key, value) => MapEntry(MeteringScreenLayoutFeature.values[int.parse(key)], value as bool),
|
<MeteringScreenLayoutFeature, bool>{
|
||||||
);
|
for (final f in MeteringScreenLayoutFeature.values)
|
||||||
|
f: data[f.index.toString()] as bool? ?? true
|
||||||
|
};
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => map((key, value) => MapEntry(key.index.toString(), value));
|
Map<String, dynamic> toJson() => map((key, value) => MapEntry(key.index.toString(), value));
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,18 +33,9 @@ class _MeteringScreenLayoutFeaturesDialogState extends State<MeteringScreenLayou
|
||||||
child: Text(S.of(context).meteringScreenLayoutHint),
|
child: Text(S.of(context).meteringScreenLayoutHint),
|
||||||
),
|
),
|
||||||
const SizedBox(height: Dimens.grid16),
|
const SizedBox(height: Dimens.grid16),
|
||||||
...MeteringScreenLayoutFeature.values.map(
|
_featureListTile(MeteringScreenLayoutFeature.equipmentProfiles),
|
||||||
(f) => SwitchListTile(
|
_featureListTile(MeteringScreenLayoutFeature.extremeExposurePairs),
|
||||||
contentPadding: EdgeInsets.symmetric(horizontal: Dimens.dialogTitlePadding.left),
|
_featureListTile(MeteringScreenLayoutFeature.filmPicker),
|
||||||
title: Text(_toStringLocalized(context, f)),
|
|
||||||
value: _features[f]!,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
_features.update(f, (_) => value);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -65,6 +56,19 @@ class _MeteringScreenLayoutFeaturesDialogState extends State<MeteringScreenLayou
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _featureListTile(MeteringScreenLayoutFeature f) {
|
||||||
|
return SwitchListTile(
|
||||||
|
contentPadding: EdgeInsets.symmetric(horizontal: Dimens.dialogTitlePadding.left),
|
||||||
|
title: Text(_toStringLocalized(context, f)),
|
||||||
|
value: _features[f]!,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
_features.update(f, (_) => value);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
String _toStringLocalized(BuildContext context, MeteringScreenLayoutFeature feature) {
|
String _toStringLocalized(BuildContext context, MeteringScreenLayoutFeature feature) {
|
||||||
switch (feature) {
|
switch (feature) {
|
||||||
case MeteringScreenLayoutFeature.equipmentProfiles:
|
case MeteringScreenLayoutFeature.equipmentProfiles:
|
||||||
|
|
|
@ -2,30 +2,56 @@ import 'package:lightmeter/data/models/metering_screen_layout_config.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('fromJson', () {
|
group(
|
||||||
expect(
|
'fromJson()',
|
||||||
MeteringScreenLayoutConfigJson.fromJson({'0': true, '1': true}),
|
() {
|
||||||
{
|
test('All keys', () {
|
||||||
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
expect(
|
||||||
MeteringScreenLayoutFeature.filmPicker: true,
|
MeteringScreenLayoutConfigJson.fromJson(
|
||||||
},
|
{
|
||||||
);
|
'0': true,
|
||||||
expect(
|
'1': true,
|
||||||
MeteringScreenLayoutConfigJson.fromJson({'0': false, '1': false}),
|
'2': true,
|
||||||
{
|
},
|
||||||
MeteringScreenLayoutFeature.extremeExposurePairs: false,
|
),
|
||||||
MeteringScreenLayoutFeature.filmPicker: false,
|
{
|
||||||
},
|
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
||||||
);
|
MeteringScreenLayoutFeature.filmPicker: true,
|
||||||
});
|
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('toJson', () {
|
test('Legacy (no equipment profiles)', () {
|
||||||
|
expect(
|
||||||
|
MeteringScreenLayoutConfigJson.fromJson(
|
||||||
|
{
|
||||||
|
'0': true,
|
||||||
|
'1': true,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
{
|
||||||
|
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
||||||
|
MeteringScreenLayoutFeature.filmPicker: true,
|
||||||
|
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('toJson()', () {
|
||||||
expect(
|
expect(
|
||||||
{
|
{
|
||||||
|
MeteringScreenLayoutFeature.equipmentProfiles: true,
|
||||||
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
MeteringScreenLayoutFeature.extremeExposurePairs: true,
|
||||||
MeteringScreenLayoutFeature.filmPicker: true,
|
MeteringScreenLayoutFeature.filmPicker: true,
|
||||||
}.toJson(),
|
}.toJson(),
|
||||||
{'0': true, '1': true},
|
{
|
||||||
|
'2': true,
|
||||||
|
'0': true,
|
||||||
|
'1': true,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue