From 8a32dcfbc72c91def1d29896ece7bf50cfc63f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Fri, 15 Sep 2023 20:46:47 +0200 Subject: [PATCH] Store correct list of available manifest properties --- lib/manifique/metadata.rb | 3 ++- spec/fixtures/mastodon-web-app-manifest.json | 1 - spec/manifique/metadata_spec.rb | 13 ++++++++++--- spec/manifique/web_client_spec.rb | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/manifique/metadata.rb b/lib/manifique/metadata.rb index 97219b5..1063a15 100644 --- a/lib/manifique/metadata.rb +++ b/lib/manifique/metadata.rb @@ -17,7 +17,8 @@ module Manifique [ :name, :short_name, :description, :icons, :theme_color, :background_color, :display, :start_url, :scope, :share_target ].map(&:to_s).each do |prop| - self.send("#{prop}=", manifest[prop]) if manifest[prop] + next unless manifest[prop] + self.send("#{prop}=", manifest[prop]) self.from_web_manifest.add(prop) end end diff --git a/spec/fixtures/mastodon-web-app-manifest.json b/spec/fixtures/mastodon-web-app-manifest.json index 8fa7253..9e9e922 100644 --- a/spec/fixtures/mastodon-web-app-manifest.json +++ b/spec/fixtures/mastodon-web-app-manifest.json @@ -9,7 +9,6 @@ "type": "image/png" } ], - "theme_color": "#282c37", "background_color": "#191b22", "display": "standalone", "start_url": "/web/timelines/home", diff --git a/spec/manifique/metadata_spec.rb b/spec/manifique/metadata_spec.rb index 254385f..772627b 100644 --- a/spec/manifique/metadata_spec.rb +++ b/spec/manifique/metadata_spec.rb @@ -4,13 +4,13 @@ require "manifique/metadata" RSpec.describe Manifique::Metadata do describe "#initialize" do - it "sets the URL when given" do + it "sets the URL" do metadata = Manifique::Metadata.new(url: "https://5apps.com") expect(metadata.url).to eq("https://5apps.com") end end - describe "#manifest=" do + describe "#load_from_web_manifest" do let(:metadata) { Manifique::Metadata.new } let(:manifest) { JSON.parse(File.read(File.join(__dir__, "..", "fixtures", "mastodon-web-app-manifest.json"))) } @@ -22,7 +22,6 @@ RSpec.describe Manifique::Metadata 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") @@ -36,6 +35,14 @@ RSpec.describe Manifique::Metadata do } ]) end + + it "stores the available property names in the from_web_manifest accessor" do + expect((metadata.from_web_manifest & [ + "name", "short_name", "description", "icons", "background_color", + "display", "start_url", "scope", "share_target" + ]).length).to eq(9) + expect(metadata.from_web_manifest).not_to include("theme_color") + end end describe "#select_icon" do diff --git a/spec/manifique/web_client_spec.rb b/spec/manifique/web_client_spec.rb index 51b9baf..3c7d7ff 100644 --- a/spec/manifique/web_client_spec.rb +++ b/spec/manifique/web_client_spec.rb @@ -189,7 +189,7 @@ RSpec.describe Manifique::WebClient do end it "knows which properties were loaded from the web app manifest" do - expect(subject.from_web_manifest.length).to eq(10) + expect(subject.from_web_manifest.length).to eq(9) end it "loads iOS icons from HTML" do