generated from Open-Attestation/react-component-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Valid / Invalid urls | ||
// v4 with Svg url with response and multibase | ||
// v4 with Svg data and multibase | ||
// v4 with Svg url with tampered response and no multibase | ||
// v4 with Svg url with bad response and multibase | ||
// v4 with Svg url with tampered response and multibase | ||
// v4 with tampered Svg data | ||
// v2 with Svg url with response and multibase | ||
|
||
// import React from "react"; | ||
import { v4 } from "@govtechsg/open-attestation"; | ||
import { render } from "@testing-library/react"; | ||
import { SvgRenderer } from "./SvgRenderer"; | ||
import fs from "fs"; | ||
// import { UnsupportedRenderer } from "./UnsupportedRenderer"; | ||
|
||
const v4WithSvgUrlAndDigestMultibase = { | ||
// TODO: Update type to v4.OpenAttestationDocument | ||
"@context": [ | ||
"https://www.w3.org/2018/credentials/v1", | ||
"https://schemata.openattestation.com/com/openattestation/4.0/alpha-context.json", | ||
], | ||
issuer: { | ||
id: "did:ethr:0xB26B4941941C51a4885E5B7D3A1B861E54405f90", | ||
type: "OpenAttestationIssuer", | ||
name: "Government Technology Agency of Singapore (GovTech)", | ||
identityProof: { identityProofType: v4.IdentityProofType.DNSDid, identifier: "example.openattestation.com" }, | ||
}, | ||
credentialStatus: { type: "OpenAttestationCredentialStatus", credentialStatusType: v4.CredentialStatusType.None }, | ||
renderMethod: { | ||
id: "http://mockbucket.com/static/svg_test.svg", | ||
type: "SvgRenderingTemplate2023", | ||
name: "SVG Certificate", | ||
digestMultibase: "z2Z98fDGXMKgjxZpWNFBE2c8fRPH5dQ9Zc2Y15vDHLHdm", | ||
url: "https://ignorethisurlthisisjusttopasstheschemacheck.com", | ||
renderMethodType: v4.RenderMethodType.EmbeddedRenderer, | ||
}, | ||
credentialSubject: { | ||
id: "urn:uuid:a013fb9d-bb03-4056-b696-05575eceaf42", | ||
type: ["SvgExample"], | ||
course: { name: "SVG Basics Workshop", fromDate: "01/01/2024", endDate: "16/01/2024" }, | ||
recipient: { name: "TAN CHEN CHEN" }, | ||
}, | ||
}; | ||
|
||
describe("component SvgRenderer with 200 response", () => { | ||
// const mockBlob = jest.fn().mockResolvedValueOnce({ | ||
// arrayBuffer: jest.fn().mockResolvedValueOnce("your array buffer data"), | ||
// }); | ||
|
||
const mockSvg = fs.readFileSync("./src/components/renderer/fixtures/example_cert.svg"); | ||
const mockBlob = jest.fn().mockResolvedValue(new Blob([mockSvg], { type: "image/svg+xml" })); | ||
const mockResponse = { blob: mockBlob }; | ||
global.fetch = jest.fn().mockResolvedValueOnce(mockResponse); | ||
|
||
it("should render correctly", () => { | ||
const svgRef = { | ||
current: null, | ||
}; | ||
|
||
const svgUrl = v4WithSvgUrlAndDigestMultibase.renderMethod.id; | ||
|
||
const { getByText } = render( | ||
<SvgRenderer svgOrUrl={svgUrl} document={v4WithSvgUrlAndDigestMultibase} svgRef={svgRef} /> | ||
); | ||
// const { getByText } = render( | ||
// <UnsupportedRenderer attachment={{ type: "application/epub+zip", data: "", filename: "" }} /> | ||
// ); | ||
// expect(getByText("Rendering of this type of attachment is not supported.")).toBeDefined(); | ||
// expect(getByText("Please check your mime-type: application/epub+zip")).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.