diff --git a/app/integration_test/drugs_test.dart b/app/integration_test/drugs_test.dart index e8caa276..37f7bf7d 100644 --- a/app/integration_test/drugs_test.dart +++ b/app/integration_test/drugs_test.dart @@ -80,12 +80,32 @@ void main() { UserData.instance.activeDrugNames = ['Ibuprofen']; group('integration test for the drugs page', () { + testWidgets('test loading', (tester) async { + when(() => mockDrugsCubit.state).thenReturn(DrugState.loading()); + await tester.pumpWidget( + ChangeNotifierProvider( + create: (context) => ActiveDrugs(), + child: MaterialApp( + home: DrugPage(testDrug, cubit: mockDrugsCubit), + localizationsDelegates: [ + AppLocalizations.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: [Locale('en', '')], + ), + ), + ); + final activitySelection = tester.firstWidget( + find.byType(Switch) + ) as Switch; + expect(activitySelection.onChanged, isNull); + }); + testWidgets('test loaded page', (tester) async { when(() => mockDrugsCubit.state) .thenReturn(DrugState.loaded()); - - late BuildContext context; - await tester.pumpWidget( ChangeNotifierProvider( create: (context) => ActiveDrugs(), @@ -107,7 +127,6 @@ void main() { ), ), ); - expect(find.text(testDrug.name.capitalize()), findsOneWidget); expect( find.textContaining( @@ -133,29 +152,22 @@ void main() { findsOneWidget, ); expect(find.byType(Disclaimer), findsOneWidget); - - // test the right color of the card - // ignore: omit_local_variable_types - final RoundedCard card = tester.firstWidget( + final card = tester.firstWidget( find.byKey( ValueKey('annotationCard'), ), - ); + ) as RoundedCard; expect( card.color, testDrug.guidelines.first.annotations.warningLevel.color, ); - - // test that drug activity can be set final activitySelection = tester.firstWidget( find.byType(Switch) ) as Switch; expect(activitySelection.onChanged, isNotNull); - - // test tooltips - context = tester.element(find.byType(Tooltip).first); + final context = tester.element(find.byType(Tooltip).first); expect( - find.byTooltip(context.l10n.drugs_page_tooltip_guideline( + find.byTooltip(context.l10n.drugs_page_tooltip_guidelines_present( testDrug.guidelines.first.externalData.first.source )), findsOneWidget, @@ -165,7 +177,6 @@ void main() { testWidgets('test loaded page without guidelines', (tester) async { when(() => mockDrugsCubit.state).thenReturn( DrugState.loaded()); - await tester.pumpWidget( ChangeNotifierProvider( create: (context) => ActiveDrugs(), @@ -190,33 +201,16 @@ void main() { ), ), ); - expect(find.text(testDrugWithoutGuidelines.name), findsOneWidget); - }); - - testWidgets('test loading', (tester) async { - when(() => mockDrugsCubit.state).thenReturn(DrugState.loading()); - - await tester.pumpWidget( - ChangeNotifierProvider( - create: (context) => ActiveDrugs(), - child: MaterialApp( - home: DrugPage(testDrug, cubit: mockDrugsCubit), - localizationsDelegates: [ - AppLocalizations.delegate, - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - supportedLocales: [Locale('en', '')], - ), - ), + final context = tester.element(find.byType(Scaffold).first); + expect( + find.text(context.l10n.drugs_page_no_guidelines_text), + findsOneWidget, + ); + expect( + find.byTooltip(context.l10n.drugs_page_tooltip_guidelines_missing), + findsOneWidget, ); - - final activitySelection = tester.firstWidget( - find.byType(Switch) - ) as Switch; - expect(activitySelection.onChanged, isNull); }); }); } diff --git a/app/lib/common/utilities/pdf_utils.dart b/app/lib/common/utilities/pdf_utils.dart index b3a43d9d..e40d24b8 100644 --- a/app/lib/common/utilities/pdf_utils.dart +++ b/app/lib/common/utilities/pdf_utils.dart @@ -230,12 +230,10 @@ List _buildUserPart( 'green': '✅', null: '❔', }; - final implication = drug.userGuideline?.annotations.implication ?? - buildContext.l10n.drugs_page_no_guidelines_for_phenotype_implication( - drug.name - ); - final recommendation = drug.userGuideline?.annotations.recommendation ?? - buildContext.l10n.drugs_page_no_guidelines_for_phenotype_recommendation; + final userGuidelineText = drug.userGuideline != null + ? '${drug.userGuideline?.annotations.implication} ' + '${drug.userGuideline?.annotations.recommendation}' + : buildContext.l10n.drugs_page_no_guidelines_text; return [ _buildSubheading(buildContext.l10n.pdf_heading_user_data), _buildTextBlockSpacer(), @@ -270,7 +268,7 @@ List _buildUserPart( _PdfSegment( child: _PdfDescription( title: buildContext.l10n.pdf_user_guideline, - text: '$implication $recommendation', + text: userGuidelineText, icon: warningLevelIcons[drug.warningLevel.name], emojiFont: emoji, ), diff --git a/app/lib/drug/widgets/annotation_cards/guideline.dart b/app/lib/drug/widgets/annotation_cards/guideline.dart index 357cf758..96a5342b 100644 --- a/app/lib/drug/widgets/annotation_cards/guideline.dart +++ b/app/lib/drug/widgets/annotation_cards/guideline.dart @@ -41,12 +41,8 @@ class GuidelineAnnotationCard extends StatelessWidget { } Widget _buildCard(BuildContext context) { - final implicationText = drug.userGuideline?.annotations.implication ?? - context.l10n.drugs_page_no_guidelines_for_phenotype_implication( - drug.name - ); - final recommendationText = drug.userGuideline?.annotations.recommendation ?? - context.l10n.drugs_page_no_guidelines_for_phenotype_recommendation; + final implicationText = drug.userGuideline?.annotations.implication; + final recommendationText = drug.userGuideline?.annotations.recommendation; return RoundedCard( key: Key('annotationCard'), radius: PharMeTheme.innerCardRadius, @@ -76,46 +72,36 @@ class GuidelineAnnotationCard extends StatelessWidget { ), SizedBox(height: PharMeTheme.smallToMediumSpace), Text.rich( - TextSpan(text: implicationText), - ), - SizedBox(height: PharMeTheme.smallToMediumSpace), - Text.rich( - TextSpan(children: [ - TextSpan( - text: context.l10n.drugs_page_recommendation_description, - style: TextStyle(fontWeight: FontWeight.bold), - ), - TextSpan(text: recommendationText), - ]), + TextSpan( + text: + implicationText ?? context.l10n.drugs_page_no_guidelines_text, + ), ), - ...[ + if (recommendationText != null) ...[ SizedBox(height: PharMeTheme.smallToMediumSpace), - Disclaimer(userGuideline: drug.userGuideline), + Text.rich( + TextSpan(children: [ + TextSpan( + text: context.l10n.drugs_page_recommendation_description, + style: TextStyle(fontWeight: FontWeight.bold), + ), + TextSpan(text: recommendationText), + ]), + ), ], + SizedBox(height: PharMeTheme.smallToMediumSpace), + Disclaimer(userGuideline: drug.userGuideline), ] ) ); } String _buildGuidelineTooltipText(BuildContext context) { - return drug.userGuideline != null - // Case 1: a guideline is present - ? context.l10n.drugs_page_tooltip_guideline( - drug.userGuideline!.externalData.first.source + return drug.userOrFirstGuideline != null + ? context.l10n.drugs_page_tooltip_guidelines_present( + drug.userOrFirstGuideline!.externalData.first.source ) - : drug.userOrFirstGuideline != null - // Case 2: a guideline for the drug is present but not for the genotype - ? drug.guidelineGenotypes.all(UserData.instance.genotypeResults!.isMissing) - // Case 2.1: all genes are not tested - ? context.l10n.drugs_page_tooltip_missing_guideline_not_tested - // Case 2.2: at least some genes tested - : context.l10n.drugs_page_tooltip_missing_guideline_for_drug_or_genotype( - context.l10n.drugs_page_tooltip_missing_genotype - ) - // Case 3: the drug has no guidelines - : context.l10n.drugs_page_tooltip_missing_guideline_for_drug_or_genotype( - context.l10n.drugs_page_tooltip_missing_drug - ); + : context.l10n.drugs_page_tooltip_guidelines_missing; } List _buildHeader(BuildContext context) { diff --git a/app/lib/l10n/app_en.arb b/app/lib/l10n/app_en.arb index e6c8c266..bcbea058 100644 --- a/app/lib/l10n/app_en.arb +++ b/app/lib/l10n/app_en.arb @@ -126,16 +126,7 @@ "drugs_page_active_warn_header": "Are you sure you want to change the medication usage status?", "drugs_page_active_warn": "This can interact with your results for other medications.", "drugs_page_header_guideline": "DNA-based clinical guideline", - "drugs_page_no_guidelines_for_phenotype_implication": "More information is needed to comment on your DNA's influence on {drugName}.", - "@drugs_page_no_guidelines_for_phenotype_implication": { - "placeholders": { - "drugName": { - "type": "String", - "example": "bupropion" - } - } - }, - "drugs_page_no_guidelines_for_phenotype_recommendation": "Clinical dosing may apply; no pharmacogenomic recommendation can be made at this time. Consult your pharmacist or doctor for more information.", + "drugs_page_no_guidelines_text": "No pharmacogenomic recommendation can be made at this time. Consult your pharmacist or doctor for more information.", "drugs_page_sources_description": "Tap here to review the corresponding guideline published by {source}", "@drugs_page_sources_description": { "placeholders": { @@ -145,7 +136,7 @@ } } }, - "drugs_page_tooltip_guideline": "{source} guidelines are used to inform the content on this page. These guidelines provide recommendations on which drugs to use based on your DNA.", + "drugs_page_tooltip_guidelines_present": "{source} guidelines are used to inform the content on this page. These guidelines provide recommendations on which drugs to use based on your DNA.", "@drugs_page_tooltip_guideline": { "placeholders": { "source": { @@ -154,18 +145,7 @@ } } }, - "drugs_page_tooltip_missing_drug": "this medication", - "drugs_page_tooltip_missing_genotype": "your genotype", - "drugs_page_tooltip_missing_guideline_for_drug_or_genotype": "Guidelines provide recommendations on which medications to use based on your DNA. However, no guideline is present for {drugOrGenotype} (yet).", - "@drugs_page_tooltip_missing_guideline_for_drug_or_genotype": { - "placeholders": { - "drugOrGenotype": { - "type": "String", - "example": "this medication" - } - } - }, - "drugs_page_tooltip_missing_guideline_not_tested": "Guidelines provide recommendations on which medications to use based on your DNA. However, your genetic test result does not include the information needed to make such a recommendation for this medication.", + "drugs_page_tooltip_guidelines_missing": "Guidelines provide recommendations on which medications to use based on your DNA. However, no guideline is present for this medication (yet).", "drugs_page_recommendation_description": "What to do: ", "report_content_explanation": "This is your PGx test report. Tap on a gene name for more details on your results and a list of implicated medications.",