From e0ce89880e0c819141ebbfa8a0a7303e6e7abe27 Mon Sep 17 00:00:00 2001 From: Tamara Slosarek Date: Mon, 23 Sep 2024 19:30:26 +0200 Subject: [PATCH] test(app): add report test --- .../drugs/with_any_not_handled_guideline.dart | 27 +----- ...e_any_not_handled_fallback_guidelines.dart | 29 +----- .../guidelines/aripiprazole_cyp2d6_poor.dart | 27 ++++++ .../guidelines/guideline.dart.template | 27 ++++++ ...ab5701_positive_ugt1a1_poor_guideline.dart | 29 ++++++ .../fixtures/set_user_data.dart | 12 ++- app/integration_test/report_test.dart | 92 +++++++++++++++++++ pharme.code-workspace | 5 + 8 files changed, 193 insertions(+), 55 deletions(-) create mode 100644 app/integration_test/fixtures/guidelines/aripiprazole_cyp2d6_poor.dart create mode 100644 app/integration_test/fixtures/guidelines/guideline.dart.template create mode 100644 app/integration_test/fixtures/guidelines/pazopanib_hlab5701_positive_ugt1a1_poor_guideline.dart create mode 100644 app/integration_test/report_test.dart diff --git a/app/integration_test/fixtures/drugs/with_any_not_handled_guideline.dart b/app/integration_test/fixtures/drugs/with_any_not_handled_guideline.dart index ada8ea04..e3322e71 100644 --- a/app/integration_test/fixtures/drugs/with_any_not_handled_guideline.dart +++ b/app/integration_test/fixtures/drugs/with_any_not_handled_guideline.dart @@ -2,6 +2,8 @@ import 'package:app/common/models/drug/drug.dart'; import 'package:app/common/models/drug/guideline.dart'; import 'package:app/common/models/drug/warning_level.dart'; +import '../guidelines/aripiprazole_cyp2d6_poor.dart'; + final drugWithAnyNotHandledFallbackGuideline = Drug( id: '6492f8e9918ddcae7349c30c', version: 1, @@ -13,30 +15,7 @@ final drugWithAnyNotHandledFallbackGuideline = Drug( brandNames: ['Abilify'], ), guidelines: [ - Guideline( - id: '6492f8e9918ddcae7349c304', - version: 1, - lookupkey: { - 'CYP2D6': ['0.0'], - }, - externalData: [ - GuidelineExtData( - source: 'FDA', - guidelineName: 'Table of Pharmacogenetic Associations (Section 1)', - guidelineUrl: 'https://www.fda.gov/medical-devices/precision-medicine/table-pharmacogenetic-associations#section1', - implications: { - 'CYP2D6': 'Results in higher systemic concentrations and higher adverse reaction risk. Dosage adjustment is recommended. Refer to FDA labeling for specific dosing recommendations.', - }, - recommendation: 'Might be included in implication text (imported from FDA, source only states one text per guideline)', - comments: null, - ), - ], - annotations: GuidelineAnnotations( - implication: 'You break down aripiprazole slower than expected. You have an increased risk for side effects.', - recommendation: 'Aripiprazole may be used at a lower dose. Consult your pharmacist or doctor for more information.', - warningLevel: WarningLevel.yellow, - ), - ), + aripiprazoleCyp2d6PoorGuideline, Guideline( id: '66b50b2433cbe5c07ee311d7', version: 1, diff --git a/app/integration_test/fixtures/drugs/with_multiple_any_not_handled_fallback_guidelines.dart b/app/integration_test/fixtures/drugs/with_multiple_any_not_handled_fallback_guidelines.dart index 190d207e..cbee7f20 100644 --- a/app/integration_test/fixtures/drugs/with_multiple_any_not_handled_fallback_guidelines.dart +++ b/app/integration_test/fixtures/drugs/with_multiple_any_not_handled_fallback_guidelines.dart @@ -2,6 +2,8 @@ import 'package:app/common/models/drug/drug.dart'; import 'package:app/common/models/drug/guideline.dart'; import 'package:app/common/models/drug/warning_level.dart'; +import '../guidelines/pazopanib_hlab5701_positive_ugt1a1_poor_guideline.dart'; + final drugWithMultipleAnyNotHandledFallbackGuidelines = Drug( id: '6686a865826414ec5b05c44e', version: 1, @@ -13,32 +15,7 @@ final drugWithMultipleAnyNotHandledFallbackGuidelines = Drug( brandNames: ['Votrient'], ), guidelines: [ - Guideline( - id: '6686a865826414ec5b05c436', - version: 1, - lookupkey: { - 'HLA-B': ['*57:01 positive'], - 'UGT1A1': ['Poor Metabolizer'], - }, - externalData: [ - GuidelineExtData( - source: 'FDA', - guidelineName: 'Table of Pharmacogenetic Associations (Section 2)', - guidelineUrl: 'https://www.fda.gov/medical-devices/precision-medicine/table-pharmacogenetic-associations#section2', - implications: { - 'HLA-B': 'May result in higher adverse reaction risk (liver enzyme elevations). Monitor liver function tests regardless of genotype.', - 'UGT1A1': 'Results in higher adverse reaction risk (hyperbilirubinemia).', - }, - recommendation: 'Might be included in implication text (imported from FDA, source only states one text per guideline)', - comments: null, - ), - ], - annotations: GuidelineAnnotations( - implication: 'You have an increased risk for side effects. (Test case 1)', - recommendation: 'You can still use pazopanib at standard dose. Consult your pharmacist or doctor for more information. (Test case 1)', - warningLevel: WarningLevel.yellow, - ), - ), + pazopanibHlab5701PositiveUgt1a1PoorGuideline, Guideline( id: '66b50b2433cbe5c07ee31651', version: 1, diff --git a/app/integration_test/fixtures/guidelines/aripiprazole_cyp2d6_poor.dart b/app/integration_test/fixtures/guidelines/aripiprazole_cyp2d6_poor.dart new file mode 100644 index 00000000..519049cc --- /dev/null +++ b/app/integration_test/fixtures/guidelines/aripiprazole_cyp2d6_poor.dart @@ -0,0 +1,27 @@ +import 'package:app/common/models/drug/guideline.dart'; +import 'package:app/common/models/drug/warning_level.dart'; + +final aripiprazoleCyp2d6PoorGuideline = Guideline( + id: '6492f8e9918ddcae7349c304', + version: 1, + lookupkey: { + 'CYP2D6': ['0.0'], + }, + externalData: [ + GuidelineExtData( + source: 'FDA', + guidelineName: 'Table of Pharmacogenetic Associations (Section 1)', + guidelineUrl: 'https://www.fda.gov/medical-devices/precision-medicine/table-pharmacogenetic-associations#section1', + implications: { + 'CYP2D6': 'Results in higher systemic concentrations and higher adverse reaction risk. Dosage adjustment is recommended. Refer to FDA labeling for specific dosing recommendations.', + }, + recommendation: 'Might be included in implication text (imported from FDA, source only states one text per guideline)', + comments: null, + ), + ], + annotations: GuidelineAnnotations( + implication: 'You break down aripiprazole slower than expected. You have an increased risk for side effects.', + recommendation: 'Aripiprazole may be used at a lower dose. Consult your pharmacist or doctor for more information.', + warningLevel: WarningLevel.yellow, + ), +); \ No newline at end of file diff --git a/app/integration_test/fixtures/guidelines/guideline.dart.template b/app/integration_test/fixtures/guidelines/guideline.dart.template new file mode 100644 index 00000000..a21b8e87 --- /dev/null +++ b/app/integration_test/fixtures/guidelines/guideline.dart.template @@ -0,0 +1,27 @@ +import 'package:app/common/models/drug/guideline.dart'; +import 'package:app/common/models/drug/warning_level.dart'; + +final nonCompilingPlaceholdersGuideline = Guideline( + id: null, + version: null, + lookupkey: { + null: [null], + }, + externalData: [ + GuidelineExtData( + source: null, + guidelineName: null, + guidelineUrl: null, + implications: { + null: null, + }, + recommendation: null, + comments: null, + ), + ], + annotations: GuidelineAnnotations( + implication: null, + recommendation: null, + warningLevel: WarningLevel.null, + ), +); \ No newline at end of file diff --git a/app/integration_test/fixtures/guidelines/pazopanib_hlab5701_positive_ugt1a1_poor_guideline.dart b/app/integration_test/fixtures/guidelines/pazopanib_hlab5701_positive_ugt1a1_poor_guideline.dart new file mode 100644 index 00000000..6e520ab4 --- /dev/null +++ b/app/integration_test/fixtures/guidelines/pazopanib_hlab5701_positive_ugt1a1_poor_guideline.dart @@ -0,0 +1,29 @@ +import 'package:app/common/models/drug/guideline.dart'; +import 'package:app/common/models/drug/warning_level.dart'; + +final pazopanibHlab5701PositiveUgt1a1PoorGuideline = Guideline( + id: '6686a865826414ec5b05c436', + version: 1, + lookupkey: { + 'HLA-B': ['*57:01 positive'], + 'UGT1A1': ['Poor Metabolizer'], + }, + externalData: [ + GuidelineExtData( + source: 'FDA', + guidelineName: 'Table of Pharmacogenetic Associations (Section 2)', + guidelineUrl: 'https://www.fda.gov/medical-devices/precision-medicine/table-pharmacogenetic-associations#section2', + implications: { + 'HLA-B': 'May result in higher adverse reaction risk (liver enzyme elevations). Monitor liver function tests regardless of genotype.', + 'UGT1A1': 'Results in higher adverse reaction risk (hyperbilirubinemia).', + }, + recommendation: 'Might be included in implication text (imported from FDA, source only states one text per guideline)', + comments: null, + ), + ], + annotations: GuidelineAnnotations( + implication: 'You have an increased risk for side effects. (Test case 1)', + recommendation: 'You can still use pazopanib at standard dose. Consult your pharmacist or doctor for more information. (Test case 1)', + warningLevel: WarningLevel.yellow, + ), +); \ No newline at end of file diff --git a/app/integration_test/fixtures/set_user_data.dart b/app/integration_test/fixtures/set_user_data.dart index 49e295a2..a201ee4d 100644 --- a/app/integration_test/fixtures/set_user_data.dart +++ b/app/integration_test/fixtures/set_user_data.dart @@ -12,9 +12,13 @@ class _UserDataConfig { final String allelesTested = 'allelesTested does not matter for test'; } +void setGenotypeResult(GenotypeResult genotypeResult ) { + UserData.instance.genotypeResults = UserData.instance.genotypeResults ?? {}; + UserData.instance.genotypeResults![genotypeResult.key.value] = genotypeResult; +} + void setUserDataForGuideline(Guideline guideline) { UserData.instance.labData = UserData.instance.labData ?? []; - UserData.instance.genotypeResults = UserData.instance.genotypeResults ?? {}; for (final gene in guideline.lookupkey.keys) { final lookupkeys = guideline.lookupkey[gene]!; if (lookupkeys.length != 1) { @@ -46,14 +50,12 @@ void setUserDataForGuideline(Guideline guideline) { allelesTested: userDataConfig.allelesTested, ), ); - UserData.instance.genotypeResults![ - GenotypeKey(userDataConfig.gene, userDataConfig.variant).value - ] = GenotypeResult( + setGenotypeResult(GenotypeResult( gene: userDataConfig.gene, phenotype: userDataConfig.phenotype, variant: userDataConfig.variant, allelesTested: userDataConfig.variant, lookupkey: userDataConfig.lookupkey, - ); + )); } } diff --git a/app/integration_test/report_test.dart b/app/integration_test/report_test.dart new file mode 100644 index 00000000..a1da179d --- /dev/null +++ b/app/integration_test/report_test.dart @@ -0,0 +1,92 @@ +import 'package:app/common/module.dart'; +import 'package:app/report/module.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:provider/provider.dart'; + +import 'fixtures/guidelines/aripiprazole_cyp2d6_poor.dart'; +import 'fixtures/guidelines/pazopanib_hlab5701_positive_ugt1a1_poor_guideline.dart'; +import 'fixtures/set_user_data.dart'; + +void main() { + final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.onlyPumps; + + setUp(() { + UserData.instance.labData = null; + UserData.instance.genotypeResults = null; + }); + + Future loadReportPage(WidgetTester tester) async { + await tester.pumpWidget( + ChangeNotifierProvider( + create: (context) => ActiveDrugs(), + child: MaterialApp( + home: Scaffold( + body: Builder( + builder: (context) { + return ReportPage(); + }, + ), + ), + localizationsDelegates: [ + AppLocalizations.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: [Locale('en', '')], + ), + ), + ); + } + + Future testReportContent( + WidgetTester tester, { + required List expectedGuidelines, + required List missingResults, + }) async { + expectedGuidelines.forEach(setUserDataForGuideline); + missingResults.forEach(setGenotypeResult); + await loadReportPage(tester); + final expectedGenes = [ + ...expectedGuidelines.flatMap( + (guideline) => guideline.lookupkey.keys + ), + ...missingResults.map((genotypeResult) => genotypeResult.gene), + ]; + expect( + find.byType(GeneCard, skipOffstage: false), + findsNWidgets(expectedGenes.length), + ); + for (final gene in expectedGenes.toSet()) { + final expectedGeneOccurrences = + expectedGenes.count((expectedGene) => expectedGene == gene); + expect( + find.textContaining(gene, skipOffstage: false), + findsNWidgets(expectedGeneOccurrences), + ); + } + } + + group('integration test for the report page', () { + testWidgets( + 'tests that genes for drugs with guidelines are shown', + (tester) async { + final expectedGuidelines = [ + aripiprazoleCyp2d6PoorGuideline, + pazopanibHlab5701PositiveUgt1a1PoorGuideline, + ]; + final missingResults = [ + GenotypeResult.missingResult('HLA-B', variant: '*15:02'), + ]; + await testReportContent( + tester, + expectedGuidelines: expectedGuidelines, + missingResults: missingResults, + ); + }, + ); + }); +} diff --git a/pharme.code-workspace b/pharme.code-workspace index 2c8ec0d2..4b81557b 100644 --- a/pharme.code-workspace +++ b/pharme.code-workspace @@ -35,6 +35,7 @@ "Abilify", "abiraterone", "anni", + "aripiprazole", "atorvastatin", "Backupper", "bupropion", @@ -59,7 +60,9 @@ "haplotype", "haplotypes", "Hasso", + "Hlab", "horiz", + "hyperbilirubinemia", "Ibutab", "ilike", "inhibitable", @@ -83,6 +86,8 @@ "omeprazole", "pantoprazole", "paroxetine", + "pazopanib", + "Pharmacogenetic", "pharmacogenetics", "Pharmacogenetics", "pharmacogenomic",