-
Notifications
You must be signed in to change notification settings - Fork 0
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
102 additions
and
20 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
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,79 @@ | ||
import { | ||
DamFileDownloadLinkBlockData, | ||
EmailLinkBlockData, | ||
ExternalLinkBlockData, | ||
InternalLinkBlockData, | ||
PhoneLinkBlockData, | ||
} from "@src/blocks.generated"; | ||
|
||
import { isValidLink } from "../isValidLink"; | ||
|
||
describe("isValidLink", () => { | ||
it("should return true for valid internal link", () => { | ||
const blockProps: InternalLinkBlockData = { targetPage: { id: "", name: "", path: "", documentType: "" } }; | ||
const link = { block: { type: "internal", props: blockProps }, attachedBlocks: [] }; | ||
|
||
expect(isValidLink(link)).toBe(true); | ||
}); | ||
|
||
it("should return false for invalid internal link", () => { | ||
const link = { block: { type: "internal", props: {} }, attachedBlocks: [] }; | ||
|
||
expect(isValidLink(link)).toBe(false); | ||
}); | ||
|
||
it("should return true for valid external link", () => { | ||
const blockProps: ExternalLinkBlockData = { targetUrl: "http://example.com", openInNewWindow: false }; | ||
const link = { | ||
block: { type: "external", props: blockProps }, | ||
attachedBlocks: [], | ||
}; | ||
|
||
expect(isValidLink(link)).toBe(true); | ||
}); | ||
|
||
it("should return false for invalid external link", () => { | ||
const link = { block: { type: "external", props: {} }, attachedBlocks: [] }; | ||
|
||
expect(isValidLink(link)).toBe(false); | ||
}); | ||
|
||
it("should return true for valid damFileDownload link", () => { | ||
const blockProps: DamFileDownloadLinkBlockData = { openFileType: "Download", file: { id: "", name: "", fileUrl: "", size: 0 } }; | ||
const link = { block: { type: "damFileDownload", props: blockProps }, attachedBlocks: [] }; | ||
|
||
expect(isValidLink(link)).toBe(true); | ||
}); | ||
|
||
it("should return false for invalid damFileDownload link", () => { | ||
const link = { block: { type: "damFileDownload", props: {} }, attachedBlocks: [] }; | ||
|
||
expect(isValidLink(link)).toBe(false); | ||
}); | ||
|
||
it("should return true for valid email link", () => { | ||
const blockProps: EmailLinkBlockData = { email: "[email protected]" }; | ||
const link = { block: { type: "email", props: blockProps }, attachedBlocks: [] }; | ||
|
||
expect(isValidLink(link)).toBe(true); | ||
}); | ||
|
||
it("should return false for invalid email link", () => { | ||
const link = { block: { type: "email", props: {} }, attachedBlocks: [] }; | ||
|
||
expect(isValidLink(link)).toBe(false); | ||
}); | ||
|
||
it("should return true for valid phone link", () => { | ||
const blockProps: PhoneLinkBlockData = { phone: "1234567890" }; | ||
const link = { block: { type: "phone", props: blockProps }, attachedBlocks: [] }; | ||
|
||
expect(isValidLink(link)).toBe(true); | ||
}); | ||
|
||
it("should return false for invalid phone link", () => { | ||
const link = { block: { type: "phone", props: {} }, attachedBlocks: [] }; | ||
|
||
expect(isValidLink(link)).toBe(false); | ||
}); | ||
}); |
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,19 @@ | ||
import { | ||
DamFileDownloadLinkBlockData, | ||
EmailLinkBlockData, | ||
ExternalLinkBlockData, | ||
InternalLinkBlockData, | ||
LinkBlockData, | ||
PhoneLinkBlockData, | ||
} from "@src/blocks.generated"; | ||
|
||
export const isValidLink = (link: LinkBlockData) => { | ||
return Boolean( | ||
link.block && | ||
((link.block.type === "internal" && (link.block.props as InternalLinkBlockData).targetPage) || | ||
(link.block.type === "external" && (link.block.props as ExternalLinkBlockData).targetUrl) || | ||
(link.block.type === "damFileDownload" && (link.block.props as DamFileDownloadLinkBlockData).file) || | ||
(link.block.type === "email" && (link.block.props as EmailLinkBlockData).email) || | ||
(link.block.type === "phone" && (link.block.props as PhoneLinkBlockData).phone)), | ||
); | ||
}; |