Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MHV-61850: Focus & Offline handling #32176

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const NonVaPrescription = prescription => {
<h3 className="vads-u-font-size--base vads-u-font-family--sans">
Status
</h3>
<div data-testid="rx-status">{validateField(status)}</div>
<p data-testid="rx-status">{validateField(status)}</p>
<div className="no-print">
<va-additional-info
trigger="What does this status mean?"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

const [menuOpen, setMenuOpen] = useState(false);
const [printIndex, setPrintIndex] = useState(0);
const menu = useRef(null);
const containerEl = useRef(null);
const toggleButton = useRef(null);
let toggleMenuButtonClasses =
'toggle-menu-button vads-u-justify-content--space-between';
let menuOptionsClasses = 'menu-options';
Expand All @@ -20,8 +21,14 @@
}

const handleDownload = async format => {
setMenuOpen(!menuOpen);
toggleButton.current.focus();
if (!navigator.onLine) {
setIsError(true);
return;
}

try {
setMenuOpen(!menuOpen);
setIsError(false);
if (format === DOWNLOAD_FORMAT.TXT && onText) {
onText();
Expand All @@ -43,7 +50,11 @@
};

const closeMenu = e => {
if (menu.current && menuOpen && !menu.current.contains(e.target)) {
if (
containerEl.current &&
menuOpen &&
!containerEl.current.contains(e.target)
) {
setMenuOpen(false);
}
};
Expand Down Expand Up @@ -77,23 +88,27 @@
{isLoading && (
<va-loading-indicator
message="Loading..."
setFocus
data-testid="print-download-loading-indicator"
/>
)}
{isSuccess && (
<div
className="vads-u-margin-bottom--3"
data-testid="download-success-banner"
>
<va-alert role="alert" status="success" background-only uswds>
<h2 slot="headline">Download started</h2>
<p className="vads-u-margin--0">
Check your device’s downloads location for your file.
</p>
</va-alert>
</div>
)}
{isSuccess &&
!isError && (
<div
className="vads-u-margin-bottom--3"
data-testid="download-success-banner"
>
<va-alert role="alert" status="success" background-only uswds>
<h2 slot="headline">Download started</h2>
<p className="vads-u-margin--0">
Check your device’s downloads location for your file.
</p>
</va-alert>
</div>
)}
{/* hack to generate va-alert and va-telephone web components in case there is no network at the time of download */}
<va-alert visible="false" uswds>
<va-telephone />
</va-alert>
{isError && (
<div className="vads-u-margin-bottom--3">
<va-alert role="alert" status="error" uswds>
Expand All @@ -119,10 +134,10 @@
className="print-download vads-u-margin-y--2 no-print"
role="none"
onKeyDown={handleUserKeyPress}
ref={menu}
ref={containerEl}
onFocus={handleFocus}
>
<button

Check warning on line 140 in src/applications/mhv-medications/components/shared/PrintDownload.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-medications/components/shared/PrintDownload.jsx:140:9:The <va-button> Web Component should be used instead of the button HTML element.
data-dd-action-name={`${
dataDogActionNames.shared.PRINT_OR_DOWNLOAD_BUTTON
}${list ? pageType.LIST : pageType.DETAILS}`}
Expand All @@ -131,6 +146,7 @@
onClick={() => setMenuOpen(!menuOpen)}
data-testid="print-records-button"
aria-expanded={menuOpen}
ref={toggleButton}
>
<span>Print or download</span>
<va-icon
Expand All @@ -141,7 +157,7 @@
</button>
<ul className={menuOptionsClasses} data-testid="print-download-list">
<li>
<button

Check warning on line 160 in src/applications/mhv-medications/components/shared/PrintDownload.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-medications/components/shared/PrintDownload.jsx:160:13:The <va-button> Web Component should be used instead of the button HTML element.
data-dd-action-name={`${dataDogActionNames.shared.PRINT_THIS}${
list ? 'Page Of The List' : 'Page'
} Option - ${list ? pageType.LIST : pageType.DETAILS}`}
Expand All @@ -156,7 +172,7 @@
</li>
{list && (
<li>
<button

Check warning on line 175 in src/applications/mhv-medications/components/shared/PrintDownload.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-medications/components/shared/PrintDownload.jsx:175:15:The <va-button> Web Component should be used instead of the button HTML element.
data-dd-action-name={
dataDogActionNames.medicationsListPage
.PRINT_ALL_MEDICATIONS_OPTION
Expand All @@ -172,7 +188,7 @@
</li>
)}
<li>
<button

Check warning on line 191 in src/applications/mhv-medications/components/shared/PrintDownload.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-medications/components/shared/PrintDownload.jsx:191:13:The <va-button> Web Component should be used instead of the button HTML element.
data-dd-action-name={`${
dataDogActionNames.shared.DOWNLOAD_A_PDF_OF_THIS
}${list ? 'List' : 'Page'} Option - ${
Expand All @@ -188,7 +204,7 @@
</button>
</li>
<li>
<button

Check warning on line 207 in src/applications/mhv-medications/components/shared/PrintDownload.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-medications/components/shared/PrintDownload.jsx:207:13:The <va-button> Web Component should be used instead of the button HTML element.
type="button"
data-dd-action-name={`${
dataDogActionNames.shared.DOWNLOAD_A_TEXT_FILE_OF_THIS
Expand Down Expand Up @@ -216,6 +232,6 @@
list: PropTypes.any,
onDownload: PropTypes.any,
onPrint: PropTypes.func,
onText: PropTypes.func,

Check warning on line 235 in src/applications/mhv-medications/components/shared/PrintDownload.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-medications/components/shared/PrintDownload.jsx:235:3:Callback prop types must be listed after all other prop types
isLoading: PropTypes.bool,
};
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
focusElement(document.querySelector('h1'));
}
}
}, []);

Check warning on line 155 in src/applications/mhv-medications/containers/Prescriptions.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-medications/containers/Prescriptions.jsx:155:6:React Hook useEffect has missing dependencies: 'isLoading' and 'prescriptionId'. Either include them or remove the dependency array.

useEffect(
() => {
Expand Down Expand Up @@ -426,7 +426,7 @@
updateLoadingStatus(false, '');
}
},
[

Check warning on line 429 in src/applications/mhv-medications/containers/Prescriptions.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-medications/containers/Prescriptions.jsx:429:5:React Hook useEffect has missing dependencies: 'dispatch', 'paginatedPrescriptionsList', 'printRxList', and 'selectedSortOption'. Either include them or remove the dependency array.
allergies,
allergiesError,
prescriptionsFullList,
Expand Down Expand Up @@ -620,7 +620,6 @@
)}
{showFilterContent && (
<>
<BeforeYouDownloadDropdown page={pageType.LIST} />
<PrintDownload
onDownload={handleFullListDownload}
isSuccess={
Expand All @@ -634,6 +633,7 @@
}
list
/>
<BeforeYouDownloadDropdown page={pageType.LIST} />
</>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ describe('Medicaitons Print/Download button component', () => {
});

it('should start downloading PDF on PDF button click', () => {
global.navigator = {
onLine: true,
};
const screen = setup(handleFullListDownload, false, true);
const downloadButton = screen.getByText('Download a PDF of this list');
fireEvent.click(downloadButton);
Expand All @@ -104,6 +107,9 @@ describe('Medicaitons Print/Download button component', () => {
});

it('should start downloading TXT on TXT button click', () => {
global.navigator = {
onLine: true,
};
const screen = setup(handleFullListDownload, false, true);
const downloadButton = screen.getByText(
'Download a text file (.txt) of this list',
Expand All @@ -122,6 +128,9 @@ describe('Medicaitons Print/Download button component', () => {
});

it('should start txt download using custom fn on txt button click', () => {
global.navigator = {
onLine: true,
};
const screen = setup(
undefined,
false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import moment from 'moment-timezone';

Check warning on line 1 in src/applications/mhv-medications/tests/e2e/medications-download-pdf-details-page.cypress.spec.js

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-medications/tests/e2e/medications-download-pdf-details-page.cypress.spec.js:1:1:Use date-fns or Native Date methods instead of moment.js
import MedicationsSite from './med_site/MedicationsSite';
import MedicationsDetailsPage from './pages/MedicationsDetailsPage';
import MedicationsListPage from './pages/MedicationsListPage';
Expand All @@ -21,9 +21,10 @@
detailsPage.clickDownloadMedicationDetailsAsPdfOnDetailsPage();
detailsPage.verifyLoadingSpinnerForDownloadOnDetailsPage();
listPage.verifyDownloadCompleteSuccessMessageBanner();
detailsPage.verifyFocusOnPrintOrDownloadDropdownButtonOnDetailsPage();
site.verifyDownloadedPdfFile(
'VA-medications-list-Safari-Mhvtp',
moment(),

Check warning on line 27 in src/applications/mhv-medications/tests/e2e/medications-download-pdf-details-page.cypress.spec.js

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-medications/tests/e2e/medications-download-pdf-details-page.cypress.spec.js:27:7:Consider using Native new Date().
'',
);
cy.injectAxe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('Medications Download PDF on List Page', () => {
listPage.clickDownloadListAsPDFButtonOnListPage();
listPage.verifyLoadingSpinnerForDownloadOnListPage();
listPage.verifyDownloadCompleteSuccessMessageBanner();
listPage.verifyFocusOnPrintDownloadDropDownButton();
site.verifyDownloadedPdfFile(
'VA-medications-list-Safari-Mhvtp',
moment(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('Medications Details Page Download', () => {
detailsPage.verifyFocusOnPrintOrDownloadDropdownButtonOnDetailsPage();
detailsPage.clickDownloadMedicationsDetailsAsTxtOnDetailsPage();
listPage.verifyDownloadCompleteSuccessMessageBanner();
detailsPage.verifyFocusOnPrintOrDownloadDropdownButtonOnDetailsPage();
listPage.verifyDownloadTextFileHeadless('Safari', 'Mhvtp', 'Mhvtp, Safari');
cy.injectAxe();
cy.axeCheck('main');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('Medications Download Txt on List Page', () => {
listPage.clickDownloadListAsTxtButtonOnListPage();
listPage.verifyLoadingSpinnerForDownloadOnListPage();
listPage.verifyDownloadCompleteSuccessMessageBanner();
listPage.verifyFocusOnPrintDownloadDropDownButton();
listPage.verifyDownloadTextFileHeadless('Safari', 'Mhvtp', 'Mhvtp, Safari');
});
});
Loading