Store manifest props as metadata props

This commit is contained in:
2018-06-29 15:21:28 -07:00
parent 4c0d40bd34
commit b05cad0f3f
4 changed files with 78 additions and 11 deletions

View File

@@ -2,6 +2,40 @@ require "spec_helper"
require "manifique/metadata"
RSpec.describe Manifique::Metadata do
# RSpec.describe "Manifique::MetaData" do
describe "#initialize" do
it "sets the URL when given" do
metadata = Manifique::Metadata.new(url: "https://5apps.com")
expect(metadata.url).to eq("https://5apps.com")
end
end
describe "#manifest=" do
let(:metadata) { Manifique::Metadata.new }
let(:manifest) { JSON.parse(File.read(File.join(__dir__, "..", "fixtures", "mastodon-web-app-manifest.json"))) }
before do
metadata.web_manifest = manifest
end
it "stores the manifest properties as metadata object properties" do
expect(metadata.name).to eq("kosmos.social")
expect(metadata.short_name).to eq("kosmos.social")
expect(metadata.description).to eq("A friendly place for tooting. Run by the Kosmos peeps.")
expect(metadata.theme_color).to eq("#282c37")
expect(metadata.background_color).to eq("#191b22")
expect(metadata.display).to eq("standalone")
expect(metadata.start_url).to eq("/web/timelines/home")
expect(metadata.scope).to eq("https://kosmos.social/")
expect(metadata.share_target).to eq({ "url_template" => "share?title={title}&text={text}&url={url}"})
expect(metadata.icons).to eq([
{
"src"=>"/android-chrome-192x192.png",
"sizes"=>"192x192",
"type"=>"image/png"
}
])
end
end
end

View File

@@ -144,8 +144,29 @@ RSpec.describe Manifique::WebClient do
end
it "stores the web app manifest data" do
expect(subject.manifest).to be_kind_of(Hash)
expect(subject.manifest["name"]).to eq("kosmos.social")
expect(subject.web_manifest).to be_kind_of(Hash)
expect(subject.web_manifest["name"]).to eq("kosmos.social")
end
end
context "no web app manifest present" do
before do
index_html = File.read(File.join(__dir__, "..", "fixtures", "mastodon-no-manifest.html"));
stub_request(:get, "https://kosmos.social/").
to_return(body: index_html, status: 200, headers: {
"Content-Type": "text/html; charset=utf-8"
})
end
subject { web_client.fetch_metadata }
it "returns a metadata object" do
expect(subject).to be_kind_of(Manifique::Metadata)
end
it "parses and stores metadata from HTML" do
pending
# expect(subject.html).to be_kind_of(Hash)
end
end
end