CEC-749 Generate cert UI (#141)
* Add Create Certificate page * Tests * Update permission check * Use Azure
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`DownloadFileLink Render 1`] = `
|
||||
<div>
|
||||
<a
|
||||
download="test.txt"
|
||||
>
|
||||
test.txt
|
||||
</a>
|
||||
</div>
|
||||
`;
|
||||
32
src/components/Controls/DownloadFileLink/index.jsx
Normal file
32
src/components/Controls/DownloadFileLink/index.jsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
const DownloadFileLink = ({ data, filename, mimetype }) => {
|
||||
const [link, setLink] = useState("");
|
||||
|
||||
const releaseLink = () => {
|
||||
if (link === "") return;
|
||||
URL.revokeObjectURL(link);
|
||||
};
|
||||
|
||||
const makeFile = () => {
|
||||
const file = new Blob([data], { type: mimetype ?? "text/plain" });
|
||||
|
||||
releaseLink();
|
||||
setLink(URL.createObjectURL(file));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!data) return;
|
||||
makeFile();
|
||||
return releaseLink;
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [data, filename, mimetype]);
|
||||
|
||||
return (
|
||||
<a download={filename ?? "file.txt"} href={link}>
|
||||
{filename}
|
||||
</a>
|
||||
);
|
||||
};
|
||||
|
||||
export default DownloadFileLink;
|
||||
21
src/components/Controls/DownloadFileLink/index.test.jsx
Normal file
21
src/components/Controls/DownloadFileLink/index.test.jsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from "react";
|
||||
import { render, waitFor } from "@testing-library/react";
|
||||
|
||||
import DownloadFileLink from ".";
|
||||
|
||||
describe("DownloadFileLink", () => {
|
||||
beforeAll(() => {
|
||||
global.URL.createObjectURL = jest.fn();
|
||||
global.URL.revokeObjectURL = jest.fn();
|
||||
});
|
||||
|
||||
it("Render", async () => {
|
||||
const { container } = render(
|
||||
<DownloadFileLink data={"ABCDEFGHIJK"} filename="test.txt" />
|
||||
);
|
||||
await waitFor(() => {
|
||||
/* render */
|
||||
});
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user