Skip to content

Commit

Permalink
test(app): add no mapped guideline cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Sep 24, 2024
1 parent 501dfd0 commit 033ebbd
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 52 deletions.
134 changes: 102 additions & 32 deletions app/integration_test/drugs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ import 'fixtures/drugs/warfarin_with_any_fallback_guideline.dart';
import 'fixtures/set_app_data.dart';
import 'mocks/drug_cubit.dart';

class _TestCase {
_TestCase({
required this.description,
required this.drug,
this.expectNoMappedGuidelines = false,
this.explicitNoResult,
this.explicitLookups,
});

final String description;
final Drug drug;
final bool expectNoMappedGuidelines;
final List<String>? explicitNoResult;
final Map<String, String>? explicitLookups;
}

void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.onlyPumps;
Expand All @@ -36,15 +52,22 @@ void main() {
WidgetTester tester, {
required Drug drug,
bool isLoading = false,
bool expectNoGuidelines = false,
bool expectNoMappedGuidelines = false,
bool expectDrugToBeActive = false,
bool expectNoBrandNames = false,
List<String>? explicitNoResult,
Map<String, String>? explicitLookups,
Guideline? guideline,
}) async {
Guideline? relevantGuideline;
if (!expectNoGuidelines) {
if (guideline != null || drug.guidelines.isNotEmpty) {
relevantGuideline = guideline ?? drug.guidelines.first;
setAppData(drug: drug, guideline: relevantGuideline);
setAppData(
drug: drug,
guideline: relevantGuideline,
explicitNoResult: explicitNoResult,
explicitLookups: explicitLookups,
);
}
when(() => mockDrugsCubit.state)
.thenReturn(isLoading ? DrugState.loading() : DrugState.loaded());
Expand Down Expand Up @@ -97,6 +120,7 @@ void main() {
),
) as RoundedCard;
expect(find.byType(Disclaimer), findsOneWidget);
final sourcesSection = find.byKey(Key('sourceCard'));
final context = tester.element(find.byType(Scaffold).first);
if (expectNoBrandNames) {
expect(
Expand All @@ -115,20 +139,42 @@ void main() {
);
}
}
if (expectNoGuidelines) {
if (expectNoMappedGuidelines) {
expect(card.color, WarningLevel.green.color);
expect(
find.byTooltip(context.l10n.drugs_page_tooltip_guideline_missing),
findsOneWidget,
);
expect(
find.text(context.l10n.drugs_page_guidelines_empty(drug.name)),
findsOneWidget,
);
expect(
find.text(context.l10n.drugs_page_no_guidelines_text),
findsOneWidget,
);
if (drug.guidelines.isNotEmpty) {
expect(sourcesSection, findsOneWidget);
} else {
expect(sourcesSection, findsNothing);
}
if (drug.guidelines.isEmpty) {
expect(
find.text(context.l10n.drugs_page_guidelines_empty(drug.name)),
findsOneWidget,
);
}
if (explicitNoResult != null) {
for (final noResultGene in explicitNoResult) {
final geneRowFinder = find.ancestor(
of: find.text(noResultGene),
matching: find.byType(Table),
);
expect(
find.descendant(
of: geneRowFinder,
matching: find.textContaining(context.l10n.general_not_tested),
),
findsOneWidget,
);
}
}
} else {
expect(card.color, relevantGuideline!.annotations.warningLevel.color);
expect(
Expand All @@ -145,6 +191,9 @@ void main() {
find.textContaining(relevantGuideline.annotations.recommendation),
findsOneWidget,
);
expect(sourcesSection, findsOneWidget);
}
if (!expectNoMappedGuidelines || explicitLookups != null) {
for (final genotypeKey in drug.guidelineGenotypes) {
if (genotypeKey.contains(' ')) {
expect(
Expand All @@ -161,14 +210,10 @@ void main() {
}
}

Future<void> runTestCasePerGuideline(
Map<String, Drug> testCases, {
bool expectNoGuidelines = false,
}
) async {
for (final (testCase) in testCases.entries) {
final description = 'test drug content with ${testCase.key}';
final drug = testCase.value;
Future<void> runTestCases(List<_TestCase> testCases) async {
for (final (testCase) in testCases) {
final description = 'test drug content with ${testCase.description}';
final drug = testCase.drug;
for (final (index, guideline) in drug.guidelines.indexed) {
// Run per case to ensure clean setup
final caseDescription = drug.guidelines.length > 1
Expand All @@ -181,7 +226,9 @@ void main() {
tester,
drug: drug,
guideline: guideline,
expectNoGuidelines: expectNoGuidelines,
expectNoMappedGuidelines: testCase.expectNoMappedGuidelines,
explicitNoResult: testCase.explicitNoResult,
explicitLookups: testCase.explicitLookups,
);
},
);
Expand Down Expand Up @@ -238,24 +285,47 @@ void main() {
});

group('test missing guidelines', () {
final missingGuidelinesCases = {
'for drug without guidelines': mirabegronWithoutGuidelines,
};
runTestCasePerGuideline(
missingGuidelinesCases,
expectNoGuidelines: true,
);
runTestCases([
_TestCase(
description: 'no guidelines',
drug: mirabegronWithoutGuidelines,
expectNoMappedGuidelines: true,
),
_TestCase(
description: 'no result and no explicit guideline',
drug: ibuprofenWithProperGuideline,
explicitNoResult: [
ibuprofenWithProperGuideline.guidelines.first.lookupkey.keys.first,
],
expectNoMappedGuidelines: true,
),
_TestCase(
description: 'no result and no mappable lookup',
drug: ibuprofenWithProperGuideline,
explicitLookups: {
ibuprofenWithProperGuideline.guidelines.first.lookupkey.keys.first:
'0.0',
},
expectNoMappedGuidelines: true,
),
]);
});

group('test special guidelines', () {
final specialGuidelineTestCases = <String, Drug>{
'any fallback guideline': warfarinWithAnyFallbackGuideline,
'any not handled fallback guideline':
aripiprazoleWithAnyNotHandledFallbackGuideline,
'multiple any not handled fallback guidelines':
pazopanibWithMultipleAnyNotHandledFallbackGuidelines,
};
runTestCasePerGuideline(specialGuidelineTestCases);
runTestCases([
_TestCase(
description: 'any fallback guideline',
drug: warfarinWithAnyFallbackGuideline,
),
_TestCase(
description: 'any not handled fallback guideline',
drug: aripiprazoleWithAnyNotHandledFallbackGuideline,
),
_TestCase(
description: 'multiple any not handled fallback guidelines',
drug: pazopanibWithMultipleAnyNotHandledFallbackGuidelines,
)
]);
});
});
}
61 changes: 41 additions & 20 deletions app/integration_test/fixtures/set_app_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ void setGenotypeResult(GenotypeResult genotypeResult) {
UserData.instance.genotypeResults![genotypeResult.key.value] = genotypeResult;
}

void setUserDataForGuideline(Guideline guideline) {
void setUserDataForGuideline(
Guideline guideline, {
List<String>? explicitNoResult,
Map<String, String>? explicitLookups,
}) {
UserData.instance.labData = UserData.instance.labData ?? [];
for (final gene in guideline.lookupkey.keys) {
final lookupkeys = guideline.lookupkey[gene]!;
Expand All @@ -28,9 +32,15 @@ void setUserDataForGuideline(Guideline guideline) {
);
}
var lookupkey = lookupkeys.first;
if (lookupkey == '*' || lookupkey == '~') {
if (
lookupkey == SpecialLookup.any.value ||
lookupkey == SpecialLookup.anyNotHandled.value
) {
lookupkey = 'certainly not handled lookupkey';
}
if (explicitLookups?.keys.contains(gene) ?? false) {
lookupkey = explicitLookups![gene]!;
}
final userDataConfig = _UserDataConfig(
gene: gene,
lookupkey: lookupkey,
Expand All @@ -39,24 +49,26 @@ void setUserDataForGuideline(Guideline guideline) {
// multiple HLA-B variants in the tests or overwrite a specific HLA-B
// variant, we will need to check for the genotype key (which is in the
// current setup not possible without the proper variant)
UserData.instance.labData = UserData.instance.labData!.filter(
(labResult) => labResult.gene != gene
).toList();
UserData.instance.labData!.add(
LabResult(
if (!(explicitNoResult?.contains(gene) ?? false)) {
UserData.instance.labData = UserData.instance.labData!.filter(
(labResult) => labResult.gene != gene
).toList();
UserData.instance.labData!.add(
LabResult(
gene: userDataConfig.gene,
variant: userDataConfig.variant,
phenotype: userDataConfig.phenotype,
allelesTested: userDataConfig.allelesTested,
),
);
setGenotypeResult(GenotypeResult(
gene: userDataConfig.gene,
variant: userDataConfig.variant,
phenotype: userDataConfig.phenotype,
allelesTested: userDataConfig.allelesTested,
),
);
setGenotypeResult(GenotypeResult(
gene: userDataConfig.gene,
phenotype: userDataConfig.phenotype,
variant: userDataConfig.variant,
allelesTested: userDataConfig.variant,
lookupkey: userDataConfig.lookupkey,
));
variant: userDataConfig.variant,
allelesTested: userDataConfig.variant,
lookupkey: userDataConfig.lookupkey,
));
}
}
}

Expand All @@ -69,8 +81,17 @@ void addDrugToDrugsWithGuidelines(Drug drug) {
DrugsWithGuidelines.instance.drugs!.add(drug);
}

void setAppData({required Drug drug, required Guideline guideline}) {
void setAppData({
required Drug drug,
required Guideline guideline,
List<String>? explicitNoResult,
Map<String, String>? explicitLookups,
}) {
addDrugToDrugsWithGuidelines(drug);
initializeGenotypeResultKeys().values.forEach(setGenotypeResult);
setUserDataForGuideline(guideline);
setUserDataForGuideline(
guideline,
explicitNoResult: explicitNoResult,
explicitLookups: explicitLookups,
);
}
1 change: 1 addition & 0 deletions app/lib/drug/widgets/annotation_cards/guideline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class GuidelineAnnotationCard extends StatelessWidget {
(source) => GestureDetector(
onTap: () => _launchUrl(Uri.parse(source.split('|')[1])),
child: RoundedCard(
key: Key('sourceCard'),
radius: PharMeTheme.innerCardRadius,
outerHorizontalPadding: 0,
outerVerticalPadding: 0,
Expand Down

0 comments on commit 033ebbd

Please sign in to comment.