test(stock-orders): tighten download-button assertions + mark icons decorative
Two review follow-ups from the code-quality reviewer:
- Switch the two new PDF-button tests from getByTestId to
getByRole('link', { name }) so visible-label regressions fail.
Add a rel='noopener' assertion so the security contract on
target='_blank' is locked down.
- Add aria-hidden='true' to both <Download> icons. The visible
text already supplies each link's accessible name, but marking
the icon decorative explicitly is more robust to future
library behavior changes.
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
parent
1b2f4a4f52
commit
86534f738a
2 changed files with 6 additions and 8 deletions
|
|
@ -156,20 +156,18 @@ describe("StockOrdersTable — download PDFs", () => {
|
|||
|
||||
it("renders a 'Download Stocktake PDF' link to the Stocktake PDF endpoint", () => {
|
||||
render(<StockOrdersTable rows={[]} currentStatus="" page={1} totalPages={1} />);
|
||||
const link = screen.getByTestId("download-stocktake-pdf");
|
||||
expect(link).toBeInTheDocument();
|
||||
expect(link.tagName).toBe("A");
|
||||
const link = screen.getByRole("link", { name: "Download Stocktake PDF" });
|
||||
expect(link).toHaveAttribute("href", "/api/v1/stock-items/stocktake-pdf");
|
||||
expect(link).toHaveAttribute("target", "_blank");
|
||||
expect(link).toHaveAttribute("rel", "noopener");
|
||||
});
|
||||
|
||||
it("renders a 'Download Orders PDF' link to the Orders PDF endpoint", () => {
|
||||
render(<StockOrdersTable rows={[]} currentStatus="" page={1} totalPages={1} />);
|
||||
const link = screen.getByTestId("download-orders-pdf");
|
||||
expect(link).toBeInTheDocument();
|
||||
expect(link.tagName).toBe("A");
|
||||
const link = screen.getByRole("link", { name: "Download Orders PDF" });
|
||||
expect(link).toHaveAttribute("href", "/api/v1/stock-purchases/list-pdf");
|
||||
expect(link).toHaveAttribute("target", "_blank");
|
||||
expect(link).toHaveAttribute("rel", "noopener");
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ export default function StockOrdersTable({
|
|||
className={cn(buttonVariants({ variant: "outline" }), "gap-1.5")}
|
||||
data-testid="download-stocktake-pdf"
|
||||
>
|
||||
<Download className="h-4 w-4" />
|
||||
<Download aria-hidden="true" className="h-4 w-4" />
|
||||
Download Stocktake PDF
|
||||
</a>
|
||||
<a
|
||||
|
|
@ -169,7 +169,7 @@ export default function StockOrdersTable({
|
|||
className={cn(buttonVariants({ variant: "outline" }), "gap-1.5")}
|
||||
data-testid="download-orders-pdf"
|
||||
>
|
||||
<Download className="h-4 w-4" />
|
||||
<Download aria-hidden="true" className="h-4 w-4" />
|
||||
Download Orders PDF
|
||||
</a>
|
||||
<Button
|
||||
|
|
|
|||
Loading…
Reference in a new issue