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?
139 lines
2.8 KiB
Crystal
139 lines
2.8 KiB
Crystal
require "../spec_helper"
|
|
|
|
include Nodes
|
|
|
|
describe PageConverter do
|
|
it "sets the page title" do
|
|
title = "Hello, world!"
|
|
paragraph_json = <<-JSON
|
|
[
|
|
{
|
|
"name": "ab12",
|
|
"text": "#{title}",
|
|
"type": "H3",
|
|
"markups": [],
|
|
"iframe": null,
|
|
"layout": null,
|
|
"metadata": null
|
|
}
|
|
]
|
|
JSON
|
|
data_json = default_post_json(title, paragraph_json)
|
|
data = PostResponse::Post.from_json(data_json)
|
|
|
|
page = PageConverter.new.convert(data)
|
|
|
|
page.title.should eq title
|
|
end
|
|
|
|
it "sets the author" do
|
|
post_json = <<-JSON
|
|
{
|
|
"name": "ab12",
|
|
"title": "This is a story",
|
|
"createdAt": 0,
|
|
"creator": {
|
|
"id": "abc123",
|
|
"name": "Author"
|
|
},
|
|
"content": {
|
|
"bodyModel": {
|
|
"paragraphs": []
|
|
}
|
|
}
|
|
}
|
|
JSON
|
|
post = PostResponse::Post.from_json(post_json)
|
|
|
|
page = PageConverter.new.convert(post)
|
|
|
|
page.author.name.should eq "Author"
|
|
page.author.id.should eq "abc123"
|
|
end
|
|
|
|
it "sets the publish date/time" do
|
|
post_json = <<-JSON
|
|
{
|
|
"name": "ab12",
|
|
"title": "This is a story",
|
|
"createdAt": 1000,
|
|
"creator": {
|
|
"id": "abc123",
|
|
"name": "Author"
|
|
},
|
|
"content": {
|
|
"bodyModel": {
|
|
"paragraphs": []
|
|
}
|
|
}
|
|
}
|
|
JSON
|
|
post = PostResponse::Post.from_json(post_json)
|
|
|
|
page = PageConverter.new.convert(post)
|
|
|
|
page.created_at.should eq Time.utc(1970, 1, 1, 0, 0, 1)
|
|
end
|
|
|
|
it "calls converts the remaining paragraph content" do
|
|
title = "Title"
|
|
paragraph_json = <<-JSON
|
|
[
|
|
{
|
|
"name": "ab12",
|
|
"text": "#{title}",
|
|
"type": "H3",
|
|
"markups": [],
|
|
"iframe": null,
|
|
"layout": null,
|
|
"metadata": null
|
|
},
|
|
{
|
|
"name": "ab12",
|
|
"text": "Content",
|
|
"type": "P",
|
|
"markups": [],
|
|
"iframe": null,
|
|
"layout": null,
|
|
"metadata": null
|
|
}
|
|
]
|
|
JSON
|
|
post_json = default_post_json(title, paragraph_json)
|
|
data = PostResponse::Post.from_json(post_json)
|
|
|
|
page = PageConverter.new.convert(data)
|
|
|
|
page.nodes.should eq [
|
|
Paragraph.new([
|
|
Text.new("Content"),
|
|
] of Child),
|
|
]
|
|
end
|
|
end
|
|
|
|
def default_paragraph_json
|
|
"[]"
|
|
end
|
|
|
|
def default_post_json(
|
|
title : String = "This is a story",
|
|
paragraph_json : String = default_paragraph_json
|
|
)
|
|
<<-JSON
|
|
{
|
|
"name": "ab12",
|
|
"title": "#{title}",
|
|
"createdAt": 1628974309758,
|
|
"creator": {
|
|
"id": "abc123",
|
|
"name": "Author"
|
|
},
|
|
"content": {
|
|
"bodyModel": {
|
|
"paragraphs": #{paragraph_json}
|
|
}
|
|
}
|
|
}
|
|
JSON
|
|
end
|