Skip to content

Commit

Permalink
test(app): add report test
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Sep 23, 2024
1 parent 66b057d commit e0ce898
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
),
);
27 changes: 27 additions & 0 deletions app/integration_test/fixtures/guidelines/guideline.dart.template
Original file line number Diff line number Diff line change
@@ -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,
),
);
Original file line number Diff line number Diff line change
@@ -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,
),
);
12 changes: 7 additions & 5 deletions app/integration_test/fixtures/set_user_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
);
));
}
}
92 changes: 92 additions & 0 deletions app/integration_test/report_test.dart
Original file line number Diff line number Diff line change
@@ -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<void> 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<void> testReportContent(
WidgetTester tester, {
required List<Guideline> expectedGuidelines,
required List<GenotypeResult> 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,
);
},
);
});
}
5 changes: 5 additions & 0 deletions pharme.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"Abilify",
"abiraterone",
"anni",
"aripiprazole",
"atorvastatin",
"Backupper",
"bupropion",
Expand All @@ -59,7 +60,9 @@
"haplotype",
"haplotypes",
"Hasso",
"Hlab",
"horiz",
"hyperbilirubinemia",
"Ibutab",
"ilike",
"inhibitable",
Expand All @@ -83,6 +86,8 @@
"omeprazole",
"pantoprazole",
"paroxetine",
"pazopanib",
"Pharmacogenetic",
"pharmacogenetics",
"Pharmacogenetics",
"pharmacogenomic",
Expand Down

0 comments on commit e0ce898

Please sign in to comment.