Skip to content

Commit

Permalink
Hide inventory report text when button hidden. (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdilauro authored Aug 27, 2024
1 parent 1e28ffd commit f853860
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
32 changes: 17 additions & 15 deletions src/components/StatsUsageReportsGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,24 @@ const StatsUsageReportsGroup = ({
<StatsGroup heading={heading} description={description}>
<>
{inventoryReportsEnabled && library && (
<Button
callback={(() => setShowReportForm(true)) as any}
content={
<>
Request Report &nbsp;&nbsp;
<i className="fa fa-regular fa-envelope" />
</>
}
title="Request an inventory report."
disabled={showReportForm}
/>
<>
<Button
callback={(() => setShowReportForm(true)) as any}
content={
<>
Request Report &nbsp;&nbsp;
<i className="fa fa-regular fa-envelope" />
</>
}
title="Request an inventory report."
disabled={showReportForm}
/>
<div className="stat-group-description">
These reports provide up-to-date data on both inventory and
holds for library at the time of the request.
</div>
</>
)}
<div className="stat-group-description">
These reports provide up-to-date data on both inventory and
holds for library at the time of the request.
</div>
</>
</StatsGroup>
</li>
Expand Down
30 changes: 22 additions & 8 deletions tests/jest/components/Stats.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,14 @@ describe("Dashboard Statistics", () => {
roles,
quicksightPagePath: fakeQuickSightHref,
};
const { container, getByRole, queryByRole } = renderWithProviders(
<Stats library={sampleLibraryKey} />,
{
contextProviderProps,
}
);
const {
container,
getByRole,
queryByRole,
queryByText,
} = renderWithProviders(<Stats library={sampleLibraryKey} />, {
contextProviderProps,
});

// We should always render a Usage reports group when a library is specified.
getByRole("heading", {
Expand All @@ -404,11 +406,23 @@ describe("Dashboard Statistics", () => {
const usageReportLink = getByRole("link", { name: /View Usage/i });
expect(usageReportLink).toHaveAttribute("href", fakeQuickSightHref);

const result = queryByRole("button", { name: /Request Report/i });
const requestButton = queryByRole("button", {
name: /Request Report/i,
});
const blurb = queryByText(
/These reports provide up-to-date data on both inventory and holds/i
);

// The inventory report blurb should be visible only when the button is.
if (requestButton) {
expect(blurb).not.toBeNull();
} else {
expect(blurb).toBeNull();
}

// Clean up the container after each render.
document.body.removeChild(container);
return result;
return requestButton;
};

// If the feature flag is set, the button should be visible only to sysadmins.
Expand Down

0 comments on commit f853860

Please sign in to comment.