cef1bc256d
The `name` field on the `paragraph` type contains a unique ID for the paragraph. It's not guaranteed to be there, on images for example like in the `fd8d091ab8ef` post, but it's there for everything else I can find. This enables deep linking. There's no way to get to the deep link other than opening up the web console. I wanted to link every heading, but you can actually have links in part of a heading so that's not tenable. Maybe a "permalink" link next to every heading?
108 lines
2.8 KiB
Crystal
108 lines
2.8 KiB
Crystal
require "../spec_helper"
|
|
|
|
include Nodes
|
|
|
|
describe EmbeddedConverter do
|
|
context "when the mediaResource has an iframeSrc value" do
|
|
it "returns an EmbeddedContent node" do
|
|
store = GistStore.new
|
|
paragraph = PostResponse::Paragraph.from_json <<-JSON
|
|
{
|
|
"name": "ab12",
|
|
"text": "",
|
|
"type": "IFRAME",
|
|
"href": null,
|
|
"layout": "INSET_CENTER",
|
|
"markups": [],
|
|
"iframe": {
|
|
"mediaResource": {
|
|
"id": "abc123",
|
|
"href": "https://twitter.com/user/status/1",
|
|
"iframeSrc": "https://cdn.embedly.com/widgets/...",
|
|
"iframeWidth": 500,
|
|
"iframeHeight": 281
|
|
}
|
|
},
|
|
"metadata": null
|
|
}
|
|
JSON
|
|
|
|
result = EmbeddedConverter.convert(paragraph, store)
|
|
|
|
result.should eq(
|
|
EmbeddedContent.new(
|
|
src: "https://cdn.embedly.com/widgets/...",
|
|
originalWidth: 500,
|
|
originalHeight: 281,
|
|
)
|
|
)
|
|
end
|
|
end
|
|
|
|
context "when the mediaResource has a blank iframeSrc value" do
|
|
context "and the href is unknown" do
|
|
it "returns an EmbeddedLink node" do
|
|
store = GistStore.new
|
|
paragraph = PostResponse::Paragraph.from_json <<-JSON
|
|
{
|
|
"name": "ab12",
|
|
"text": "",
|
|
"type": "IFRAME",
|
|
"href": null,
|
|
"layout": "INSET_CENTER",
|
|
"markups": [],
|
|
"iframe": {
|
|
"mediaResource": {
|
|
"id": "abc123",
|
|
"href": "https://example.com",
|
|
"iframeSrc": "",
|
|
"iframeWidth": 0,
|
|
"iframeHeight": 0
|
|
}
|
|
},
|
|
"metadata": null
|
|
}
|
|
JSON
|
|
|
|
result = EmbeddedConverter.convert(paragraph, store)
|
|
|
|
result.should eq(EmbeddedLink.new(href: "https://example.com"))
|
|
end
|
|
end
|
|
|
|
context "and the href is gist.github.com" do
|
|
it "returns an GithubGist node" do
|
|
store = GistStore.new
|
|
paragraph = PostResponse::Paragraph.from_json <<-JSON
|
|
{
|
|
"name": "ab12",
|
|
"text": "",
|
|
"type": "IFRAME",
|
|
"href": null,
|
|
"layout": "INSET_CENTER",
|
|
"markups": [],
|
|
"iframe": {
|
|
"mediaResource": {
|
|
"id": "abc123",
|
|
"href": "https://gist.github.com/user/someid",
|
|
"iframeSrc": "",
|
|
"iframeWidth": 0,
|
|
"iframeHeight": 0
|
|
}
|
|
},
|
|
"metadata": null
|
|
}
|
|
JSON
|
|
|
|
result = EmbeddedConverter.convert(paragraph, store)
|
|
|
|
result.should eq(
|
|
GithubGist.new(
|
|
href: "https://gist.github.com/user/someid",
|
|
gist_store: store
|
|
)
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|