2016-02-14 02:29:53 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe MetadataController do
|
2018-06-14 11:13:28 +08:00
|
|
|
describe 'manifest.webmanifest' do
|
2016-02-14 02:29:53 +08:00
|
|
|
it 'returns the right output' do
|
|
|
|
title = 'MyApp'
|
|
|
|
SiteSetting.title = title
|
2017-11-03 13:19:31 +08:00
|
|
|
SiteSetting.large_icon_url = "http://big.square/png"
|
|
|
|
|
2018-06-14 11:13:28 +08:00
|
|
|
get "/manifest.webmanifest"
|
2018-06-07 13:08:28 +08:00
|
|
|
expect(response.status).to eq(200)
|
2018-06-14 11:13:28 +08:00
|
|
|
expect(response.content_type).to eq('application/manifest+json')
|
2017-11-03 13:19:31 +08:00
|
|
|
manifest = JSON.parse(response.body)
|
|
|
|
|
|
|
|
expect(manifest["name"]).to eq(title)
|
|
|
|
expect(manifest["icons"].first["src"]).to eq("http://big.square/png")
|
2016-02-14 02:29:53 +08:00
|
|
|
end
|
2018-05-18 03:10:35 +08:00
|
|
|
|
|
|
|
it 'can guess mime types' do
|
2018-05-18 05:43:22 +08:00
|
|
|
SiteSetting.large_icon_url = "http://big.square/ico.jpg"
|
2018-06-14 11:13:28 +08:00
|
|
|
get "/manifest.webmanifest"
|
2018-06-07 13:08:28 +08:00
|
|
|
expect(response.status).to eq(200)
|
2018-05-18 03:10:35 +08:00
|
|
|
manifest = JSON.parse(response.body)
|
2018-05-18 05:43:22 +08:00
|
|
|
expect(manifest["icons"].first["type"]).to eq("image/jpeg")
|
2018-05-18 03:10:35 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'defaults to png' do
|
|
|
|
SiteSetting.large_icon_url = "http://big.square/noidea.bogus"
|
2018-06-14 11:13:28 +08:00
|
|
|
get "/manifest.webmanifest"
|
2018-06-07 13:08:28 +08:00
|
|
|
expect(response.status).to eq(200)
|
2018-05-18 03:10:35 +08:00
|
|
|
manifest = JSON.parse(response.body)
|
|
|
|
expect(manifest["icons"].first["type"]).to eq("image/png")
|
|
|
|
end
|
2016-02-14 02:29:53 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'opensearch.xml' do
|
|
|
|
it 'returns the right output' do
|
|
|
|
title = 'MyApp'
|
|
|
|
favicon_path = '/uploads/something/23432.png'
|
|
|
|
SiteSetting.title = title
|
|
|
|
SiteSetting.favicon_url = favicon_path
|
2018-06-07 13:08:28 +08:00
|
|
|
get "/opensearch.xml"
|
|
|
|
expect(response.status).to eq(200)
|
2016-02-14 02:29:53 +08:00
|
|
|
expect(response.body).to include(title)
|
|
|
|
expect(response.body).to include("/search?q={searchTerms}")
|
|
|
|
expect(response.body).to include('image/png')
|
|
|
|
expect(response.body).to include(favicon_path)
|
|
|
|
expect(response.content_type).to eq('application/xml')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|